From 789a2a7ae39f04fc1ad7b16ee28e5744a7dcec40 Mon Sep 17 00:00:00 2001 From: Michael Schuster Date: Mon, 9 Dec 2019 20:47:42 +0100 Subject: [PATCH] Make SettingsDialog background-aware (Dark-/Light-Mode switching) Use customizeStyle() to change link colours in the SettingsDialog and notify it's widgets via slots. Also modify the background colour of the errors messages in AccountSettings::showConnectionLabel to always use an appropiate colour for it's custom-defined background. Signed-off-by: Michael Schuster --- src/gui/accountsettings.cpp | 21 +++++++++++++++++++-- src/gui/accountsettings.h | 2 ++ src/gui/generalsettings.cpp | 27 +++++++++++++++++++++++++-- src/gui/generalsettings.h | 5 +++++ src/gui/settingsdialog.cpp | 9 +++++++++ src/gui/settingsdialog.h | 3 +++ 6 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 50ee4e8a6..843dab5ba 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -202,6 +202,8 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) } else { ui->encryptionMessage->hide(); } + + customizeStyle(); } @@ -834,13 +836,16 @@ void AccountSettings::showConnectionLabel(const QString &message, QStringList er "border-width: 1px; border-style: solid; border-color: #aaaaaa;" "border-radius:5px;"); if (errors.isEmpty()) { - ui->connectLabel->setText(message); + QString msg = message; + Theme::replaceLinkColorStringBackgroundAware(msg); + ui->connectLabel->setText(msg); ui->connectLabel->setToolTip(QString()); ui->connectLabel->setStyleSheet(QString()); } else { errors.prepend(message); - const QString msg = errors.join(QLatin1String("\n")); + QString msg = errors.join(QLatin1String("\n")); qCDebug(lcAccountSettings) << msg; + Theme::replaceLinkColorStringBackgroundAware(msg, QColor("#bb4d4d")); ui->connectLabel->setText(msg); ui->connectLabel->setToolTip(QString()); ui->connectLabel->setStyleSheet(errStyle); @@ -1241,6 +1246,18 @@ bool AccountSettings::event(QEvent *e) return QWidget::event(e); } +void AccountSettings::slotStyleChanged() +{ + customizeStyle(); +} + +void AccountSettings::customizeStyle() +{ + QString msg = ui->connectLabel->text(); + Theme::replaceLinkColorStringBackgroundAware(msg); + ui->connectLabel->setText(msg); +} + } // namespace OCC #include "accountsettings.moc" diff --git a/src/gui/accountsettings.h b/src/gui/accountsettings.h index e283df26f..11a5fe604 100644 --- a/src/gui/accountsettings.h +++ b/src/gui/accountsettings.h @@ -69,6 +69,7 @@ public slots: void slotOpenOC(); void slotUpdateQuota(qint64, qint64); void slotAccountStateChanged(); + void slotStyleChanged(); AccountState *accountsState() { return _accountState; } @@ -129,6 +130,7 @@ private: bool event(QEvent *) override; void createAccountToolbox(); void openIgnoredFilesDialog(const QString & absFolderPath); + void customizeStyle(); /// Returns the alias of the selected folder, empty string if none QString selectedFolderAlias() const; diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 62381d36d..c2d5873af 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -70,7 +70,8 @@ GeneralSettings::GeneralSettings(QWidget *parent) connect(_ui->legalNoticeButton, &QPushButton::clicked, this, &GeneralSettings::slotShowLegalNotice); loadMiscSettings(); - slotUpdateInfo(); + // updater info now set in: customizeStyle + //slotUpdateInfo(); // misc connect(_ui->monoIconsCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings); @@ -109,6 +110,8 @@ GeneralSettings::GeneralSettings(QWidget *parent) // accountAdded means the wizard was finished and the wizard might change some options. connect(AccountManager::instance(), &AccountManager::accountAdded, this, &GeneralSettings::loadMiscSettings); + + customizeStyle(); } GeneralSettings::~GeneralSettings() @@ -149,7 +152,11 @@ void GeneralSettings::slotUpdateInfo() connect(updater, &OCUpdater::downloadStateChanged, this, &GeneralSettings::slotUpdateInfo, Qt::UniqueConnection); connect(_ui->restartButton, &QAbstractButton::clicked, updater, &OCUpdater::slotStartInstaller, Qt::UniqueConnection); connect(_ui->restartButton, &QAbstractButton::clicked, qApp, &QApplication::quit, Qt::UniqueConnection); - _ui->updateStateLabel->setText(updater->statusString()); + + QString status = updater->statusString(); + Theme::replaceLinkColorStringBackgroundAware(status); + _ui->updateStateLabel->setText(status); + _ui->restartButton->setVisible(updater->downloadState() == OCUpdater::DownloadComplete); } else { // can't have those infos from sparkle currently @@ -211,4 +218,20 @@ void GeneralSettings::slotShowLegalNotice() delete notice; } +void GeneralSettings::slotStyleChanged() +{ + customizeStyle(); +} + +void GeneralSettings::customizeStyle() +{ + // setup about section + QString about = Theme::instance()->about(); + Theme::replaceLinkColorStringBackgroundAware(about); + _ui->aboutLabel->setText(about); + + // updater info + slotUpdateInfo(); +} + } // namespace OCC diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index 12abf3660..f7a759161 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -39,6 +39,9 @@ public: ~GeneralSettings(); QSize sizeHint() const override; +public slots: + void slotStyleChanged(); + private slots: void saveMiscSettings(); void slotToggleLaunchOnStartup(bool); @@ -50,6 +53,8 @@ private slots: void slotShowLegalNotice(); private: + void customizeStyle(); + Ui::GeneralSettings *_ui; QPointer _ignoreEditor; QPointer _syncLogDialog; diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index f98acf3c3..68467e901 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -104,6 +104,9 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) GeneralSettings *generalSettings = new GeneralSettings; _ui->stack->addWidget(generalSettings); + // Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching) + connect(this, &SettingsDialog::styleChanged, generalSettings, &GeneralSettings::slotStyleChanged); + QAction *networkAction = createColorAwareAction(QLatin1String(":/client/resources/network.png"), tr("Network")); _actionGroup->addAction(networkAction); _toolBar->addAction(networkAction); @@ -156,6 +159,9 @@ void SettingsDialog::changeEvent(QEvent *e) case QEvent::PaletteChange: case QEvent::ThemeChange: customizeStyle(); + + // Notify the other widgets (Dark-/Light-Mode switching) + emit styleChanged(); break; default: break; @@ -248,6 +254,9 @@ void SettingsDialog::accountAdded(AccountState *s) _actionGroupWidgets.insert(accountAction, accountSettings); _actionForAccount.insert(s->account().data(), accountAction); accountAction->trigger(); + + // Connect styleChanged event, to adapt (Dark-/Light-Mode switching) + connect(this, &SettingsDialog::styleChanged, accountSettings, &AccountSettings::slotStyleChanged); connect(accountSettings, &AccountSettings::folderChanged, _gui, &ownCloudGui::slotFoldersChanged); connect(accountSettings, &AccountSettings::openFolderAlias, diff --git a/src/gui/settingsdialog.h b/src/gui/settingsdialog.h index 869e796a4..67cf29e23 100644 --- a/src/gui/settingsdialog.h +++ b/src/gui/settingsdialog.h @@ -63,6 +63,9 @@ public slots: void slotAccountAvatarChanged(); void slotAccountDisplayNameChanged(); +signals: + void styleChanged(); + protected: void reject() override; void accept() override;