From 848d5c87895e507945a7a95b9ece4e0c9f0c6423 Mon Sep 17 00:00:00 2001 From: fourtf Date: Wed, 25 Sep 2019 23:47:13 +0200 Subject: [PATCH] Fixes #1336 Pause on hover breaks moves selection --- src/widgets/helper/ChannelView.cpp | 54 ++++++++++++++++-------------- src/widgets/helper/ChannelView.hpp | 18 +++++----- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index e10d670ee..c6c60597e 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1,5 +1,17 @@ #include "ChannelView.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "Application.hpp" #include "common/Common.hpp" #include "controllers/accounts/AccountController.hpp" @@ -25,19 +37,6 @@ #include "widgets/helper/EffectLabel.hpp" #include "widgets/splits/Split.hpp" -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - #define DRAW_WIDTH (this->width()) #define SELECTION_RESUME_SCROLLING_MSG_THRESHOLD 3 #define CHAT_HOVER_PAUSE_DURATION 1000 @@ -122,7 +121,7 @@ ChannelView::ChannelView(BaseWidget *parent) for (auto it = this->pauses_.begin(); it != this->pauses_.end();) it = it->second ? this->pauses_.erase(it) : ++it; - this->updatePauseTimer(); + this->updatePauses(); }); auto shortcut = new QShortcut(QKeySequence("Ctrl+C"), this); @@ -232,7 +231,7 @@ void ChannelView::pause(PauseReason reason, boost::optional msecs) this->pauses_[reason] = boost::none; } - this->updatePauseTimer(); + this->updatePauses(); } void ChannelView::unpause(PauseReason reason) @@ -240,23 +239,17 @@ void ChannelView::unpause(PauseReason reason) /// Remove the value from the map this->pauses_.erase(reason); - this->updatePauseTimer(); - - /// Move selection - this->selection_.selectionMin.messageIndex -= this->pauseSelectionOffset_; - this->selection_.selectionMax.messageIndex -= this->pauseSelectionOffset_; - this->selection_.start.messageIndex -= this->pauseSelectionOffset_; - this->selection_.end.messageIndex -= this->pauseSelectionOffset_; - - this->pauseSelectionOffset_ = 0; + this->updatePauses(); } -void ChannelView::updatePauseTimer() +void ChannelView::updatePauses() { using namespace std::chrono; if (this->pauses_.empty()) { + this->unpaused(); + /// No pauses so we can stop the timer this->pauseEnd_ = boost::none; this->pauseTimer_.stop(); @@ -292,6 +285,17 @@ void ChannelView::updatePauseTimer() } } +void ChannelView::unpaused() +{ + /// Move selection + this->selection_.selectionMin.messageIndex -= this->pauseSelectionOffset_; + this->selection_.selectionMax.messageIndex -= this->pauseSelectionOffset_; + this->selection_.start.messageIndex -= this->pauseSelectionOffset_; + this->selection_.end.messageIndex -= this->pauseSelectionOffset_; + + this->pauseSelectionOffset_ = 0; +} + void ChannelView::themeChangedEvent() { BaseWidget::themeChangedEvent(); diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 0aed55a5c..308681624 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -1,22 +1,21 @@ #pragma once -#include "common/FlagsEnum.hpp" -#include "messages/Image.hpp" -#include "messages/LimitedQueue.hpp" -#include "messages/LimitedQueueSnapshot.hpp" -#include "messages/Selection.hpp" -#include "widgets/BaseWidget.hpp" - #include #include #include #include #include #include - #include #include +#include "common/FlagsEnum.hpp" +#include "messages/Image.hpp" +#include "messages/LimitedQueue.hpp" +#include "messages/LimitedQueueSnapshot.hpp" +#include "messages/Selection.hpp" +#include "widgets/BaseWidget.hpp" + namespace chatterino { enum class HighlightState; @@ -146,7 +145,8 @@ private: void addContextMenuItems(const MessageLayoutElement *hoveredElement, MessageLayout *layout); int getLayoutWidth() const; - void updatePauseTimer(); + void updatePauses(); + void unpaused(); QTimer *layoutCooldown_; bool layoutQueued_;