From 23feba7e5a1396110d543a676e018bcbdfa50d39 Mon Sep 17 00:00:00 2001 From: Mike Skec Date: Sat, 27 Feb 2021 09:23:59 +1100 Subject: Adds emoji toggle preference. --- src/dialogs/settingsdialog.cpp | 28 +++++++++++++++++++ src/dialogs/settingsdialog.hpp | 3 ++ src/dialogs/settingsdialog.ui | 63 +++++++++++++++++++++++++++++++++--------- src/documentstyle.cpp | 20 +++++++++----- src/kristall.hpp | 4 +++ src/main.cpp | 20 ++++++++++++++ 6 files changed, 118 insertions(+), 20 deletions(-) (limited to 'src') 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 @@ + + + Render emojis + + + Whether to render emojis in a page. + + + + + + + + + On + + + emojisBtnGroup + + + + + + + Off + + + emojisBtnGroup + + + + + + Max. Number of Redirections - + 5 - + Redirection Handling - + - + Network Timeout - + ms @@ -416,14 +450,14 @@ - + Additional toolbar buttons - + @@ -455,7 +489,7 @@ - + Total cache size limit @@ -465,7 +499,7 @@ - + KiB @@ -479,7 +513,7 @@ - + Cached item size threshold @@ -489,7 +523,7 @@ - + KiB @@ -503,7 +537,7 @@ - + Cached item life @@ -513,7 +547,7 @@ - + @@ -1503,6 +1537,8 @@ urlbarhl_none fancyquotes_on fancyquotes_off + emojis_on + emojis_off max_redirects redirection_mode network_timeout @@ -1598,5 +1634,6 @@ + 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); + } } -- cgit v1.2.3