From 24012cfc7f396177732e9a8b7d849045a65a5512 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Tue, 1 Aug 2023 20:47:17 +0200 Subject: [PATCH] DolphinQt: Adjust panel-specific colors and syntax highlighting for dark theme. --- .../Config/GameConfigHighlighter.cpp | 27 ++++++++++-- .../DolphinQt/Config/Mapping/IOWindow.cpp | 33 +++++++++++---- .../DolphinQt/Debugger/CodeViewWidget.cpp | 6 +-- Source/Core/DolphinQt/MainWindow.cpp | 6 +++ Source/Core/DolphinQt/Settings.cpp | 5 +++ Source/Core/DolphinQt/Settings.h | 1 + .../SkylanderPortal/SkylanderPortalWindow.cpp | 42 +++++++++++++------ .../SkylanderPortal/SkylanderPortalWindow.h | 5 ++- 8 files changed, 97 insertions(+), 28 deletions(-) diff --git a/Source/Core/DolphinQt/Config/GameConfigHighlighter.cpp b/Source/Core/DolphinQt/Config/GameConfigHighlighter.cpp index 0d892b18a5..4473fde5a9 100644 --- a/Source/Core/DolphinQt/Config/GameConfigHighlighter.cpp +++ b/Source/Core/DolphinQt/Config/GameConfigHighlighter.cpp @@ -3,6 +3,11 @@ #include "DolphinQt/Config/GameConfigHighlighter.h" +#include +#include + +#include "DolphinQt/Settings.h" + struct HighlightingRule { QRegularExpression pattern; @@ -13,22 +18,36 @@ GameConfigHighlighter::~GameConfigHighlighter() = default; GameConfigHighlighter::GameConfigHighlighter(QTextDocument* parent) : QSyntaxHighlighter(parent) { + const bool is_dark_theme = Settings::Instance().IsThemeDark(); + QTextCharFormat equal_format; - equal_format.setForeground(Qt::red); + if (is_dark_theme) + equal_format.setForeground(QBrush{QColor(255, 96, 96)}); + else + equal_format.setForeground(Qt::red); QTextCharFormat section_format; section_format.setFontWeight(QFont::Bold); QTextCharFormat comment_format; - comment_format.setForeground(Qt::darkGreen); + if (is_dark_theme) + comment_format.setForeground(QBrush{QColor(0, 220, 0)}); + else + comment_format.setForeground(Qt::darkGreen); comment_format.setFontItalic(true); QTextCharFormat const_format; const_format.setFontWeight(QFont::Bold); - const_format.setForeground(Qt::blue); + if (is_dark_theme) + const_format.setForeground(QBrush{QColor(132, 132, 255)}); + else + const_format.setForeground(Qt::blue); QTextCharFormat num_format; - num_format.setForeground(Qt::darkBlue); + if (is_dark_theme) + num_format.setForeground(QBrush{QColor(66, 138, 255)}); + else + num_format.setForeground(Qt::darkBlue); m_rules.emplace_back(HighlightingRule{QRegularExpression(QStringLiteral("=")), equal_format}); m_rules.emplace_back( diff --git a/Source/Core/DolphinQt/Config/Mapping/IOWindow.cpp b/Source/Core/DolphinQt/Config/Mapping/IOWindow.cpp index 8bec82f015..d70ae2d68f 100644 --- a/Source/Core/DolphinQt/Config/Mapping/IOWindow.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/IOWindow.cpp @@ -6,6 +6,8 @@ #include #include +#include +#include #include #include #include @@ -38,7 +40,6 @@ namespace { -// TODO: Make sure these functions return colors that will be visible in the current theme. QTextCharFormat GetSpecialCharFormat() { QTextCharFormat format; @@ -49,7 +50,10 @@ QTextCharFormat GetSpecialCharFormat() QTextCharFormat GetLiteralCharFormat() { QTextCharFormat format; - format.setForeground(QBrush{Qt::darkMagenta}); + if (Settings::Instance().IsThemeDark()) + format.setForeground(QBrush{QColor(171, 132, 219)}); + else + format.setForeground(QBrush{Qt::darkMagenta}); return format; } @@ -57,35 +61,50 @@ QTextCharFormat GetInvalidCharFormat() { QTextCharFormat format; format.setUnderlineStyle(QTextCharFormat::WaveUnderline); - format.setUnderlineColor(Qt::darkRed); + if (Settings::Instance().IsThemeDark()) + format.setUnderlineColor(QColor(255, 69, 0)); + else + format.setUnderlineColor(Qt::darkRed); return format; } QTextCharFormat GetControlCharFormat() { QTextCharFormat format; - format.setForeground(QBrush{Qt::darkGreen}); + if (Settings::Instance().IsThemeDark()) + format.setForeground(QBrush{QColor(0, 220, 0)}); + else + format.setForeground(QBrush{Qt::darkGreen}); return format; } QTextCharFormat GetVariableCharFormat() { QTextCharFormat format; - format.setForeground(QBrush{Qt::darkYellow}); + if (Settings::Instance().IsThemeDark()) + format.setForeground(QBrush{QColor(226, 226, 0)}); + else + format.setForeground(QBrush{Qt::darkYellow}); return format; } QTextCharFormat GetBarewordCharFormat() { QTextCharFormat format; - format.setForeground(QBrush{Qt::darkBlue}); + if (Settings::Instance().IsThemeDark()) + format.setForeground(QBrush{QColor(66, 138, 255)}); + else + format.setForeground(QBrush{Qt::darkBlue}); return format; } QTextCharFormat GetCommentCharFormat() { QTextCharFormat format; - format.setForeground(QBrush{Qt::darkGray}); + if (Settings::Instance().IsThemeDark()) + format.setForeground(QBrush{QColor(176, 176, 176)}); + else + format.setForeground(QBrush{Qt::darkGray}); return format; } } // namespace diff --git a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp index 65ddd69692..5507875997 100644 --- a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp @@ -307,7 +307,7 @@ void CodeViewWidget::Update(const Core::CPUThreadGuard* guard) const std::optional pc = guard ? std::make_optional(power_pc.GetPPCState().pc) : std::nullopt; - const bool dark_theme = qApp->palette().color(QPalette::Base).valueF() < 0.5; + const bool dark_theme = Settings::Instance().IsThemeDark(); m_branches.clear(); @@ -350,7 +350,7 @@ void CodeViewWidget::Update(const Core::CPUThreadGuard* guard) } else if (color != 0xFFFFFF) { - item->setBackground(dark_theme ? QColor(color).darker(240) : QColor(color)); + item->setBackground(dark_theme ? QColor(color).darker(400) : QColor(color)); } } @@ -372,7 +372,7 @@ void CodeViewWidget::Update(const Core::CPUThreadGuard* guard) description_item->setText( tr("--> %1").arg(QString::fromStdString(debug_interface.GetDescription(branch_addr)))); - param_item->setForeground(Qt::magenta); + param_item->setForeground(dark_theme ? QColor(255, 135, 255) : Qt::magenta); } if (ins == "blr") diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 1f5223179c..67d4ac46bb 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -1728,8 +1728,14 @@ bool MainWindow::nativeEvent(const QByteArray& eventType, void* message, qintptr const bool was_dark_before = settings.IsSystemDark(); settings.UpdateSystemDark(); if (settings.IsSystemDark() != was_dark_before) + { settings.SetCurrentUserStyle(settings.GetCurrentUserStyle()); + // force the colors in the Skylander window to update + if (m_skylander_window) + m_skylander_window->RefreshList(); + } + // TODO: When switching from light to dark, the window decorations remain light. Qt seems very // convinced that it needs to change these in response to this message, so even if we set them // to dark here, Qt sets them back to light afterwards. diff --git a/Source/Core/DolphinQt/Settings.cpp b/Source/Core/DolphinQt/Settings.cpp index 3c4461db1c..ebcf90ee8e 100644 --- a/Source/Core/DolphinQt/Settings.cpp +++ b/Source/Core/DolphinQt/Settings.cpp @@ -163,6 +163,11 @@ bool Settings::IsSystemDark() return s_system_dark; } +bool Settings::IsThemeDark() +{ + return qApp->palette().color(QPalette::Base).valueF() < 0.5; +} + // Calling this before the main window has been created breaks the style of some widgets. void Settings::SetCurrentUserStyle(const QString& stylesheet_name) { diff --git a/Source/Core/DolphinQt/Settings.h b/Source/Core/DolphinQt/Settings.h index b95b768250..5583ed0628 100644 --- a/Source/Core/DolphinQt/Settings.h +++ b/Source/Core/DolphinQt/Settings.h @@ -56,6 +56,7 @@ public: void UpdateSystemDark(); void SetSystemDark(bool dark); bool IsSystemDark(); + bool IsThemeDark(); void SetCurrentUserStyle(const QString& stylesheet_name); QString GetCurrentUserStyle() const; diff --git a/Source/Core/DolphinQt/SkylanderPortal/SkylanderPortalWindow.cpp b/Source/Core/DolphinQt/SkylanderPortal/SkylanderPortalWindow.cpp index af3d463b8c..2ef2d43edb 100644 --- a/Source/Core/DolphinQt/SkylanderPortal/SkylanderPortalWindow.cpp +++ b/Source/Core/DolphinQt/SkylanderPortal/SkylanderPortalWindow.cpp @@ -612,6 +612,8 @@ void SkylanderPortalWindow::UpdateCurrentIDs() void SkylanderPortalWindow::RefreshList() { + const bool is_dark_theme = Settings::Instance().IsThemeDark(); + const int row = m_skylander_list->currentRow(); m_skylander_list->clear(); if (m_only_show_collection->isChecked()) @@ -635,8 +637,16 @@ void SkylanderPortalWindow::RefreshList() { const uint qvar = (ids.first << 16) | ids.second; QListWidgetItem* skylander = new QListWidgetItem(file.baseName()); - skylander->setBackground(GetBaseColor(ids)); - skylander->setForeground(QBrush(QColor(0, 0, 0, 255))); + if (is_dark_theme) + { + skylander->setBackground(GetBaseColor(ids, true)); + skylander->setForeground(QBrush(QColor(220, 220, 220))); + } + else + { + skylander->setBackground(GetBaseColor(ids, false)); + skylander->setForeground(QBrush(QColor(0, 0, 0))); + } skylander->setData(1, qvar); m_skylander_list->addItem(skylander); } @@ -652,8 +662,16 @@ void SkylanderPortalWindow::RefreshList() { const uint qvar = (entry.first.first << 16) | entry.first.second; QListWidgetItem* skylander = new QListWidgetItem(tr(entry.second.name)); - skylander->setBackground(GetBaseColor(entry.first)); - skylander->setForeground(QBrush(QColor(0, 0, 0, 255))); + if (is_dark_theme) + { + skylander->setBackground(GetBaseColor(entry.first, true)); + skylander->setForeground(QBrush(QColor(220, 220, 220))); + } + else + { + skylander->setBackground(GetBaseColor(entry.first, false)); + skylander->setForeground(QBrush(QColor(0, 0, 0))); + } skylander->setData(1, qvar); m_skylander_list->addItem(skylander); } @@ -897,27 +915,27 @@ int SkylanderPortalWindow::GetElementRadio() return -1; } -QBrush SkylanderPortalWindow::GetBaseColor(std::pair ids) +QBrush SkylanderPortalWindow::GetBaseColor(std::pair ids, bool dark_theme) { auto skylander = IOS::HLE::USB::list_skylanders.find(ids); if (skylander == IOS::HLE::USB::list_skylanders.end()) - return QBrush(QColor(255, 255, 255, 255)); + return QBrush(dark_theme ? QColor(32, 32, 32) : QColor(255, 255, 255)); switch ((*skylander).second.game) { case IOS::HLE::USB::Game::SpyrosAdv: - return QBrush(QColor(240, 255, 240, 255)); + return QBrush(dark_theme ? QColor(10, 42, 90) : QColor(240, 255, 240)); case IOS::HLE::USB::Game::Giants: - return QBrush(QColor(255, 240, 215, 255)); + return QBrush(dark_theme ? QColor(120, 16, 12) : QColor(255, 240, 215)); case IOS::HLE::USB::Game::SwapForce: - return QBrush(QColor(240, 245, 255, 255)); + return QBrush(dark_theme ? QColor(28, 45, 12) : QColor(240, 245, 255)); case IOS::HLE::USB::Game::TrapTeam: - return QBrush(QColor(255, 240, 240, 255)); + return QBrush(dark_theme ? QColor(0, 56, 76) : QColor(255, 240, 240)); case IOS::HLE::USB::Game::Superchargers: - return QBrush(QColor(247, 228, 215, 255)); + return QBrush(dark_theme ? QColor(90, 12, 12) : QColor(247, 228, 215)); default: - return QBrush(QColor(255, 255, 255, 255)); + return QBrush(dark_theme ? QColor(32, 32, 32) : QColor(255, 255, 255)); } } diff --git a/Source/Core/DolphinQt/SkylanderPortal/SkylanderPortalWindow.h b/Source/Core/DolphinQt/SkylanderPortal/SkylanderPortalWindow.h index 72ce63420a..293b056199 100644 --- a/Source/Core/DolphinQt/SkylanderPortal/SkylanderPortalWindow.h +++ b/Source/Core/DolphinQt/SkylanderPortal/SkylanderPortalWindow.h @@ -37,6 +37,8 @@ public: explicit SkylanderPortalWindow(QWidget* parent = nullptr); ~SkylanderPortalWindow() override; + void RefreshList(); + protected: std::array m_edit_skylanders; std::array, MAX_SKYLANDERS> m_sky_slots; @@ -60,7 +62,6 @@ private: // Behind the scenes void OnEmulationStateChanged(Core::State state); void OnCollectionPathChanged(); - void RefreshList(); void UpdateCurrentIDs(); void CreateSkyfile(const QString& path, bool load_after); void LoadSkyfilePath(u8 slot, const QString& path); @@ -71,7 +72,7 @@ private: QString GetFilePath(u16 id, u16 var); u8 GetCurrentSlot(); int GetElementRadio(); - QBrush GetBaseColor(std::pair ids); + QBrush GetBaseColor(std::pair ids, bool dark_theme); int GetGameID(IOS::HLE::USB::Game game); int GetElementID(IOS::HLE::USB::Element elem);