From 1c0ed6b1aa8229c32cb8b94fb3e8d3056c8c53f6 Mon Sep 17 00:00:00 2001 From: fourtf Date: Tue, 3 Sep 2019 13:09:33 +0200 Subject: [PATCH] slightly changed layout for logs and cache --- src/widgets/settingspages/GeneralPage.cpp | 16 ++++++--- src/widgets/settingspages/GeneralPage.hpp | 13 ++++++-- src/widgets/settingspages/ModerationPage.cpp | 35 +++++++++++++------- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 473c8e4dc..934d4f432 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -430,11 +430,19 @@ void GeneralPage::initLayout(SettingsLayout &layout) cachePathLabel->setToolTip(newPath); }); - layout.addButton("Choose", [this]() { - getSettings()->cachePath = QFileDialog::getExistingDirectory(this); - }); + // Choose and reset buttons + { + auto box = new QHBoxLayout; - layout.addButton("Reset", []() { getSettings()->cachePath = ""; }); + box->addWidget(layout.makeButton("Choose cache path", [this]() { + getSettings()->cachePath = QFileDialog::getExistingDirectory(this); + })); + box->addWidget(layout.makeButton( + "Reset", []() { getSettings()->cachePath = ""; })); + box->addStretch(1); + + layout.addLayout(box); + } layout.addTitle("AppData"); layout.addDescription("All local files like settings and cache files are " diff --git a/src/widgets/settingspages/GeneralPage.hpp b/src/widgets/settingspages/GeneralPage.hpp index e1600a108..de6b7ac51 100644 --- a/src/widgets/settingspages/GeneralPage.hpp +++ b/src/widgets/settingspages/GeneralPage.hpp @@ -69,14 +69,21 @@ public: bool editable = false); template - QPushButton *addButton(const QString &text, OnClick onClick) + QPushButton *makeButton(const QString &text, OnClick onClick) { auto button = new QPushButton(text); + this->groups_.back().widgets.push_back({button, {text}}); + QObject::connect(button, &QPushButton::clicked, onClick); + return button; + } + + template + QPushButton *addButton(const QString &text, OnClick onClick) + { + auto button = makeButton(text, onClick); auto layout = new QHBoxLayout(); layout->addWidget(button); layout->addStretch(1); - this->groups_.back().widgets.push_back({button, {text}}); - QObject::connect(button, &QPushButton::clicked, onClick); this->addLayout(layout); return button; } diff --git a/src/widgets/settingspages/ModerationPage.cpp b/src/widgets/settingspages/ModerationPage.cpp index 38f0944c1..b6c526a45 100644 --- a/src/widgets/settingspages/ModerationPage.cpp +++ b/src/widgets/settingspages/ModerationPage.cpp @@ -83,13 +83,10 @@ ModerationPage::ModerationPage() auto logs = tabs.appendTab(new QVBoxLayout, "Logs"); { + logs.append(this->createCheckBox("Enable logging", + getSettings()->enableLogging)); auto logsPathLabel = logs.emplace(); - // Show how big (size-wise) the logs are - auto logsPathSizeLabel = logs.emplace(); - logsPathSizeLabel->setText( - QtConcurrent::run([] { return fetchLogDirectorySize(); })); - // Logs (copied from LoggingMananger) getSettings()->logPath.connect([logsPathLabel](const QString &logPath, auto) mutable { @@ -109,13 +106,27 @@ ModerationPage::ModerationPage() logsPathLabel->setTextInteractionFlags(Qt::TextBrowserInteraction | Qt::LinksAccessibleByKeyboard); logsPathLabel->setOpenExternalLinks(true); - logs.append(this->createCheckBox("Enable logging", - getSettings()->enableLogging)); + auto buttons = logs.emplace().withoutMargin(); + + // Select and Reset + auto selectDir = buttons.emplace("Select log directory "); + auto resetDir = buttons.emplace("Reset"); + + getSettings()->logPath.connect( + [element = resetDir.getElement()](const QString &path) { + element->setEnabled(!path.isEmpty()); + }); + + buttons->addStretch(); logs->addStretch(1); - auto selectDir = logs.emplace("Set custom logpath"); - // Setting custom logpath + // Show how big (size-wise) the logs are + auto logsPathSizeLabel = logs.emplace(); + logsPathSizeLabel->setText( + QtConcurrent::run([] { return fetchLogDirectorySize(); })); + + // Select event QObject::connect( selectDir.getElement(), &QPushButton::clicked, this, [this, logsPathSizeLabel]() mutable { @@ -128,8 +139,9 @@ ModerationPage::ModerationPage() QtConcurrent::run([] { return fetchLogDirectorySize(); })); }); + buttons->addSpacing(16); + // Reset custom logpath - auto resetDir = logs.emplace("Reset logpath"); QObject::connect(resetDir.getElement(), &QPushButton::clicked, this, [logsPathSizeLabel]() mutable { getSettings()->logPath = ""; @@ -139,8 +151,7 @@ ModerationPage::ModerationPage() [] { return fetchLogDirectorySize(); })); }); - // Logs end - } + } // logs end auto modMode = tabs.appendTab(new QVBoxLayout, "Moderation buttons"); {