Make OwncloudWizard and its pages background-aware (Dark-/Light-Mode switching)
authorMichael Schuster <michael@schuster.ms>
Thu, 19 Dec 2019 19:26:27 +0000 (20:26 +0100)
committerMichael Schuster <48932272+misch7@users.noreply.github.com>
Thu, 19 Dec 2019 21:07:30 +0000 (22:07 +0100)
Signed-off-by: Michael Schuster <michael@schuster.ms>
src/gui/wizard/owncloudadvancedsetuppage.cpp
src/gui/wizard/owncloudadvancedsetuppage.h
src/gui/wizard/owncloudhttpcredspage.cpp
src/gui/wizard/owncloudhttpcredspage.h
src/gui/wizard/owncloudsetuppage.cpp
src/gui/wizard/owncloudsetuppage.h
src/gui/wizard/owncloudwizard.cpp
src/gui/wizard/owncloudwizard.h

index 7cfb796447fdb1c99c01fb523334ba74d96e0164..1c278f66a285182912e0548670172316411412f6 100644 (file)
@@ -389,4 +389,13 @@ QString OwncloudAdvancedSetupPage::checkLocalSpace(qint64 remoteSize) const
     return (availableLocalSpace()>remoteSize) ? QString() : tr("There isn't enough free space in the local folder!");
 }
 
+void OwncloudAdvancedSetupPage::slotStyleChanged()
+{
+    customizeStyle();
+}
+
+void OwncloudAdvancedSetupPage::customizeStyle()
+{
+}
+
 } // namespace OCC
index 9ebf9fc70f149490d16f9d664b354423fa96733f..e3d328a18e989227d9f987a70e34c2aeb92577a7 100644 (file)
@@ -51,6 +51,7 @@ signals:
 
 public slots:
     void setErrorString(const QString &);
+    void slotStyleChanged();
 
 private slots:
     void slotSelectFolder();
@@ -67,6 +68,7 @@ private:
     QUrl serverUrl() const;
     qint64 availableLocalSpace() const;
     QString checkLocalSpace(qint64 remoteSize) const;
+    void customizeStyle();
 
     Ui_OwncloudAdvancedSetupPage _ui;
     bool _checking;
index 265d3bf3c559a1696822423d20a4e41d613c67bf..12f3e78d1553b4d8211bda75ad1d4d7b64abaccb 100644 (file)
@@ -194,5 +194,13 @@ AbstractCredentials *OwncloudHttpCredsPage::getCredentials() const
     return new HttpCredentialsGui(_ui.leUsername->text(), _ui.lePassword->text(), _ocWizard->_clientSslCertificate, _ocWizard->_clientSslKey);
 }
 
+void OwncloudHttpCredsPage::slotStyleChanged()
+{
+    customizeStyle();
+}
+
+void OwncloudHttpCredsPage::customizeStyle()
+{
+}
 
 } // namespace OCC
index 83fc55ad4caf2eb36d41472c0bd3e547fd3dee7d..adc46117d91b8cef09e0ee9bcb169032b1420227 100644 (file)
@@ -46,10 +46,14 @@ public:
 Q_SIGNALS:
     void connectToOCUrl(const QString &);
 
+public slots:
+    void slotStyleChanged();
+
 private:
     void startSpinner();
     void stopSpinner();
     void setupCustomization();
+    void customizeStyle();
 
     Ui_OwncloudHttpCredsPage _ui;
     bool _connected;
index fb2499c86b95f323d8c044c56b11a2796d24d606..758f05eedbf472a2f20d8a02a14586693c918219 100644 (file)
@@ -89,29 +89,15 @@ OwncloudSetupPage::OwncloudSetupPage(QWidget *parent)
     connect(_ui.nextButton, &QPushButton::clicked, _ui.slideShow, &SlideShow::nextSlide);
     connect(_ui.prevButton, &QPushButton::clicked, _ui.slideShow, &SlideShow::prevSlide);
 
-       auto widgetBgLightness = OwncloudSetupPage::palette().color(OwncloudSetupPage::backgroundRole()).lightness();
-       bool widgetHasDarkBg =
-        (widgetBgLightness >= 125)
-        ? false
-        : true;
-       _ui.nextButton->setIcon(theme->uiThemeIcon(QString("control-next.svg"), widgetHasDarkBg));
-    _ui.prevButton->setIcon(theme->uiThemeIcon(QString("control-prev.svg"), widgetHasDarkBg));
-
-       // QPushButtons are a mess when it comes to consistent background coloring without stylesheets,
-       // so we do it here even though this is an exceptional styling method here
-    _ui.createAccountButton->setStyleSheet("QPushButton {background-color: #0082C9; color: white}");
-
     _ui.slideShow->startShow();
