+
+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;
+ }
+}
+
+void ChatView::scrollContentsBy(int dx, int dy)
+{
+ QGraphicsView::scrollContentsBy(dx, dy);
+ checkChatLineCaches();
+}
+
+void ChatView::setHasCache(ChatLine* line, bool hasCache)
+{
+ if (hasCache)
+ _linesWithCache.insert(line);
+ else
+ _linesWithCache.remove(line);
+}
+
+bool ChatView::requestBacklogForScroll()
+{
+ if (!verticalScrollBar()->isVisible()) {
+ // Not able to scroll, fetch backlog
+ //
+ // Future improvement: continue fetching backlog in chunks until the scrollbar is visible,
+ // or the beginning of the buffer has been reached.
+ scene()->requestBacklog();
+ _backlogRequestedBeforeScrollable = true;
+ // Backlog has been requested
+ return true;
+ }
+ else {
+ // Scrollbar already visible, no backlog requested
+ return false;
+ }
+}
+
+void ChatView::checkChatLineCaches()
+{
+ qreal top = mapToScene(viewport()->rect().topLeft()).y() - 10; // some grace area to avoid premature cleaning
+ qreal bottom = mapToScene(viewport()->rect().bottomRight()).y() + 10;
+ QSet<ChatLine*>::iterator iter = _linesWithCache.begin();
+ while (iter != _linesWithCache.end()) {
+ ChatLine* line = *iter;
+ if (line->pos().y() + line->height() < top || line->pos().y() > bottom) {
+ line->clearCache();
+ iter = _linesWithCache.erase(iter);
+ }
+ else
+ ++iter;
+ }
+}