-void ChatView::sceneHeightChangedAt(qreal ypos, qreal hdiff) {
- setSceneRect(scene()->sceneRect());
- int y = mapFromScene(0, ypos).y();
- if(y <= viewport()->height() + 2) { // be a bit tolerant here, also FIXME (why we need the 2px?)
- verticalScrollBar()->setValue(verticalScrollBar()->value() + hdiff);
+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()));
+}
+
+void ChatView::lastLineChanged(QGraphicsItem *chatLine, qreal offset) {
+ Q_UNUSED(chatLine)
+ // disabled until further testing/discussion
+ //if(!scene()->isScrollingAllowed())
+ // return;
+
+ QAbstractSlider *vbar = verticalScrollBar();
+ Q_ASSERT(vbar);
+ if(vbar->maximum() - vbar->value() <= (offset + 5) * _currentScaleFactor ) { // 5px grace area
+ vbar->setValue(vbar->maximum());