+ scene()->updateForViewport(viewport()->width(), viewport()->height());
+ adjustSceneRect();
+
+ _lastScrollbarPos = verticalScrollBar()->maximum();
+ verticalScrollBar()->setValue(verticalScrollBar()->maximum());
+}
+
+void ChatView::adjustSceneRect() {
+ // Workaround for QTBUG-6322
+ // If the viewport's sceneRect() is (almost) as wide as as the viewport itself,
+ // Qt wants to reserve space for scrollbars even if they're turned off, resulting in
+ // an ugly white space at the bottom of the ChatView.
+ // Since the view's scene's width actually doesn't matter at all, we just adjust it
+ // by some hopefully large enough value to avoid this problem.
+
+ setSceneRect(scene()->sceneRect().adjusted(0, 0, -25 ,0));
+}
+
+void ChatView::mouseMoveWhileSelecting(const QPointF &scenePos) {
+ int y = (int)mapFromScene(scenePos).y();
+ _scrollOffset = 0;
+ if(y < 0)
+ _scrollOffset = y;
+ else if(y > height())
+ _scrollOffset = y - height();
+
+ if(_scrollOffset && !_scrollTimer.isActive())
+ _scrollTimer.start();
+}
+
+void ChatView::scrollTimerTimeout() {
+ // scroll view
+ QAbstractSlider *vbar = verticalScrollBar();
+ if(_scrollOffset < 0 && vbar->value() > 0)
+ vbar->setValue(qMax(vbar->value() + _scrollOffset, 0));
+ else if(_scrollOffset > 0 && vbar->value() < vbar->maximum())
+ vbar->setValue(qMin(vbar->value() + _scrollOffset, vbar->maximum()));