From fd299f113c3e746f8d4d8f873ec5eb33de802da4 Mon Sep 17 00:00:00 2001 From: pajlada Date: Sun, 24 Nov 2024 13:18:42 +0100 Subject: [PATCH] feat: Add setting to hide scrollbar thumb (#5731) Hiding the scrollbar thumb will disable all mouse click/drag interaction in the scrollbar --- CHANGELOG.md | 1 + src/singletons/Settings.hpp | 6 ++++ src/widgets/OverlayWindow.cpp | 2 +- src/widgets/Scrollbar.cpp | 40 ++++++++++++++++++++--- src/widgets/Scrollbar.hpp | 14 ++++++-- src/widgets/settingspages/GeneralPage.cpp | 5 +++ 6 files changed, 61 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 574f3ba6..fcb5ce55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ - Minor: Made usernames in bits and sub messages clickable. (#5686) - 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) - 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) - Bugfix: Fixed restricted users usernames not being clickable. (#5405) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index fa039184..b5bd914c 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -224,6 +224,12 @@ public: {300, 500}, }; + // Scrollbar + BoolSetting hideScrollbarThumb = { + "/appearance/scrollbar/hideThumb", + false, + }; + /// Behaviour BoolSetting allowDuplicateMessages = {"/behaviour/allowDuplicateMessages", true}; diff --git a/src/widgets/OverlayWindow.cpp b/src/widgets/OverlayWindow.cpp index ce7ee248..c454843f 100644 --- a/src/widgets/OverlayWindow.cpp +++ b/src/widgets/OverlayWindow.cpp @@ -126,7 +126,7 @@ OverlayWindow::OverlayWindow(IndirectChannel channel, this->holder_.managedConnect(this->channel_.getChannelChanged(), [this]() { this->channelView_.setChannel(this->channel_.get()); }); - this->channelView_.scrollbar()->setShowThumb(false); + this->channelView_.scrollbar()->setHideThumb(true); this->setAutoFillBackground(false); this->resize(300, 500); diff --git a/src/widgets/Scrollbar.cpp b/src/widgets/Scrollbar.cpp index 4aef4503..24bdd804 100644 --- a/src/widgets/Scrollbar.cpp +++ b/src/widgets/Scrollbar.cpp @@ -41,6 +41,13 @@ Scrollbar::Scrollbar(size_t messagesLimit, ChannelView *parent) &Scrollbar::resetBounds); this->setMouseTracking(true); + + getSettings()->hideScrollbarThumb.connect( + [this](bool newValue) { + this->settingHideThumb = newValue; + this->update(); + }, + this->signalHolder); } boost::circular_buffer Scrollbar::getHighlights() const @@ -285,7 +292,7 @@ void Scrollbar::paintEvent(QPaintEvent * /*event*/) bool enableElevatedMessageHighlights = getSettings()->enableElevatedMessageHighlight; - if (this->showThumb_) + if (this->shouldShowThumb()) { this->thumbRect_.setX(xOffset); @@ -369,6 +376,11 @@ void Scrollbar::resizeEvent(QResizeEvent * /*event*/) void Scrollbar::mouseMoveEvent(QMouseEvent *event) { + if (!this->shouldHandleMouseEvents()) + { + return; + } + if (this->mouseDownLocation_ == MouseLocation::Outside) { auto moveLocation = this->locationOfMouseEvent(event); @@ -394,12 +406,22 @@ void Scrollbar::mouseMoveEvent(QMouseEvent *event) void Scrollbar::mousePressEvent(QMouseEvent *event) { + if (!this->shouldHandleMouseEvents()) + { + return; + } + this->mouseDownLocation_ = this->locationOfMouseEvent(event); this->update(); } void Scrollbar::mouseReleaseEvent(QMouseEvent *event) { + if (!this->shouldHandleMouseEvents()) + { + return; + } + auto releaseLocation = this->locationOfMouseEvent(event); if (this->mouseDownLocation_ != releaseLocation) { @@ -452,17 +474,27 @@ void Scrollbar::updateScroll() this->update(); } -void Scrollbar::setShowThumb(bool showThumb) +void Scrollbar::setHideThumb(bool hideThumb) { - if (this->showThumb_ == showThumb) + if (this->hideThumb == hideThumb) { return; } - this->showThumb_ = showThumb; + this->hideThumb = hideThumb; this->update(); } +bool Scrollbar::shouldShowThumb() const +{ + return !(this->hideThumb || this->settingHideThumb); +} + +bool Scrollbar::shouldHandleMouseEvents() const +{ + return this->shouldShowThumb(); +} + Scrollbar::MouseLocation Scrollbar::locationOfMouseEvent( QMouseEvent *event) const { diff --git a/src/widgets/Scrollbar.hpp b/src/widgets/Scrollbar.hpp index 65fad101..44250f4a 100644 --- a/src/widgets/Scrollbar.hpp +++ b/src/widgets/Scrollbar.hpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -127,7 +128,12 @@ public: /// unaffected by simultaneous shifts of minimum and maximum. qreal getRelativeCurrentValue() const; - void setShowThumb(bool showthumb); + void setHideThumb(bool hideThumb); + + /// Returns true if we should show the thumb (the handle you can drag) + bool shouldShowThumb() const; + + bool shouldHandleMouseEvents() const; // offset the desired value without breaking smooth scolling void offset(qreal value); @@ -171,7 +177,9 @@ private: boost::circular_buffer highlights_; bool atBottom_{false}; - bool showThumb_ = true; + bool hideThumb{false}; + /// Controlled by the "Hide scrollbar thumb" setting + bool settingHideThumb{false}; MouseLocation mouseOverLocation_ = MouseLocation::Outside; MouseLocation mouseDownLocation_ = MouseLocation::Outside; @@ -189,6 +197,8 @@ private: pajlada::Signals::NoArgSignal currentValueChanged_; pajlada::Signals::NoArgSignal desiredValueChanged_; + + pajlada::Signals::SignalHolder signalHolder; }; } // namespace chatterino diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 58cc3731..c57837fd 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -458,6 +458,11 @@ void GeneralPage::initLayout(GeneralPageView &layout) }, false); + layout.addCheckbox( + "Hide scrollbar thumb", s.hideScrollbarThumb, false, + "Hiding the scrollbar thumb (the handle you can drag) will disable " + "all mouse interaction in the scrollbar."); + layout.addTitle("Messages"); layout.addCheckbox( "Separate with lines", s.separateMessages, false,