diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-01-02 12:20:34 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-01-02 12:41:49 +0100 |
| commit | 05df68b1331dbfdf9aff98139a9a1f96f147e651 (patch) | |
| tree | 3f84db83e289a37166ef84fe7422f668ef8a92d9 /src | |
| parent | b35e6959aef83d9d0873621513d7d7d33d9f141e (diff) | |
| download | kristall-05df68b1331dbfdf9aff98139a9a1f96f147e651.tar.gz | |
Fix bug with fancy url bar styling
We are now also using a custom colour for it in the default light/dark themes, just because we can get a little more control over how it looks. The OS Default theme uses the 'mid' colour from palette
Diffstat (limited to 'src')
| -rw-r--r-- | src/browsertab.cpp | 14 | ||||
| -rw-r--r-- | src/browsertab.hpp | 2 | ||||
| -rw-r--r-- | src/kristall.hpp | 4 | ||||
| -rw-r--r-- | src/main.cpp | 11 |
4 files changed, 22 insertions, 9 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp index 60c3f40..b20d538 100644 --- a/src/browsertab.cpp +++ b/src/browsertab.cpp @@ -1115,7 +1115,7 @@ void BrowserTab::setUrlBarText(const QString & text) void BrowserTab::updateUrlBarStyle() { // https://stackoverflow.com/a/14424003 - static const auto setLineEditTextFormat = + const auto setLineEditTextFormat = [](QLineEdit* l, const QList<QTextLayout::FormatRange>& f) { if (!l) return; @@ -1138,7 +1138,6 @@ void BrowserTab::updateUrlBarStyle() // Set all text to default colour if url bar // is focused, is at an internal location (like about:...), // or has an invalid URL. - static bool no_style = false; if (!kristall::options.fancy_urlbar || this->ui->url_bar->hasFocus() || !url.isValid() || @@ -1146,16 +1145,16 @@ void BrowserTab::updateUrlBarStyle() mainWindow->settings_visible) { // Disable styling - if (!no_style) + if (!this->no_url_style) { setLineEditTextFormat(this->ui->url_bar, QList<QTextLayout::FormatRange>()); - no_style = true; + this->no_url_style = true; } return; } - no_style = false; + this->no_url_style = false; // Styling enabled: 'authority' (hostname, port, etc) of // the URL is highlighted (i.e default colour), @@ -1173,11 +1172,10 @@ void BrowserTab::updateUrlBarStyle() QList<QTextLayout::FormatRange> formats; // We only need to create one style, which is the - // non-authority colour text (grey-ish, we use the theme's - // placeholder text colour for this). + // non-authority colour text (grey-ish, determined by theme in kristall:setTheme) // The rest of the text is in default theme foreground colour. QTextCharFormat f; - f.setForeground(mainWindow->palette().color(QPalette::Mid)); + f.setForeground(kristall::options.fancy_urlbar_dim_colour); // Create format range for left-side of URL QTextLayout::FormatRange fr_left; diff --git a/src/browsertab.hpp b/src/browsertab.hpp index cbb21c4..2b3854e 100644 --- a/src/browsertab.hpp +++ b/src/browsertab.hpp @@ -207,6 +207,8 @@ public: bool needs_rerender; QString page_title; + + bool no_url_style = false; }; #endif // BROWSERTAB_HPP diff --git a/src/kristall.hpp b/src/kristall.hpp index b191aec..88e7ed9 100644 --- a/src/kristall.hpp +++ b/src/kristall.hpp @@ -47,6 +47,10 @@ struct GenericSettings bool use_os_scheme_handler = false; bool show_hidden_files_in_dirs = false; bool fancy_urlbar = true; + + // This is set automatically + QColor fancy_urlbar_dim_colour; + TextDisplay gophermap_display = FormattedText; int max_redirections = 5; RedirectionWarning redirection_policy = WarnOnHostChange; diff --git a/src/main.cpp b/src/main.cpp index 2b5e635..ce64040 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -428,12 +428,17 @@ void kristall::saveSettings() void kristall::setTheme(Theme theme) { assert(app != nullptr); + if(theme == Theme::os_default) { app->setStyleSheet(""); QIcon::setThemeName(""); + + // Use "mid" colour for our URL bar dim colour: + kristall::options.fancy_urlbar_dim_colour + = app->palette().color(QPalette::Mid); } - if(theme == Theme::light) + else if(theme == Theme::light) { QFile file(":/light.qss"); file.open(QFile::ReadOnly | QFile::Text); @@ -441,6 +446,8 @@ void kristall::setTheme(Theme theme) app->setStyleSheet(stream.readAll()); QIcon::setThemeName("light"); + + kristall::options.fancy_urlbar_dim_colour = QColor(128, 128, 128, 255); } else if(theme == Theme::dark) { @@ -450,6 +457,8 @@ void kristall::setTheme(Theme theme) app->setStyleSheet(stream.readAll()); QIcon::setThemeName("dark"); + + kristall::options.fancy_urlbar_dim_colour = QColor(150, 150, 150, 255); } } |
