From 9bf17318f91b0d5a42c970491d0963178fd23938 Mon Sep 17 00:00:00 2001 From: Mike Skec Date: Tue, 16 Feb 2021 20:40:36 +1100 Subject: Add seperate 'icon theme' preference --- src/dialogs/settingsdialog.cpp | 22 ++++++++++++ src/dialogs/settingsdialog.hpp | 2 ++ src/dialogs/settingsdialog.ui | 81 ++++++++++++++++++++++++------------------ src/kristall.hpp | 10 ++++++ src/main.cpp | 65 ++++++++++++++++++++++++++------- 5 files changed, 132 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/dialogs/settingsdialog.cpp b/src/dialogs/settingsdialog.cpp index 36e4291..4cc0ed6 100644 --- a/src/dialogs/settingsdialog.cpp +++ b/src/dialogs/settingsdialog.cpp @@ -34,6 +34,11 @@ SettingsDialog::SettingsDialog(QWidget *parent) : this->ui->ui_theme->addItem(tr("Light"), QVariant::fromValue(int(Theme::light))); this->ui->ui_theme->addItem(tr("Dark"), QVariant::fromValue(int(Theme::dark))); + this->ui->icon_theme->clear(); + this->ui->icon_theme->addItem(tr("Automatic"), QVariant::fromValue(int(IconTheme::automatic))); + this->ui->icon_theme->addItem(tr("Light"), QVariant::fromValue(int(IconTheme::light))); + this->ui->icon_theme->addItem(tr("Dark"), QVariant::fromValue(int(IconTheme::dark))); + this->ui->ui_density->clear(); this->ui->ui_density->addItem(tr("Compact"), QVariant::fromValue(int(UIDensity::compact))); this->ui->ui_density->addItem(tr("Classic"), QVariant::fromValue(int(UIDensity::classic))); @@ -209,6 +214,15 @@ void SettingsDialog::setOptions(const GenericSettings &options) } } + this->ui->icon_theme->setCurrentIndex(0); + for(int i = 0; i < this->ui->icon_theme->count(); i++) { + if(this->ui->icon_theme->itemData(i).toInt() == int(options.icon_theme)) { + this->ui->icon_theme->setCurrentIndex(i); + break; + } + } + + this->ui->ui_density->setCurrentIndex(0); for(int i = 0; i < this->ui->ui_density->count(); ++i) { if (this->ui->ui_density->itemData(i).toInt() == int(options.ui_density)) { @@ -700,6 +714,14 @@ void SettingsDialog::on_ui_theme_currentIndexChanged(int index) kristall::setTheme(this->current_options.theme); } +void SettingsDialog::on_icon_theme_currentIndexChanged(int index) +{ + this->current_options.icon_theme = IconTheme(this->ui->icon_theme->itemData(index).toInt()); + + kristall::setIconTheme(this->current_options.icon_theme, this->current_options.theme); +} + + void SettingsDialog::on_ui_density_currentIndexChanged(int index) { this->current_options.ui_density = UIDensity(this->ui->ui_density->itemData(index).toInt()); diff --git a/src/dialogs/settingsdialog.hpp b/src/dialogs/settingsdialog.hpp index cc7c302..226abed 100644 --- a/src/dialogs/settingsdialog.hpp +++ b/src/dialogs/settingsdialog.hpp @@ -120,6 +120,8 @@ private slots: void on_ui_theme_currentIndexChanged(int index); + void on_icon_theme_currentIndexChanged(int index); + void on_ui_density_currentIndexChanged(int index); void on_fancypants_on_clicked(); diff --git a/src/dialogs/settingsdialog.ui b/src/dialogs/settingsdialog.ui index 56bbcaf..b1890e3 100644 --- a/src/dialogs/settingsdialog.ui +++ b/src/dialogs/settingsdialog.ui @@ -43,52 +43,62 @@ + + + Icon Theme + + + + + + + UI Density - + - + Start Page: - + about://blank - + Search engine: - + true - + Enabled Protocols - + @@ -133,14 +143,14 @@ - + Text Rendering - + @@ -167,14 +177,14 @@ - + Enable text highlights - + @@ -201,14 +211,14 @@ - + Gopher Map - + @@ -235,14 +245,14 @@ - + Unknown Scheme - + @@ -266,14 +276,14 @@ - + Hidden files in file:// directories - + @@ -297,14 +307,14 @@ - + URL bar highlights - + @@ -328,7 +338,7 @@ - + Use typographer's quotes @@ -338,7 +348,7 @@ - + @@ -362,38 +372,38 @@ - + Max. Number of Redirections - + 5 - + Redirection Handling - + - + Network Timeout - + ms @@ -406,14 +416,14 @@ - + Additional toolbar buttons - + @@ -431,7 +441,7 @@ - + Total cache size limit @@ -441,7 +451,7 @@ - + KiB @@ -455,7 +465,7 @@ - + Cached item size threshold @@ -465,7 +475,7 @@ - + KiB @@ -479,7 +489,7 @@ - + Cached item life @@ -489,7 +499,7 @@ - + minutes @@ -1384,6 +1394,7 @@ tabWidget ui_theme + icon_theme ui_density start_page search_engine diff --git a/src/kristall.hpp b/src/kristall.hpp index 08b9d0f..26f3235 100644 --- a/src/kristall.hpp +++ b/src/kristall.hpp @@ -36,6 +36,13 @@ enum class RequestState : int StartedWeb = 255, }; +enum class IconTheme : int +{ + automatic = -1, + dark = 0, + light = 1 +}; + struct GenericSettings { enum TextDisplay { @@ -53,6 +60,7 @@ struct GenericSettings QString start_page = "about:favourites"; QString search_engine = "gemini://geminispace.info/search?%1"; Theme theme = Theme::light; + IconTheme icon_theme = IconTheme::automatic; UIDensity ui_density = UIDensity::compact; TextDisplay text_display = FormattedText; bool enable_text_decoration = false; @@ -136,6 +144,8 @@ namespace kristall void setTheme(Theme theme); + void setIconTheme(IconTheme icotheme, Theme uitheme); + void setUiDensity(UIDensity density, bool previewing); extern QString default_font_family, default_font_family_fixed; diff --git a/src/main.cpp b/src/main.cpp index 09975bb..6a3e110 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -341,13 +341,21 @@ void GenericSettings::load(QSettings &settings) enable_text_decoration = settings.value("text_decoration", false).toBool(); QString theme_name = settings.value("theme", "os_default").toString(); - if(theme_name== "dark") + if(theme_name == "dark") theme = Theme::dark; else if(theme_name == "light") theme = Theme::light; else theme = Theme::os_default; + QString icon_theme_name = settings.value("icon_theme", "auto").toString(); + if (icon_theme_name == "light") + icon_theme = IconTheme::light; + else if (icon_theme_name == "dark") + icon_theme = IconTheme::dark; + else + icon_theme = IconTheme::automatic; + QString density = settings.value("ui_density", "compact").toString(); if(density == "compact") ui_density = UIDensity::compact; @@ -392,6 +400,14 @@ void GenericSettings::save(QSettings &settings) const } settings.setValue("theme", theme_name); + QString icon_theme_name = "auto"; + switch(icon_theme) { + case IconTheme::dark: icon_theme_name = "dark"; break; + case IconTheme::light: icon_theme_name = "light"; break; + case IconTheme::automatic: icon_theme_name = "auto"; break; + } + settings.setValue("icon_theme", icon_theme_name); + QString density = "compact"; switch(ui_density) { case UIDensity::compact: density = "compact"; break; @@ -458,14 +474,6 @@ void kristall::setTheme(Theme theme) { app->setStyleSheet(""); - // For Linux we use standard icon set, - // for Windows & Mac we need to include our own icons. -#if defined Q_OS_WIN32 || defined Q_OS_DARWIN - QIcon::setThemeName("light"); -#else - QIcon::setThemeName(""); -#endif - // Use "mid" colour for our URL bar dim colour: QColor col = app->palette().color(QPalette::WindowText); col.setAlpha(150); @@ -478,8 +486,6 @@ void kristall::setTheme(Theme theme) QTextStream stream(&file); app->setStyleSheet(stream.readAll()); - QIcon::setThemeName("light"); - kristall::options.fancy_urlbar_dim_colour = QColor(128, 128, 128, 255); } else if(theme == Theme::dark) @@ -489,15 +495,48 @@ void kristall::setTheme(Theme theme) QTextStream stream(&file); app->setStyleSheet(stream.readAll()); - QIcon::setThemeName("dark"); - kristall::options.fancy_urlbar_dim_colour = QColor(150, 150, 150, 255); } + kristall::setIconTheme(kristall::options.icon_theme, theme); + if (main_window && main_window->curTab()) main_window->curTab()->updateUrlBarStyle(); } +void kristall::setIconTheme(IconTheme icotheme, Theme uitheme) +{ + assert(app != nullptr); + + static const QString icothemes[] = { + "light", // Light theme (dark icons) + "dark" // Dark theme (light icons) + }; + + if (icotheme == IconTheme::automatic) + { + if (uitheme == Theme::os_default) + { + // For Linux we use standard system icon set, + // for Windows & Mac we just use our default light theme icons. + #if defined Q_OS_WIN32 || defined Q_OS_DARWIN + QIcon::setThemeName("light"); + #else + QIcon::setThemeName(""); + #endif + + return; + } + + // Use icon theme based on UI theme + QIcon::setThemeName(icothemes[(int)uitheme]); + return; + } + + // Use icon specified by user + QIcon::setThemeName(icothemes[(int)icotheme]); +} + void kristall::setUiDensity(UIDensity density, bool previewing) { assert(app != nullptr); -- cgit v1.2.3