From 425f9d41cd337133d5677744eef937a8a2a61212 Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Sun, 7 Jun 2020 10:46:23 +0200 Subject: Adds support for light/dark widget theme, adds experiemental support for http style sheets. --- src/mainwindow.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cf12877..e8dbd23 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -7,9 +7,12 @@ #include #include #include +#include +#include -MainWindow::MainWindow(QWidget *parent) : +MainWindow::MainWindow(QApplication * app, QWidget *parent) : QMainWindow(parent), + application(app), settings("xqTechnologies", "Kristall"), ui(new Ui::MainWindow), url_status(new QLabel()) @@ -60,6 +63,8 @@ MainWindow::MainWindow(QWidget *parent) : } settings.endGroup(); } + + reloadTheme(); } MainWindow::~MainWindow() @@ -206,6 +211,7 @@ void MainWindow::on_actionSettings_triggered() dialog.setGeminiStyle(this->current_style); dialog.setStartPage(this->settings.value("start_page").toString()); dialog.setProtocols(this->protocols); + dialog.setUiTheme(this->settings.value("theme").toString()); if(dialog.exec() != QDialog::Accepted) return; @@ -214,9 +220,13 @@ void MainWindow::on_actionSettings_triggered() this->settings.setValue("start_page", url.toString()); } + this->settings.setValue("theme", dialog.uiTheme()); + this->protocols = dialog.protocols(); this->current_style = dialog.geminiStyle(); this->saveSettings(); + + this->reloadTheme(); } void MainWindow::on_actionNew_Tab_triggered() @@ -277,3 +287,25 @@ void MainWindow::on_actionAbout_Qt_triggered() { QMessageBox::aboutQt(this, "Kristall"); } + +void MainWindow::reloadTheme() +{ + QString theme = settings.value("theme").toString(); + if(theme.isEmpty()) + theme = "light"; + + if(theme == "light") + { + QFile file(":/light.qss"); + file.open(QFile::ReadOnly | QFile::Text); + QTextStream stream(&file); + application->setStyleSheet(stream.readAll()); + } + else if(theme == "dark") + { + QFile file(":/dark.qss"); + file.open(QFile::ReadOnly | QFile::Text); + QTextStream stream(&file); + application->setStyleSheet(stream.readAll()); + } +} -- cgit v1.2.3