Skip to content

Commit

Permalink
Merge pull request #149 from cristian64/unix_dark_theme
Browse files Browse the repository at this point in the history
Add Light, Dark Gray, and Dark themes along with the System theme.
  • Loading branch information
dreamsyntax authored May 24, 2024
2 parents c7d0d7f + 249abbf commit 0f988e3
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 15 deletions.
185 changes: 180 additions & 5 deletions Source/GUI/GUICommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <QApplication>
#include <QCoreApplication>
#include <QFontMetrics>
#include <QStringList>
#include <QToolTip>

namespace GUICommon
{
Expand Down Expand Up @@ -71,15 +73,188 @@ QString getNameFromBase(const Common::MemBase base)
}
}

void changeApplicationStyle(int index)
void changeApplicationStyle(const ApplicationStyle style)
{
if (index == 0)
QApplication::setStyle(QStringLiteral("fusion"));

if (style == ApplicationStyle::System)
{
qApp->setPalette({});
QToolTip::setPalette({});
qApp->setStyleSheet({});
return;
}

if (style == ApplicationStyle::Light)
{
QPalette palette;
palette.setColor(QPalette::All, QPalette::Window, QColor(239, 239, 239));
palette.setColor(QPalette::Disabled, QPalette::Window, QColor(239, 239, 239));
palette.setColor(QPalette::All, QPalette::WindowText, QColor(0, 0, 0));
palette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(190, 190, 190));
palette.setColor(QPalette::All, QPalette::Base, QColor(255, 255, 255));
palette.setColor(QPalette::Disabled, QPalette::Base, QColor(239, 239, 239));
palette.setColor(QPalette::All, QPalette::AlternateBase, QColor(247, 247, 247));
palette.setColor(QPalette::Disabled, QPalette::AlternateBase, QColor(247, 247, 247));
palette.setColor(QPalette::All, QPalette::ToolTipBase, QColor(255, 255, 220));
palette.setColor(QPalette::Disabled, QPalette::ToolTipBase, QColor(255, 255, 220));
palette.setColor(QPalette::All, QPalette::ToolTipText, QColor(0, 0, 0));
palette.setColor(QPalette::Disabled, QPalette::ToolTipText, QColor(0, 0, 0));
palette.setColor(QPalette::All, QPalette::PlaceholderText, QColor(119, 119, 119));
palette.setColor(QPalette::Disabled, QPalette::PlaceholderText, QColor(119, 119, 119));
palette.setColor(QPalette::All, QPalette::Text, QColor(0, 0, 0));
palette.setColor(QPalette::Disabled, QPalette::Text, QColor(190, 190, 190));
palette.setColor(QPalette::All, QPalette::Button, QColor(239, 239, 239));
palette.setColor(QPalette::Disabled, QPalette::Button, QColor(239, 239, 239));
palette.setColor(QPalette::All, QPalette::ButtonText, QColor(0, 0, 0));
palette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(190, 190, 190));
palette.setColor(QPalette::All, QPalette::BrightText, QColor(255, 255, 255));
palette.setColor(QPalette::Disabled, QPalette::BrightText, QColor(255, 255, 255));
palette.setColor(QPalette::All, QPalette::Light, QColor(255, 255, 255));
palette.setColor(QPalette::Disabled, QPalette::Light, QColor(255, 255, 255));
palette.setColor(QPalette::All, QPalette::Midlight, QColor(202, 202, 202));
palette.setColor(QPalette::Disabled, QPalette::Midlight, QColor(202, 202, 202));
palette.setColor(QPalette::All, QPalette::Dark, QColor(159, 159, 159));
palette.setColor(QPalette::Disabled, QPalette::Dark, QColor(190, 190, 190));
palette.setColor(QPalette::All, QPalette::Mid, QColor(184, 184, 184));
palette.setColor(QPalette::Disabled, QPalette::Mid, QColor(184, 184, 184));
palette.setColor(QPalette::All, QPalette::Shadow, QColor(118, 118, 118));
palette.setColor(QPalette::Disabled, QPalette::Shadow, QColor(177, 177, 177));
palette.setColor(QPalette::All, QPalette::Highlight, QColor(48, 140, 198));
palette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(145, 145, 145));
palette.setColor(QPalette::All, QPalette::HighlightedText, QColor(255, 255, 255));
palette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(255, 255, 255));
palette.setColor(QPalette::All, QPalette::Link, QColor(0, 0, 255));
palette.setColor(QPalette::Disabled, QPalette::Link, QColor(0, 0, 255));
palette.setColor(QPalette::All, QPalette::LinkVisited, QColor(255, 0, 255));
palette.setColor(QPalette::Disabled, QPalette::LinkVisited, QColor(255, 0, 255));

