-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from wheremyfoodat/rhappy
[Qt] Add MainWindow class and implement theme selection
- Loading branch information
Showing
5 changed files
with
124 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <QApplication> | ||
#include <QComboBox> | ||
#include <QMenuBar> | ||
#include <QPalette> | ||
#include <QtWidgets> | ||
|
||
#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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,12 @@ | ||
#include <QApplication> | ||
#include <QtWidgets> | ||
|
||
#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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<int>(currentTheme)); | ||
|
||
themeSelect->setGeometry(40, 40, 100, 50); | ||
themeSelect->show(); | ||
connect(themeSelect, &QComboBox::currentIndexChanged, this, [&](int index) { setTheme(static_cast<Theme>(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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters