From 2a75b1760dffc64450cf30919ae7e4ae196f343c Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Thu, 25 Mar 2021 13:33:38 +0300 Subject: [PATCH] UI: Options: Simplify ScrollArea. --- src/ui/form/controls/controlutil.cpp | 25 ++++++++++++++++--------- src/ui/form/controls/controlutil.h | 2 ++ src/ui/form/opt/pages/mainpage.cpp | 25 +++++++++++++------------ src/ui/form/opt/pages/mainpage.h | 14 -------------- src/ui/form/opt/pages/optionspage.cpp | 13 +------------ src/ui/form/opt/pages/optionspage.h | 1 - 6 files changed, 32 insertions(+), 48 deletions(-) diff --git a/src/ui/form/controls/controlutil.cpp b/src/ui/form/controls/controlutil.cpp index 7d5c21cb..c2326f24 100644 --- a/src/ui/form/controls/controlutil.cpp +++ b/src/ui/form/controls/controlutil.cpp @@ -148,15 +148,7 @@ QLayout *ControlUtil::createScrollLayout(QLayout *content, bool isBgTransparent) auto scrollAreaContent = new QWidget(); scrollAreaContent->setLayout(content); - auto scrollArea = new QScrollArea(); - scrollArea->setContentsMargins(0, 0, 0, 0); - scrollArea->setWidgetResizable(true); - scrollArea->setWidget(scrollAreaContent); - - if (isBgTransparent) { - scrollArea->setStyleSheet("QScrollArea { background: transparent; }"); - scrollAreaContent->setStyleSheet(".QWidget { background: transparent; }"); - } + auto scrollArea = wrapToScrollArea(scrollAreaContent, isBgTransparent); auto layout = new QHBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); @@ -165,6 +157,21 @@ QLayout *ControlUtil::createScrollLayout(QLayout *content, bool isBgTransparent) return layout; } +QWidget *ControlUtil::wrapToScrollArea(QWidget *content, bool isBgTransparent) +{ + auto c = new QScrollArea(); + c->setContentsMargins(0, 0, 0, 0); + c->setWidgetResizable(true); + c->setWidget(content); + + if (isBgTransparent) { + c->setStyleSheet("QScrollArea { background: transparent; }"); + content->setAutoFillBackground(false); + } + + return c; +} + QFont ControlUtil::fontDemiBold() { QFont font; diff --git a/src/ui/form/controls/controlutil.h b/src/ui/form/controls/controlutil.h index 1b6cf5bf..1aa574ad 100644 --- a/src/ui/form/controls/controlutil.h +++ b/src/ui/form/controls/controlutil.h @@ -39,7 +39,9 @@ public: static QBoxLayout *createLayoutByWidgets( const QList &widgets, Qt::Orientation o = Qt::Vertical); static QFrame *createSeparator(Qt::Orientation o = Qt::Horizontal); + static QLayout *createScrollLayout(QLayout *content, bool isBgTransparent = true); + static QWidget *wrapToScrollArea(QWidget *content, bool isBgTransparent = true); static QFont fontDemiBold(); diff --git a/src/ui/form/opt/pages/mainpage.cpp b/src/ui/form/opt/pages/mainpage.cpp index b9d34dbf..39b9c135 100644 --- a/src/ui/form/opt/pages/mainpage.cpp +++ b/src/ui/form/opt/pages/mainpage.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -61,19 +62,19 @@ void MainPage::setupTabBar() { m_tabBar = new QTabWidget(); - m_optionsPage = new OptionsPage(ctrl()); - m_addressesPage = new AddressesPage(ctrl()); - m_rulesPage = new RulesPage(ctrl()); - m_applicationsPage = new ApplicationsPage(ctrl()); - m_statisticsPage = new StatisticsPage(ctrl()); - m_schedulePage = new SchedulePage(ctrl()); + auto optionsPage = ControlUtil::wrapToScrollArea(new OptionsPage(ctrl())); + auto addressesPage = new AddressesPage(ctrl()); + auto rulesPage = new RulesPage(ctrl()); + auto applicationsPage = new ApplicationsPage(ctrl()); + auto statisticsPage = new StatisticsPage(ctrl()); + auto schedulePage = new SchedulePage(ctrl()); - m_tabBar->addTab(m_optionsPage, IconCache::icon(":/icons/cog.png"), QString()); - m_tabBar->addTab(m_addressesPage, IconCache::icon(":/icons/map-marker.png"), QString()); - m_tabBar->addTab(m_rulesPage, IconCache::icon(":/icons/task-list.png"), QString()); - m_tabBar->addTab(m_applicationsPage, IconCache::icon(":/icons/window.png"), QString()); - m_tabBar->addTab(m_statisticsPage, IconCache::icon(":/icons/database.png"), QString()); - m_tabBar->addTab(m_schedulePage, IconCache::icon(":/icons/clock.png"), QString()); + m_tabBar->addTab(optionsPage, IconCache::icon(":/icons/cog.png"), QString()); + m_tabBar->addTab(addressesPage, IconCache::icon(":/icons/map-marker.png"), QString()); + m_tabBar->addTab(rulesPage, IconCache::icon(":/icons/task-list.png"), QString()); + m_tabBar->addTab(applicationsPage, IconCache::icon(":/icons/window.png"), QString()); + m_tabBar->addTab(statisticsPage, IconCache::icon(":/icons/database.png"), QString()); + m_tabBar->addTab(schedulePage, IconCache::icon(":/icons/clock.png"), QString()); m_tabBar->setTabVisible(2, false); // TODO: Impl. Network Rules } diff --git a/src/ui/form/opt/pages/mainpage.h b/src/ui/form/opt/pages/mainpage.h index 08900deb..cf6f112f 100644 --- a/src/ui/form/opt/pages/mainpage.h +++ b/src/ui/form/opt/pages/mainpage.h @@ -5,13 +5,6 @@ QT_FORWARD_DECLARE_CLASS(QTabWidget) -class AddressesPage; -class ApplicationsPage; -class OptionsPage; -class RulesPage; -class SchedulePage; -class StatisticsPage; - class MainPage : public BasePage { Q_OBJECT @@ -39,13 +32,6 @@ private: QPushButton *m_btOk = nullptr; QPushButton *m_btApply = nullptr; QPushButton *m_btCancel = nullptr; - - OptionsPage *m_optionsPage = nullptr; - AddressesPage *m_addressesPage = nullptr; - RulesPage *m_rulesPage = nullptr; - ApplicationsPage *m_applicationsPage = nullptr; - StatisticsPage *m_statisticsPage = nullptr; - SchedulePage *m_schedulePage = nullptr; }; #endif // MAINPAGE_H diff --git a/src/ui/form/opt/pages/optionspage.cpp b/src/ui/form/opt/pages/optionspage.cpp index 9234b622..50acf4b3 100644 --- a/src/ui/form/opt/pages/optionspage.cpp +++ b/src/ui/form/opt/pages/optionspage.cpp @@ -102,17 +102,6 @@ void OptionsPage::retranslateDriverMessage() } void OptionsPage::setupUi() -{ - // Main Layout - auto mainLayout = setupMainLayout(); - - // Scroll Area - auto scrollLayout = ControlUtil::createScrollLayout(mainLayout); - - this->setLayout(scrollLayout); -} - -QLayout *OptionsPage::setupMainLayout() { // Column #1 auto colLayout1 = setupColumn1(); @@ -127,7 +116,7 @@ QLayout *OptionsPage::setupMainLayout() layout->addLayout(colLayout2); layout->addStretch(); - return layout; + this->setLayout(layout); } QLayout *OptionsPage::setupColumn1() diff --git a/src/ui/form/opt/pages/optionspage.h b/src/ui/form/opt/pages/optionspage.h index 1af2600b..b1896a7b 100644 --- a/src/ui/form/opt/pages/optionspage.h +++ b/src/ui/form/opt/pages/optionspage.h @@ -24,7 +24,6 @@ private: void retranslateDriverMessage(); void setupUi(); - QLayout *setupMainLayout(); QLayout *setupColumn1(); void setupStartupBox(); void setupTrafficBox();