qApp->setPalette(palette);
QToolTip::setPalette(palette);

const int padding{QFontMetrics(QFont()).height() / 2};
qApp->setStyleSheet(QString(R"(
QToolTip {
padding: %1px;
border: 1px solid rgb(239, 239, 239);
background: rgb(255, 255, 255);
}
)")
.arg(padding));
}
else if (style == ApplicationStyle::DarkGray)
{
QApplication::setStyle(QStringLiteral("fusion"));
QPalette palette;
palette.setColor(QPalette::All, QPalette::Window, QColor(50, 50, 50));
palette.setColor(QPalette::Disabled, QPalette::Window, QColor(55, 55, 55));
palette.setColor(QPalette::All, QPalette::WindowText, QColor(200, 200, 200));
palette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(108, 108, 108));
palette.setColor(QPalette::All, QPalette::Base, QColor(25, 25, 25));
palette.setColor(QPalette::Disabled, QPalette::Base, QColor(30, 30, 30));
palette.setColor(QPalette::All, QPalette::AlternateBase, QColor(38, 38, 38));
palette.setColor(QPalette::Disabled, QPalette::AlternateBase, QColor(42, 42, 42));
palette.setColor(QPalette::All, QPalette::ToolTipBase, QColor(45, 45, 45));
palette.setColor(QPalette::Disabled, QPalette::ToolTipBase, QColor(45, 45, 45));
palette.setColor(QPalette::All, QPalette::ToolTipText, QColor(200, 200, 200));
palette.setColor(QPalette::Disabled, QPalette::ToolTipText, QColor(200, 200, 200));
palette.setColor(QPalette::All, QPalette::PlaceholderText, QColor(90, 90, 90));
palette.setColor(QPalette::Disabled, QPalette::PlaceholderText, QColor(90, 90, 90));
palette.setColor(QPalette::All, QPalette::Text, QColor(200, 200, 200));
palette.setColor(QPalette::Disabled, QPalette::Text, QColor(108, 108, 108));
palette.setColor(QPalette::All, QPalette::Button, QColor(54, 54, 54));
palette.setColor(QPalette::Disabled, QPalette::Button, QColor(54, 54, 54));
palette.setColor(QPalette::All, QPalette::ButtonText, QColor(200, 200, 200));
palette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(108, 108, 108));
palette.setColor(QPalette::All, QPalette::BrightText, QColor(75, 75, 75));
palette.setColor(QPalette::Disabled, QPalette::BrightText, QColor(255, 255, 255));
palette.setColor(QPalette::All, QPalette::Light, QColor(26, 26, 26));
palette.setColor(QPalette::Disabled, QPalette::Light, QColor(26, 26, 26));
palette.setColor(QPalette::All, QPalette::Midlight, QColor(40, 40, 40));
palette.setColor(QPalette::Disabled, QPalette::Midlight, QColor(40, 40, 40));
palette.setColor(QPalette::All, QPalette::Dark, QColor(108, 108, 108));
palette.setColor(QPalette::Disabled, QPalette::Dark, QColor(108, 108, 108));
palette.setColor(QPalette::All, QPalette::Mid, QColor(71, 71, 71));
palette.setColor(QPalette::Disabled, QPalette::Mid, QColor(71, 71, 71));
palette.setColor(QPalette::All, QPalette::Shadow, QColor(25, 25, 25));
palette.setColor(QPalette::Disabled, QPalette::Shadow, QColor(37, 37, 37));
palette.setColor(QPalette::All, QPalette::Highlight, QColor(45, 140, 225));
palette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(45, 140, 225).darker());
palette.setColor(QPalette::All, QPalette::HighlightedText, QColor(255, 255, 255));
palette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(40, 40, 40));
palette.setColor(QPalette::All, QPalette::Link, QColor(40, 130, 220));
palette.setColor(QPalette::Disabled, QPalette::Link, QColor(40, 130, 220).darker());
palette.setColor(QPalette::All, QPalette::LinkVisited, QColor(110, 70, 150));
palette.setColor(QPalette::Disabled, QPalette::LinkVisited, QColor(110, 70, 150).darker());

