From 741c71adff886f590081501932ec1520058d7def Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Mon, 29 Jun 2020 00:08:56 +0200 Subject: Changes theme initialization a tad. --- src/main.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/main.cpp') 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"); + } +} -- cgit v1.2.3