feat: Add setting to hide scrollbar thumb (#5731)

Hiding the scrollbar thumb will disable all mouse click/drag interaction
in the scrollbar
This commit is contained in:
pajlada
2024-11-24 13:18:42 +01:00
committed by GitHub
parent 14c4bb6459
commit fd299f113c
6 changed files with 61 additions and 7 deletions
+1 -1
View File
@@ -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);
+36 -4
View File
@@ -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<ScrollbarHighlight> 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
{
+12 -2
View File
@@ -5,6 +5,7 @@
#include <boost/circular_buffer.hpp>
#include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp>
#include <QPropertyAnimation>
#include <QWidget>
@@ -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<ScrollbarHighlight> 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
@@ -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,