Fixes #1336 Pause on hover breaks moves selection

This commit is contained in:
fourtf 2019-09-25 23:47:13 +02:00
parent 4e48416600
commit 848d5c8789
2 changed files with 38 additions and 34 deletions

View file

@ -1,5 +1,17 @@
#include "ChannelView.hpp" #include "ChannelView.hpp"
#include <QClipboard>
#include <QDebug>
#include <QDesktopServices>
#include <QGraphicsBlurEffect>
#include <QMessageBox>
#include <QPainter>
#include <algorithm>
#include <chrono>
#include <cmath>
#include <functional>
#include <memory>
#include "Application.hpp" #include "Application.hpp"
#include "common/Common.hpp" #include "common/Common.hpp"
#include "controllers/accounts/AccountController.hpp" #include "controllers/accounts/AccountController.hpp"
@ -25,19 +37,6 @@
#include "widgets/helper/EffectLabel.hpp" #include "widgets/helper/EffectLabel.hpp"
#include "widgets/splits/Split.hpp" #include "widgets/splits/Split.hpp"
#include <QClipboard>
#include <QDebug>
#include <QDesktopServices>
#include <QGraphicsBlurEffect>
#include <QMessageBox>
#include <QPainter>
#include <algorithm>
#include <chrono>
#include <cmath>
#include <functional>
#include <memory>
#define DRAW_WIDTH (this->width()) #define DRAW_WIDTH (this->width())
#define SELECTION_RESUME_SCROLLING_MSG_THRESHOLD 3 #define SELECTION_RESUME_SCROLLING_MSG_THRESHOLD 3
#define CHAT_HOVER_PAUSE_DURATION 1000 #define CHAT_HOVER_PAUSE_DURATION 1000
@ -122,7 +121,7 @@ ChannelView::ChannelView(BaseWidget *parent)
for (auto it = this->pauses_.begin(); it != this->pauses_.end();) for (auto it = this->pauses_.begin(); it != this->pauses_.end();)
it = it->second ? this->pauses_.erase(it) : ++it; it = it->second ? this->pauses_.erase(it) : ++it;
this->updatePauseTimer(); this->updatePauses();
}); });
auto shortcut = new QShortcut(QKeySequence("Ctrl+C"), this); auto shortcut = new QShortcut(QKeySequence("Ctrl+C"), this);
@ -232,7 +231,7 @@ void ChannelView::pause(PauseReason reason, boost::optional<uint> msecs)
this->pauses_[reason] = boost::none; this->pauses_[reason] = boost::none;
} }
this->updatePauseTimer(); this->updatePauses();
} }
void ChannelView::unpause(PauseReason reason) void ChannelView::unpause(PauseReason reason)
@ -240,23 +239,17 @@ void ChannelView::unpause(PauseReason reason)
/// Remove the value from the map /// Remove the value from the map
this->pauses_.erase(reason); this->pauses_.erase(reason);
this->updatePauseTimer(); this->updatePauses();
/// 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::updatePauseTimer() void ChannelView::updatePauses()
{ {
using namespace std::chrono; using namespace std::chrono;
if (this->pauses_.empty()) if (this->pauses_.empty())
{ {
this->unpaused();
/// No pauses so we can stop the timer /// No pauses so we can stop the timer
this->pauseEnd_ = boost::none; this->pauseEnd_ = boost::none;
this->pauseTimer_.stop(); 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() void ChannelView::themeChangedEvent()
{ {
BaseWidget::themeChangedEvent(); BaseWidget::themeChangedEvent();

View file

@ -1,22 +1,21 @@
#pragma once #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 <QPaintEvent> #include <QPaintEvent>
#include <QScroller> #include <QScroller>
#include <QTimer> #include <QTimer>
#include <QWheelEvent> #include <QWheelEvent>
#include <QWidget> #include <QWidget>
#include <pajlada/signals/signal.hpp> #include <pajlada/signals/signal.hpp>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#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 { namespace chatterino {
enum class HighlightState; enum class HighlightState;
@ -146,7 +145,8 @@ private:
void addContextMenuItems(const MessageLayoutElement *hoveredElement, void addContextMenuItems(const MessageLayoutElement *hoveredElement,
MessageLayout *layout); MessageLayout *layout);
int getLayoutWidth() const; int getLayoutWidth() const;
void updatePauseTimer(); void updatePauses();
void unpaused();
QTimer *layoutCooldown_; QTimer *layoutCooldown_;
bool layoutQueued_; bool layoutQueued_;