From 7ff4d2bdabb7b10b5011d4a4102a793f71a90c27 Mon Sep 17 00:00:00 2001 From: pajlada Date: Mon, 25 Nov 2024 00:18:10 +0100 Subject: [PATCH] feat: Add setting to hide scrollbar highlights (#5732) --- CHANGELOG.md | 1 + src/singletons/Settings.hpp | 4 + src/widgets/Scrollbar.cpp | 106 ++++++++++++---------- src/widgets/Scrollbar.hpp | 6 ++ src/widgets/settingspages/GeneralPage.cpp | 3 + 5 files changed, 72 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebef9fd6..22bb267c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ - Minor: Mentions of FrankerFaceZ and BetterTTV in settings are standardized as such. (#5698) - Minor: Emote names are no longer duplicated when using smarter emote completion. (#5705) - Minor: Added a setting to hide the scrollbar thumb (the handle you can drag). Hiding the scrollbar thumb will disable mouse click & drag interactions in the scrollbar. (#5731) +- Minor: Added a setting to hide the scrollbar highlights. (#5732) - Minor: The window layout is now backed up like the other settings. (#5647) - Bugfix: Fixed tab move animation occasionally failing to start after closing a tab. (#5426, #5612) - Bugfix: If a network request errors with 200 OK, Qt's error code is now reported instead of the HTTP status. (#5378) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index b5bd914c..0becafa0 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -229,6 +229,10 @@ public: "/appearance/scrollbar/hideThumb", false, }; + BoolSetting hideScrollbarHighlights = { + "/appearance/scrollbar/hideHighlights", + false, + }; /// Behaviour BoolSetting allowDuplicateMessages = {"/behaviour/allowDuplicateMessages", diff --git a/src/widgets/Scrollbar.cpp b/src/widgets/Scrollbar.cpp index 24bdd804..d860a241 100644 --- a/src/widgets/Scrollbar.cpp +++ b/src/widgets/Scrollbar.cpp @@ -48,6 +48,13 @@ Scrollbar::Scrollbar(size_t messagesLimit, ChannelView *parent) this->update(); }, this->signalHolder); + + getSettings()->hideScrollbarHighlights.connect( + [this](bool newValue) { + this->settingHideHighlights = newValue; + this->update(); + }, + this->signalHolder); } boost::circular_buffer Scrollbar::getHighlights() const @@ -309,62 +316,60 @@ void Scrollbar::paintEvent(QPaintEvent * /*event*/) } } - // draw highlights - if (this->highlights_.empty()) + if (this->shouldShowHighlights() && !this->highlights_.empty()) { - return; - } + size_t nHighlights = this->highlights_.size(); + int w = this->width(); + float dY = static_cast(this->height()) / + static_cast(nHighlights); + int highlightHeight = + static_cast(std::ceil(std::max(this->scale() * 2.0F, dY))); - size_t nHighlights = this->highlights_.size(); - int w = this->width(); - float dY = - static_cast(this->height()) / static_cast(nHighlights); - int highlightHeight = - static_cast(std::ceil(std::max(this->scale() * 2.0F, dY))); - - for (size_t i = 0; i < nHighlights; i++) - { - const auto &highlight = this->highlights_[i]; - - if (highlight.isNull()) + for (size_t i = 0; i < nHighlights; i++) { - continue; - } + const auto &highlight = this->highlights_[i]; - if (highlight.isRedeemedHighlight() && !enableRedeemedHighlights) - { - continue; - } - - if (highlight.isFirstMessageHighlight() && - !enableFirstMessageHighlights) - { - continue; - } - - if (highlight.isElevatedMessageHighlight() && - !enableElevatedMessageHighlights) - { - continue; - } - - QColor color = highlight.getColor(); - color.setAlpha(255); - - int y = static_cast(dY * static_cast(i)); - switch (highlight.getStyle()) - { - case ScrollbarHighlight::Default: { - painter.fillRect(w / 8 * 3, y, w / 4, highlightHeight, color); + if (highlight.isNull()) + { + continue; } - break; - case ScrollbarHighlight::Line: { - painter.fillRect(0, y, w, 1, color); + if (highlight.isRedeemedHighlight() && !enableRedeemedHighlights) + { + continue; } - break; - case ScrollbarHighlight::None:; + if (highlight.isFirstMessageHighlight() && + !enableFirstMessageHighlights) + { + continue; + } + + if (highlight.isElevatedMessageHighlight() && + !enableElevatedMessageHighlights) + { + continue; + } + + QColor color = highlight.getColor(); + color.setAlpha(255); + + int y = static_cast(dY * static_cast(i)); + switch (highlight.getStyle()) + { + case ScrollbarHighlight::Default: { + painter.fillRect(w / 8 * 3, y, w / 4, highlightHeight, + color); + } + break; + + case ScrollbarHighlight::Line: { + painter.fillRect(0, y, w, 1, color); + } + break; + + case ScrollbarHighlight::None:; + } } } } @@ -490,6 +495,11 @@ bool Scrollbar::shouldShowThumb() const return !(this->hideThumb || this->settingHideThumb); } +bool Scrollbar::shouldShowHighlights() const +{ + return !this->settingHideHighlights; +} + bool Scrollbar::shouldHandleMouseEvents() const { return this->shouldShowThumb(); diff --git a/src/widgets/Scrollbar.hpp b/src/widgets/Scrollbar.hpp index 44250f4a..cb1dd058 100644 --- a/src/widgets/Scrollbar.hpp +++ b/src/widgets/Scrollbar.hpp @@ -133,6 +133,9 @@ public: /// Returns true if we should show the thumb (the handle you can drag) bool shouldShowThumb() const; + /// Returns true if we should show the highlights + bool shouldShowHighlights() const; + bool shouldHandleMouseEvents() const; // offset the desired value without breaking smooth scolling @@ -181,6 +184,9 @@ private: /// Controlled by the "Hide scrollbar thumb" setting bool settingHideThumb{false}; + /// Controlled by the "Hide scrollbar highlights" setting + bool settingHideHighlights{false}; + MouseLocation mouseOverLocation_ = MouseLocation::Outside; MouseLocation mouseDownLocation_ = MouseLocation::Outside; QPoint lastMousePosition_; diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index c57837fd..28de20e7 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -463,6 +463,9 @@ void GeneralPage::initLayout(GeneralPageView &layout) "Hiding the scrollbar thumb (the handle you can drag) will disable " "all mouse interaction in the scrollbar."); + layout.addCheckbox("Hide scrollbar highlights", s.hideScrollbarHighlights, + false); + layout.addTitle("Messages"); layout.addCheckbox( "Separate with lines", s.separateMessages, false,