qApp->setPalette(palette);
QToolTip::setPalette(palette);

const int padding{QFontMetrics(QFont()).height() / 2};
qApp->setStyleSheet(QString(R"(
QToolTip {
padding: %1px;
border: 1px solid rgb(30, 30, 30);
background: rgb(45, 45, 45);
}
)")
.arg(padding));
}
else if (index == 1)
else if (style == ApplicationStyle::Dark)
{
QApplication::setStyle(QStringLiteral("windowsvista"));
QPalette palette;
palette.setColor(QPalette::All, QPalette::Window, QColor(22, 22, 22));
palette.setColor(QPalette::Disabled, QPalette::Window, QColor(30, 30, 30));
palette.setColor(QPalette::All, QPalette::WindowText, QColor(180, 180, 180));
palette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(90, 90, 90));
palette.setColor(QPalette::All, QPalette::Base, QColor(35, 35, 35));
palette.setColor(QPalette::Disabled, QPalette::Base, QColor(30, 30, 30));
palette.setColor(QPalette::All, QPalette::AlternateBase, QColor(40, 40, 40));
palette.setColor(QPalette::Disabled, QPalette::AlternateBase, QColor(35, 35, 35));
palette.setColor(QPalette::All, QPalette::ToolTipBase, QColor(0, 0, 0));
palette.setColor(QPalette::Disabled, QPalette::ToolTipBase, QColor(0, 0, 0));
palette.setColor(QPalette::All, QPalette::ToolTipText, QColor(170, 170, 170));
palette.setColor(QPalette::Disabled, QPalette::ToolTipText, QColor(170, 170, 170));
palette.setColor(QPalette::All, QPalette::PlaceholderText, QColor(100, 100, 100));
palette.setColor(QPalette::Disabled, QPalette::PlaceholderText, QColor(100, 100, 100));
palette.setColor(QPalette::All, QPalette::Text, QColor(200, 200, 200));
palette.setColor(QPalette::Disabled, QPalette::Text, QColor(90, 90, 90));
palette.setColor(QPalette::All, QPalette::Button, QColor(30, 30, 30));
palette.setColor(QPalette::Disabled, QPalette::Button, QColor(20, 20, 20));
palette.setColor(QPalette::All, QPalette::ButtonText, QColor(180, 180, 180));
palette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(90, 90, 90));
palette.setColor(QPalette::All, QPalette::BrightText, QColor(75, 75, 75));
palette.setColor(QPalette::Disabled, QPalette::BrightText, QColor(255, 255, 255));
palette.setColor(QPalette::All, QPalette::Light, QColor(0, 0, 0));
palette.setColor(QPalette::Disabled, QPalette::Light, QColor(0, 0, 0));
palette.setColor(QPalette::All, QPalette::Midlight, QColor(40, 40, 40));
palette.setColor(QPalette::Disabled, QPalette::Midlight, QColor(40, 40, 40));
palette.setColor(QPalette::All, QPalette::Dark, QColor(90, 90, 90));
palette.setColor(QPalette::Disabled, QPalette::Dark, QColor(90, 90, 90));
palette.setColor(QPalette::All, QPalette::Mid, QColor(60, 60, 60));
palette.setColor(QPalette::Disabled, QPalette::Mid, QColor(60, 60, 60));
palette.setColor(QPalette::All, QPalette::Shadow, QColor(10, 10, 10));
palette.setColor(QPalette::Disabled, QPalette::Shadow, QColor(20, 20, 20));
palette.setColor(QPalette::All, QPalette::Highlight, QColor(35, 130, 200));
palette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(35, 130, 200).darker());
palette.setColor(QPalette::All, QPalette::HighlightedText, QColor(240, 240, 240));
palette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(35, 35, 35));
palette.setColor(QPalette::All, QPalette::Link, QColor(40, 130, 220));
palette.setColor(QPalette::Disabled, QPalette::Link, QColor(40, 130, 220).darker());
palette.setColor(QPalette::All, QPalette::LinkVisited, QColor(110, 70, 150));
palette.setColor(QPalette::Disabled, QPalette::LinkVisited, QColor(110, 70, 150).darker());

