From 6b039e4b7f8cf37eb530667eabb1b1e97c01de28 Mon Sep 17 00:00:00 2001 From: "DIASPORA\\chris" Date: Thu, 1 Jan 2026 03:08:34 +0100 Subject: [PATCH] Add light/dark mode switch --- bcmainwindow.cpp | 27 ++++++++++++++++++++++ bcmainwindow.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/bcmainwindow.cpp b/bcmainwindow.cpp index bf83904..924fe98 100644 --- a/bcmainwindow.cpp +++ b/bcmainwindow.cpp @@ -166,6 +166,33 @@ void BCMainWindow::initMainWindow() // die Daten des eBikes laden _dataManager.loadXmlBikeData(":/bikeinfo.xml"_L1); _consoleAction->trigger(); + + + // --- STATUSBAR SETUP --- + QStatusBar *statBar = statusBar(); + + // Optional: Normale Nachricht links + statBar->showMessage("Ready"); + + // 1. Unseren Switcher erstellen + ThemeSwitchButton *themeBtn = new ThemeSwitchButton(this); + + // 2. WICHTIG: Rechts hinzufügen + statBar->addPermanentWidget(themeBtn); + + // 3. Signal verbinden: Button klick -> Theme ändern + connect(themeBtn, &ThemeSwitchButton::themeChanged, this, [this](bool isDark){ + if (isDark) + { + //applyFluentDarkTheme(*qApp); // Funktion von vorhin + statusBar()->showMessage("Dark Mode Activated", 3000); + } + else + { + //applyFluentLightTheme(*qApp); // Funktion von vorhin + statusBar()->showMessage("Light Mode Activated", 3000); + } + }); } diff --git a/bcmainwindow.h b/bcmainwindow.h index 67d60e0..ba4cf0f 100644 --- a/bcmainwindow.h +++ b/bcmainwindow.h @@ -88,4 +88,62 @@ protected: }; + + +class ThemeSwitchButton : public QPushButton +{ + Q_OBJECT + +public: + explicit ThemeSwitchButton(QWidget *parent = nullptr) + : QPushButton(parent), m_isDarkMode(true) + { + // 1. Visuelles Setup: Flach, keine Ränder, Hand-Cursor + setFlat(true); + setCursor(Qt::PointingHandCursor); + setFixedSize(24, 24); // Kleiner Footprint im StatusBar + + // CSS: Transparent, damit es sich nahtlos in den StatusBar einfügt + // Schriftgröße etwas erhöhen, damit die Emojis gut erkennbar sind + setStyleSheet(R"( + QPushButton { + border: none; + background-color: transparent; + font-size: 11pt; + } + QPushButton:hover { + background-color: rgba(128, 128, 128, 30); // Leichter Hover-Effekt + border-radius: 4px; + } + )"); + + // 2. Initialer Status (Startet im Dark Mode -> zeigt Mond) + updateIcon(); + + // 3. Klick verbinden + connect(this, &QPushButton::clicked, this, &ThemeSwitchButton::toggle); + } + +signals: + void themeChanged(bool isDark); + +private slots: + void toggle() { + m_isDarkMode = !m_isDarkMode; + updateIcon(); + emit themeChanged(m_isDarkMode); + } + +private: + void updateIcon() { + // Logik: + // Ist Dark Mode an? Zeige Mond (oder Sonne, je nach Geschmack). + // Hier: Zeige das Symbol des AKTUELLEN Modus. + setText(m_isDarkMode ? "🌙" : "☀️"); + setToolTip(m_isDarkMode ? "Switch to Light Mode" : "Switch to Dark Mode"); + } + + bool m_isDarkMode; +}; + #endif // BCMAINWINDOW_H