]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Avoid unnecessary animations when switching view modes
authorPeter Penz <peter.penz19@gmail.com>
Tue, 17 Jan 2012 22:42:55 +0000 (23:42 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 17 Jan 2012 22:45:23 +0000 (23:45 +0100)
Thanks to Nikita Skovoroda for the initial patch and the analyses.

BUG: 290947
FIXED-IN: 4.8.0

src/kitemviews/kitemlistview.cpp

index 49e23f9b73ed877582ed715c594d32151a254928..b6af42849da49acad3e455c761b2b25da0adf6d9 100644 (file)
@@ -401,7 +401,7 @@ void KItemListView::setGeometry(const QRectF& rect)
         }
 
         if (!m_layoutTimer->isActive()) {
         }
 
         if (!m_layoutTimer->isActive()) {
-          m_layoutTimer->start();
+            m_layoutTimer->start();
         }
     }
 }
         }
     }
 }
@@ -788,15 +788,23 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
         }
 
         m_layouter->markAsDirty();
         }
 
         m_layouter->markAsDirty();
-        if (m_model->count() == count && maximumScrollOffset() > size().height()) {
-            const int scrollBarExtent = style()->pixelMetric(QStyle::PM_ScrollBarExtent);
-            QSizeF layouterSize = m_layouter->size();
-            if (scrollOrientation() == Qt::Vertical) {
-                layouterSize.rwidth() -= scrollBarExtent;
-            } else {
-                layouterSize.rheight() -= scrollBarExtent;
+        if (m_model->count() == count && m_activeTransactions == 0) {
+            // Check whether a scrollbar is required to show the inserted items. In this case
+            // the size of the layouter will be decreased before calling doLayout(): This prevents
+            // an unnecessary temporary animation due to the geometry change of the inserted scrollbar.
+            const bool verticalScrollOrientation = (scrollOrientation() == Qt::Vertical);
+            const bool decreaseLayouterSize = ( verticalScrollOrientation && maximumScrollOffset() > size().height()) ||
+                                              (!verticalScrollOrientation && maximumScrollOffset() > size().width());
+            if (decreaseLayouterSize) {
+                const int scrollBarExtent = style()->pixelMetric(QStyle::PM_ScrollBarExtent);
+                QSizeF layouterSize = m_layouter->size();
+                if (verticalScrollOrientation) {
+                    layouterSize.rwidth() -= scrollBarExtent;
+                } else {
+                    layouterSize.rheight() -= scrollBarExtent;
+                }
+                m_layouter->setSize(layouterSize);
             }
             }
-            m_layouter->setSize(layouterSize);
         }
 
         if (!hasMultipleRanges) {
         }
 
         if (!hasMultipleRanges) {
@@ -880,7 +888,14 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
 
         m_layouter->markAsDirty();
         if (!hasMultipleRanges) {
 
         m_layouter->markAsDirty();
         if (!hasMultipleRanges) {
+            // The decrease-layout-size optimization in KItemListView::slotItemsInserted()
+            // assumes an updated geometry. If items are removed during an active transaction,
+            // the transaction will be temporary deactivated so that doLayout() triggers a
+            // geometry update if necessary.
+            const int activeTransactions = m_activeTransactions;
+            m_activeTransactions = 0;
             doLayout(Animation, index, -count);
             doLayout(Animation, index, -count);
+            m_activeTransactions = activeTransactions;
         }
     }
 
         }
     }