Implement issue #1219: Update the marker line when quassel loses focus
authorChris H (Shade / Zren) <zrenfire@gmail.com>
Thu, 22 Aug 2013 22:25:51 +0000 (18:25 -0400)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 14 Jan 2014 00:04:53 +0000 (01:04 +0100)
Solves issue #1219 on bugs.quassel-irc.org.

We now listen for QEvent::WindowDeactivate in the main window. This
should pickup on window closing/minimizing/losing focus. We also change
view->setMarkerLine() to Client::setMarkerLine which will send an event
to the syncher, and eventually arrives at ChatView::markerLineSet, which
moves the marker line for us.

src/qtui/bufferwidget.cpp
src/qtui/bufferwidget.h
src/qtui/mainwin.cpp
src/qtui/settingspages/chatviewsettingspage.ui

index c5fbff2..3f6ba6d 100644 (file)
@@ -40,7 +40,8 @@
 BufferWidget::BufferWidget(QWidget *parent)
     : AbstractBufferContainer(parent),
     _chatViewSearchController(new ChatViewSearchController(this)),
-    _autoMarkerLine(true)
+    _autoMarkerLine(true),
+    _autoMarkerLineOnLostFocus(true)
 {
     ui.setupUi(this);
     layout()->setContentsMargins(0, 0, 0, 0);
@@ -99,6 +100,7 @@ BufferWidget::BufferWidget(QWidget *parent)
 
     ChatViewSettings s;
     s.initAndNotify("AutoMarkerLine", this, SLOT(setAutoMarkerLine(QVariant)), true);
+    s.initAndNotify("AutoMarkerLineOnLostFocus", this, SLOT(setAutoMarkerLineOnLostFocus(QVariant)), true);
 }
 
 
@@ -114,6 +116,11 @@ void BufferWidget::setAutoMarkerLine(const QVariant &v)
     _autoMarkerLine = v.toBool();
 }
 
+void BufferWidget::setAutoMarkerLineOnLostFocus(const QVariant &v)
+{
+    _autoMarkerLineOnLostFocus = v.toBool();
+}
+
 
 AbstractChatView *BufferWidget::createChatView(BufferId id)
 {
@@ -270,14 +277,14 @@ void BufferWidget::setMarkerLine(ChatView *view, bool allowGoingBack)
     if (lastLine) {
         QModelIndex idx = lastLine->index();
         MsgId msgId = idx.data(MessageModel::MsgIdRole).value<MsgId>();
+        BufferId bufId = view->scene()->singleBufferId();
 
         if (!allowGoingBack) {
-            BufferId bufId = view->scene()->singleBufferId();
             MsgId oldMsgId = Client::markerLine(bufId);
             if (oldMsgId.isValid() && msgId <= oldMsgId)
                 return;
         }
-        view->setMarkerLine(msgId);
+        Client::setMarkerLine(bufId, msgId);
     }
 }
 
index 8a93a38..88d5a4e 100644 (file)
@@ -42,6 +42,7 @@ public:
 
     inline ChatViewSearchBar *searchBar() const { return ui.searchBar; }
     void addActionsToMenu(QMenu *, const QPointF &pos);
+    virtual inline bool autoMarkerLineOnLostFocus() const { return _autoMarkerLineOnLostFocus; }
 
 public slots:
     virtual void setMarkerLine(ChatView *view = 0, bool allowGoingBack = true);
@@ -63,6 +64,7 @@ private slots:
     void zoomOriginal();
 
     void setAutoMarkerLine(const QVariant &);
+    void setAutoMarkerLineOnLostFocus(const QVariant &);
 
 private:
     Ui::BufferWidget ui;
@@ -71,6 +73,7 @@ private:
     ChatViewSearchController *_chatViewSearchController;
 
     bool _autoMarkerLine;
+    bool _autoMarkerLineOnLostFocus;
 };
 
 
index 1798256..b984e56 100644 (file)
@@ -1395,10 +1395,19 @@ void MainWin::onFullScreenToggled()
 
 bool MainWin::event(QEvent *event)
 {
-    if (event->type() == QEvent::WindowActivate) {
-        BufferId buffer = Client::bufferModel()->currentBuffer();
-        if (buffer.isValid())
-            Client::instance()->markBufferAsRead(buffer);
+    switch(event->type()) {
+    case QEvent::WindowActivate: {
+        BufferId bufferId = Client::bufferModel()->currentBuffer();
+        if (bufferId.isValid())
+            Client::instance()->markBufferAsRead(bufferId);
+        break;
+    }
+    case QEvent::WindowDeactivate:
+        if (bufferWidget()->autoMarkerLineOnLostFocus())
+            bufferWidget()->setMarkerLine();
+        break;
+    default:
+        break;
     }
     return QMainWindow::event(event);
 }
index 073ae2d..31cf9eb 100644 (file)
      </property>
     </widget>
    </item>
+   <item>
+    <widget class="QCheckBox" name="autoMarkerLineOnLostFocus">
+     <property name="toolTip">
+      <string>Set the marker line to the bottom of the current chat window when Quassel loses focus.</string>
+     </property>
+     <property name="text">
+      <string>Set marker line automatically when Quassel loses focus</string>
+     </property>
+     <property name="checked">
+      <bool>true</bool>
+     </property>
+     <property name="settingsKey" stdset="0">
+      <string>AutoMarkerLineOnLostFocus</string>
+     </property>
+     <property name="defaultValue" stdset="0">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout_4">
      <item>