Skip to content

Commit

Permalink
feat: Add setting to hide scrollbar thumb (#5731)
Browse files Browse the repository at this point in the history
Hiding the scrollbar thumb will disable all mouse click/drag interaction
in the scrollbar
  • Loading branch information
pajlada authored Nov 24, 2024
1 parent 14c4bb6 commit fd299f1
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/singletons/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ class Settings
{300, 500},
};

// Scrollbar
BoolSetting hideScrollbarThumb = {
"/appearance/scrollbar/hideThumb",
false,
};

/// Behaviour
BoolSetting allowDuplicateMessages = {"/behaviour/allowDuplicateMessages",
true};
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/OverlayWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 36 additions & 4 deletions src/widgets/Scrollbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -285,7 +292,7 @@ void Scrollbar::paintEvent(QPaintEvent * /*event*/)
bool enableElevatedMessageHighlights =
getSettings()->enableElevatedMessageHighlight;

if (this->showThumb_)
if (this->shouldShowThumb())
{
this->thumbRect_.setX(xOffset);

Expand Down Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
{
Expand Down
14 changes: 12 additions & 2 deletions src/widgets/Scrollbar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <boost/circular_buffer.hpp>
#include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp>
#include <QPropertyAnimation>
#include <QWidget>

Expand Down Expand Up @@ -127,7 +128,12 @@ class Scrollbar : public BaseWidget
/// 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);
Expand Down Expand Up @@ -171,7 +177,9 @@ class Scrollbar : public BaseWidget
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;
Expand All @@ -189,6 +197,8 @@ class Scrollbar : public BaseWidget

pajlada::Signals::NoArgSignal currentValueChanged_;
pajlada::Signals::NoArgSignal desiredValueChanged_;

pajlada::Signals::SignalHolder signalHolder;
};

} // namespace chatterino
5 changes: 5 additions & 0 deletions src/widgets/settingspages/GeneralPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fd299f1

Please sign in to comment.