Fix markerline placement on relayout
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 17 Jun 2010 14:59:52 +0000 (16:59 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 17 Jun 2010 14:59:52 +0000 (16:59 +0200)
src/qtui/chatscene.cpp
src/qtui/chatscene.h

index d78ee1c..f7d4bd1 100644 (file)
@@ -212,24 +212,31 @@ void ChatScene::setMarkerLineVisible(bool visible) {
 }
 
 void ChatScene::setMarkerLine(MsgId msgId) {
-  if(msgId.isValid()) {
-    ChatLine *line = chatLine(msgId, false);
-    if(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);
-        return;
-      }
+  if(!isSingleBufferScene())
+    return;
+  if(!msgId.isValid()) {
+    msgId = Client::markerLine(singleBufferId());
+    if(!msgId.isValid()) {
+      _markerLineValid = false;
+      _markerLine->setVisible(false);
+      return;
+    }
+  }
+
+  ChatLine *line = chatLine(msgId, false);
+  if(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);
+      return;
     }
   }
-  _markerLineValid = false;
-  _markerLine->setVisible(false);
 }
 
 void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
@@ -364,12 +371,8 @@ void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
   }
 
   // now move the marker line if necessary. we don't need to do anything if we appended lines though...
-  if(isSingleBufferScene()) {
-    if(!_markerLineValid || !atBottom) {
-      MsgId msgId = Client::markerLine(singleBufferId());
-      setMarkerLine(msgId);
-    }
-  }
+  if(!_markerLineValid || !atBottom)
+    setMarkerLine();
 }
 
 void ChatScene::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
@@ -465,10 +468,7 @@ void ChatScene::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int e
 
 void ChatScene::rowsRemoved() {
   // move the marker line if necessary
-  if(isSingleBufferScene()) {
-    MsgId msgId = Client::markerLine(singleBufferId());
-    setMarkerLine(msgId);
-  }
+  setMarkerLine();
 }
 
 void ChatScene::dataChanged(const QModelIndex &tl, const QModelIndex &br) {
@@ -518,6 +518,7 @@ void ChatScene::layout(int start, int end, qreal width) {
 
   updateSceneRect(width);
   setHandleXLimits();
+  setMarkerLine();
   emit layoutChanged();
 
 //   clock_t endT = clock();
index c4a8b01..56212ad 100644 (file)
@@ -127,7 +127,7 @@ public:
   void layout(int start, int end, qreal width);
 
   void setMarkerLineVisible(bool visible = true);
-  void setMarkerLine(MsgId msgId);
+  void setMarkerLine(MsgId msgId = MsgId());
 
   // these are used by the chatitems to notify the scene and manage selections
   void setSelectingItem(ChatItem *item);