mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
rewrote the pausing chat on hover functionality
This commit is contained in:
parent
795758f618
commit
f6d02fffc9
2 changed files with 34 additions and 48 deletions
|
@ -54,9 +54,12 @@ ChannelView::ChannelView(BaseWidget *parent)
|
||||||
this->scrollBar.getCurrentValueChanged().connect([this] {
|
this->scrollBar.getCurrentValueChanged().connect([this] {
|
||||||
// Whenever the scrollbar value has been changed, re-render the ChatWidgetView
|
// Whenever the scrollbar value has been changed, re-render the ChatWidgetView
|
||||||
this->actuallyLayoutMessages(true);
|
this->actuallyLayoutMessages(true);
|
||||||
this->goToBottom->setVisible(this->enableScrollingToBottom && this->scrollBar.isVisible() &&
|
|
||||||
!this->scrollBar.isAtBottom() &&
|
if (!this->isPaused()) {
|
||||||
!this->scrollToBottomAfterTemporaryPause);
|
this->goToBottom->setVisible(this->enableScrollingToBottom &&
|
||||||
|
this->scrollBar.isVisible() &&
|
||||||
|
!this->scrollBar.isAtBottom());
|
||||||
|
}
|
||||||
|
|
||||||
this->queueUpdate();
|
this->queueUpdate();
|
||||||
});
|
});
|
||||||
|
@ -98,21 +101,10 @@ ChannelView::ChannelView(BaseWidget *parent)
|
||||||
|
|
||||||
this->pauseTimeout.setSingleShot(true);
|
this->pauseTimeout.setSingleShot(true);
|
||||||
QObject::connect(&this->pauseTimeout, &QTimer::timeout, [this] {
|
QObject::connect(&this->pauseTimeout, &QTimer::timeout, [this] {
|
||||||
|
|
||||||
this->pausedTemporarily = false;
|
this->pausedTemporarily = false;
|
||||||
if (!this->isPaused() && this->scrollToBottomAfterTemporaryPause) {
|
this->layoutMessages();
|
||||||
this->scrollBar.scrollToBottom();
|
|
||||||
}
|
|
||||||
|
|
||||||
this->scrollToBottomAfterTemporaryPause = false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 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(
|
app->settings->showLastMessageIndicator.connect(
|
||||||
[this](auto, auto) {
|
[this](auto, auto) {
|
||||||
this->update(); //
|
this->update(); //
|
||||||
|
@ -134,7 +126,7 @@ ChannelView::ChannelView(BaseWidget *parent)
|
||||||
this->scrollBar.setGeometry(this->width() - this->scrollBar.width(), 0,
|
this->scrollBar.setGeometry(this->width() - this->scrollBar.width(), 0,
|
||||||
this->scrollBar.width(), this->height());
|
this->scrollBar.width(), this->height());
|
||||||
});
|
});
|
||||||
}
|
} // namespace widgets
|
||||||
|
|
||||||
ChannelView::~ChannelView()
|
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
|
// Perhaps also if the user scrolled with the scrollwheel in this ChatWidget in the last 0.2
|
||||||
// seconds or something
|
// seconds or something
|
||||||
if (this->enableScrollingToBottom && this->showingLatestMessages && showScrollbar) {
|
if (this->enableScrollingToBottom && this->showingLatestMessages && showScrollbar) {
|
||||||
this->scrollBar.scrollToBottom(this->messageWasAdded &&
|
if (!this->isPaused()) {
|
||||||
|
this->scrollBar.scrollToBottom(
|
||||||
|
this->messageWasAdded &&
|
||||||
app->settings->enableSmoothScrollingNewMessages.getValue());
|
app->settings->enableSmoothScrollingNewMessages.getValue());
|
||||||
|
}
|
||||||
this->messageWasAdded = false;
|
this->messageWasAdded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,14 +488,6 @@ void ChannelView::detachChannel()
|
||||||
|
|
||||||
void ChannelView::pause(int msecTimeout)
|
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->pausedTemporarily = true;
|
||||||
|
|
||||||
this->pauseTimeout.start(msecTimeout);
|
this->pauseTimeout.start(msecTimeout);
|
||||||
|
@ -535,10 +522,8 @@ void ChannelView::setSelection(const SelectionItem &start, const SelectionItem &
|
||||||
{
|
{
|
||||||
// selections
|
// selections
|
||||||
if (!this->selecting && start != end) {
|
if (!this->selecting && start != end) {
|
||||||
this->messagesAddedSinceSelectionPause =
|
this->messagesAddedSinceSelectionPause = 0;
|
||||||
(this->scrollToBottomAfterTemporaryPause || this->scrollBar.isAtBottom()) ? 0 : 100;
|
|
||||||
|
|
||||||
this->beginPause();
|
|
||||||
this->selecting = true;
|
this->selecting = true;
|
||||||
this->pausedBySelection = true;
|
this->pausedBySelection = true;
|
||||||
}
|
}
|
||||||
|
@ -577,17 +562,17 @@ bool ChannelView::isPaused()
|
||||||
return this->pausedTemporarily || this->pausedBySelection;
|
return this->pausedTemporarily || this->pausedBySelection;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelView::beginPause()
|
// void ChannelView::beginPause()
|
||||||
{
|
//{
|
||||||
if (this->scrollBar.isAtBottom()) {
|
// if (this->scrollBar.isAtBottom()) {
|
||||||
this->scrollBar.setDesiredValue(this->scrollBar.getDesiredValue() - 0.001);
|
// this->scrollBar.setDesiredValue(this->scrollBar.getDesiredValue() - 0.001);
|
||||||
this->layoutMessages();
|
// this->layoutMessages();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
void ChannelView::endPause()
|
// void ChannelView::endPause()
|
||||||
{
|
//{
|
||||||
}
|
//}
|
||||||
|
|
||||||
void ChannelView::paintEvent(QPaintEvent * /*event*/)
|
void ChannelView::paintEvent(QPaintEvent * /*event*/)
|
||||||
{
|
{
|
||||||
|
@ -675,6 +660,9 @@ void ChannelView::drawMessages(QPainter &painter)
|
||||||
|
|
||||||
void ChannelView::wheelEvent(QWheelEvent *event)
|
void ChannelView::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
|
this->pausedBySelection = false;
|
||||||
|
this->pausedTemporarily = false;
|
||||||
|
|
||||||
if (this->scrollBar.isVisible()) {
|
if (this->scrollBar.isVisible()) {
|
||||||
auto app = getApp();
|
auto app = getApp();
|
||||||
|
|
||||||
|
@ -745,6 +733,7 @@ void ChannelView::enterEvent(QEvent *)
|
||||||
void ChannelView::leaveEvent(QEvent *)
|
void ChannelView::leaveEvent(QEvent *)
|
||||||
{
|
{
|
||||||
this->pausedTemporarily = false;
|
this->pausedTemporarily = false;
|
||||||
|
this->layoutMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||||
|
@ -892,14 +881,10 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
auto app = getApp();
|
auto app = getApp();
|
||||||
|
|
||||||
if (this->selecting) {
|
if (this->selecting) {
|
||||||
if (this->messagesAddedSinceSelectionPause <= SELECTION_RESUME_SCROLLING_MSG_THRESHOLD) {
|
if (this->messagesAddedSinceSelectionPause > SELECTION_RESUME_SCROLLING_MSG_THRESHOLD) {
|
||||||
// don't scroll
|
this->showingLatestMessages = false;
|
||||||
this->scrollBar.scrollToBottom(false);
|
|
||||||
// this->scrollBar.setDesiredValue(this->scrollBar.getDesiredValue() -
|
|
||||||
// this->messagesAddedSinceSelectionPause);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->scrollToBottomAfterTemporaryPause = false;
|
|
||||||
this->pausedBySelection = false;
|
this->pausedBySelection = false;
|
||||||
this->selecting = false;
|
this->selecting = false;
|
||||||
this->pauseTimeout.stop();
|
this->pauseTimeout.stop();
|
||||||
|
|
|
@ -86,10 +86,11 @@ private:
|
||||||
bool updateQueued = false;
|
bool updateQueued = false;
|
||||||
bool messageWasAdded = false;
|
bool messageWasAdded = false;
|
||||||
bool lastMessageHasAlternateBackground = false;
|
bool lastMessageHasAlternateBackground = false;
|
||||||
|
|
||||||
bool pausedTemporarily = false;
|
bool pausedTemporarily = false;
|
||||||
bool pausedBySelection = false;
|
bool pausedBySelection = false;
|
||||||
bool scrollToBottomAfterTemporaryPause = false;
|
|
||||||
int messagesAddedSinceSelectionPause = 0;
|
int messagesAddedSinceSelectionPause = 0;
|
||||||
|
|
||||||
QTimer pauseTimeout;
|
QTimer pauseTimeout;
|
||||||
boost::optional<messages::MessageElement::Flags> overrideFlags;
|
boost::optional<messages::MessageElement::Flags> overrideFlags;
|
||||||
messages::MessageLayoutPtr lastReadMessage;
|
messages::MessageLayoutPtr lastReadMessage;
|
||||||
|
@ -104,8 +105,8 @@ private:
|
||||||
messages::MessageElement::Flags getFlags() const;
|
messages::MessageElement::Flags getFlags() const;
|
||||||
bool isPaused();
|
bool isPaused();
|
||||||
|
|
||||||
void beginPause();
|
// void beginPause();
|
||||||
void endPause();
|
// void endPause();
|
||||||
|
|
||||||
ChannelPtr channel;
|
ChannelPtr channel;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue