Skip to content

Commit

Permalink
set up tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
samamou committed Sep 25, 2024
1 parent 5bf3ed6 commit deed24c
Showing 1 changed file with 68 additions and 10 deletions.
78 changes: 68 additions & 10 deletions src/app/StartScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <QApplication>
#include <QDesktopServices>
#include <QIcon>
#include <QKeyEvent>
#include <QLabel>
#include <QNetworkAccessManager>
Expand All @@ -15,7 +16,10 @@
#include <QPixmap>
#include <QPointer>
#include <QSettings>
#include <QSplitter>
#include <QTabWidget>
#include <QTextLayout>
#include <QVBoxLayout>

#include <score_git_info.hpp>

Expand Down Expand Up @@ -265,6 +269,7 @@ class StartScreen : public QWidget
void exitApp() W_SIGNAL(exitApp)

void addLoadCrashedSession();
void setupTabs();

protected:
void paintEvent(QPaintEvent* event) override;
Expand All @@ -273,6 +278,7 @@ class StartScreen : public QWidget
private:
QPixmap m_background;
InteractiveLabel* m_crashLabel{};
QTabWidget* tabWidget;
};
struct StartScreenLink
{
Expand All @@ -293,26 +299,46 @@ struct StartScreenLink
StartScreen::StartScreen(const QPointer<QRecentFilesMenu>& recentFiles, QWidget* parent)
: QWidget(parent)
{
QWidget* headerWidget = new QWidget(this);
QHBoxLayout* headerLayout = new QHBoxLayout(headerWidget);
headerLayout->setContentsMargins(10, 10, 10, 0);

QLabel* logoLabel = new QLabel(headerWidget);

QPixmap placeholderPixmap(300, 100); //TODO: replace placeholder with logo
placeholderPixmap.fill(Qt::gray);
logoLabel->setPixmap(placeholderPixmap);
logoLabel->setFixedSize(placeholderPixmap.size());

headerLayout->addWidget(logoLabel, 0, Qt::AlignLeft);

tabWidget = new QTabWidget(this);

setupTabs();

QVBoxLayout* mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(headerWidget);
mainLayout->addWidget(tabWidget);
setLayout(mainLayout);

// Workaround until https://bugreports.qt.io/browse/QTBUG-103225 is fixed
#if defined(__APPLE__)
static constexpr double font_factor = 96. / 72.;
#else
static constexpr double font_factor = 1.;
#endif
QFont f("Ubuntu", 14 * font_factor, QFont::Light);
QFont f("Ubuntu", 14 * font_factor, QFont::Light);
f.setHintingPreference(QFont::HintingPreference::PreferFullHinting);
f.setStyleStrategy(QFont::PreferAntialias);

QFont titleFont("Montserrat", 14 * font_factor, QFont::DemiBold);
QFont titleFont("Montserrat", 14 * font_factor, QFont::DemiBold);
titleFont.setHintingPreference(QFont::HintingPreference::PreferFullHinting);
titleFont.setStyleStrategy(QFont::PreferAntialias);

this->setEnabled(true);
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); //| Qt::WindowStaysOnTopHint);
setWindowModality(Qt::ApplicationModal);

m_background = score::get_pixmap(":/startscreen/startscreensplash.png");

if(QPainter painter; painter.begin(&m_background))
{
painter.setRenderHint(QPainter::Antialiasing, true);
Expand All @@ -326,7 +352,8 @@ StartScreen::StartScreen(const QPointer<QRecentFilesMenu>& recentFiles, QWidget*
}

// Weird code here is because the window size seems to scale only to integer ratios.
setFixedSize(m_background.size() / std::floor(qApp->devicePixelRatio()));
// setFixedSize(m_background.size() / std::floor(qApp->devicePixelRatio()));
setFixedSize(600, 500);

{
// new version
Expand All @@ -350,10 +377,11 @@ StartScreen::StartScreen(const QPointer<QRecentFilesMenu>& recentFiles, QWidget*
label->move(280, 170);
label->show();
}
}, [] {}};
},
[] {}};
}

float label_x = 300;
float label_x = 50;
float label_y = 215;

{ // recent files
Expand Down Expand Up @@ -404,7 +432,7 @@ StartScreen::StartScreen(const QPointer<QRecentFilesMenu>& recentFiles, QWidget*
m_crashLabel, &score::InteractiveLabel::labelPressed, this,
&score::StartScreen::loadCrashedSession);

label_x = 510;
label_x = 310;
label_y = 215;
{ // Create new
InteractiveLabel* label = new InteractiveLabel{titleFont, qApp->tr("New"), "", this};
Expand Down Expand Up @@ -433,7 +461,8 @@ StartScreen::StartScreen(const QPointer<QRecentFilesMenu>& recentFiles, QWidget*
QSettings settings;
auto library_path = settings.value("Library/RootPath").toString();
InteractiveLabel* label = new InteractiveLabel{
titleFont, qApp->tr("Examples"), "https://github.com/ossia/score-examples", this};
titleFont, qApp->tr("Examples"), "https://github.com/ossia/score-examples",
this};
label->setPixmaps(
score::get_pixmap(":/icons/load_examples_off.png"),
score::get_pixmap(":/icons/load_examples_on.png"));
Expand Down Expand Up @@ -479,6 +508,35 @@ StartScreen::StartScreen(const QPointer<QRecentFilesMenu>& recentFiles, QWidget*
}
}

void StartScreen::setupTabs()
{

QWidget* homeTab = new QWidget;
QVBoxLayout* homeLayout = new QVBoxLayout;
QLabel* homeLabel = new QLabel("Create new score");
homeLayout->addWidget(homeLabel);
homeTab->setLayout(homeLayout);

QWidget* learnTab = new QWidget;
QVBoxLayout* learnLayout = new QVBoxLayout;
QLabel* learnLabel = new QLabel("Browse examples");
learnLayout->addWidget(learnLabel);
learnTab->setLayout(learnLayout);

QWidget* communityTab = new QWidget;
QVBoxLayout* communityLayout = new QVBoxLayout;
QLabel* communityLabel = new QLabel("Get Involved");
communityLayout->addWidget(communityLabel);
communityTab->setLayout(communityLayout);

// Add tabs to the QTabWidget
tabWidget->addTab(homeTab, QIcon(":/icons/home_icon.png"), "Home");
tabWidget->addTab(learnTab, QIcon(":/icons/learn_icon.png"), "Learn");
tabWidget->addTab(communityTab, QIcon(":/icons/community_icon.png"), "Community");

tabWidget->setTabPosition(QTabWidget::West); // Tabs clickable from the left
}

void StartScreen::addLoadCrashedSession()
{
m_crashLabel->show();
Expand All @@ -489,7 +547,7 @@ void StartScreen::addLoadCrashedSession()
void StartScreen::paintEvent(QPaintEvent* event)
{
QPainter painter(this);
painter.drawPixmap(0, 0, m_background);
painter.fillRect(rect(), Qt::black);
}

void StartScreen::keyPressEvent(QKeyEvent* event)
Expand Down

0 comments on commit deed24c

Please sign in to comment.