+ChatItem *ChatScene::chatItemAt(const QPointF &scenePos) const
+{
+ foreach(QGraphicsItem *item, items(scenePos, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder)) {
+ ChatLine *line = qgraphicsitem_cast<ChatLine *>(item);
+ if (line)
+ return line->itemAt(line->mapFromScene(scenePos));
+ }
+ return 0;
+}
+
+
+bool ChatScene::containsBuffer(const BufferId &id) const
+{
+ MessageFilter *filter = qobject_cast<MessageFilter *>(model());
+ if (filter)
+ return filter->containsBuffer(id);
+ else
+ return false;
+}
+
+
+void ChatScene::setMarkerLineVisible(bool visible)
+{
+ _markerLineVisible = visible;
+ if (visible && _markerLineValid)
+ markerLine()->setVisible(true);
+ else
+ markerLine()->setVisible(false);
+}
+
+
+void ChatScene::setMarkerLine(MsgId msgId)
+{
+ if (!isSingleBufferScene())
+ return;
+
+ if (!msgId.isValid())
+ msgId = Client::markerLine(singleBufferId());
+
+ if (msgId.isValid()) {
+ ChatLine *line = chatLine(msgId, false, true);
+ if (line) {
+ markerLine()->setChatLine(line);
+ // if this was the last line, we won't see it because it's outside the sceneRect
+ // .. which is exactly what we want :)
+ markerLine()->setPos(line->pos() + QPointF(0, line->height()));
+
+ // DayChange messages might have been hidden outside the scene rect, don't make the markerline visible then!
+ if (markerLine()->pos().y() >= sceneRect().y()) {
+ _markerLineValid = true;
+ if (_markerLineVisible)
+ markerLine()->setVisible(true);
+ if (_markerLineJumpPending) {
+ _markerLineJumpPending = false;
+ if (markerLine()->isVisible()) {
+ markerLine()->ensureVisible(QRectF(), 50, 50);
+ }
+ }
+ return;
+ }
+ }
+ }
+ _markerLineValid = false;
+ markerLine()->setVisible(false);
+}
+
+
+void ChatScene::jumpToMarkerLine(bool requestBacklog)
+{
+ if (!isSingleBufferScene())
+ return;
+
+ if (markerLine()->isVisible()) {
+ markerLine()->ensureVisible(QRectF(), 50, 50);
+ return;
+ }
+ if (!_markerLineValid && requestBacklog) {
+ MsgId msgId = Client::markerLine(singleBufferId());
+ if (msgId.isValid()) {
+ _markerLineJumpPending = true;
+ Client::backlogManager()->requestBacklog(singleBufferId(), msgId, -1, -1, 0);
+
+ // If we filtered out the lastSeenMsg (by changing filters after setting it), we'd never jump because the above request
+ // won't fetch any prior lines. Thus, trigger a dynamic backlog request just in case, so repeated
+ // jump tries will eventually cause enough backlog to be fetched.
+ // This is a bit hackish, but not wasteful, as jumping to the top of the ChatView would trigger a dynamic fetch anyway.
+ this->requestBacklog();
+ }
+ }
+}
+
+
+void ChatScene::rowsInserted(const QModelIndex &index, int start, int end)
+{
+ Q_UNUSED(index);