From 376cfbf9c334708bf5d7d913fdbe43b7369766c3 Mon Sep 17 00:00:00 2001 From: garak Date: Wed, 14 Aug 2019 17:39:23 -0400 Subject: [PATCH] add light and dark themes --- forms/mainwindow.ui | 9 +++- include/mainwindow.h | 1 + porymap.pro | 3 +- resources/themes.qrc | 6 +++ resources/themes/dark.qss | 95 ++++++++++++++++++++++++++++++++++++++ resources/themes/light.qss | 95 ++++++++++++++++++++++++++++++++++++++ src/mainwindow.cpp | 40 ++++++++++++++++ 7 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 resources/themes.qrc create mode 100644 resources/themes/dark.qss create mode 100644 resources/themes/light.qss diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index a8a20bd5..f6921ee0 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -1281,7 +1281,7 @@ - Transparency + Opacity @@ -2827,6 +2827,8 @@ + + @@ -3083,6 +3085,11 @@ Ctrl+Shift+N + + + Themes... + + diff --git a/include/mainwindow.h b/include/mainwindow.h index 5f0c9f46..1aae4d32 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -141,6 +141,7 @@ private slots: void on_toolButton_ExpandAll_clicked(); void on_toolButton_CollapseAll_clicked(); void on_actionAbout_Porymap_triggered(); + void on_actionThemes_triggered(); void on_pushButton_AddCustomHeaderField_clicked(); void on_pushButton_DeleteCustomHeaderField_clicked(); void on_tableWidget_CustomHeaderFields_cellChanged(int row, int column); diff --git a/porymap.pro b/porymap.pro index 4ab7305c..8d75df64 100644 --- a/porymap.pro +++ b/porymap.pro @@ -144,7 +144,8 @@ FORMS += forms/mainwindow.ui \ forms/mapimageexporter.ui RESOURCES += \ - resources/images.qrc + resources/images.qrc \ + resources/themes.qrc INCLUDEPATH += include INCLUDEPATH += include/core diff --git a/resources/themes.qrc b/resources/themes.qrc new file mode 100644 index 00000000..4c2d8878 --- /dev/null +++ b/resources/themes.qrc @@ -0,0 +1,6 @@ + + + themes/dark.qss + themes/light.qss + + diff --git a/resources/themes/dark.qss b/resources/themes/dark.qss new file mode 100644 index 00000000..70965acd --- /dev/null +++ b/resources/themes/dark.qss @@ -0,0 +1,95 @@ +/* DARK theme for porymap */ + +/* General Widgets */ + +QWidget { + background: #31332b; + color: #F8F8F2; +} + +QWidget::item:selected { + background: #49483E; +} + +QWidget::item:focus { + background: #49483E; + border: none; +} + +/* Combo Boxes */ + +QComboBox { + background: #272822; + color: #F8F8F2; +} + +QComboBox QAbstractItemView { + background: #31332b; + color: #75715E; + selection-background-color: #49483E; +} + +/* Spin Boxes */ + +QSpinBox { + background: #272822; + color: #F8F8F2; +} + +/* Line Edits */ + +QLineEdit { + background: #272822; + color: #F8F8F2; +} + +/* Frames, Labels */ + +#label_spritePixmap { + background: #272822; + color: #F8F8F2; +} + +/* Checkboxes */ + +QCheckBox, QRadioButton { + border: none; +} + +QRadioButton::indicator::unchecked, QCheckBox::indicator::unchecked { + border: 1px solid #49483E; + background: none; +} + +QRadioButton::indicator:unchecked:hover, QCheckBox::indicator:unchecked:hover { + border: 1px solid #F8F8F2; +} + +QRadioButton::indicator::checked, QCheckBox::indicator::checked { + border: 1px solid #49483E; + background: #49483E; +} + +QRadioButton::indicator:checked:hover, QCheckBox::indicator:checked:hover { + border: 1px solid #F8F8F2; + background: #F8F8F2; +} + +/* Map List View */ + +QTreeView { + background: #272822; +} + +QTreeView::item:hover { + background: #49483E; +} + +QTreeView::item:selected { + background: #49483E; + color: #F8F8F2; +} + +QTreeView::branch { + background: #272822; +} diff --git a/resources/themes/light.qss b/resources/themes/light.qss new file mode 100644 index 00000000..59d75cb1 --- /dev/null +++ b/resources/themes/light.qss @@ -0,0 +1,95 @@ +/* LIGHT theme for porymap */ + +/* General Widgets */ + +QWidget { + background: #F5F5F5; + color: #3C3C3C; +} + +QWidget::item:selected { + background: #CACACA; +} + +QWidget::item:focus { + background: #CACACA; + border: none; +} + +/* Combo Boxes */ + +QComboBox { + background: #F5F5F5; + color: #3C3C3C; +} + +QComboBox QAbstractItemView { + background: #F5F5F5; + color: #898989; + selection-background-color: #707070; +} + +/* Spin Boxes */ + +QSpinBox { + background: #F5F5F5; + color: #3C3C3C; +} + +/* Line Edits */ + +QLineEdit { + background: #F5F5F5; + color: #3C3C3C; +} + +/* Frames, Labels */ + +#label_spritePixmap { + background: #F5F5F5; + color: #3C3C3C; +} + +/* Checkboxes */ + +QCheckBox, QRadioButton { + border: none; +} + +QRadioButton::indicator::unchecked, QCheckBox::indicator::unchecked { + border: 1px solid #CACACA; + background: none; +} + +QRadioButton::indicator:unchecked:hover, QCheckBox::indicator:unchecked:hover { + border: 1px solid #3C3C3C; +} + +QRadioButton::indicator::checked, QCheckBox::indicator::checked { + border: 1px solid #CACACA; + background: #CACACA; +} + +QRadioButton::indicator:checked:hover, QCheckBox::indicator:checked:hover { + border: 1px solid #3C3C3C; + background: #3C3C3C; +} + +/* Map List View */ + +QTreeView { + background: #F5F5F5; +} + +QTreeView::item:hover { + background: #CACACA; +} + +QTreeView::item:selected { + background: #CACACA; + color: #3C3C3C; +} + +QTreeView::branch { + background: #F5F5F5; +} diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 99a12949..6d3ebb7d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -11,6 +11,7 @@ #include "customattributestable.h" #include +#include #include #include #include @@ -2119,6 +2120,45 @@ void MainWindow::on_actionAbout_Porymap_triggered() window->show(); } +void MainWindow::on_actionThemes_triggered() +{ + QStringList themes; + QRegularExpression re(":/themes/([A-z0-9_]+).qss"); + themes.append("default"); + QDirIterator it(":/themes", QDirIterator::Subdirectories); + while (it.hasNext()) { + QString themeName = re.match(it.next()).captured(1); + themes.append(themeName); + } + + QDialog themeSelectorWindow(this); + QFormLayout form(&themeSelectorWindow); + + NoScrollComboBox *themeSelector = new NoScrollComboBox(); + themeSelector->addItems(themes); + form.addRow(new QLabel("Themes"), themeSelector); + + QDialogButtonBox buttonBox(QDialogButtonBox::Apply | QDialogButtonBox::Close, Qt::Horizontal, &themeSelectorWindow); + form.addRow(&buttonBox); + connect(&buttonBox, &QDialogButtonBox::clicked, [&themeSelectorWindow, &buttonBox, themeSelector, this](QAbstractButton *button){ + if (button == buttonBox.button(QDialogButtonBox::Apply)) { + QString theme = themeSelector->currentText(); + if (theme == "default") { + setStyleSheet(""); + return; + } + + QFile File(QString(":/themes/%1.qss").arg(theme)); + File.open(QFile::ReadOnly); + QString stylesheet = QLatin1String(File.readAll()); + setStyleSheet(stylesheet); + } + }); + connect(&buttonBox, SIGNAL(rejected()), &themeSelectorWindow, SLOT(reject())); + + themeSelectorWindow.exec(); +} + void MainWindow::on_pushButton_AddCustomHeaderField_clicked() { int rowIndex = this->ui->tableWidget_CustomHeaderFields->rowCount();