+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());
+ }
+}
+
+void ChatView::verticalScrollbarChanged(int newPos) {
+ QAbstractSlider *vbar = verticalScrollBar();
+ Q_ASSERT(vbar);
+
+ // check for backlog request
+ if(newPos < _lastScrollbarPos) {
+ int relativePos = 100;
+ if(vbar->maximum() - vbar->minimum() != 0)
+ relativePos = (newPos - vbar->minimum()) * 100 / (vbar->maximum() - vbar->minimum());
+
+ if(relativePos < 20) {
+ scene()->requestBacklog();
+ }
+ }
+ _lastScrollbarPos = newPos;
+
+ // FIXME: Fugly workaround for the ChatView scrolling up 1px on buffer switch
+ if(vbar->maximum() - newPos <= 2)
+ vbar->setValue(vbar->maximum());
+}
+
+MsgId ChatView::lastMsgId() const {
+ if(!scene())
+ return MsgId();
+
+ QAbstractItemModel *model = scene()->model();
+ if(!model || model->rowCount() == 0)
+ return MsgId();
+
+ return model->data(model->index(model->rowCount() - 1, 0), MessageModel::MsgIdRole).value<MsgId>();
+}
+
+void ChatView::addActionsToMenu(QMenu *menu, const QPointF &pos) {
+ // zoom actions
+ BufferWidget *bw = qobject_cast<BufferWidget *>(bufferContainer());
+ if(bw) {
+ bw->addActionsToMenu(menu, pos);
+ menu->addSeparator();
+ }
+}
+
+void ChatView::zoomIn() {
+ _currentScaleFactor *= 1.2;
+ scale(1.2, 1.2);
+ scene()->setWidth(viewport()->width() / _currentScaleFactor - 2);
+}
+
+void ChatView::zoomOut() {
+ _currentScaleFactor /= 1.2;
+ scale(1 / 1.2, 1 / 1.2);
+ scene()->setWidth(viewport()->width() / _currentScaleFactor - 2);
+}
+
+void ChatView::zoomOriginal() {
+ scale(1/_currentScaleFactor, 1/_currentScaleFactor);
+ _currentScaleFactor = 1;
+ scene()->setWidth(viewport()->width() - 2);
+}
+
+void ChatView::invalidateFilter() {
+ // if this is the currently selected chatview
+ // invalidate immediately
+ if(isVisible()) {
+ _scene->filter()->invalidateFilter();
+ _invalidateFilter = false;
+ }
+ // otherwise invalidate whenever the view is shown
+ else {
+ _invalidateFilter = true;
+ }