From e40dab9f9895c5457d4a45473007fc87173b7bc9 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Thu, 9 Nov 2017 22:04:40 +0200 Subject: [PATCH] Improve settings menu layout --- include/UserSettingsPage.h | 9 +++++++-- src/UserSettingsPage.cc | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/UserSettingsPage.h b/include/UserSettingsPage.h index 6f6da2c5..d8160cbe 100644 --- a/include/UserSettingsPage.h +++ b/include/UserSettingsPage.h @@ -25,8 +25,9 @@ class Toggle; -constexpr int OptionMargin = 6; -constexpr int LayoutSideMargin = 300; +constexpr int OptionMargin = 6; +constexpr int LayoutTopMargin = 50; +constexpr int LayoutBottomMargin = LayoutTopMargin; class UserSettings { @@ -63,6 +64,7 @@ public: protected: void showEvent(QShowEvent *event) override; + void resizeEvent(QResizeEvent *event) override; signals: void moveBack(); @@ -71,6 +73,7 @@ signals: private: // Layouts QVBoxLayout *topLayout_; + QVBoxLayout *mainLayout_; QHBoxLayout *topBarLayout_; // Shared settings object. @@ -78,4 +81,6 @@ private: Toggle *trayToggle_; QComboBox *themeCombo_; + + int sideMargin_ = 0; }; diff --git a/src/UserSettingsPage.cc b/src/UserSettingsPage.cc index fb5f983c..10754cfd 100644 --- a/src/UserSettingsPage.cc +++ b/src/UserSettingsPage.cc @@ -107,10 +107,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge general_->setFont(QFont("Open Sans Bold", 17)); general_->setStyleSheet("color: #5d6565"); - auto mainLayout_ = new QVBoxLayout; + mainLayout_ = new QVBoxLayout; mainLayout_->setSpacing(7); mainLayout_->setContentsMargins( - LayoutSideMargin, LayoutSideMargin / 6, LayoutSideMargin, LayoutSideMargin / 6); + sideMargin_, LayoutTopMargin, sideMargin_, LayoutBottomMargin); mainLayout_->addWidget(general_, 1, Qt::AlignLeft | Qt::AlignVCenter); mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addLayout(trayOptionLayout_); @@ -143,3 +143,13 @@ UserSettingsPage::showEvent(QShowEvent *) themeCombo_->setCurrentIndex((settings_->theme() == "default" ? 0 : 1)); trayToggle_->setState(!settings_->isTrayEnabled()); // Treats true as "off" } + +void +UserSettingsPage::resizeEvent(QResizeEvent *event) +{ + sideMargin_ = width() * 0.2; + mainLayout_->setContentsMargins( + sideMargin_, LayoutTopMargin, sideMargin_, LayoutBottomMargin); + + QWidget::resizeEvent(event); +}