[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r2921: Rework the message log scrollbar logic so it's consistent ag (vidalia/trunk/src/vidalia/log)



Author: edmanm
Date: 2008-08-02 20:35:46 -0400 (Sat, 02 Aug 2008)
New Revision: 2921

Modified:
   vidalia/trunk/src/vidalia/log/logtreewidget.cpp
   vidalia/trunk/src/vidalia/log/logtreewidget.h
Log:
Rework the message log scrollbar logic so it's consistent again on Qt 4.4.0.
Fixes ticket #369.


Modified: vidalia/trunk/src/vidalia/log/logtreewidget.cpp
===================================================================
--- vidalia/trunk/src/vidalia/log/logtreewidget.cpp	2008-08-02 18:17:08 UTC (rev 2920)
+++ vidalia/trunk/src/vidalia/log/logtreewidget.cpp	2008-08-03 00:35:46 UTC (rev 2921)
@@ -28,8 +28,9 @@
   
   /* Default to always scrolling to the most recent item added */
   _scrollOnNewItem = true;
-  connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
-          this, SLOT(onVerticalScroll(int)));
+  setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
+  connect(verticalScrollBar(), SIGNAL(sliderReleased()),
+          this, SLOT(verticalSliderReleased()));
 }
 
 /** Called when the user moves the vertical scrollbar. If the user has the
@@ -37,10 +38,13 @@
  * items when added. Otherwise, leave the scrollbar alone since they are
  * probably looking at something in their history. */
 void
-LogTreeWidget::onVerticalScroll(int value)
+LogTreeWidget::verticalSliderReleased()
 {
-  QScrollBar *scrollbar = verticalScrollBar();
-  _scrollOnNewItem = (value >= (scrollbar->maximum()-scrollbar->singleStep()));
+  QScrollBar *scrollBar = verticalScrollBar();
+  if (header()->sortIndicatorOrder() == Qt::AscendingOrder)
+    _scrollOnNewItem = (scrollBar->value() == scrollBar->maximum());
+  else
+    _scrollOnNewItem = (scrollBar->value() == scrollBar->minimum());
 }
 
 /** Cast a QList of QTreeWidgetItem pointers to a list of LogTreeWidget
@@ -182,11 +186,23 @@
     delete takeTopLevelItem(0);
   }
   
-  /* Add the new message item and scroll to it (if necessary) */
+  /* Add the new message item and scroll to it (if necessary) 
+   * NOTE: We disable sorting, add the new item, and then re-enable sorting
+   *       to force the result to be sorted immediately. Otherwise, the new
+   *       message is not sorted until the message log has focus again.
+   */
+  setSortingEnabled(false); 
   addMessageItem(item);
+  setSortingEnabled(true);
+
   if (_scrollOnNewItem) {
-    scrollToItem(item);
+    QScrollBar *scrollBar = verticalScrollBar();
+    if (header()->sortIndicatorOrder() == Qt::AscendingOrder)
+      scrollBar->setValue(scrollBar->maximum());
+    else
+      scrollBar->setValue(scrollBar->minimum());
   }
+
   return item;
 }
 

Modified: vidalia/trunk/src/vidalia/log/logtreewidget.h
===================================================================
--- vidalia/trunk/src/vidalia/log/logtreewidget.h	2008-08-02 18:17:08 UTC (rev 2920)
+++ vidalia/trunk/src/vidalia/log/logtreewidget.h	2008-08-03 00:35:46 UTC (rev 2921)
@@ -76,7 +76,7 @@
 
 private slots:
   /** Called when the user moves the vertical scroll bar. */
-  void onVerticalScroll(int value);
+  void verticalSliderReleased();
 
 private:
   /** Adds a message log item. */