diff --git a/CMakeLists.txt b/CMakeLists.txt index 22294821f..2c13d6346 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 000000000..2612f04ad --- /dev/null +++ b/include/panda_qt/main_window.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "panda_qt/screen.hpp" + +class MainWindow : public QMainWindow { + Q_OBJECT + + private: + enum class Theme : int { + System = 0, + Light = 1, + Dark = 2, + }; + + QComboBox* themeSelect = nullptr; + QMenuBar* menuBar = nullptr; + ScreenWidget screen; + + Theme currentTheme; + void setTheme(Theme theme); + + public: + MainWindow(QApplication* app, QWidget* parent = nullptr); + ~MainWindow(); +}; \ No newline at end of file diff --git a/src/panda_qt/main.cpp b/src/panda_qt/main.cpp index 34e71915a..56391e659 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 000000000..a27c3319f --- /dev/null +++ b/src/panda_qt/main_window.cpp @@ -0,0 +1,87 @@ +#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(); + + // Set our menu bar up + menuBar = new QMenuBar(this); + setMenuBar(menuBar); + + auto pandaMenu = menuBar->addMenu(tr("PANDA")); + auto pandaAction = pandaMenu->addAction(tr("panda...")); + + // 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::setTheme(Theme theme) { + currentTheme = theme; + + switch (theme) { + case Theme::Dark: { + 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); + 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 diff --git a/src/panda_qt/screen.cpp b/src/panda_qt/screen.cpp index 62cac106e..496edb47c 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);