UI: Options: Add ScrollArea.

This commit is contained in:
Nodir Temirkhodjaev 2021-03-25 12:57:56 +03:00
parent 287e389dfb
commit 42751356e8
6 changed files with 176 additions and 75 deletions

View File

@ -9,6 +9,7 @@
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QScrollArea>
#include <QToolButton>
#include <QWidgetAction>
@ -142,6 +143,28 @@ QFrame *ControlUtil::createSeparator(Qt::Orientation o)
return c;
}
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 layout = new QHBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(scrollArea);
return layout;
}
QFont ControlUtil::fontDemiBold()
{
QFont font;

View File

@ -6,13 +6,14 @@
#include <functional>
QT_FORWARD_DECLARE_CLASS(QBoxLayout)
QT_FORWARD_DECLARE_CLASS(QCheckBox)
QT_FORWARD_DECLARE_CLASS(QComboBox)
QT_FORWARD_DECLARE_CLASS(QFrame)
QT_FORWARD_DECLARE_CLASS(QBoxLayout)
QT_FORWARD_DECLARE_CLASS(QLabel)
QT_FORWARD_DECLARE_CLASS(QMenu)
QT_FORWARD_DECLARE_CLASS(QLayout)
QT_FORWARD_DECLARE_CLASS(QLineEdit)
QT_FORWARD_DECLARE_CLASS(QMenu)
QT_FORWARD_DECLARE_CLASS(QPushButton)
QT_FORWARD_DECLARE_CLASS(QToolButton)
@ -38,6 +39,7 @@ public:
static QBoxLayout *createLayoutByWidgets(
const QList<QWidget *> &widgets, Qt::Orientation o = Qt::Vertical);
static QFrame *createSeparator(Qt::Orientation o = Qt::Horizontal);
static QLayout *createScrollLayout(QLayout *content, bool isBgTransparent = true);
static QFont fontDemiBold();

View File

@ -47,9 +47,20 @@ void MainPage::setupUi()
layout->setContentsMargins(6, 6, 6, 6);
// Main Tab Bar
m_tabBar = new QTabWidget();
setupTabBar();
layout->addWidget(m_tabBar);
// Dialog butons
auto buttonsLayout = setupDialogButtons();
layout->addLayout(buttonsLayout);
this->setLayout(layout);
}
void MainPage::setupTabBar()
{
m_tabBar = new QTabWidget();
m_optionsPage = new OptionsPage(ctrl());
m_addressesPage = new AddressesPage(ctrl());
m_rulesPage = new RulesPage(ctrl());
@ -65,12 +76,6 @@ void MainPage::setupUi()
m_tabBar->addTab(m_schedulePage, IconCache::icon(":/icons/clock.png"), QString());
m_tabBar->setTabVisible(2, false); // TODO: Impl. Network Rules
// Dialog butons
auto buttonsLayout = setupDialogButtons();
layout->addLayout(buttonsLayout);
this->setLayout(layout);
}
QLayout *MainPage::setupDialogButtons()

View File

@ -24,6 +24,7 @@ protected slots:
private:
void setupUi();
void setupTabBar();
QLayout *setupDialogButtons();
void setupOkApplyButtons();

View File

