-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::sceneHeightChanged(qreal dh) {
+ QAbstractSlider *vbar = verticalScrollBar();
+ Q_ASSERT(vbar);
+ if(vbar->maximum() - vbar->value() <= dh + 5) // in case we had scrolled only about half a line to the bottom we allow a grace of 5
+ vbar->setValue(vbar->maximum());