diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-02-27 09:23:59 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-02-27 11:47:39 +0100 |
| commit | 23feba7e5a1396110d543a676e018bcbdfa50d39 (patch) | |
| tree | d4e2a6fed26a490a5ba2df4f755f6ad90b2203b1 /src | |
| parent | 435532d97dcfbb23e46f51f690914fd910cc65ee (diff) | |
| download | kristall-23feba7e5a1396110d543a676e018bcbdfa50d39.tar.gz | |
Adds emoji toggle preference.
Diffstat (limited to 'src')
| -rw-r--r-- | src/dialogs/settingsdialog.cpp | 28 | ||||
| -rw-r--r-- | src/dialogs/settingsdialog.hpp | 3 | ||||
| -rw-r--r-- | src/dialogs/settingsdialog.ui | 63 | ||||
| -rw-r--r-- | src/documentstyle.cpp | 20 | ||||
| -rw-r--r-- | src/kristall.hpp | 4 | ||||
| -rw-r--r-- | src/main.cpp | 20 |
6 files changed, 118 insertions, 20 deletions
diff --git a/src/dialogs/settingsdialog.cpp b/src/dialogs/settingsdialog.cpp index e9c0e45..4bd0f8c 100644 --- a/src/dialogs/settingsdialog.cpp +++ b/src/dialogs/settingsdialog.cpp @@ -301,6 +301,24 @@ void SettingsDialog::setOptions(const GenericSettings &options) this->ui->urlbarhl_none->setChecked(true); } + if (kristall::EMOJIS_SUPPORTED && this->current_options.emojis_enabled) + { + this->ui->emojis_on->setChecked(true); + } + else + { + this->ui->emojis_off->setChecked(true); + + // Grey out emoji options on unsupported emoji builds + if (!kristall::EMOJIS_SUPPORTED) + { + this->ui->emojis_on->setEnabled(false); + this->ui->emojis_off->setEnabled(false); + this->ui->emojis_label->setToolTip( + this->ui->emojis_label->toolTip() + " (not supported in this build)"); + } + } + if(this->current_options.fancy_quotes) { this->ui->fancyquotes_on->setChecked(true); } else { @@ -831,6 +849,16 @@ void SettingsDialog::on_urlbarhl_none_clicked() this->current_options.fancy_urlbar = false; } +void SettingsDialog::on_emojis_on_clicked() +{ + this->current_options.emojis_enabled = true; +} + +void SettingsDialog::on_emojis_off_clicked() +{ + this->current_options.emojis_enabled = false; +} + void SettingsDialog::on_fancyquotes_on_clicked() { this->current_options.fancy_quotes = true; diff --git a/src/dialogs/settingsdialog.hpp b/src/dialogs/settingsdialog.hpp index adeb004..114396e 100644 --- a/src/dialogs/settingsdialog.hpp +++ b/src/dialogs/settingsdialog.hpp @@ -149,6 +149,9 @@ private slots: void on_fancyquotes_on_clicked(); void on_fancyquotes_off_clicked(); + void on_emojis_on_clicked(); + void on_emojis_off_clicked(); + void on_redirection_mode_currentIndexChanged(int index); void on_max_redirects_valueChanged(int arg1); diff --git a/src/dialogs/settingsdialog.ui b/src/dialogs/settingsdialog.ui index cccb3f5..04db3e2 100644 --- a/src/dialogs/settingsdialog.ui +++ b/src/dialogs/settingsdialog.ui @@ -373,37 +373,71 @@ </layout> </item> <item row="13" column="0"> + <widget class="QLabel" name="emojis_label"> + <property name="text"> + <string>Render emojis</string> + </property> + <property name="toolTip"> + <string>Whether to render emojis in a page.</string> + </property> + </widget> + </item> + <item row="13" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_17"> + <item> + <widget class="QRadioButton" name="emojis_on"> + <property name="text"> + <string>On</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">emojisBtnGroup</string> + </attribute> + </widget> + </item> + <item> + <widget class="QRadioButton" name="emojis_off"> + <property name="text"> + <string>Off</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">emojisBtnGroup</string> + </attribute> + </widget> + </item> + </layout> + </item> + <item row="14" column="0"> <widget class="QLabel" name="label_26"> <property name="text"> <string>Max. Number of Redirections</string> </property> </widget> </item> - <item row="13" column="1"> + <item row="14" column="1"> <widget class="QSpinBox" name="max_redirects"> <property name="value"> <number>5</number> </property> </widget> </item> - <item row="14" column="0"> + <item row="15" column="0"> <widget class="QLabel" name="label_27"> <property name="text"> <string>Redirection Handling</string> </property> </widget> </item> - <item row="14" column="1"> + <item row="15" column="1"> <widget class="QComboBox" name="redirection_mode"/> </item> - <item row="15" column="0"> + <item row="16" column="0"> <widget class="QLabel" name="label_28"> <property name="text"> <string>Network Timeout</string> </property> </widget> </item> - <item row="15" column="1"> + <item row="16" column="1"> <widget class="QSpinBox" name="network_timeout"> <property name="suffix"> <string> ms</string> @@ -416,14 +450,14 @@ </property> </widget> </item> - <item row="16" column="0"> + <item row="17" column="0"> <widget class="QLabel" name="label_29"> <property name="text"> <string>Additional toolbar buttons</string> </property> </widget> </item> - <item row="16" column="1"> + <item row="17" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_99"> <item> <widget class="QCheckBox" name="enable_home_btn"> @@ -455,7 +489,7 @@ </item> </layout> </item> - <item row="17" column="0"> + <item row="18" column="0"> <widget class="QLabel" name="label_30"> <property name="text"> <string>Total cache size limit</string> @@ -465,7 +499,7 @@ </property> </widget> </item> - <item row="17" column="1"> + <item row="18" column="1"> <widget class="QSpinBox" name="cache_limit"> <property name="suffix"> <string> KiB</string> @@ -479,7 +513,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 size threshold</string> @@ -489,7 +523,7 @@ </property> </widget> </item> - <item row="18" column="1"> + <item row="19" column="1"> <widget class="QSpinBox" name="cache_threshold"> <property name="suffix"> <string> KiB</string> @@ -503,7 +537,7 @@ </widget> </item> - <item row="19" column="0"> + <item row="20" column="0"> <widget class="QLabel" name="label_31"> <property name="text"> <string>Cached item life</string> @@ -513,7 +547,7 @@ </property> </widget> </item> - <item row="19" column="1"> + <item row="20" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_25"> <item> <widget class="QSpinBox" name="cache_life"> @@ -1503,6 +1537,8 @@ <tabstop>urlbarhl_none</tabstop> <tabstop>fancyquotes_on</tabstop> <tabstop>fancyquotes_off</tabstop> + <tabstop>emojis_on</tabstop> + <tabstop>emojis_off</tabstop> <tabstop>max_redirects</tabstop> <tabstop>redirection_mode</tabstop> <tabstop>network_timeout</tabstop> @@ -1598,5 +1634,6 @@ <buttongroup name="hiddenFilesBtnGroup"/> <buttongroup name="urlbarBtnGroup"/> <buttongroup name="quotesBtnGroup"/> + <buttongroup name="emojisBtnGroup"/> </buttongroups> </ui> diff --git a/src/documentstyle.cpp b/src/documentstyle.cpp index 5edef73..11d29e7 100644 --- a/src/documentstyle.cpp +++ b/src/documentstyle.cpp @@ -430,6 +430,8 @@ DocumentStyle DocumentStyle::derive(const QUrl &url) const auto const patchup_font = [](QFont & font, bool fixed=false) { // Set the "fallback" font, just to be absolutely sure. + // Note the main purpose of this is to avoid emoji fonts + // from taking precedence over text fonts. // (fixes *nix default font issues) emojiFonts[1] = fixed ? kristall::default_font_family_fixed @@ -438,7 +440,7 @@ DocumentStyle DocumentStyle::derive(const QUrl &url) const // Set the primary font as the preferred font. // We ensure that the font family is available first, // so that we don't get an ugly default font - // (fixes Windows' default font) + // (fixes Windows' default font problem) QFontDatabase db; if (!db.families().contains(font.family())) { @@ -451,12 +453,16 @@ DocumentStyle DocumentStyle::derive(const QUrl &url) const emojiFonts.front() = font.family(); } - // We don't support emoji fonts on lower than Qt 5.13 - #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) - font.setFamily(emojiFonts.front()); - #else - font.setFamilies(emojiFonts); - #endif + // Set emoji fonts if supported and enabled. + if (kristall::EMOJIS_SUPPORTED && + kristall::options.emojis_enabled) + { + font.setFamilies(emojiFonts); + } + else + { + font.setFamily(emojiFonts.front()); + } }; patchup_font(themed.h1_font); diff --git a/src/kristall.hpp b/src/kristall.hpp index 8ae8cb2..638fe42 100644 --- a/src/kristall.hpp +++ b/src/kristall.hpp @@ -69,6 +69,7 @@ struct GenericSettings bool show_hidden_files_in_dirs = false; bool fancy_urlbar = true; bool fancy_quotes = true; + bool emojis_enabled = true; // This is set automatically QColor fancy_urlbar_dim_colour; @@ -155,6 +156,9 @@ namespace kristall void saveWindowState(); extern QString default_font_family, default_font_family_fixed; + + //! Whether emojis are supprted in current build configuration + extern const bool EMOJIS_SUPPORTED; } #endif // KRISTALL_HPP diff --git a/src/main.cpp b/src/main.cpp index 546371c..645630f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,15 @@ QDir kristall::dirs::offline_pages; QDir kristall::dirs::themes; QDir kristall::dirs::styles; +// We need QFont::setFamilies for emojis to work properly, +// Qt versions below 5.13 don't support this. +const bool kristall::EMOJIS_SUPPORTED = +#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) + false; +#else + true; +#endif + QString toFingerprintString(QSslCertificate const & certificate) { return QCryptographicHash::hash(certificate.toDer(), QCryptographicHash::Sha256).toHex(':'); @@ -379,6 +388,10 @@ void GenericSettings::load(QSettings &settings) fancy_quotes = settings.value("fancy_quotes", true).toBool(); + emojis_enabled = kristall::EMOJIS_SUPPORTED + ? settings.value("emojis_enabled", true).toBool() + : false; + max_redirections = settings.value("max_redirections", 5).toInt(); redirection_policy = RedirectionWarning(settings.value("redirection_policy ", WarnOnHostChange).toInt()); @@ -439,6 +452,13 @@ void GenericSettings::save(QSettings &settings) const settings.setValue("cache_threshold", cache_threshold); settings.setValue("cache_life", cache_life); settings.setValue("cache_unlimited_life", cache_unlimited_life); + + if (kristall::EMOJIS_SUPPORTED) + { + // Save emoji pref only if emojis are supported, so if user changes to a build + // with emoji support, they get it out of the box. + settings.setValue("emojis_enabled", emojis_enabled); + } } |
