X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fqtui%2Fchatview.cpp;h=1a24c6ff10162e3a45ac1359edd941dc77b9d2bc;hb=c8ddabf364eff2400c61cea395aefe69eb8ba1b3;hp=3074882df1ffdcbdb571eb770b10efb2fc4441e6;hpb=a95ad2de573027f9bee36db972bcae4195168d0c;p=quassel.git diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index 3074882d..1a24c6ff 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2020 by the Quassel Project * + * Copyright (C) 2005-2022 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -84,6 +84,9 @@ void ChatView::init(MessageFilter* filter) connect(verticalScrollBar(), &QAbstractSlider::valueChanged, this, &ChatView::verticalScrollbarChanged); _lastScrollbarPos = verticalScrollBar()->maximum(); + // Workaround for the ChatView scrolling up a fair bit when scrollbar becomes visible + verticalScrollBar()->installEventFilter(this); + connect(Client::networkModel(), &NetworkModel::markerLineSet, this, &ChatView::markerLineSet); // only connect if client is synched with a core @@ -100,8 +103,7 @@ bool ChatView::event(QEvent* event) case Qt::Key_Down: case Qt::Key_PageUp: case Qt::Key_PageDown: - if (!verticalScrollBar()->isVisible()) { - scene()->requestBacklog(); + if (requestBacklogForScroll()) { return true; } default: @@ -110,7 +112,7 @@ bool ChatView::event(QEvent* event) } if (event->type() == QEvent::TouchBegin && ((QTouchEvent*)event)->device()->type() == QTouchDevice::TouchScreen) { - // Enable scrolling by draging, disable selecting/clicking content + // Enable scrolling by dragging, disable selecting/clicking content setDragMode(QGraphicsView::ScrollHandDrag); setInteractive(false); // if scrollbar is not visible we need to request backlog below else we need to accept @@ -145,8 +147,7 @@ bool ChatView::event(QEvent* event) if (event->type() == QEvent::Wheel || (event->type() == QEvent::TouchBegin && ((QTouchEvent*)event)->device()->type() == QTouchDevice::TouchScreen) || event->type() == QEvent::TouchUpdate) { - if (!verticalScrollBar()->isVisible()) { - scene()->requestBacklog(); + if (requestBacklogForScroll()) { return true; } } @@ -159,6 +160,28 @@ bool ChatView::event(QEvent* event) return QGraphicsView::event(event); } +bool ChatView::eventFilter(QObject* watched, QEvent* event) +{ + QAbstractSlider* vbar = verticalScrollBar(); + Q_ASSERT(vbar); + + if (watched != vbar) { + // Ignore and pass through all events not featuring the scrollbar + return false; + } + if (event->type() == QEvent::Show) { + // FIXME: Workaround for the ChatView scrolling up a fair bit when transitioning from the + // vertical scrollbar not being visible, to becoming visible. This happens especially + // often when no initial backlog is loaded. + if (_backlogRequestedBeforeScrollable) { + _backlogRequestedBeforeScrollable = false; + vbar->setValue(vbar->maximum()); + } + } + // Pass through all events + return false; +} + void ChatView::resizeEvent(QResizeEvent* event) { // if view is currently scrolled to bottom, we want it that way after resizing @@ -168,7 +191,7 @@ void ChatView::resizeEvent(QResizeEvent* event) // if scrolling to bottom, do it immediately. if (atBottom) { - // we can reduce viewport updates if we scroll to the bottom allready at the beginning + // we can reduce viewport updates if we scroll to the bottom already at the beginning verticalScrollBar()->setValue(verticalScrollBar()->maximum()); } @@ -409,6 +432,24 @@ void ChatView::setHasCache(ChatLine* line, bool hasCache) _linesWithCache.remove(line); } +bool ChatView::requestBacklogForScroll() +{ + if (!verticalScrollBar()->isVisible()) { + // Not able to scroll, fetch backlog + // + // Future improvement: continue fetching backlog in chunks until the scrollbar is visible, + // or the beginning of the buffer has been reached. + scene()->requestBacklog(); + _backlogRequestedBeforeScrollable = true; + // Backlog has been requested + return true; + } + else { + // Scrollbar already visible, no backlog requested + return false; + } +} + void ChatView::checkChatLineCaches() { qreal top = mapToScene(viewport()->rect().topLeft()).y() - 10; // some grace area to avoid premature cleaning