gui: Add Dark Mode support with toggle switch

- Added dark.qss stylesheet for dark theme
- Implemented toggleTheme() slot in PalladiumGUI
- Added 'Dark Mode' checkbox to Settings menu
- Theme preference is saved in QSettings (darkModeEnabled)
- Updated palladium.qrc to include style resources
This commit is contained in:
NotRin7
2025-11-18 17:34:01 +01:00
parent 4063da67c3
commit 91975bb8bb
4 changed files with 199 additions and 1 deletions

View File

@@ -83,4 +83,8 @@
<file alias="spinner-034">res/movies/spinner-034.png</file>
<file alias="spinner-035">res/movies/spinner-035.png</file>
</qresource>
<qresource prefix="/">
<file>res/styles/dark.qss</file>
</qresource>
</RCC>

View File

@@ -61,6 +61,8 @@
#include <QVBoxLayout>
#include <QWindow>
#include <QFile>
#include <QTextStream>
const std::string PalladiumGUI::DEFAULT_UIPLATFORM =
#if defined(Q_OS_MAC)
@@ -79,7 +81,25 @@ PalladiumGUI::PalladiumGUI(interfaces::Node& node, const PlatformStyle *_platfor
platformStyle(_platformStyle),
m_network_style(networkStyle)
{
// --- DARK MODE AUTO-LOAD ---
QSettings settings;
bool isDark = settings.value("darkModeEnabled", false).toBool();
if (isDark) {
// Stylesheet laden
QFile f(":/res/styles/dark.qss");
if (f.open(QFile::ReadOnly | QFile::Text)) {
QTextStream ts(&f);
qApp->setStyleSheet(ts.readAll());
f.close();
}
// Wichtig: Den Haken im Menü setzen!
if(themeAction) {
themeAction->setChecked(true);
}
}
//QSettings settings;
if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) {
// Restore failed (perhaps missing setting), center the window
move(QGuiApplication::primaryScreen()->availableGeometry().center() - frameGeometry().center());
@@ -414,6 +434,10 @@ void PalladiumGUI::createActions()
connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C), this), &QShortcut::activated, this, &PalladiumGUI::showDebugWindowActivateConsole);
connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_D), this), &QShortcut::activated, this, &PalladiumGUI::showDebugWindow);
themeAction = new QAction(tr("&Dark Mode"), this);
themeAction->setCheckable(true);
connect(themeAction, SIGNAL(triggered()), this, SLOT(toggleTheme()));
}
void PalladiumGUI::createMenuBar()
@@ -506,6 +530,8 @@ void PalladiumGUI::createMenuBar()
help->addSeparator();
help->addAction(aboutAction);
help->addAction(aboutQtAction);
settings->addAction(themeAction);
}
void PalladiumGUI::createToolBars()
@@ -1463,3 +1489,23 @@ void UnitDisplayStatusBarControl::onMenuSelection(QAction* action)
optionsModel->setDisplayUnit(action->data());
}
}
void PalladiumGUI::toggleTheme()
{
QSettings settings;
if (themeAction->isChecked()) {
// 1. Dark Mode laden
QFile f(":/res/styles/dark.qss");
if (f.open(QFile::ReadOnly | QFile::Text)) {
QTextStream ts(&f);
qApp->setStyleSheet(ts.readAll());
f.close();
}
// 2. Speichern, dass er an ist
settings.setValue("darkModeEnabled", true);
} else {
// 1. Standard Theme (Weiß)
qApp->setStyleSheet("");
// 2. Speichern, dass er aus ist
settings.setValue("darkModeEnabled", false);
}
}

View File

@@ -153,7 +153,7 @@ private:
QAction* m_close_wallet_action{nullptr};
QAction* m_wallet_selector_label_action = nullptr;
QAction* m_wallet_selector_action = nullptr;
QAction *themeAction;
QLabel *m_wallet_selector_label = nullptr;
QComboBox* m_wallet_selector = nullptr;
@@ -308,6 +308,8 @@ public Q_SLOTS:
void setTrayIconVisible(bool);
void showModalOverlay();
void toggleTheme();
};
class UnitDisplayStatusBarControl : public QLabel

146
src/qt/res/styles/dark.qss Normal file
View File

@@ -0,0 +1,146 @@
/* =======================================================
PALLADIUM CORE DARK THEME (dark.qss)
======================================================= */
/* --- GRUNDLAGEN --- */
QWidget {
background-color: #2D2D2D;
color: #E0E0E0;
selection-background-color: #007BFF;
selection-color: #FFFFFF;
outline: none;
}
/* --- MENÜLEISTE (Oben: File, Settings...) --- */
QMenuBar {
background-color: #2D2D2D;
color: #E0E0E0;
border-bottom: 1px solid #3A3A3A;
}
QMenuBar::item {
background-color: transparent;
padding: 6px 10px;
}
QMenuBar::item:selected {
background-color: #3A3A3A;
}
QMenu {
background-color: #2D2D2D;
border: 1px solid #555;
}
QMenu::item {
padding: 5px 20px;
}
QMenu::item:selected {
background-color: #007BFF;
color: white;
}
/* --- TOOLBAR (Die Icons oben) --- */
/* Wir machen sie etwas heller, damit schwarze Icons sichtbar bleiben */
QToolBar {
background-color: #3D3D3D;
border-bottom: 1px solid #3A3A3A;
padding: 2px;
spacing: 5px;
}
QToolButton {
background-color: transparent;
border: 1px solid transparent;
border-radius: 4px;
padding: 4px;
color: #E0E0E0;
}
QToolButton:hover {
background-color: #4D4D4D;
border: 1px solid #555;
}
QToolButton:checked {
background-color: #007BFF;
color: white;
}
/* --- TABS (Overview, Send, Receive) --- */
QTabWidget::pane {
border: 1px solid #3A3A3A;
}
QTabBar::tab {
background: #1E1E1E;
color: #AAAAAA;
padding: 8px 20px;
border: 1px solid #3A3A3A;
border-bottom: none;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
margin-right: 2px;
}
QTabBar::tab:selected {
background: #2D2D2D; /* Gleiche Farbe wie Hintergrund */
color: #FFFFFF;
border-bottom: 1px solid #2D2D2D; /* "Verbindet" den Tab mit dem Inhalt */
font-weight: bold;
}
/* --- EINGABEFELDER --- */
QLineEdit, QTextEdit, QPlainTextEdit, QSpinBox, QDoubleSpinBox {
background-color: #1E1E1E;
color: #FFFFFF;
border: 1px solid #3A3A3A;
border-radius: 3px;
padding: 4px;
}
QLineEdit:focus {
border: 1px solid #007BFF;
}
/* --- LISTEN & TABELLEN (Transaktionen) --- */
QTableView, QListView, QTreeWidget {
background-color: #1E1E1E;
alternate-background-color: #252525;
color: #E0E0E0;
gridline-color: #333;
border: 1px solid #3A3A3A;
}
QHeaderView::section {
background-color: #333;
color: #E0E0E0;
padding: 4px;
border: 1px solid #444;
}
/* --- BUTTONS --- */
QPushButton {
background-color: #444;
border: 1px solid #555;
border-radius: 4px;
padding: 5px 15px;
color: white;
}
QPushButton:hover {
background-color: #555;
}
QPushButton:pressed {
background-color: #007BFF;
border-color: #007BFF;
}
/* --- STATUSBAR (Unten) --- */
QStatusBar {
background-color: #2D2D2D;
color: #888;
border-top: 1px solid #3A3A3A;
}