+void ChatView::verticalScrollbarChanged(int newPos) {
+ QAbstractSlider *vbar = verticalScrollBar();
+ Q_ASSERT(vbar);
+
+ // FIXME dirty hack to battle the "I just scroll up a pixel on hide()/show()" problem
+ if(vbar->maximum() - vbar->value() < 5) vbar->setValue(vbar->maximum());
+
+ 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;
+}
+
+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>();