Properly handle synced marker lines
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 1 May 2010 15:58:46 +0000 (17:58 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 1 May 2010 16:01:01 +0000 (18:01 +0200)
This reacts to changes from the NetworkModel, and also properly redraws
the marker line on change. Also, you can hide the line now.

src/qtui/chatline.cpp
src/qtui/chatview.cpp
src/qtui/chatview.h

index 7e0acd5..08d089e 100644 (file)
@@ -206,8 +206,7 @@ void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
     MsgId myMsgId = myIdx.data(MessageModel::MsgIdRole).value<MsgId>();
     Message::Flags flags = (Message::Flags)myIdx.data(MessageModel::FlagsRole).toInt();
 
-    // don't show the marker if we wrote that new line
-    if(!(flags & Message::Self)) {
+    if(chatView()->isMarkerLineVisible()) {
       BufferId bufferId = BufferId(chatScene()->idString().toInt());
       MsgId lastSeenMsgId = Client::networkModel()->markerLineMsgId(bufferId);
       if(lastSeenMsgId < myMsgId && lastSeenMsgId >= prevMsgId) {
index 453ac04..ddec8fb 100644 (file)
@@ -55,6 +55,8 @@ void ChatView::init(MessageFilter *filter) {
   _bufferContainer = 0;
   _currentScaleFactor = 1;
   _invalidateFilter = false;
+  _markerLineVisible = true;
+  _markedLine = 0;
 
   setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
@@ -79,6 +81,8 @@ void ChatView::init(MessageFilter *filter) {
   connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int)));
   _lastScrollbarPos = verticalScrollBar()->value();
 
+  connect(Client::networkModel(), SIGNAL(markerLineSet(BufferId,MsgId)), SLOT(markerLineSet(BufferId,MsgId)));
+
   // only connect if client is synched with a core
   if(Client::isConnected())
     connect(Client::ignoreListManager(), SIGNAL(ignoreListChanged()), this, SLOT(invalidateFilter()));
@@ -256,6 +260,45 @@ ChatLine *ChatView::lastVisibleChatLine() const {
   return 0;
 }
 
+void ChatView::setMarkerLineVisible(bool visible) {
+  if(visible != _markerLineVisible) {
+    _markerLineVisible = visible;
+  }
+}
+
+void ChatView::setMarkedLine(ChatLine *line) {
+  if(_markedLine == line)
+    return;
+
+  if(!scene()->isSingleBufferScene())
+    return;
+
+  if(line) {
+    BufferId bufId = scene()->singleBufferId();
+    Client::setMarkerLine(bufId, line->msgId());
+  }
+}
+
+void ChatView::markerLineSet(BufferId buffer, MsgId msg) {
+  if(!scene()->isSingleBufferScene() || scene()->singleBufferId() != buffer)
+    return;
+
+  ChatLine *newLine = scene()->chatLine(msg);
+  if(_markedLine == newLine)
+    return;
+
+  ChatLine *oldLine = _markedLine;
+  _markedLine = newLine;
+
+  if(oldLine)
+    oldLine->update();
+
+  if(newLine) {
+    setMarkerLineVisible(true);
+    newLine->update();
+  }
+}
+
 void ChatView::addActionsToMenu(QMenu *menu, const QPointF &pos) {
   // zoom actions
   BufferWidget *bw = qobject_cast<BufferWidget *>(bufferContainer());
index 4fb3661..3f9e29c 100644 (file)
@@ -71,12 +71,18 @@ public:
 
   virtual bool event(QEvent *event);
 
+  inline bool isMarkerLineVisible() const { return _markerLineVisible; }
+  inline ChatLine *markedLine() const { return _markedLine; }
+
 public slots:
   inline virtual void clear() {}
   void zoomIn();
   void zoomOut();
   void zoomOriginal();
 
+  void setMarkerLineVisible(bool visible = true);
+  void setMarkedLine(ChatLine *line);
+
 protected:
   virtual void resizeEvent(QResizeEvent *event);
 
@@ -89,6 +95,7 @@ private slots:
   void mouseMoveWhileSelecting(const QPointF &scenePos);
   void scrollTimerTimeout();
   void invalidateFilter();
+  void markerLineSet(BufferId buffer, MsgId msg);
 
 private:
   void init(MessageFilter *filter);
@@ -100,6 +107,8 @@ private:
   QTimer _scrollTimer;
   int _scrollOffset;
   bool _invalidateFilter;
+  bool _markerLineVisible;
+  ChatLine *_markedLine;
 };