diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-02-16 20:40:36 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-02-16 11:11:23 +0100 |
| commit | 9bf17318f91b0d5a42c970491d0963178fd23938 (patch) | |
| tree | 97c525fc9e3b1042dd7a659102fa1cace206fae9 /src | |
| parent | 7820c0fb5cbfb5d41fa484aa5f9d0481318cfbeb (diff) | |
| download | kristall-9bf17318f91b0d5a42c970491d0963178fd23938.tar.gz | |
Add seperate 'icon theme' preference
Diffstat (limited to 'src')
| -rw-r--r-- | src/dialogs/settingsdialog.cpp | 22 | ||||
| -rw-r--r-- | src/dialogs/settingsdialog.hpp | 2 | ||||
| -rw-r--r-- | src/dialogs/settingsdialog.ui | 81 | ||||
| -rw-r--r-- | src/kristall.hpp | 10 | ||||
| -rw-r--r-- | src/main.cpp | 65 |
5 files changed, 132 insertions, 48 deletions
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>(int(Theme::light))); this->ui->ui_theme->addItem(tr("Dark"), QVariant::fromValue<int>(int(Theme::dark))); + this->ui->icon_theme->clear(); + this->ui->icon_theme->addItem(tr("Automatic"), QVariant::fromValue<int>(int(IconTheme::automatic))); + this->ui->icon_theme->addItem(tr("Light"), QVariant::fromValue<int>(int(IconTheme::light))); + this->ui->icon_theme->addItem(tr("Dark"), QVariant::fromValue<int>(int(IconTheme::dark))); + this->ui->ui_density->clear(); this->ui->ui_density->addItem(tr("Compact"), QVariant::fromValue<int>(int(UIDensity::compact))); this->ui->ui_density->addItem(tr("Classic"), QVariant::fromValue<int>(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 @@ <widget class="QComboBox" name="ui_theme"/> </item> <item row="1" column="0"> + <widget class="QLabel" name="label_34"> + <property name="text"> + <string>Icon Theme</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QComboBox" name="icon_theme"/> + </item> + <item row="2" column="0"> <widget class="QLabel" name="label_1"> <property name="text"> <string>UI Density</string> </property> </widget> </item> - <item row="1" column="1"> + <item row="2" column="1"> <widget class="QComboBox" name="ui_density"/> </item> - <item row="2" column="0"> + <item row="3" column="0"> <widget class="QLabel" name="label_14"> <property name="text"> <string>Start Page:</string> </property> </widget> </item> - <item row="2" column="1"> + <item row="3" column="1"> <widget class="QLineEdit" name="start_page"> <property name="placeholderText"> <string>about://blank</string> </property> </widget> </item> - <item row="3" column="0"> + <item row="4" column="0"> <widget class="QLabel" name="label_40"> <property name="text"> <string>Search engine:</string> </property> </widget> </item> - <item row="3" column="1"> + <item row="4" column="1"> <widget class="QComboBox" name="search_engine"> <property name="editable"> <bool>true</bool> </property> </widget> </item> - <item row="4" column="0"> + <item row="5" column="0"> <widget class="QLabel" name="label_16"> <property name="text"> <string>Enabled Protocols</string> </property> </widget> </item> - <item row="4" column="1"> + <item row="5" column="1"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QCheckBox" name="enable_gemini"> @@ -133,14 +143,14 @@ </item> </layout> </item> - <item row="5" column="0"> + <item row="6" column="0"> <widget class="QLabel" name="label_19"> <property name="text"> <string>Text Rendering</string> </property> </widget> </item> - <item row="5" column="1"> + <item row="6" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_5"> <item> <widget class="QRadioButton" name="fancypants_on"> @@ -167,14 +177,14 @@ </item> </layout> </item> - <item row="6" column="0"> + <item row="7" column="0"> <widget class="QLabel" name="label_18"> <property name="text"> <string>Enable text highlights</string> </property> </widget> </item> - <item row="6" column="1"> + <item row="7" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_3"> <item> <widget class="QRadioButton" name="texthl_on"> @@ -201,14 +211,14 @@ </item> </layout> </item> - <item row="7" column="0"> + <item row="8" column="0"> <widget class="QLabel" name="label_20"> <property name="text"> <string>Gopher Map</string> </property> </widget> </item> - <item row="7" column="1"> + <item row="8" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_4"> <item> <widget class="QRadioButton" name="gophermap_icon"> @@ -235,14 +245,14 @@ </item> </layout> </item> - <item row="8" column="0"> + <item row="9" column="0"> <widget class="QLabel" name="label_22"> <property name="text"> <string>Unknown Scheme</string> </property> </widget> </item> - <item row="8" column="1"> + <item row="9" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_7"> <item> <widget class="QRadioButton" name="scheme_os_default"> @@ -266,14 +276,14 @@ </item> </layout> </item> - <item row="9" column="0"> + <item row="10" column="0"> <widget class="QLabel" name="label_23"> <property name="text"> <string>Hidden files in file:// directories</string> </property> </widget> </item> - <item row="9" column="1"> + <item row="10" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_8"> <item> <widget class="QRadioButton" name="show_hidden_files"> @@ -297,14 +307,14 @@ </item> </layout> </item> - <item row="10" column="0"> + <item row="11" column="0"> <widget class="QLabel" name="label_24"> <property name="text"> <string>URL bar highlights</string> </property> </widget> </item> - <item row="10" column="1"> + <item row="11" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_9"> <item> <widget class="QRadioButton" name="urlbarhl_fancy"> @@ -328,7 +338,7 @@ </item> </layout> </item> - <item row="11" column="0"> + <item row="12" column="0"> <widget class="QLabel" name="label_39"> <property name="text"> <string>Use typographer's quotes</string> @@ -338,7 +348,7 @@ </property> </widget> </item> - <item row="11" column="1"> + <item row="12" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_10"> <item> <widget class="QRadioButton" name="fancyquotes_on"> @@ -362,38 +372,38 @@ </item> </layout> </item> - <item row="12" column="0"> + <item row="13" column="0"> <widget class="QLabel" name="label_26"> <property name="text"> <string>Max. Number of Redirections</string> </property> </widget> </item> - <item row="12" column="1"> + <item row="13" column="1"> <widget class="QSpinBox" name="max_redirects"> <property name="value"> <number>5</number> </property> </widget> </item> - <item row="13" column="0"> + <item row="14" column="0"> <widget class="QLabel" name="label_27"> <property name="text"> <string>Redirection Handling</string> </property> </widget> </item> - <item row="13" column="1"> + <item row="14" column="1"> <widget class="QComboBox" name="redirection_mode"/> </item> - <item row="14" column="0"> + <item row="15" column="0"> <widget class="QLabel" name="label_28"> <property name="text"> <string>Network Timeout</string> </property> </widget> </item> - <item row="14" column="1"> + <item row="15" column="1"> <widget class="QSpinBox" name="network_timeout"> <property name="suffix"> <string> ms</string> @@ -406,14 +416,14 @@ </property> </widget> </item> - <item row="15" column="0"> + <item row="16" column="0"> <widget class="QLabel" name="label_29"> <property name="text"> <string>Additional toolbar buttons</string> </property> </widget> </item> - <item row="15" column="1"> + <item row="16" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_99"> <item> <widget class="QCheckBox" name="enable_home_btn"> @@ -431,7 +441,7 @@ </item> </layout> </item> - <item row="16" column="0"> + <item row="17" column="0"> <widget class="QLabel" name="label_30"> <property name="text"> <string>Total cache size limit</string> @@ -441,7 +451,7 @@ </property> </widget> </item> - <item row="16" column="1"> + <item row="17" column="1"> <widget class="QSpinBox" name="cache_limit"> <property name="suffix"> <string> KiB</string> @@ -455,7 +465,7 @@ </widget> </item> - <item row="17" column="0"> + <item row="18" column="0"> <widget class="QLabel" name="label_31"> <property name="text"> <string>Cached item size threshold</string> @@ -465,7 +475,7 @@ </property> </widget> </item> - <item row="17" column="1"> + <item row="18" column="1"> <widget class="QSpinBox" name="cache_threshold"> <property name="suffix"> <string> KiB</string> @@ -479,7 +489,7 @@ </widget> </item> - <item row="18" column="0"> + <item row="19" column="0"> <widget class="QLabel" name="label_31"> <property name="text"> <string>Cached item life</string> @@ -489,7 +499,7 @@ </property> </widget> </item> - <item row="18" column="1"> + <item row="19" column="1"> <widget class="QSpinBox" name="cache_life"> <property name="suffix"> <string> minutes</string> @@ -1384,6 +1394,7 @@ <tabstops> <tabstop>tabWidget</tabstop> <tabstop>ui_theme</tabstop> + <tabstop>icon_theme</tabstop> <tabstop>ui_density</tabstop> <tabstop>start_page</tabstop> <tabstop>search_engine</tabstop> 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); |
