Flow2: Make ProgressIndicator's background-aware (Dark-/Light-Mode switching)
authorMichael Schuster <michael@schuster.ms>
Sat, 21 Dec 2019 03:31:45 +0000 (04:31 +0100)
committerMichael Schuster <48932272+misch7@users.noreply.github.com>
Tue, 24 Dec 2019 06:46:57 +0000 (07:46 +0100)
Signed-off-by: Michael Schuster <michael@schuster.ms>
src/gui/creds/webflowcredentialsdialog.cpp
src/gui/creds/webflowcredentialsdialog.h
src/gui/wizard/flow2authcredspage.cpp
src/gui/wizard/flow2authcredspage.h
src/gui/wizard/flow2authwidget.cpp
src/gui/wizard/flow2authwidget.h
src/gui/wizard/owncloudwizard.cpp

index b47cef562f7faa3135d86e9b71dd3d7512c59f47..46c5a16090095f58fc203a9790987e31309b12f7 100644 (file)
@@ -33,6 +33,9 @@ WebFlowCredentialsDialog::WebFlowCredentialsDialog(Account *account, bool useFlo
 
         connect(_flow2AuthWidget, &Flow2AuthWidget::urlCatched, this, &WebFlowCredentialsDialog::urlCatched);
 
+        // Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching)
+        connect(this, &WebFlowCredentialsDialog::styleChanged, _flow2AuthWidget, &Flow2AuthWidget::slotStyleChanged);
+
         // allow Flow2 page to poll on window activation
         connect(this, &WebFlowCredentialsDialog::onActivate, _flow2AuthWidget, &Flow2AuthWidget::slotPollNow);
     } else {
@@ -52,6 +55,8 @@ WebFlowCredentialsDialog::WebFlowCredentialsDialog(Account *account, bool useFlo
     WizardCommon::initErrorLabel(_errorLabel);
 
     setLayout(_layout);
+
+    customizeStyle();
 }
 
 void WebFlowCredentialsDialog::closeEvent(QCloseEvent* e) {
@@ -93,6 +98,14 @@ void WebFlowCredentialsDialog::setError(const QString &error) {
 void WebFlowCredentialsDialog::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;
     case QEvent::ActivationChange:
         if(isActiveWindow())
             emit onActivate();
@@ -104,6 +117,11 @@ void WebFlowCredentialsDialog::changeEvent(QEvent *e)
     QDialog::changeEvent(e);
 }
 
+void WebFlowCredentialsDialog::customizeStyle()
+{
+    // HINT: Customize dialog's own style here, if necessary in the future (Dark-/Light-Mode switching)
+}
+
 void WebFlowCredentialsDialog::slotShowSettingsDialog()
 {
     // bring window to top but slightly delay, to avoid being hidden behind the SettingsDialog
index 880eec1b7e9b77868b9c9da5154b89e3eddf926c..ba252714a6eef8c6189f8e977291dbd14f73aaf8 100644 (file)
@@ -37,9 +37,12 @@ public slots:
 
 signals:
     void urlCatched(const QString user, const QString pass, const QString host);
+    void styleChanged();
     void onActivate();
 
 private:
+    void customizeStyle();
+
     bool _useFlow2;
 
     Flow2AuthWidget *_flow2AuthWidget;
index 82406edc0db7d425b737db98184d5396adb5c620..97df052ec6cc1a8c336424487666e9ae13e5bf05 100644 (file)
@@ -55,6 +55,8 @@ Flow2AuthCredsPage::Flow2AuthCredsPage()
 
     _ui.horizontalLayout->addWidget(_progressIndi);
     stopSpinner(false);
+
+    customizeStyle();
 }
 
 void Flow2AuthCredsPage::initializePage()
@@ -203,4 +205,15 @@ void Flow2AuthCredsPage::stopSpinner(bool showStatusLabel)
     _ui.copyLinkButton->setEnabled(true);
 }
 
+void Flow2AuthCredsPage::slotStyleChanged()
+{
+    customizeStyle();
+}
+
+void Flow2AuthCredsPage::customizeStyle()
+{
+    if(_progressIndi)
+        _progressIndi->setColor(QGuiApplication::palette().color(QPalette::Text));
+}
+
 } // namespace OCC
index 100b569abd78fc5dafe038d5318b57afb528960c..eac4a0c372dc8519031f07b7e5fdd52238f2c8be 100644 (file)
@@ -49,6 +49,7 @@ public Q_SLOTS:
     void asyncAuthResult(Flow2Auth::Result, const QString &user, const QString &appPassword);
     void slotPollNow();
     void slotStatusChanged(int secondsLeft);
+    void slotStyleChanged();
 
 signals:
     void connectToOCUrl(const QString &);
@@ -67,6 +68,7 @@ protected slots:
 private:
     void startSpinner();
     void stopSpinner(bool showStatusLabel);
+    void customizeStyle();
 
     QProgressIndicator *_progressIndi;
 };
index d1464525e6fa08831063b78828e0100849777f8c..d66d1981453f3647acdc46cf2206486dbdd25f13 100644 (file)
@@ -64,6 +64,8 @@ Flow2AuthWidget::Flow2AuthWidget(Account *account, QWidget *parent)
     connect(_asyncAuth.data(), &Flow2Auth::statusChanged, this, &Flow2AuthWidget::slotStatusChanged);
     connect(this, &Flow2AuthWidget::pollNow, _asyncAuth.data(), &Flow2Auth::slotPollNow);
     _asyncAuth->start();
+
+    customizeStyle();
 }
 
 void Flow2AuthWidget::asyncAuthResult(Flow2Auth::Result r, const QString &user,
@@ -161,4 +163,15 @@ void Flow2AuthWidget::stopSpinner(bool showStatusLabel)
     _ui.copyLinkButton->setEnabled(true);
 }
 
+void Flow2AuthWidget::slotStyleChanged()
+{
+    customizeStyle();
+}
+
+void Flow2AuthWidget::customizeStyle()
+{
+    if(_progressIndi)
+        _progressIndi->setColor(QGuiApplication::palette().color(QPalette::Text));
+}
+
 } // namespace OCC
index dfbba8aa027f5d6929480bfd53bb3318bb10729f..0912657a79c99c898a19b1071b37154c8614c201 100644 (file)
@@ -39,6 +39,7 @@ public Q_SLOTS:
     void asyncAuthResult(Flow2Auth::Result, const QString &user, const QString &appPassword);
     void slotPollNow();
     void slotStatusChanged(int secondsLeft);
+    void slotStyleChanged();
 
 signals:
     void urlCatched(const QString user, const QString pass, const QString host);
@@ -58,6 +59,7 @@ protected slots:
 private:
     void startSpinner();
     void stopSpinner(bool showStatusLabel);
+    void customizeStyle();
 
     QProgressIndicator *_progressIndi;
 };
index ad38ba013dabea07a7bfaef4831b29bbcf68d5ed..2076136ffe81af7d88f3bf56665e1a496f667802 100644 (file)
@@ -106,6 +106,7 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
     // 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);
+    connect(this, &OwncloudWizard::styleChanged, _flow2CredsPage, &Flow2AuthCredsPage::slotStyleChanged);
 
     customizeStyle();