qApp->setPalette(palette);
QToolTip::setPalette(palette);

const int padding{QFontMetrics(QFont()).height() / 2};
qApp->setStyleSheet(QString(R"(
QToolTip {
padding: %1px;
border: 1px solid rgb(50, 50, 50);
background: rgb(10, 10, 10);
}
)")
.arg(padding));
}
}

Expand Down
10 changes: 9 additions & 1 deletion Source/GUI/GUICommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ extern QStringList g_memBaseNames;
QString getStringFromType(Common::MemType type, size_t length = 0);
QString getNameFromBase(Common::MemBase base);

void changeApplicationStyle(int);
enum class ApplicationStyle
{
System = 0,
Light,
DarkGray,
Dark,
};

void changeApplicationStyle(ApplicationStyle style);

extern bool g_valueEditing;
} // namespace GUICommon
6 changes: 3 additions & 3 deletions Source/GUI/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ MainWindow::MainWindow()
restoreGeometry(SConfig::getInstance().getMainWindowGeometry());
if (SConfig::getInstance().getMainWindowState().size())
restoreState(SConfig::getInstance().getMainWindowState());
#ifdef _WIN32
GUICommon::changeApplicationStyle(SConfig::getInstance().getTheme());
#endif

GUICommon::changeApplicationStyle(
static_cast<GUICommon::ApplicationStyle>(SConfig::getInstance().getTheme()));

m_watcher->restoreWatchModel(SConfig::getInstance().getWatchModel());
m_actAutoHook->setChecked(SConfig::getInstance().getAutoHook());
Expand Down
13 changes: 7 additions & 6 deletions Source/GUI/Settings/DlgSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ DlgSettings::DlgSettings(QWidget* parent) : QDialog(parent)
{
QGroupBox* grbCoreSettings = new QGroupBox("Core settings");
m_cmbTheme = new QComboBox();
m_cmbTheme->addItem("Dark", 0);
m_cmbTheme->addItem("Light", 1);
connect(m_cmbTheme, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
GUICommon::changeApplicationStyle);
m_cmbTheme->addItem("System", static_cast<int>(GUICommon::ApplicationStyle::System));
m_cmbTheme->addItem("Light", static_cast<int>(GUICommon::ApplicationStyle::Light));
m_cmbTheme->addItem("Dark Gray", static_cast<int>(GUICommon::ApplicationStyle::DarkGray));
m_cmbTheme->addItem("Dark", static_cast<int>(GUICommon::ApplicationStyle::Dark));
connect(m_cmbTheme, &QComboBox::currentIndexChanged, this, [](const int index) {
GUICommon::changeApplicationStyle(static_cast<GUICommon::ApplicationStyle>(index));
});

QFormLayout* coreSettingsInputLayout = new QFormLayout();
coreSettingsInputLayout->addRow("Theme", m_cmbTheme);
Expand Down Expand Up @@ -126,9 +129,7 @@ DlgSettings::DlgSettings(QWidget* parent) : QDialog(parent)
grbMemorySizeSettings->setLayout(memorySettingsInputLayout);

QVBoxLayout* mainLayout = new QVBoxLayout;
#ifdef _WIN32
mainLayout->addWidget(grbCoreSettings);
#endif
mainLayout->addWidget(grbTimerSettings);
mainLayout->addWidget(grbScannerSettings);
mainLayout->addWidget(grbViewerSettings);
Expand Down

0 comments on commit 0f988e3

Please sign in to comment.