Make SettingsDialog background-aware (Dark-/Light-Mode switching)
authorMichael Schuster <michael@schuster.ms>
Mon, 9 Dec 2019 19:47:42 +0000 (20:47 +0100)
committerMichael Schuster <48932272+misch7@users.noreply.github.com>
Mon, 9 Dec 2019 20:37:21 +0000 (21:37 +0100)
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 <michael@schuster.ms>
src/gui/accountsettings.cpp
src/gui/accountsettings.h
src/gui/generalsettings.cpp
src/gui/generalsettings.h
src/gui/settingsdialog.cpp
src/gui/settingsdialog.h

index 50ee4e8a6f626d4839e6304defb1aabc0b3db2d2..843dab5ba4df324d751b047f501cfedc02d5a8ff 100644 (file)
@@ -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"
index e283df26fc096cc02047f3053932f5d4bd107b72..11a5fe604392775dc010ef9815facfb9bf843c71 100644 (file)
@@ -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;
index 62381d36ddbcea8124b2705b5a3f3874f4bf8844..c2d5873afe21a894098678ab176e372ca56c655f 100644 (file)
@@ -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
index 12abf366022634c43b53637dfe2b341aeffa10c3..f7a7591612358e7dffae023be67888b7f76dd281 100644 (file)
@@ -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<IgnoreListEditor> _ignoreEditor;
     QPointer<SyncLogDialog> _syncLogDialog;
index f98acf3c38a2f5d7a4dbc5e43ce93a5c9037749b..68467e90151289f24d25dee5b1ae4ab9240b7a00 100644 (file)
@@ -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,
index 869e796a41b8406b2d657b31f66434a17c17514f..67cf29e235127696133df9ef210c1030a8aa1a37 100644 (file)
@@ -63,6 +63,9 @@ public slots:
     void slotAccountAvatarChanged();
     void slotAccountDisplayNameChanged();
 
+signals:
+    void styleChanged();
+
 protected:
     void reject() override;
     void accept() override;