-
-    QPalette pal = _ui.slideShow->palette();
-    pal.setColor(QPalette::WindowText, theme->wizardHeaderBackgroundColor());
-    _ui.slideShow->setPalette(pal);
 #else
     _ui.createAccountButton->hide();
     _ui.loginButton->hide();
     _ui.installLink->hide();
     _ui.slideShow->hide();
 #endif
+
+    customizeStyle();
 }
 
 void OwncloudSetupPage::setServerUrl(const QString &newUrl)
@@ -434,4 +420,28 @@ OwncloudSetupPage::~OwncloudSetupPage()
 {
 }
 
+void OwncloudSetupPage::slotStyleChanged()
+{
+    customizeStyle();
+}
+
+void OwncloudSetupPage::customizeStyle()
+{
+#ifdef WITH_PROVIDERS
+    Theme *theme = Theme::instance();
+
+    bool widgetHasDarkBg = Theme::isDarkColor(QGuiApplication::palette().base().color());
+    _ui.nextButton->setIcon(theme->uiThemeIcon(QString("control-next.svg"), widgetHasDarkBg));
+    _ui.prevButton->setIcon(theme->uiThemeIcon(QString("control-prev.svg"), widgetHasDarkBg));
+
+    // QPushButtons are a mess when it comes to consistent background coloring without stylesheets,
+    // so we do it here even though this is an exceptional styling method here
+    _ui.createAccountButton->setStyleSheet("QPushButton {background-color: #0082C9; color: white}");
+
+    QPalette pal = _ui.slideShow->palette();
+    pal.setColor(QPalette::WindowText, theme->wizardHeaderBackgroundColor());
+    _ui.slideShow->setPalette(pal);
+#endif
+}
+
 } // namespace OCC
index 0bcea045004271d6ab1a739fece283afd065bbba..6e7ed93b0164b171ef184d529d954750473ecb34 100644 (file)
@@ -62,6 +62,7 @@ public slots:
     void startSpinner();
     void stopSpinner();
     void slotCertificateAccepted();
+    void slotStyleChanged();
 
 protected slots:
     void slotUrlChanged(const QString &);
@@ -78,6 +79,7 @@ signals:
 
 private:
     bool urlHasChanged();
+    void customizeStyle();
 
     Ui_OwncloudSetupPage _ui;
 
index e4dda0fbd242a9121d53f9563b935872ac03e8ae..19f6d33cfbff53884ce5e0f5a5e113093571f978 100644 (file)
@@ -100,6 +100,13 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
     setTitleFormat(Qt::RichText);
     setSubTitleFormat(Qt::RichText);
     setButtonText(QWizard::CustomButton1, tr("Skip folders configuration"));
+
+
+    // Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching)
+    connect(this, &OwncloudWizard::styleChanged, _setupPage, &OwncloudSetupPage::slotStyleChanged);
+    connect(this, &OwncloudWizard::styleChanged, _advancedSetupPage, &OwncloudAdvancedSetupPage::slotStyleChanged);
+
+    customizeStyle();
 }
 
 void OwncloudWizard::setAccount(AccountPtr account)
@@ -277,4 +284,27 @@ AbstractCredentials *OwncloudWizard::getCredentials() const
     return nullptr;
 }
 
+void OwncloudWizard::changeEvent(QEvent *e)
+{
+    switch (e->type()) {
+    case QEvent::StyleChange:
+    case QEvent::PaletteChange:
+    case QEvent::ThemeChange:
+        customizeStyle();
+
+        // Notify the other widgets (Dark-/Light-Mode switching)
+        emit styleChanged();
+        break;
+    default:
+        break;
+    }
+
+    QWizard::changeEvent(e);
+}
+
+void OwncloudWizard::customizeStyle()
+{
+    // HINT: Customize wizard's own style here, if necessary in the future (Dark-/Light-Mode switching)
+}
+
 } // end namespace
index c1d290d4b1b13ea2c3391a2352646b5f24300eeb..88ca4d731a5b53275887d4573c19d7ddf96ed7ba 100644 (file)
@@ -96,8 +96,14 @@ signals:
     void basicSetupFinished(int);
     void skipFolderConfiguration();
     void needCertificate();
+    void styleChanged();
+
+protected:
+    void changeEvent(QEvent *) override;
 
 private:
+    void customizeStyle();
+
     AccountPtr _account;
     OwncloudSetupPage *_setupPage;
     OwncloudHttpCredsPage *_httpCredsPage;