aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix (xq) Queißner <git@mq32.de>2020-06-29 00:08:56 +0200
committerFelix (xq) Queißner <git@mq32.de>2020-06-29 00:08:56 +0200
commit741c71adff886f590081501932ec1520058d7def (patch)
tree28009a20d9f15f682b694e794d09eaceb88a5022 /src
parent6edd9e7a12a3827fb6aac62a88be01085e41e176 (diff)
downloadkristall-741c71adff886f590081501932ec1520058d7def.tar.gz
Changes theme initialization a tad.
Diffstat (limited to 'src')
-rw-r--r--src/dialogs/settingsdialog.cpp2
-rw-r--r--src/kristall.hpp2
-rw-r--r--src/main.cpp35
-rw-r--r--src/mainwindow.cpp35
-rw-r--r--src/mainwindow.hpp2
5 files changed, 43 insertions, 33 deletions
diff --git a/src/dialogs/settingsdialog.cpp b/src/dialogs/settingsdialog.cpp
index 980957c..6f69c40 100644
--- a/src/dialogs/settingsdialog.cpp
+++ b/src/dialogs/settingsdialog.cpp
@@ -563,6 +563,8 @@ void SettingsDialog::on_start_page_textChanged(const QString &start_page)
void SettingsDialog::on_ui_theme_currentIndexChanged(int index)
{
this->current_options.theme = Theme(this->ui->ui_theme->itemData(index).toInt());
+
+ kristall::setTheme(this->current_options.theme);
}
void SettingsDialog::on_fancypants_on_clicked()
diff --git a/src/kristall.hpp b/src/kristall.hpp
index ef9ab10..e214137 100644
--- a/src/kristall.hpp
+++ b/src/kristall.hpp
@@ -96,6 +96,8 @@ namespace kristall
}
void saveSettings();
+
+ void setTheme(Theme theme);
}
#endif // KRISTALL_HPP
diff --git a/src/main.cpp b/src/main.cpp
index 555734e..ef204a0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -31,6 +31,7 @@ QString toFingerprintString(QSslCertificate const & certificate)
}
static QSettings * app_settings_ptr;
+static QApplication * app;
#define SSTR(X) STR(X)
#define STR(X) #X
@@ -49,11 +50,15 @@ static QDir derive_dir(QDir const & parent, QString subdir)
return child;
}
+
+
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setApplicationVersion(SSTR(KRISTALL_VERSION));
+ ::app = &app;
+
kristall::clipboard = app.clipboard();
QCommandLineParser cli_parser;
@@ -177,6 +182,8 @@ int main(int argc, char *argv[])
kristall::favourites.load(app_settings);
+ kristall::setTheme(kristall::options.theme);
+
MainWindow w(&app);
auto urls = cli_parser.positionalArguments();
@@ -301,3 +308,31 @@ void kristall::saveSettings()
app_settings.sync();
}
+
+void kristall::setTheme(Theme theme)
+{
+ assert(app != nullptr);
+ if(theme == Theme::os_default)
+ {
+ app->setStyleSheet("");
+ QIcon::setThemeName("light");
+ }
+ if(theme == Theme::light)
+ {
+ QFile file(":/light.qss");
+ file.open(QFile::ReadOnly | QFile::Text);
+ QTextStream stream(&file);
+ app->setStyleSheet(stream.readAll());
+
+ QIcon::setThemeName("light");
+ }
+ else if(theme == Theme::dark)
+ {
+ QFile file(":/dark.qss");
+ file.open(QFile::ReadOnly | QFile::Text);
+ QTextStream stream(&file);
+ app->setStyleSheet(stream.readAll());
+
+ QIcon::setThemeName("dark");
+ }
+}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index b0305df..79352cb 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -71,8 +71,6 @@ MainWindow::MainWindow(QApplication * app, QWidget *parent) :
this->ui->favourites_view->setContextMenuPolicy(Qt::CustomContextMenu);
this->ui->history_view->setContextMenuPolicy(Qt::CustomContextMenu);
-
- reloadTheme();
}
MainWindow::~MainWindow()
@@ -209,8 +207,10 @@ void MainWindow::on_actionSettings_triggered()
dialog.setGeminiSslTrust(kristall::trust::gemini);
dialog.setHttpsSslTrust(kristall::trust::https);
- if(dialog.exec() != QDialog::Accepted)
+ if(dialog.exec() != QDialog::Accepted) {
+ kristall::setTheme(kristall::options.theme);
return;
+ }
kristall::trust::gemini = dialog.geminiSslTrust();
kristall::trust::https = dialog.httpsSslTrust();
@@ -221,7 +221,7 @@ void MainWindow::on_actionSettings_triggered()
kristall::saveSettings();
- this->reloadTheme();
+ kristall::setTheme(kristall::options.theme);
}
void MainWindow::on_actionNew_Tab_triggered()
@@ -283,33 +283,6 @@ void MainWindow::on_actionAbout_Qt_triggered()
QMessageBox::aboutQt(this, "Kristall");
}
-void MainWindow::reloadTheme()
-{
- if(kristall::options.theme == Theme::os_default)
- {
- application->setStyleSheet("");
- QIcon::setThemeName("light");
- }
- if(kristall::options.theme == Theme::light)
- {
- QFile file(":/light.qss");
- file.open(QFile::ReadOnly | QFile::Text);
- QTextStream stream(&file);
- application->setStyleSheet(stream.readAll());
-
- QIcon::setThemeName("light");
- }
- else if(kristall::options.theme == Theme::dark)
- {
- QFile file(":/dark.qss");
- file.open(QFile::ReadOnly | QFile::Text);
- QTextStream stream(&file);
- application->setStyleSheet(stream.readAll());
-
- QIcon::setThemeName("dark");
- }
-}
-
void MainWindow::setFileStatus(const DocumentStats &stats)
{
if(stats.isValid()) {
diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp
index daf50b8..e845bc8 100644
--- a/src/mainwindow.hpp
+++ b/src/mainwindow.hpp
@@ -89,8 +89,6 @@ private: // slots
private:
- void reloadTheme();
-
void setFileStatus(DocumentStats const & stats);
public: