From 837bf7524fc5a8a008a52699746d2552f7385c9a Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 30 Sep 2023 17:51:48 +0300 Subject: [PATCH] Add dark theme button --- include/panda_qt/main_window.hpp | 8 +++++++ src/panda_qt/main_window.cpp | 36 +++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/include/panda_qt/main_window.hpp b/include/panda_qt/main_window.hpp index 5bb4f80c..668b1751 100644 --- a/include/panda_qt/main_window.hpp +++ b/include/panda_qt/main_window.hpp @@ -1,6 +1,9 @@ #pragma once #include +#include +#include +#include #include #include "panda_qt/screen.hpp" @@ -9,8 +12,13 @@ class MainWindow : public QMainWindow { Q_OBJECT private: + QMenuBar* menuBar = nullptr; + QPushButton* themeButton = nullptr; ScreenWidget screen; + void setDarkTheme(); + public: MainWindow(QApplication* app, QWidget* parent = nullptr); + ~MainWindow(); }; \ No newline at end of file diff --git a/src/panda_qt/main_window.cpp b/src/panda_qt/main_window.cpp index 50b06adc..2c3b83a5 100644 --- a/src/panda_qt/main_window.cpp +++ b/src/panda_qt/main_window.cpp @@ -4,7 +4,41 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent) setWindowTitle("Alber"); // Enable drop events for loading ROMs setAcceptDrops(true); - resize(320, 240); screen.show(); + + // Set our menu bar up + menuBar = new QMenuBar(this); + setMenuBar(menuBar); + + auto pandaMenu = menuBar->addMenu(tr("PANDA")); + auto pandaAction = pandaMenu->addAction(tr("panda...")); + + auto themeButton = new QPushButton(tr("Dark theme"), this); + themeButton->setGeometry(40, 40, 100, 400); + themeButton->show(); + connect(themeButton, &QPushButton::pressed, this, [&]() { setDarkTheme(); }); +} + +MainWindow::~MainWindow() { delete menuBar; } + +void MainWindow::setDarkTheme() { + QApplication::setStyle(QStyleFactory::create("Fusion")); + + QPalette p; + p.setColor(QPalette::Window, QColor(53, 53, 53)); + p.setColor(QPalette::WindowText, Qt::white); + p.setColor(QPalette::Base, QColor(25, 25, 25)); + p.setColor(QPalette::AlternateBase, QColor(53, 53, 53)); + p.setColor(QPalette::ToolTipBase, Qt::white); + p.setColor(QPalette::ToolTipText, Qt::white); + p.setColor(QPalette::Text, Qt::white); + p.setColor(QPalette::Button, QColor(53, 53, 53)); + p.setColor(QPalette::ButtonText, Qt::white); + p.setColor(QPalette::BrightText, Qt::red); + p.setColor(QPalette::Link, QColor(42, 130, 218)); + + p.setColor(QPalette::Highlight, QColor(42, 130, 218)); + p.setColor(QPalette::HighlightedText, Qt::black); + qApp->setPalette(p); } \ No newline at end of file