From a69aed80e67dc3460cf66e09ef72cec468596b9b Mon Sep 17 00:00:00 2001 From: Michael Schuster Date: Sat, 21 Dec 2019 04:31:45 +0100 Subject: [PATCH] Flow2: Make ProgressIndicator's background-aware (Dark-/Light-Mode switching) Signed-off-by: Michael Schuster --- src/gui/creds/webflowcredentialsdialog.cpp | 18 ++++++++++++++++++ src/gui/creds/webflowcredentialsdialog.h | 3 +++ src/gui/wizard/flow2authcredspage.cpp | 13 +++++++++++++ src/gui/wizard/flow2authcredspage.h | 2 ++ src/gui/wizard/flow2authwidget.cpp | 13 +++++++++++++ src/gui/wizard/flow2authwidget.h | 2 ++ src/gui/wizard/owncloudwizard.cpp | 1 + 7 files changed, 52 insertions(+) diff --git a/src/gui/creds/webflowcredentialsdialog.cpp b/src/gui/creds/webflowcredentialsdialog.cpp index b47cef562f..46c5a16090 100644 --- a/src/gui/creds/webflowcredentialsdialog.cpp +++ b/src/gui/creds/webflowcredentialsdialog.cpp @@ -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 diff --git a/src/gui/creds/webflowcredentialsdialog.h b/src/gui/creds/webflowcredentialsdialog.h index 880eec1b7e..ba252714a6 100644 --- a/src/gui/creds/webflowcredentialsdialog.h +++ b/src/gui/creds/webflowcredentialsdialog.h @@ -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; diff --git a/src/gui/wizard/flow2authcredspage.cpp b/src/gui/wizard/flow2authcredspage.cpp index 82406edc0d..97df052ec6 100644 --- a/src/gui/wizard/flow2authcredspage.cpp +++ b/src/gui/wizard/flow2authcredspage.cpp @@ -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 diff --git a/src/gui/wizard/flow2authcredspage.h b/src/gui/wizard/flow2authcredspage.h index 100b569abd..eac4a0c372 100644 --- a/src/gui/wizard/flow2authcredspage.h +++ b/src/gui/wizard/flow2authcredspage.h @@ -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; }; diff --git a/src/gui/wizard/flow2authwidget.cpp b/src/gui/wizard/flow2authwidget.cpp index d1464525e6..d66d198145 100644 --- a/src/gui/wizard/flow2authwidget.cpp +++ b/src/gui/wizard/flow2authwidget.cpp @@ -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 diff --git a/src/gui/wizard/flow2authwidget.h b/src/gui/wizard/flow2authwidget.h index dfbba8aa02..0912657a79 100644 --- a/src/gui/wizard/flow2authwidget.h +++ b/src/gui/wizard/flow2authwidget.h @@ -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; }; diff --git a/src/gui/wizard/owncloudwizard.cpp b/src/gui/wizard/owncloudwizard.cpp index ad38ba013d..2076136ffe 100644 --- a/src/gui/wizard/owncloudwizard.cpp +++ b/src/gui/wizard/owncloudwizard.cpp @@ -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();