From 155d2b8f246e8c4e4e09a401ff17db0602eb41c8 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 30 Sep 2023 17:07:54 +0300 Subject: [PATCH 1/4] [Qt] Add MainWindow class --- CMakeLists.txt | 4 ++-- include/panda_qt/main_window.hpp | 16 ++++++++++++++++ src/panda_qt/main.cpp | 10 ++-------- src/panda_qt/main_window.cpp | 10 ++++++++++ src/panda_qt/screen.cpp | 2 ++ 5 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 include/panda_qt/main_window.hpp create mode 100644 src/panda_qt/main_window.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 22294821..2c13d634 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,8 +179,8 @@ set(RENDERER_SW_SOURCE_FILES src/core/renderer_sw/renderer_sw.cpp) # Frontend source files if(ENABLE_QT_GUI) - set(FRONTEND_SOURCE_FILES src/panda_qt/main.cpp src/panda_qt/screen.cpp) - set(FRONTEND_HEADER_FILES include/panda_qt/screen.hpp) + set(FRONTEND_SOURCE_FILES src/panda_qt/main.cpp src/panda_qt/screen.cpp src/panda_qt/main_window.cpp) + set(FRONTEND_HEADER_FILES include/panda_qt/screen.hpp include/panda_qt/main_window.hpp) source_group("Source Files\\Qt" FILES ${FRONTEND_SOURCE_FILES}) source_group("Header Files\\Qt" FILES ${FRONTEND_HEADER_FILES}) diff --git a/include/panda_qt/main_window.hpp b/include/panda_qt/main_window.hpp new file mode 100644 index 00000000..5bb4f80c --- /dev/null +++ b/include/panda_qt/main_window.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +#include "panda_qt/screen.hpp" + +class MainWindow : public QMainWindow { + Q_OBJECT + + private: + ScreenWidget screen; + + public: + MainWindow(QApplication* app, QWidget* parent = nullptr); +}; \ No newline at end of file diff --git a/src/panda_qt/main.cpp b/src/panda_qt/main.cpp index 34e71915..56391e65 100644 --- a/src/panda_qt/main.cpp +++ b/src/panda_qt/main.cpp @@ -1,18 +1,12 @@ #include -#include +#include "panda_qt/main_window.hpp" #include "panda_qt/screen.hpp" int main(int argc, char *argv[]) { QApplication app(argc, argv); - QWidget window; + MainWindow window(&app); - window.resize(320, 240); window.show(); - window.setWindowTitle("Alber"); - ScreenWidget screen(&window); - screen.show(); - screen.resize(320, 240); - return app.exec(); } \ No newline at end of file diff --git a/src/panda_qt/main_window.cpp b/src/panda_qt/main_window.cpp new file mode 100644 index 00000000..50b06adc --- /dev/null +++ b/src/panda_qt/main_window.cpp @@ -0,0 +1,10 @@ +#include "panda_qt/main_window.hpp" + +MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent), screen(this) { + setWindowTitle("Alber"); + // Enable drop events for loading ROMs + setAcceptDrops(true); + + resize(320, 240); + screen.show(); +} \ No newline at end of file diff --git a/src/panda_qt/screen.cpp b/src/panda_qt/screen.cpp index 62cac106..496edb47 100644 --- a/src/panda_qt/screen.cpp +++ b/src/panda_qt/screen.cpp @@ -20,6 +20,8 @@ #ifdef PANDA3DS_ENABLE_OPENGL ScreenWidget::ScreenWidget(QWidget* parent) : QWidget(parent) { // Create a native window for use with our graphics API of choice + resize(320, 240); + setAutoFillBackground(false); setAttribute(Qt::WA_NativeWindow, true); setAttribute(Qt::WA_NoSystemBackground, true); 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 2/4] 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 From 36506e18bb300a1786bd3692a0316bf4746a466d Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 30 Sep 2023 18:35:50 +0300 Subject: [PATCH 3/4] [Qt] Implement theme selection --- include/panda_qt/main_window.hpp | 11 +++-- src/panda_qt/main_window.cpp | 85 ++++++++++++++++++++++++-------- 2 files changed, 72 insertions(+), 24 deletions(-) diff --git a/include/panda_qt/main_window.hpp b/include/panda_qt/main_window.hpp index 668b1751..ebd2407e 100644 --- a/include/panda_qt/main_window.hpp +++ b/include/panda_qt/main_window.hpp @@ -1,9 +1,9 @@ #pragma once #include +#include #include #include -#include #include #include "panda_qt/screen.hpp" @@ -12,11 +12,16 @@ class MainWindow : public QMainWindow { Q_OBJECT private: + enum class Theme : int { + System = 0, Light = 1, Dark = 2, + }; + + QComboBox* themeSelect = nullptr; QMenuBar* menuBar = nullptr; - QPushButton* themeButton = nullptr; ScreenWidget screen; - void setDarkTheme(); + Theme currentTheme; + void setTheme(Theme theme); public: MainWindow(QApplication* app, QWidget* parent = nullptr); diff --git a/src/panda_qt/main_window.cpp b/src/panda_qt/main_window.cpp index 2c3b83a5..e32290c8 100644 --- a/src/panda_qt/main_window.cpp +++ b/src/panda_qt/main_window.cpp @@ -14,31 +14,74 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent) 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(); }); + // Set up theme selection + setTheme(Theme::Dark); + themeSelect = new QComboBox(this); + themeSelect->addItem("System"); + themeSelect->addItem("Light"); + themeSelect->addItem("Dark"); + themeSelect->setCurrentIndex(static_cast(currentTheme)); + + themeSelect->setGeometry(40, 40, 100, 50); + themeSelect->show(); + connect(themeSelect, &QComboBox::currentIndexChanged, this, [&](int index) { setTheme(static_cast(index)); }); } MainWindow::~MainWindow() { delete menuBar; } -void MainWindow::setDarkTheme() { - QApplication::setStyle(QStyleFactory::create("Fusion")); +void MainWindow::setTheme(Theme theme) { + currentTheme = theme; - 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)); + switch (theme) { + case Theme::Dark: { + QApplication::setStyle(QStyleFactory::create("Fusion")); - p.setColor(QPalette::Highlight, QColor(42, 130, 218)); - p.setColor(QPalette::HighlightedText, Qt::black); - qApp->setPalette(p); + 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); + break; + } + + case Theme::Light: { + QApplication::setStyle(QStyleFactory::create("Fusion")); + + QPalette p; + p.setColor(QPalette::Window, Qt::white); + p.setColor(QPalette::WindowText, Qt::black); + p.setColor(QPalette::Base, QColor(243, 243, 243)); + p.setColor(QPalette::AlternateBase, Qt::white); + p.setColor(QPalette::ToolTipBase, Qt::black); + p.setColor(QPalette::ToolTipText, Qt::black); + p.setColor(QPalette::Text, Qt::black); + p.setColor(QPalette::Button, Qt::white); + p.setColor(QPalette::ButtonText, Qt::black); + 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::white); + qApp->setPalette(p); + break; + } + + case Theme::System: { + qApp->setPalette(this->style()->standardPalette()); + qApp->setStyle(QStyleFactory::create("WindowsVista")); + qApp->setStyleSheet(""); + break; + } + } } \ No newline at end of file From 4329976dbcaff0a44598c58090d390246cb3a65b Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 30 Sep 2023 18:39:05 +0300 Subject: [PATCH 4/4] clang-format --- include/panda_qt/main_window.hpp | 4 +++- src/panda_qt/main_window.cpp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/panda_qt/main_window.hpp b/include/panda_qt/main_window.hpp index ebd2407e..2612f04a 100644 --- a/include/panda_qt/main_window.hpp +++ b/include/panda_qt/main_window.hpp @@ -13,7 +13,9 @@ class MainWindow : public QMainWindow { private: enum class Theme : int { - System = 0, Light = 1, Dark = 2, + System = 0, + Light = 1, + Dark = 2, }; QComboBox* themeSelect = nullptr; diff --git a/src/panda_qt/main_window.cpp b/src/panda_qt/main_window.cpp index e32290c8..a27c3319 100644 --- a/src/panda_qt/main_window.cpp +++ b/src/panda_qt/main_window.cpp @@ -10,7 +10,7 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent) // Set our menu bar up menuBar = new QMenuBar(this); setMenuBar(menuBar); - + auto pandaMenu = menuBar->addMenu(tr("PANDA")); auto pandaAction = pandaMenu->addAction(tr("panda...")); @@ -78,7 +78,7 @@ void MainWindow::setTheme(Theme theme) { } case Theme::System: { - qApp->setPalette(this->style()->standardPalette()); + qApp->setPalette(this->style()->standardPalette()); qApp->setStyle(QStyleFactory::create("WindowsVista")); qApp->setStyleSheet(""); break;