mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-06 14:15:41 +12:00
[Qt] Add separate configuration window for theme
This commit is contained in:
parent
95c1923c37
commit
101cc4d0ac
5 changed files with 136 additions and 107 deletions
|
@ -185,8 +185,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 src/panda_qt/main_window.cpp src/panda_qt/about_window.cpp)
|
||||
set(FRONTEND_HEADER_FILES include/panda_qt/screen.hpp include/panda_qt/main_window.hpp include/panda_qt/about_window.hpp)
|
||||
set(FRONTEND_SOURCE_FILES src/panda_qt/main.cpp src/panda_qt/screen.cpp src/panda_qt/main_window.cpp src/panda_qt/about_window.cpp src/panda_qt/config_window.cpp)
|
||||
set(FRONTEND_HEADER_FILES include/panda_qt/screen.hpp include/panda_qt/main_window.hpp include/panda_qt/about_window.hpp include/panda_qt/config_window.hpp)
|
||||
|
||||
source_group("Source Files\\Qt" FILES ${FRONTEND_SOURCE_FILES})
|
||||
source_group("Header Files\\Qt" FILES ${FRONTEND_HEADER_FILES})
|
||||
|
|
29
include/panda_qt/config_window.hpp
Normal file
29
include/panda_qt/config_window.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include <QApplication>
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QPalette>
|
||||
#include <QWidget>
|
||||
#include <QtWidgets>
|
||||
|
||||
class ConfigWindow : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
enum class Theme : int {
|
||||
System = 0,
|
||||
Light = 1,
|
||||
Dark = 2,
|
||||
GreetingsCat = 3,
|
||||
};
|
||||
|
||||
Theme currentTheme;
|
||||
QComboBox* themeSelect = nullptr;
|
||||
|
||||
void setTheme(Theme theme);
|
||||
|
||||
public:
|
||||
ConfigWindow(QWidget* parent = nullptr);
|
||||
~ConfigWindow();
|
||||
};
|
|
@ -1,9 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <QApplication>
|
||||
#include <QComboBox>
|
||||
#include <QMenuBar>
|
||||
#include <QPalette>
|
||||
#include <QtWidgets>
|
||||
#include <atomic>
|
||||
#include <filesystem>
|
||||
|
@ -13,6 +11,7 @@
|
|||
|
||||
#include "emulator.hpp"
|
||||
#include "panda_qt/about_window.hpp"
|
||||
#include "panda_qt/config_window.hpp"
|
||||
#include "panda_qt/screen.hpp"
|
||||
#include "services/hid.hpp"
|
||||
|
||||
|
@ -20,13 +19,6 @@ class MainWindow : public QMainWindow {
|
|||
Q_OBJECT
|
||||
|
||||
private:
|
||||
enum class Theme : int {
|
||||
System = 0,
|
||||
Light = 1,
|
||||
Dark = 2,
|
||||
GreetingsCat = 3,
|
||||
};
|
||||
|
||||
// Types of messages we might send from the GUI thread to the emulator thread
|
||||
enum class MessageType {
|
||||
LoadROM, Reset, Pause, Resume, TogglePause, DumpRomFS, PressKey, ReleaseKey
|
||||
|
@ -58,11 +50,9 @@ class MainWindow : public QMainWindow {
|
|||
|
||||
ScreenWidget screen;
|
||||
AboutWindow* aboutWindow;
|
||||
QComboBox* themeSelect = nullptr;
|
||||
ConfigWindow* configWindow;
|
||||
QMenuBar* menuBar = nullptr;
|
||||
|
||||
Theme currentTheme;
|
||||
void setTheme(Theme theme);
|
||||
void swapEmuBuffer();
|
||||
void emuThreadMainLoop();
|
||||
void selectROM();
|
||||
|
|
99
src/panda_qt/config_window.cpp
Normal file
99
src/panda_qt/config_window.cpp
Normal file
|
@ -0,0 +1,99 @@
|
|||
#include "panda_qt/config_window.hpp"
|
||||
|
||||
ConfigWindow::ConfigWindow(QWidget* parent) : QDialog(parent) {
|
||||
setWindowTitle(tr("Configuration"));
|
||||
|
||||
// Set up theme selection
|
||||
setTheme(Theme::Dark);
|
||||
themeSelect = new QComboBox(this);
|
||||
themeSelect->addItem(tr("System"));
|
||||
themeSelect->addItem(tr("Light"));
|
||||
themeSelect->addItem(tr("Dark"));
|
||||
themeSelect->addItem(tr("Greetings Cat"));
|
||||
themeSelect->setCurrentIndex(static_cast<int>(currentTheme));
|
||||
|
||||
themeSelect->setGeometry(40, 40, 100, 50);
|
||||
themeSelect->show();
|
||||
connect(themeSelect, &QComboBox::currentIndexChanged, this, [&](int index) { setTheme(static_cast<Theme>(index)); });
|
||||
}
|
||||
|
||||
void ConfigWindow::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::GreetingsCat: {
|
||||
QApplication::setStyle(QStyleFactory::create("Fusion"));
|
||||
|
||||
QPalette p;
|
||||
p.setColor(QPalette::Window, QColor(250, 207, 228));
|
||||
p.setColor(QPalette::WindowText, QColor(225, 22, 137));
|
||||
p.setColor(QPalette::Base, QColor(250, 207, 228));
|
||||
p.setColor(QPalette::AlternateBase, QColor(250, 207, 228));
|
||||
p.setColor(QPalette::ToolTipBase, QColor(225, 22, 137));
|
||||
p.setColor(QPalette::ToolTipText, QColor(225, 22, 137));
|
||||
p.setColor(QPalette::Text, QColor(225, 22, 137));
|
||||
p.setColor(QPalette::Button, QColor(250, 207, 228));
|
||||
p.setColor(QPalette::ButtonText, QColor(225, 22, 137));
|
||||
p.setColor(QPalette::BrightText, Qt::black);
|
||||
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::System: {
|
||||
qApp->setPalette(this->style()->standardPalette());
|
||||
qApp->setStyle(QStyleFactory::create("WindowsVista"));
|
||||
qApp->setStyleSheet("");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConfigWindow::~ConfigWindow() { delete themeSelect; }
|
|
@ -29,9 +29,11 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
|||
auto pauseAction = emulationMenu->addAction(tr("Pause"));
|
||||
auto resumeAction = emulationMenu->addAction(tr("Resume"));
|
||||
auto resetAction = emulationMenu->addAction(tr("Reset"));
|
||||
auto configureAction = emulationMenu->addAction(tr("Configure"));
|
||||
connect(pauseAction, &QAction::triggered, this, [this]() { sendMessage(EmulatorMessage{.type = MessageType::Pause}); });
|
||||
connect(resumeAction, &QAction::triggered, this, [this]() { sendMessage(EmulatorMessage{.type = MessageType::Resume}); });
|
||||
connect(resetAction, &QAction::triggered, this, [this]() { sendMessage(EmulatorMessage{.type = MessageType::Reset}); });
|
||||
connect(configureAction, &QAction::triggered, this, [this]() { configWindow->show(); });
|
||||
|
||||
auto dumpRomFSAction = toolsMenu->addAction(tr("Dump RomFS"));
|
||||
connect(dumpRomFSAction, &QAction::triggered, this, &MainWindow::dumpRomFS);
|
||||
|
@ -39,21 +41,9 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
|||
auto aboutAction = aboutMenu->addAction(tr("About Panda3DS"));
|
||||
connect(aboutAction, &QAction::triggered, this, &MainWindow::showAboutMenu);
|
||||
|
||||
// Set up theme selection
|
||||
setTheme(Theme::Dark);
|
||||
themeSelect = new QComboBox(this);
|
||||
themeSelect->addItem(tr("System"));
|
||||
themeSelect->addItem(tr("Light"));
|
||||
themeSelect->addItem(tr("Dark"));
|
||||
themeSelect->addItem(tr("Greetings Cat"));
|
||||
themeSelect->setCurrentIndex(static_cast<int>(currentTheme));
|
||||
|
||||
themeSelect->setGeometry(40, 40, 100, 50);
|
||||
themeSelect->show();
|
||||
connect(themeSelect, &QComboBox::currentIndexChanged, this, [&](int index) { setTheme(static_cast<Theme>(index)); });
|
||||
|
||||
// Set up misc objects
|
||||
aboutWindow = new AboutWindow(nullptr);
|
||||
configWindow = new ConfigWindow(this);
|
||||
|
||||
emu = new Emulator();
|
||||
emu->setOutputSize(screen.surfaceWidth, screen.surfaceHeight);
|
||||
|
@ -142,7 +132,7 @@ MainWindow::~MainWindow() {
|
|||
delete emu;
|
||||
delete menuBar;
|
||||
delete aboutWindow;
|
||||
delete themeSelect;
|
||||
delete configWindow;
|
||||
}
|
||||
|
||||
// Send a message to the emulator thread. Lock the mutex and just push back to the vector.
|
||||
|
@ -151,85 +141,6 @@ void MainWindow::sendMessage(const EmulatorMessage& message) {
|
|||
messageQueue.push_back(message);
|
||||
}
|
||||
|
||||
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::GreetingsCat: {
|
||||
QApplication::setStyle(QStyleFactory::create("Fusion"));
|
||||
|
||||
QPalette p;
|
||||
p.setColor(QPalette::Window, QColor(250, 207, 228));
|
||||
p.setColor(QPalette::WindowText, QColor(225, 22, 137));
|
||||
p.setColor(QPalette::Base, QColor(250, 207, 228));
|
||||
p.setColor(QPalette::AlternateBase, QColor(250, 207, 228));
|
||||
p.setColor(QPalette::ToolTipBase, QColor(225, 22, 137));
|
||||
p.setColor(QPalette::ToolTipText, QColor(225, 22, 137));
|
||||
p.setColor(QPalette::Text, QColor(225, 22, 137));
|
||||
p.setColor(QPalette::Button, QColor(250, 207, 228));
|
||||
p.setColor(QPalette::ButtonText, QColor(225, 22, 137));
|
||||
p.setColor(QPalette::BrightText, Qt::black);
|
||||
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::System: {
|
||||
qApp->setPalette(this->style()->standardPalette());
|
||||
qApp->setStyle(QStyleFactory::create("WindowsVista"));
|
||||
qApp->setStyleSheet("");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::dumpRomFS() {
|
||||
auto folder = QFileDialog::getExistingDirectory(
|
||||
this, tr("Select folder to dump RomFS files to"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
|
||||
|
|
Loading…
Add table
Reference in a new issue