Skip to content

Commit

Permalink
dark theme working in preferences.
Browse files Browse the repository at this point in the history
  • Loading branch information
ponchio committed Feb 1, 2024
1 parent 636db6c commit 64f23a2
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 37 deletions.
4 changes: 3 additions & 1 deletion relightlab/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ void MainWindow::createMenu() {
menuFile->addAction(qRelightApp->action("new_project"));
menuFile->addAction(qRelightApp->action("open_project"));

recentMenu = new QMenu(tr("&Recent Projects"), this);
recentMenu = new QMenu("&Recent Projects", this);
menuFile->addMenu(recentMenu);
updateRecentProjectsMenu();

menuFile->addSeparator();
menuFile->addAction(qRelightApp->action("save_project"));
menuFile->addAction(qRelightApp->action("save_project_as"));
menuFile->addSeparator();
menuFile->addAction(qRelightApp->action("preferences"));
menuFile->addSeparator();
menuFile->addAction(qRelightApp->action("exit"));

setMenuBar(menubar);
Expand Down
17 changes: 16 additions & 1 deletion relightlab/preferences.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#include "preferences.h"
#include "tabwidget.h"
#include "relightapp.h"

#include <QVBoxLayout>
#include <QPushButton>
#include <QCheckBox>

Preferences::Preferences(QWidget *parent): QDialog(parent) {
setWindowTitle("Preferences - RelightLab");
setModal(true);

tabs = new TabWidget;

QWidget *appearance = new QWidget;
QWidget *appearance = buildAppearance();
tabs->addTab(appearance, "Appearance");

QWidget *performances = new QWidget;
Expand All @@ -26,3 +29,15 @@ Preferences::Preferences(QWidget *parent): QDialog(parent) {

connect(closeButton, &QPushButton::clicked, this, &QDialog::accept);
}

QWidget *Preferences::buildAppearance() {
QWidget *widget = new QWidget;
QVBoxLayout *content = new QVBoxLayout;
QCheckBox *dark = new QCheckBox("Dark theme (requires restart)");
dark->setChecked(QSettings().value("dark", true).toBool());
content->addWidget(dark);
widget->setLayout(content);

connect(dark, SIGNAL(toggled(bool)), qRelightApp, SLOT(setDarkTheme(bool)));
return widget;
}
1 change: 1 addition & 0 deletions relightlab/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Preferences: public QDialog {

private:
TabWidget *tabs;
QWidget *buildAppearance();
};

#endif // PREFERENCES_H
79 changes: 47 additions & 32 deletions relightlab/relightapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
#include "../relight/processqueue.h"
#include "imageframe.h"
#include "recentprojects.h"
#include "mainwindow.h"
#include "preferences.h"

#include <QMessageBox>
#include <QFileDialog>
#include <QStyleFactory>
#include <QStyle>
#include <QAction>

#include <QDebug>
Expand All @@ -16,17 +19,40 @@ RelightApp::RelightApp(int &argc, char **argv): QApplication(argc, argv) {
QMessageBox::critical(nullptr, "Temporary folder is needed", "Could not create a temporary file for the scripts.\nSelect a folder in File->Preferences");
}

this->setStyle(QStyleFactory::create("Fusion"));

QIcon::setThemeSearchPaths(QStringList() << ":/icons");
QIcon::setThemeName("light");


QFile style(":/css/style.qss");
style.open(QFile::ReadOnly);
setStyleSheet(style.readAll());
//Default font size can be read using QApplication::font().pointSize(), not pointPixel

dark_palette.setColor(QPalette::Window,QColor(53,53,53));
dark_palette.setColor(QPalette::WindowText,Qt::white);
dark_palette.setColor(QPalette::Disabled,QPalette::WindowText,QColor(127,127,127));
dark_palette.setColor(QPalette::Base,QColor(42,42,42));
dark_palette.setColor(QPalette::AlternateBase,QColor(66,66,66));
dark_palette.setColor(QPalette::ToolTipBase,Qt::white);
dark_palette.setColor(QPalette::ToolTipText,Qt::white);
dark_palette.setColor(QPalette::Text,Qt::white);
dark_palette.setColor(QPalette::Disabled,QPalette::Text,QColor(127,127,127));
dark_palette.setColor(QPalette::Dark,QColor(35,35,35));
dark_palette.setColor(QPalette::Shadow,QColor(20,20,20));
dark_palette.setColor(QPalette::Button,QColor(53,53,53));
dark_palette.setColor(QPalette::ButtonText,Qt::white);
dark_palette.setColor(QPalette::Disabled,QPalette::ButtonText,QColor(127,127,127));
dark_palette.setColor(QPalette::BrightText,Qt::red);
dark_palette.setColor(QPalette::Link,QColor(42,130,218));
dark_palette.setColor(QPalette::Highlight,QColor(42,130,218));
dark_palette.setColor(QPalette::Disabled,QPalette::Highlight,QColor(80,80,80));
dark_palette.setColor(QPalette::HighlightedText,Qt::white);
dark_palette.setColor(QPalette::Disabled,QPalette::HighlightedText,QColor(127,127,127));

this->setStyle(QStyleFactory::create("Fusion"));

setAttribute(Qt::AA_DontShowIconsInMenus);
QIcon::setThemeSearchPaths(QStringList() << ":/icons");


ProcessQueue &queue = ProcessQueue::instance();
queue.start();

Expand Down Expand Up @@ -58,36 +84,22 @@ RelightApp::RelightApp(int &argc, char **argv): QApplication(argc, argv) {
}

void RelightApp::run() {
setDarkStyle();
qDebug() << QSettings().allKeys();
bool dark = QSettings().value("dark", false).toBool();
if(dark) {
QIcon::setThemeName("dark");
setPalette(dark_palette);
} else {
QIcon::setThemeName("light");
}


mainwindow = new MainWindow;
mainwindow->showMaximized();
}

void RelightApp::setDarkStyle() {
QIcon::setThemeName("dark");
QPalette darkPalette;
darkPalette.setColor(QPalette::Window,QColor(53,53,53));
darkPalette.setColor(QPalette::WindowText,Qt::white);
darkPalette.setColor(QPalette::Disabled,QPalette::WindowText,QColor(127,127,127));
darkPalette.setColor(QPalette::Base,QColor(42,42,42));
darkPalette.setColor(QPalette::AlternateBase,QColor(66,66,66));
darkPalette.setColor(QPalette::ToolTipBase,Qt::white);
darkPalette.setColor(QPalette::ToolTipText,Qt::white);
darkPalette.setColor(QPalette::Text,Qt::white);
darkPalette.setColor(QPalette::Disabled,QPalette::Text,QColor(127,127,127));
darkPalette.setColor(QPalette::Dark,QColor(35,35,35));
darkPalette.setColor(QPalette::Shadow,QColor(20,20,20));
darkPalette.setColor(QPalette::Button,QColor(53,53,53));
darkPalette.setColor(QPalette::ButtonText,Qt::white);
darkPalette.setColor(QPalette::Disabled,QPalette::ButtonText,QColor(127,127,127));
darkPalette.setColor(QPalette::BrightText,Qt::red);
darkPalette.setColor(QPalette::Link,QColor(42,130,218));
darkPalette.setColor(QPalette::Highlight,QColor(42,130,218));
darkPalette.setColor(QPalette::Disabled,QPalette::Highlight,QColor(80,80,80));
darkPalette.setColor(QPalette::HighlightedText,Qt::white);
darkPalette.setColor(QPalette::Disabled,QPalette::HighlightedText,QColor(127,127,127));

qApp->setPalette(darkPalette);
void RelightApp::setDarkTheme(bool dark) {
QSettings().setValue("dark", dark);
}

void RelightApp::newProject() {
Expand Down Expand Up @@ -217,7 +229,9 @@ void RelightApp::saveProjectAs() {
}

void RelightApp::openPreferences() {

if(!preferences)
preferences = new Preferences(mainwindow);
preferences->show();
}

void RelightApp::close() {
Expand Down Expand Up @@ -245,9 +259,10 @@ bool RelightApp::needsSavingProceed() {
QAction *RelightApp::addAction(const QString &id, const QString &label, const QString &icon, const QString &shortcut, const char *method) {
QAction *a = new QAction(label);
a->setShortcut(shortcut);
if(icon != "")
if(icon != "") {
//a->setIcon(QIcon(icon));
a->setIcon(QIcon::fromTheme(icon));
}
actions[id] = a;
if(method)
connect(a, SIGNAL(triggered()), this, method);
Expand Down
8 changes: 6 additions & 2 deletions relightlab/relightapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#include <QVariant>

#include "../src/project.h"
#include "mainwindow.h"


#define qRelightApp (static_cast<RelightApp *>(QCoreApplication::instance()))

class Preferences;
class MainWindow;

class RelightApp: public QApplication {
Q_OBJECT
Expand All @@ -21,6 +23,7 @@ class RelightApp: public QApplication {

QMap<QString, QAction *> actions;
MainWindow *mainwindow = nullptr;
Preferences *preferences = nullptr;

RelightApp(int &argc, char **argv);
virtual ~RelightApp() {}
Expand All @@ -35,11 +38,11 @@ public slots:
void close();

void openPreferences();
void setDarkTheme(bool on);

public:
Project &project() { return m_project; }
QAction *action(const QString &id) { return actions[id]; }
void setDarkStyle();
QString lastProjectDir() {
return QSettings().value("LastProjectDir", QDir::homePath()).toString();
}
Expand All @@ -54,6 +57,7 @@ public slots:

//keep memory of current project filename for quick saving.
QString project_filename;
QPalette dark_palette;
};

#endif
6 changes: 5 additions & 1 deletion relightlab/relightlab.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
QT += widgets
QT += widgets svg
CONFIG += c++11

#TODO: this might be needed in CMake
#find_package(Qt5Svg REQUIRED)
#target_link_libraries( ${APP_NAME} Qt5::Svg )

DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += _USE_MATH_DEFINES
DEFINES += NOMINMAX
Expand Down

0 comments on commit 64f23a2

Please sign in to comment.