From f6d02fffc99ec203e1b90733dd9237fdb451f6c0 Mon Sep 17 00:00:00 2001 From: fourtf Date: Thu, 17 May 2018 17:27:20 +0200 Subject: [PATCH] rewrote the pausing chat on hover functionality --- src/widgets/helper/channelview.cpp | 75 ++++++++++++------------------ src/widgets/helper/channelview.hpp | 7 +-- 2 files changed, 34 insertions(+), 48 deletions(-) diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index f30ab2323..07e7044f2 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -54,9 +54,12 @@ ChannelView::ChannelView(BaseWidget *parent) this->scrollBar.getCurrentValueChanged().connect([this] { // Whenever the scrollbar value has been changed, re-render the ChatWidgetView this->actuallyLayoutMessages(true); - this->goToBottom->setVisible(this->enableScrollingToBottom && this->scrollBar.isVisible() && - !this->scrollBar.isAtBottom() && - !this->scrollToBottomAfterTemporaryPause); + + if (!this->isPaused()) { + this->goToBottom->setVisible(this->enableScrollingToBottom && + this->scrollBar.isVisible() && + !this->scrollBar.isAtBottom()); + } this->queueUpdate(); }); @@ -98,21 +101,10 @@ ChannelView::ChannelView(BaseWidget *parent) this->pauseTimeout.setSingleShot(true); QObject::connect(&this->pauseTimeout, &QTimer::timeout, [this] { - this->pausedTemporarily = false; - if (!this->isPaused() && this->scrollToBottomAfterTemporaryPause) { - this->scrollBar.scrollToBottom(); - } - - this->scrollToBottomAfterTemporaryPause = false; + this->layoutMessages(); }); - // auto e = new QResizeEvent(this->size(), this->size()); - // this->resizeEvent(e); - // delete e; - - // this->scrollBar.resize(this->scrollBar.width(), this->height() + 1); - app->settings->showLastMessageIndicator.connect( [this](auto, auto) { this->update(); // @@ -134,7 +126,7 @@ ChannelView::ChannelView(BaseWidget *parent) this->scrollBar.setGeometry(this->width() - this->scrollBar.width(), 0, this->scrollBar.width(), this->height()); }); -} +} // namespace widgets ChannelView::~ChannelView() { @@ -260,8 +252,11 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) // Perhaps also if the user scrolled with the scrollwheel in this ChatWidget in the last 0.2 // seconds or something if (this->enableScrollingToBottom && this->showingLatestMessages && showScrollbar) { - this->scrollBar.scrollToBottom(this->messageWasAdded && - app->settings->enableSmoothScrollingNewMessages.getValue()); + if (!this->isPaused()) { + this->scrollBar.scrollToBottom( + this->messageWasAdded && + app->settings->enableSmoothScrollingNewMessages.getValue()); + } this->messageWasAdded = false; } @@ -493,14 +488,6 @@ void ChannelView::detachChannel() void ChannelView::pause(int msecTimeout) { - if (!this->pauseTimeout.isActive()) { - this->scrollToBottomAfterTemporaryPause = this->scrollBar.isAtBottom(); - } - - this->beginPause(); - - // this->scrollBar.setDesiredValue(this->scrollBar.getDesiredValue() - 0.01); - this->pausedTemporarily = true; this->pauseTimeout.start(msecTimeout); @@ -535,10 +522,8 @@ void ChannelView::setSelection(const SelectionItem &start, const SelectionItem & { // selections if (!this->selecting && start != end) { - this->messagesAddedSinceSelectionPause = - (this->scrollToBottomAfterTemporaryPause || this->scrollBar.isAtBottom()) ? 0 : 100; + this->messagesAddedSinceSelectionPause = 0; - this->beginPause(); this->selecting = true; this->pausedBySelection = true; } @@ -577,17 +562,17 @@ bool ChannelView::isPaused() return this->pausedTemporarily || this->pausedBySelection; } -void ChannelView::beginPause() -{ - if (this->scrollBar.isAtBottom()) { - this->scrollBar.setDesiredValue(this->scrollBar.getDesiredValue() - 0.001); - this->layoutMessages(); - } -} +// void ChannelView::beginPause() +//{ +// if (this->scrollBar.isAtBottom()) { +// this->scrollBar.setDesiredValue(this->scrollBar.getDesiredValue() - 0.001); +// this->layoutMessages(); +// } +//} -void ChannelView::endPause() -{ -} +// void ChannelView::endPause() +//{ +//} void ChannelView::paintEvent(QPaintEvent * /*event*/) { @@ -675,6 +660,9 @@ void ChannelView::drawMessages(QPainter &painter) void ChannelView::wheelEvent(QWheelEvent *event) { + this->pausedBySelection = false; + this->pausedTemporarily = false; + if (this->scrollBar.isVisible()) { auto app = getApp(); @@ -745,6 +733,7 @@ void ChannelView::enterEvent(QEvent *) void ChannelView::leaveEvent(QEvent *) { this->pausedTemporarily = false; + this->layoutMessages(); } void ChannelView::mouseMoveEvent(QMouseEvent *event) @@ -892,14 +881,10 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event) auto app = getApp(); if (this->selecting) { - if (this->messagesAddedSinceSelectionPause <= SELECTION_RESUME_SCROLLING_MSG_THRESHOLD) { - // don't scroll - this->scrollBar.scrollToBottom(false); - // this->scrollBar.setDesiredValue(this->scrollBar.getDesiredValue() - - // this->messagesAddedSinceSelectionPause); + if (this->messagesAddedSinceSelectionPause > SELECTION_RESUME_SCROLLING_MSG_THRESHOLD) { + this->showingLatestMessages = false; } - this->scrollToBottomAfterTemporaryPause = false; this->pausedBySelection = false; this->selecting = false; this->pauseTimeout.stop(); diff --git a/src/widgets/helper/channelview.hpp b/src/widgets/helper/channelview.hpp index a3c9b6632..98f028d9a 100644 --- a/src/widgets/helper/channelview.hpp +++ b/src/widgets/helper/channelview.hpp @@ -86,10 +86,11 @@ private: bool updateQueued = false; bool messageWasAdded = false; bool lastMessageHasAlternateBackground = false; + bool pausedTemporarily = false; bool pausedBySelection = false; - bool scrollToBottomAfterTemporaryPause = false; int messagesAddedSinceSelectionPause = 0; + QTimer pauseTimeout; boost::optional overrideFlags; messages::MessageLayoutPtr lastReadMessage; @@ -104,8 +105,8 @@ private: messages::MessageElement::Flags getFlags() const; bool isPaused(); - void beginPause(); - void endPause(); + // void beginPause(); + // void endPause(); ChannelPtr channel;