Pause chat while hovering. Fixes #208

Also pauses when clicking with double-click-links enabled and while
selecting text
This commit is contained in:
fourtf 2018-01-05 11:22:51 +01:00
parent 4ac03f396f
commit df81a0e5a5
5 changed files with 103 additions and 37 deletions

View file

@ -10,6 +10,11 @@ template <typename T>
class LimitedQueueSnapshot class LimitedQueueSnapshot
{ {
public: public:
LimitedQueueSnapshot()
: length(0)
{
}
LimitedQueueSnapshot(std::shared_ptr<std::vector<std::shared_ptr<std::vector<T>>>> _chunks, LimitedQueueSnapshot(std::shared_ptr<std::vector<std::shared_ptr<std::vector<T>>>> _chunks,
size_t _length, size_t _firstChunkOffset, size_t _lastChunkEnd) size_t _length, size_t _firstChunkOffset, size_t _lastChunkEnd)
: chunks(_chunks) : chunks(_chunks)

View file

@ -50,6 +50,7 @@ public:
FloatSetting mouseScrollMultiplier = {"/behaviour/mouseScrollMultiplier", 1.0}; FloatSetting mouseScrollMultiplier = {"/behaviour/mouseScrollMultiplier", 1.0};
StringSetting streamlinkPath = {"/behaviour/streamlink/path", ""}; StringSetting streamlinkPath = {"/behaviour/streamlink/path", ""};
StringSetting preferredQuality = {"/behaviour/streamlink/quality", "Choose"}; StringSetting preferredQuality = {"/behaviour/streamlink/quality", "Choose"};
BoolSetting pauseChatHover = {"/behaviour/pauseChatHover", false};
/// Commands /// Commands
BoolSetting allowCommandsAtEnd = {"/commands/allowCommandsAtEnd", false}; BoolSetting allowCommandsAtEnd = {"/commands/allowCommandsAtEnd", false};

View file

@ -26,6 +26,7 @@
#define LAYOUT_WIDTH \ #define LAYOUT_WIDTH \
(this->width() - (this->scrollBar.isVisible() ? 16 : 4) * this->getDpiMultiplier()) (this->width() - (this->scrollBar.isVisible() ? 16 : 4) * this->getDpiMultiplier())
#define PAUSE_TIME 1000
using namespace chatterino::messages; using namespace chatterino::messages;
@ -91,6 +92,8 @@ ChannelView::ChannelView(BaseWidget *parent)
this->updateTimer.start(); this->updateTimer.start();
} }
}); });
this->pauseTimeout.setSingleShot(true);
} }
ChannelView::~ChannelView() ChannelView::~ChannelView()
@ -357,7 +360,11 @@ bool ChannelView::getEnableScrollingToBottom() const
messages::LimitedQueueSnapshot<SharedMessageRef> ChannelView::getMessagesSnapshot() messages::LimitedQueueSnapshot<SharedMessageRef> ChannelView::getMessagesSnapshot()
{ {
return this->messages.getSnapshot(); if (!this->paused) {
this->snapshot = this->messages.getSnapshot();
}
return this->snapshot;
} }
void ChannelView::setChannel(std::shared_ptr<Channel> newChannel) void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
@ -446,6 +453,13 @@ void ChannelView::detachChannel()
this->messageRemovedConnection.disconnect(); this->messageRemovedConnection.disconnect();
} }
void ChannelView::pause(int msecTimeout)
{
this->paused = true;
this->pauseTimeout.start(msecTimeout);
}
void ChannelView::resizeEvent(QResizeEvent *) void ChannelView::resizeEvent(QResizeEvent *)
{ {
this->scrollBar.resize(this->scrollBar.width(), height()); this->scrollBar.resize(this->scrollBar.width(), height());
@ -882,8 +896,22 @@ void ChannelView::wheelEvent(QWheelEvent *event)
} }
} }
void ChannelView::enterEvent(QEvent *)
{
// this->pause(PAUSE_TIME);
}
void ChannelView::leaveEvent(QEvent *)
{
this->paused = false;
}
void ChannelView::mouseMoveEvent(QMouseEvent *event) void ChannelView::mouseMoveEvent(QMouseEvent *event)
{ {
if (singletons::SettingManager::getInstance().pauseChatHover.getValue()) {
this->pause(300);
}
auto tooltipWidget = TooltipWidget::getInstance(); auto tooltipWidget = TooltipWidget::getInstance();
std::shared_ptr<messages::MessageRef> message; std::shared_ptr<messages::MessageRef> message;
QPoint relativePos; QPoint relativePos;
@ -896,6 +924,16 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
return; return;
} }
// is selecting
if (this->selecting) {
this->pause(500);
int index = message->getSelectionIndex(relativePos);
this->setSelection(this->selection.start, SelectionItem(messageIndex, index));
this->queueUpdate();
}
// message under cursor is collapsed // message under cursor is collapsed
if (message->isCollapsed()) { if (message->isCollapsed()) {
this->setCursor(Qt::PointingHandCursor); this->setCursor(Qt::PointingHandCursor);
@ -903,15 +941,6 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
return; return;
} }
// is selecting
if (this->selecting) {
int index = message->getSelectionIndex(relativePos);
this->setSelection(this->selection.start, SelectionItem(messageIndex, index));
this->repaint();
}
// check if word underneath cursor // check if word underneath cursor
const messages::Word *hoverWord; const messages::Word *hoverWord;
if ((hoverWord = message->tryGetWordPart(relativePos)) == nullptr) { if ((hoverWord = message->tryGetWordPart(relativePos)) == nullptr) {
@ -937,6 +966,10 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
void ChannelView::mousePressEvent(QMouseEvent *event) void ChannelView::mousePressEvent(QMouseEvent *event)
{ {
if (singletons::SettingManager::getInstance().linksDoubleClickOnly.getValue()) {
this->pause(200);
}
this->isMouseDown = true; this->isMouseDown = true;
this->lastPressPosition = event->screenPos(); this->lastPressPosition = event->screenPos();
@ -989,6 +1022,10 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
return; return;
} }
if (this->selecting) {
this->paused = false;
}
this->isMouseDown = false; this->isMouseDown = false;
this->selecting = false; this->selecting = false;

View file

@ -39,6 +39,7 @@ public:
void clearSelection(); void clearSelection();
void setEnableScrollingToBottom(bool); void setEnableScrollingToBottom(bool);
bool getEnableScrollingToBottom() const; bool getEnableScrollingToBottom() const;
void pause(int msecTimeout);
void setChannel(std::shared_ptr<Channel> channel); void setChannel(std::shared_ptr<Channel> channel);
messages::LimitedQueueSnapshot<messages::SharedMessageRef> getMessagesSnapshot(); messages::LimitedQueueSnapshot<messages::SharedMessageRef> getMessagesSnapshot();
@ -56,6 +57,9 @@ protected:
virtual void paintEvent(QPaintEvent *) override; virtual void paintEvent(QPaintEvent *) override;
virtual void wheelEvent(QWheelEvent *event) override; virtual void wheelEvent(QWheelEvent *event) override;
virtual void enterEvent(QEvent *) override;
virtual void leaveEvent(QEvent *) override;
virtual void mouseMoveEvent(QMouseEvent *event) override; virtual void mouseMoveEvent(QMouseEvent *event) override;
virtual void mousePressEvent(QMouseEvent *event) override; virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override; virtual void mouseReleaseEvent(QMouseEvent *event) override;
@ -72,6 +76,10 @@ private:
QTimer updateTimer; QTimer updateTimer;
bool updateQueued = false; bool updateQueued = false;
bool messageWasAdded = false; bool messageWasAdded = false;
bool paused = false;
QTimer pauseTimeout;
messages::LimitedQueueSnapshot<messages::SharedMessageRef> snapshot;
void detachChannel(); void detachChannel();
void actuallyLayoutMessages(); void actuallyLayoutMessages();

View file

@ -327,15 +327,27 @@ QVBoxLayout *SettingsDialog::createBehaviourTab()
auto form = new QFormLayout(); auto form = new QFormLayout();
form->addRow("Window:", // WINDOW
createCheckbox("Window always on top (requires restart)", settings.windowTopMost)); {
form->addRow("Window:", createCheckbox("Window always on top (requires restart)",
settings.windowTopMost));
// form->addRow("Messages:", createCheckbox("Mention users with a @ (except in // form->addRow("Messages:", createCheckbox("Mention users with a @ (except in
// commands)", // commands)",
// settings.mentionUsersWithAt)); // settings.mentionUsersWithAt));
form->addRow("Messages:", createCheckbox("Hide input box if empty", settings.hideEmptyInput)); }
form->addRow( // MESSAGES
"", createCheckbox("Show last read message indicator", settings.showLastMessageIndicator)); {
form->addRow("Messages:",
createCheckbox("Hide input box if empty", settings.hideEmptyInput));
form->addRow("", createCheckbox("Show last read message indicator",
settings.showLastMessageIndicator));
}
// PAUSE
{
form->addRow("Pause chat:", createCheckbox("When hovering", settings.pauseChatHover));
}
// MOUSE SCROLL SPEED
{
auto scroll = new QSlider(Qt::Horizontal); auto scroll = new QSlider(Qt::Horizontal);
form->addRow("Mouse scroll speed:", scroll); form->addRow("Mouse scroll speed:", scroll);
@ -348,7 +360,9 @@ QVBoxLayout *SettingsDialog::createBehaviourTab()
float newScrollValue = (mul * 2.1f) + 0.1f; float newScrollValue = (mul * 2.1f) + 0.1f;
singletons::SettingManager::getInstance().mouseScrollMultiplier = newScrollValue; singletons::SettingManager::getInstance().mouseScrollMultiplier = newScrollValue;
}); });
}
// STREAMLINK
{
form->addRow("Streamlink path:", createLineEdit(settings.streamlinkPath)); form->addRow("Streamlink path:", createLineEdit(settings.streamlinkPath));
form->addRow(this->createCombobox( form->addRow(this->createCombobox(
"Preferred quality:", settings.preferredQuality, "Preferred quality:", settings.preferredQuality,
@ -356,6 +370,7 @@ QVBoxLayout *SettingsDialog::createBehaviourTab()
[](const QString &newValue, pajlada::Settings::Setting<std::string> &setting) { [](const QString &newValue, pajlada::Settings::Setting<std::string> &setting) {
setting = newValue.toStdString(); setting = newValue.toStdString();
})); }));
}
layout->addLayout(form); layout->addLayout(form);