+// Workaround for QTBUG-6322
+// The viewport rect gets some margins where it shouldn't, resulting in scrollbars to appear
+void ChatView::adjustSceneRect() {
+ static qreal voffset = 0;
+ static bool offsetStable = false;
+
+ QRectF rect = scene()->sceneRect();
+ if(rect.height() <= viewport()->height()) {
+ setSceneRect(rect);
+ return;
+ }
+ if(offsetStable && rect.height() > viewport()->height())
+ setSceneRect(rect.adjusted(0, 0, 0, voffset));
+ else {
+ setSceneRect(rect);
+
+ QScrollBar *vbar = verticalScrollBar();
+ qreal sceneHeight = rect.height();
+ qreal viewHeight = vbar->maximum() + viewport()->height() - vbar->minimum();
+ if(sceneHeight != viewHeight) {
+ voffset = sceneHeight - viewHeight;
+ // qDebug() << "Adjusting ChatView offset to" << voffset << "(QTBUG-6322)";
+ if(sceneHeight + voffset <= viewport()->height()) {
+ setSceneRect(rect.adjusted(0, -voffset, 0, 0));
+ offsetStable = false;
+ return;
+ } else
+ setSceneRect(rect.adjusted(0, 0, 0, voffset));
+ }
+ if(vbar->maximum() + viewport()->height() - vbar->minimum() != sceneHeight)
+ qWarning() << "Workaround for QTBUG-6322 failed!1!!" << vbar->maximum() + viewport()->height() - vbar->minimum() << sceneHeight;
+ else
+ offsetStable = true;
+ }
+}
+
+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;
+