mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-03-12 06:39:14 +01:00
DolphinQt: Adjust panel-specific colors and syntax highlighting for dark theme.
This commit is contained in:
parent
c2e29153e9
commit
24012cfc7f
@ -3,6 +3,11 @@
|
|||||||
|
|
||||||
#include "DolphinQt/Config/GameConfigHighlighter.h"
|
#include "DolphinQt/Config/GameConfigHighlighter.h"
|
||||||
|
|
||||||
|
#include <QBrush>
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
|
#include "DolphinQt/Settings.h"
|
||||||
|
|
||||||
struct HighlightingRule
|
struct HighlightingRule
|
||||||
{
|
{
|
||||||
QRegularExpression pattern;
|
QRegularExpression pattern;
|
||||||
@ -13,22 +18,36 @@ GameConfigHighlighter::~GameConfigHighlighter() = default;
|
|||||||
|
|
||||||
GameConfigHighlighter::GameConfigHighlighter(QTextDocument* parent) : QSyntaxHighlighter(parent)
|
GameConfigHighlighter::GameConfigHighlighter(QTextDocument* parent) : QSyntaxHighlighter(parent)
|
||||||
{
|
{
|
||||||
|
const bool is_dark_theme = Settings::Instance().IsThemeDark();
|
||||||
|
|
||||||
QTextCharFormat equal_format;
|
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;
|
QTextCharFormat section_format;
|
||||||
section_format.setFontWeight(QFont::Bold);
|
section_format.setFontWeight(QFont::Bold);
|
||||||
|
|
||||||
QTextCharFormat comment_format;
|
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);
|
comment_format.setFontItalic(true);
|
||||||
|
|
||||||
QTextCharFormat const_format;
|
QTextCharFormat const_format;
|
||||||
const_format.setFontWeight(QFont::Bold);
|
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;
|
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(HighlightingRule{QRegularExpression(QStringLiteral("=")), equal_format});
|
||||||
m_rules.emplace_back(
|
m_rules.emplace_back(
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
#include <QBrush>
|
||||||
|
#include <QColor>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
@ -38,7 +40,6 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// TODO: Make sure these functions return colors that will be visible in the current theme.
|
|
||||||
QTextCharFormat GetSpecialCharFormat()
|
QTextCharFormat GetSpecialCharFormat()
|
||||||
{
|
{
|
||||||
QTextCharFormat format;
|
QTextCharFormat format;
|
||||||
@ -49,7 +50,10 @@ QTextCharFormat GetSpecialCharFormat()
|
|||||||
QTextCharFormat GetLiteralCharFormat()
|
QTextCharFormat GetLiteralCharFormat()
|
||||||
{
|
{
|
||||||
QTextCharFormat format;
|
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;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,35 +61,50 @@ QTextCharFormat GetInvalidCharFormat()
|
|||||||
{
|
{
|
||||||
QTextCharFormat format;
|
QTextCharFormat format;
|
||||||
format.setUnderlineStyle(QTextCharFormat::WaveUnderline);
|
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;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCharFormat GetControlCharFormat()
|
QTextCharFormat GetControlCharFormat()
|
||||||
{
|
{
|
||||||
QTextCharFormat format;
|
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;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCharFormat GetVariableCharFormat()
|
QTextCharFormat GetVariableCharFormat()
|
||||||
{
|
{
|
||||||
QTextCharFormat format;
|
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;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCharFormat GetBarewordCharFormat()
|
QTextCharFormat GetBarewordCharFormat()
|
||||||
{
|
{
|
||||||
QTextCharFormat format;
|
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;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCharFormat GetCommentCharFormat()
|
QTextCharFormat GetCommentCharFormat()
|
||||||
{
|
{
|
||||||
QTextCharFormat format;
|
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;
|
return format;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -307,7 +307,7 @@ void CodeViewWidget::Update(const Core::CPUThreadGuard* guard)
|
|||||||
const std::optional<u32> pc =
|
const std::optional<u32> pc =
|
||||||
guard ? std::make_optional(power_pc.GetPPCState().pc) : std::nullopt;
|
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();
|
m_branches.clear();
|
||||||
|
|
||||||
@ -350,7 +350,7 @@ void CodeViewWidget::Update(const Core::CPUThreadGuard* guard)
|
|||||||
}
|
}
|
||||||
else if (color != 0xFFFFFF)
|
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(
|
description_item->setText(
|
||||||
tr("--> %1").arg(QString::fromStdString(debug_interface.GetDescription(branch_addr))));
|
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")
|
if (ins == "blr")
|
||||||
|
@ -1728,8 +1728,14 @@ bool MainWindow::nativeEvent(const QByteArray& eventType, void* message, qintptr
|
|||||||
const bool was_dark_before = settings.IsSystemDark();
|
const bool was_dark_before = settings.IsSystemDark();
|
||||||
settings.UpdateSystemDark();
|
settings.UpdateSystemDark();
|
||||||
if (settings.IsSystemDark() != was_dark_before)
|
if (settings.IsSystemDark() != was_dark_before)
|
||||||
|
{
|
||||||
settings.SetCurrentUserStyle(settings.GetCurrentUserStyle());
|
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
|
// 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
|
// 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.
|
// to dark here, Qt sets them back to light afterwards.
|
||||||
|
@ -163,6 +163,11 @@ bool Settings::IsSystemDark()
|
|||||||
return s_system_dark;
|
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.
|
// Calling this before the main window has been created breaks the style of some widgets.
|
||||||
void Settings::SetCurrentUserStyle(const QString& stylesheet_name)
|
void Settings::SetCurrentUserStyle(const QString& stylesheet_name)
|
||||||
{
|
{
|
||||||
|
@ -56,6 +56,7 @@ public:
|
|||||||
void UpdateSystemDark();
|
void UpdateSystemDark();
|
||||||
void SetSystemDark(bool dark);
|
void SetSystemDark(bool dark);
|
||||||
bool IsSystemDark();
|
bool IsSystemDark();
|
||||||
|
bool IsThemeDark();
|
||||||
void SetCurrentUserStyle(const QString& stylesheet_name);
|
void SetCurrentUserStyle(const QString& stylesheet_name);
|
||||||
QString GetCurrentUserStyle() const;
|
QString GetCurrentUserStyle() const;
|
||||||
|
|
||||||
|
@ -612,6 +612,8 @@ void SkylanderPortalWindow::UpdateCurrentIDs()
|
|||||||
|
|
||||||
void SkylanderPortalWindow::RefreshList()
|
void SkylanderPortalWindow::RefreshList()
|
||||||
{
|
{
|
||||||
|
const bool is_dark_theme = Settings::Instance().IsThemeDark();
|
||||||
|
|
||||||
const int row = m_skylander_list->currentRow();
|
const int row = m_skylander_list->currentRow();
|
||||||
m_skylander_list->clear();
|
m_skylander_list->clear();
|
||||||
if (m_only_show_collection->isChecked())
|
if (m_only_show_collection->isChecked())
|
||||||
@ -635,8 +637,16 @@ void SkylanderPortalWindow::RefreshList()
|
|||||||
{
|
{
|
||||||
const uint qvar = (ids.first << 16) | ids.second;
|
const uint qvar = (ids.first << 16) | ids.second;
|
||||||
QListWidgetItem* skylander = new QListWidgetItem(file.baseName());
|
QListWidgetItem* skylander = new QListWidgetItem(file.baseName());
|
||||||
skylander->setBackground(GetBaseColor(ids));
|
if (is_dark_theme)
|
||||||
skylander->setForeground(QBrush(QColor(0, 0, 0, 255)));
|
{
|
||||||
|
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);
|
skylander->setData(1, qvar);
|
||||||
m_skylander_list->addItem(skylander);
|
m_skylander_list->addItem(skylander);
|
||||||
}
|
}
|
||||||
@ -652,8 +662,16 @@ void SkylanderPortalWindow::RefreshList()
|
|||||||
{
|
{
|
||||||
const uint qvar = (entry.first.first << 16) | entry.first.second;
|
const uint qvar = (entry.first.first << 16) | entry.first.second;
|
||||||
QListWidgetItem* skylander = new QListWidgetItem(tr(entry.second.name));
|
QListWidgetItem* skylander = new QListWidgetItem(tr(entry.second.name));
|
||||||
skylander->setBackground(GetBaseColor(entry.first));
|
if (is_dark_theme)
|
||||||
skylander->setForeground(QBrush(QColor(0, 0, 0, 255)));
|
{
|
||||||
|
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);
|
skylander->setData(1, qvar);
|
||||||
m_skylander_list->addItem(skylander);
|
m_skylander_list->addItem(skylander);
|
||||||
}
|
}
|
||||||
@ -897,27 +915,27 @@ int SkylanderPortalWindow::GetElementRadio()
|
|||||||
return -1;
|
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);
|
auto skylander = IOS::HLE::USB::list_skylanders.find(ids);
|
||||||
|
|
||||||
if (skylander == IOS::HLE::USB::list_skylanders.end())
|
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)
|
switch ((*skylander).second.game)
|
||||||
{
|
{
|
||||||
case IOS::HLE::USB::Game::SpyrosAdv:
|
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:
|
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:
|
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:
|
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:
|
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:
|
default:
|
||||||
return QBrush(QColor(255, 255, 255, 255));
|
return QBrush(dark_theme ? QColor(32, 32, 32) : QColor(255, 255, 255));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,8 @@ public:
|
|||||||
explicit SkylanderPortalWindow(QWidget* parent = nullptr);
|
explicit SkylanderPortalWindow(QWidget* parent = nullptr);
|
||||||
~SkylanderPortalWindow() override;
|
~SkylanderPortalWindow() override;
|
||||||
|
|
||||||
|
void RefreshList();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::array<QLineEdit*, MAX_SKYLANDERS> m_edit_skylanders;
|
std::array<QLineEdit*, MAX_SKYLANDERS> m_edit_skylanders;
|
||||||
std::array<std::optional<Skylander>, MAX_SKYLANDERS> m_sky_slots;
|
std::array<std::optional<Skylander>, MAX_SKYLANDERS> m_sky_slots;
|
||||||
@ -60,7 +62,6 @@ private:
|
|||||||
// Behind the scenes
|
// Behind the scenes
|
||||||
void OnEmulationStateChanged(Core::State state);
|
void OnEmulationStateChanged(Core::State state);
|
||||||
void OnCollectionPathChanged();
|
void OnCollectionPathChanged();
|
||||||
void RefreshList();
|
|
||||||
void UpdateCurrentIDs();
|
void UpdateCurrentIDs();
|
||||||
void CreateSkyfile(const QString& path, bool load_after);
|
void CreateSkyfile(const QString& path, bool load_after);
|
||||||
void LoadSkyfilePath(u8 slot, const QString& path);
|
void LoadSkyfilePath(u8 slot, const QString& path);
|
||||||
@ -71,7 +72,7 @@ private:
|
|||||||
QString GetFilePath(u16 id, u16 var);
|
QString GetFilePath(u16 id, u16 var);
|
||||||
u8 GetCurrentSlot();
|
u8 GetCurrentSlot();
|
||||||
int GetElementRadio();
|
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 GetGameID(IOS::HLE::USB::Game game);
|
||||||
int GetElementID(IOS::HLE::USB::Element elem);
|
int GetElementID(IOS::HLE::USB::Element elem);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user