@ -103,16 +103,76 @@ void OptionsPage::retranslateDriverMessage()
void OptionsPage::setupUi()
{
// Column #1
auto colLayout1 = new QVBoxLayout();
colLayout1->setSpacing(10);
// Main Layout
auto mainLayout = setupMainLayout();
// Scroll Area
auto scrollLayout = ControlUtil::createScrollLayout(mainLayout);
this->setLayout(scrollLayout);
}
QLayout *OptionsPage::setupMainLayout()
{
// Column #1
auto colLayout1 = setupColumn1();
// Column #2
auto colLayout2 = setupColumn2();
// Main layout
auto layout = new QHBoxLayout();
layout->addLayout(colLayout1);
layout->addStretch();
layout->addLayout(colLayout2);
layout->addStretch();
return layout;
}
QLayout *OptionsPage::setupColumn1()
{
auto layout = new QVBoxLayout();
layout->setSpacing(10);
m_cbHotKeys = ControlUtil::createCheckBox(
settings()->hotKeyEnabled(), [&](bool) { setIniEdited(true); });
// Startup Group Box
setupStartupBox();
layout->addWidget(m_gbStartup);
// Traffic Group Box
setupTrafficBox();
layout->addWidget(m_gbTraffic);
// Global Group Box
setupGlobalBox();
layout->addWidget(m_gbGlobal);
layout->addStretch();
return layout;
}
void OptionsPage::setupStartupBox()
{
m_cbStart = ControlUtil::createCheckBox(
settings()->startWithWindows(), [&](bool) { setIniEdited(true); });
m_cbProvBoot = ControlUtil::createCheckBox(conf()->provBoot(), [&](bool checked) {
conf()->setProvBoot(checked);
ctrl()->setConfFlagsEdited(true);
});
m_gbStartup = new QGroupBox(this);
auto layout = new QVBoxLayout();
layout->addWidget(m_cbStart);
layout->addWidget(m_cbProvBoot);
m_gbStartup->setLayout(layout);
}
void OptionsPage::setupTrafficBox()
{
m_cbFilterEnabled = ControlUtil::createCheckBox(conf()->filterEnabled(), [&](bool checked) {
conf()->setFilterEnabled(checked);
ctrl()->setConfFlagsEdited(true);
@ -133,29 +193,40 @@ void OptionsPage::setupUi()
conf()->setAllowAllNew(checked);
ctrl()->setConfFlagsEdited(true);
});
m_gbTraffic = new QGroupBox(this);
auto layout = new QVBoxLayout();
layout->addWidget(m_cbFilterEnabled);
layout->addWidget(m_cbFilterLocals);
layout->addWidget(m_cbStopTraffic);
layout->addWidget(m_cbStopInetTraffic);
layout->addWidget(m_cbAllowAllNew);
m_gbTraffic->setLayout(layout);
}
void OptionsPage::setupGlobalBox()
{
m_cbHotKeys = ControlUtil::createCheckBox(
settings()->hotKeyEnabled(), [&](bool) { setIniEdited(true); });
m_gbStartup = new QGroupBox(this);
auto startupLayout = new QVBoxLayout();
startupLayout->addWidget(m_cbStart);
startupLayout->addWidget(m_cbProvBoot);
m_gbStartup->setLayout(startupLayout);
colLayout1->addWidget(m_gbStartup);
m_gbTraffic = new QGroupBox(this);
auto trafficLayout = new QVBoxLayout();
trafficLayout->addWidget(m_cbFilterEnabled);
trafficLayout->addWidget(m_cbFilterLocals);
trafficLayout->addWidget(m_cbStopTraffic);
trafficLayout->addWidget(m_cbStopInetTraffic);
trafficLayout->addWidget(m_cbAllowAllNew);
m_gbTraffic->setLayout(trafficLayout);
colLayout1->addWidget(m_gbTraffic);
// Password Row
auto passwordLayout = new QHBoxLayout();
passwordLayout->setSpacing(6);
auto passwordLayout = setupPasswordLayout();
// Language Row
auto langLayout = setupLangLayout();
m_gbGlobal = new QGroupBox(this);
auto layout = new QVBoxLayout();
layout->addWidget(m_cbHotKeys);
layout->addLayout(passwordLayout);
layout->addLayout(langLayout);
m_gbGlobal->setLayout(layout);
}
QLayout *OptionsPage::setupPasswordLayout()
{
auto layout = new QHBoxLayout();
layout->setSpacing(6);
m_cbPassword = ControlUtil::createCheckBox(settings()->hasPassword(), [&](bool checked) {
if (checked) {
@ -169,51 +240,10 @@ void OptionsPage::setupUi()
setupEditPassword();
passwordLayout->addWidget(m_cbPassword);
passwordLayout->addWidget(m_editPassword);
layout->addWidget(m_cbPassword);
layout->addWidget(m_editPassword);
// Language Row
auto langLayout = new QHBoxLayout();
langLayout->setSpacing(10);
m_labelLanguage = ControlUtil::createLabel();
setupComboLanguage();
langLayout->addWidget(m_labelLanguage);
langLayout->addWidget(m_comboLanguage);
m_gbGlobal = new QGroupBox(this);
auto globalLayout = new QVBoxLayout();
globalLayout->addWidget(m_cbHotKeys);
globalLayout->addLayout(passwordLayout);
globalLayout->addLayout(langLayout);
m_gbGlobal->setLayout(globalLayout);
colLayout1->addWidget(m_gbGlobal);
colLayout1->addStretch();
// Column #2
auto colLayout2 = new QVBoxLayout();
colLayout2->setSpacing(10);
setupDriverBox();
setupNewVersionBox();
setupNewVersionUpdate();
colLayout2->addWidget(m_gbDriver);
colLayout2->addWidget(m_gbNewVersion);
colLayout2->addStretch();
// Main layout
auto layout = new QHBoxLayout();
layout->addLayout(colLayout1);
layout->addStretch();
layout->addLayout(colLayout2);
layout->addStretch();
this->setLayout(layout);
return layout;
}
void OptionsPage::setupEditPassword()
@ -235,6 +265,21 @@ void OptionsPage::setupEditPassword()
connect(m_cbPassword, &QCheckBox::toggled, this, refreshEditPassword);
}
QLayout *OptionsPage::setupLangLayout()
{
auto layout = new QHBoxLayout();
layout->setSpacing(10);
m_labelLanguage = ControlUtil::createLabel();
setupComboLanguage();
layout->addWidget(m_labelLanguage);
layout->addWidget(m_comboLanguage);
return layout;
}
void OptionsPage::setupComboLanguage()
{
m_comboLanguage =
@ -254,6 +299,23 @@ void OptionsPage::setupComboLanguage()
connect(translationManager(), &TranslationManager::languageChanged, this, refreshComboLanguage);
}
QLayout *OptionsPage::setupColumn2()
{
auto layout = new QVBoxLayout();
layout->setSpacing(10);
setupDriverBox();
setupNewVersionBox();
setupNewVersionUpdate();
layout->addWidget(m_gbDriver);
layout->addWidget(m_gbNewVersion);
layout->addStretch();
return layout;
}
void OptionsPage::setupDriverBox()
{
m_gbDriver = new QGroupBox(this);

View File

@ -24,8 +24,16 @@ private:
void retranslateDriverMessage();
void setupUi();
QLayout *setupMainLayout();
QLayout *setupColumn1();
void setupStartupBox();
void setupTrafficBox();
void setupGlobalBox();
QLayout *setupPasswordLayout();
void setupEditPassword();
QLayout *setupLangLayout();
void setupComboLanguage();
QLayout *setupColumn2();
void setupDriverBox();
void setupDriverIcon();
void setupNewVersionBox();