DolphinQt: Adjust panel-specific colors and syntax highlighting for dark theme.

This commit is contained in:
Admiral H. Curtiss 2023-08-01 20:47:17 +02:00
parent c2e29153e9
commit 24012cfc7f
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
8 changed files with 97 additions and 28 deletions

View File

@ -3,6 +3,11 @@
#include "DolphinQt/Config/GameConfigHighlighter.h"
#include <QBrush>
#include <QColor>
#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(

View File

@ -6,6 +6,8 @@
#include <optional>
#include <thread>
#include <QBrush>
#include <QColor>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QHeaderView>
@ -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

View File

@ -307,7 +307,7 @@ void CodeViewWidget::Update(const Core::CPUThreadGuard* guard)
const std::optional<u32> 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")

View File

@ -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.

View File

@ -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)
{

View File

@ -56,6 +56,7 @@ public:
void UpdateSystemDark();
void SetSystemDark(bool dark);
bool IsSystemDark();
bool IsThemeDark();
void SetCurrentUserStyle(const QString& stylesheet_name);
QString GetCurrentUserStyle() const;

View File

@ -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<const u16, const u16> ids)
QBrush SkylanderPortalWindow::GetBaseColor(std::pair<const u16, const u16> 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));
}
}

View File

@ -37,6 +37,8 @@ public:
explicit SkylanderPortalWindow(QWidget* parent = nullptr);
~SkylanderPortalWindow() override;
void RefreshList();
protected:
std::array<QLineEdit*, MAX_SKYLANDERS> m_edit_skylanders;
std::array<std::optional<Skylander>, 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<const u16, const u16> ids);
QBrush GetBaseColor(std::pair<const u16, const u16> ids, bool dark_theme);
int GetGameID(IOS::HLE::USB::Game game);
int GetElementID(IOS::HLE::USB::Element elem);