Merge pull request #5968 from nextcloud/bugfix/dark-mode-folder-wizard-warning-color

Fix folder wizard warning color for local path in dark mode
This commit is contained in:
Matthieu Gallien 2023-09-16 19:58:52 +02:00 committed by GitHub
commit 6ebc94f166
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 5 deletions

View file

@ -41,6 +41,21 @@
#include <cstdlib> #include <cstdlib>
namespace
{
constexpr QColor darkWarnYellow(63, 63, 0);
constexpr QColor lightWarnYellow(255, 255, 192);
QPalette yellowWarnWidgetPalette(const QPalette &existingPalette)
{
const auto warnYellow = OCC::Theme::instance()->darkMode() ? darkWarnYellow : lightWarnYellow;
auto modifiedPalette = existingPalette;
modifiedPalette.setColor(QPalette::Window, warnYellow);
modifiedPalette.setColor(QPalette::Base, warnYellow);
return modifiedPalette;
}
}
namespace OCC { namespace OCC {
QString FormatWarningsWizardPage::formatWarnings(const QStringList &warnings) const QString FormatWarningsWizardPage::formatWarnings(const QStringList &warnings) const
@ -162,10 +177,8 @@ void FolderWizardLocalPath::changeEvent(QEvent *e)
void FolderWizardLocalPath::changeStyle() void FolderWizardLocalPath::changeStyle()
{ {
const auto warnYellow = Theme::isDarkColor(QGuiApplication::palette().base().color()) ? QColor(63, 63, 0) : QColor(255, 255, 192); const auto yellowWarnPalette = yellowWarnWidgetPalette(_ui.warnLabel->palette());
auto modifiedPalette = _ui.warnLabel->palette(); _ui.warnLabel->setPalette(yellowWarnPalette);
modifiedPalette.setColor(QPalette::Window, warnYellow);
_ui.warnLabel->setPalette(modifiedPalette);
} }
// ================================================================================= // =================================================================================
@ -192,6 +205,8 @@ FolderWizardRemotePath::FolderWizardRemotePath(const AccountPtr &account)
_ui.folderTreeWidget->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); _ui.folderTreeWidget->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
// Make sure that there will be a scrollbar when the contents is too wide // Make sure that there will be a scrollbar when the contents is too wide
_ui.folderTreeWidget->header()->setStretchLastSection(false); _ui.folderTreeWidget->header()->setStretchLastSection(false);
changeStyle();
} }
void FolderWizardRemotePath::slotAddRemoteFolder() void FolderWizardRemotePath::slotAddRemoteFolder()
@ -523,6 +538,28 @@ void FolderWizardRemotePath::showWarn(const QString &msg) const
} }
} }
void FolderWizardRemotePath::changeEvent(QEvent *e)
{
switch (e->type()) {
case QEvent::StyleChange:
case QEvent::PaletteChange:
case QEvent::ThemeChange:
// Notify the other widgets (Dark-/Light-Mode switching)
changeStyle();
break;
default:
break;
}
FormatWarningsWizardPage::changeEvent(e);
}
void FolderWizardRemotePath::changeStyle()
{
const auto yellowWarnPalette = yellowWarnWidgetPalette(_ui.warnLabel->palette());
_ui.warnLabel->setPalette(yellowWarnPalette);
}
// ==================================================================================== // ====================================================================================
FolderWizardSelectiveSync::FolderWizardSelectiveSync(const AccountPtr &account) FolderWizardSelectiveSync::FolderWizardSelectiveSync(const AccountPtr &account)

View file

@ -94,7 +94,6 @@ public:
void cleanupPage() override; void cleanupPage() override;
protected slots: protected slots:
void showWarn(const QString & = QString()) const; void showWarn(const QString & = QString()) const;
void slotAddRemoteFolder(); void slotAddRemoteFolder();
void slotCreateRemoteFolder(const QString &); void slotCreateRemoteFolder(const QString &);
@ -110,6 +109,12 @@ protected slots:
void slotLsColFolderEntry(); void slotLsColFolderEntry();
void slotTypedPathFound(const QStringList &subpaths); void slotTypedPathFound(const QStringList &subpaths);
protected:
void changeEvent(QEvent *) override;
private slots:
void changeStyle();
private: private:
LsColJob *runLsColJob(const QString &path); LsColJob *runLsColJob(const QString &path);
void recursiveInsert(QTreeWidgetItem *parent, QStringList pathTrail, QString path); void recursiveInsert(QTreeWidgetItem *parent, QStringList pathTrail, QString path);