]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Further animation optimizations
authorPeter Penz <peter.penz19@gmail.com>
Mon, 30 Jan 2012 11:59:38 +0000 (12:59 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Mon, 30 Jan 2012 12:01:13 +0000 (13:01 +0100)
- Assure a proper minimim width in the compact mode.
- Don't calculate the old position of hidden items to animate the
  moving. Just show them directly.

src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemlistview.h
src/views/dolphinitemlistcontainer.cpp

index 4b2c742d98d95d9a6fce0690354a3abba79be935..a0820f7e50f4845b6c0bbc41f7540d8e9cdcfe67 100644 (file)
@@ -147,15 +147,10 @@ void KItemListView::setItemSize(const QSizeF& itemSize)
 
     m_itemSize = itemSize;
 
-    const bool emptySize = itemSize.isEmpty();
-    if (emptySize) {
+    if (itemSize.isEmpty()) {
         updateVisibleRolesSizes();
     } else {
-        if (itemSize.width() < previousSize.width() || itemSize.height() < previousSize.height()) {
-            prepareLayoutForIncreasedItemCount(itemSize, ItemSize);
-        } else {
-            m_layouter->setItemSize(itemSize);
-        }
+        m_layouter->setItemSize(itemSize);
     }
 
     m_sizeHintResolver->clearCache();
@@ -394,12 +389,7 @@ void KItemListView::setGeometry(const QRectF& rect)
         // The item size is not dynamic and most probably the geometry change results
         // in animated position changes of the items. Trigger an asynchronous relayout
         // with m_layoutTimer to prevent performance bottlenecks.
-        if (m_model->count() > 0) {
-            prepareLayoutForIncreasedItemCount(newSize, LayouterSize);
-        } else {
-            m_layouter->setSize(newSize);
-        }
-
+        m_layouter->setSize(newSize);
         if (!m_layoutTimer->isActive()) {
             m_layoutTimer->start();
         }
@@ -1462,9 +1452,14 @@ bool KItemListView::moveWidget(KItemListWidget* widget, const QPointF& newPos)
     // create-animation on the new position will be used instead. This is done
     // to prevent "irritating" moving-animations.
     const QPointF oldPos = widget->pos();
-    const qreal xDiff = qAbs(oldPos.x() - newPos.x());
-    const qreal yDiff = qAbs(oldPos.y() - newPos.y());
-    if (xDiff <= m_itemSize.width() || yDiff <= m_itemSize.height()) {
+    const qreal xMax = m_itemSize.width();
+    const qreal yMax = m_itemSize.height();
+    
+    const bool startMovingAnim =    xMax <= 0
+                                 || yMax <= 0
+                                 || qAbs(oldPos.x() - newPos.x()) <= xMax
+                                 || qAbs(oldPos.y() - newPos.y()) <= yMax;
+    if (startMovingAnim) {
         // The moving animation is done inside a column or a row.
         m_animation->start(widget, KItemListViewAnimation::MovingAnimation, newPos);
         return true;
@@ -1538,52 +1533,6 @@ void KItemListView::setWidgetIndex(KItemListWidget* widget, int index)
     initializeItemListWidget(widget);
 }
 
-void KItemListView::prepareLayoutForIncreasedItemCount(const QSizeF& size, SizeType sizeType)
-{
-    // Calculate the first visible index and last visible index for the current size
-    const int currentFirst = m_layouter->firstVisibleIndex();
-    const int currentLast = m_layouter->lastVisibleIndex();
-
-    const QSizeF currentSize = (sizeType == LayouterSize) ? m_layouter->size() : m_layouter->itemSize();
-
-    // Calculate the first visible index and last visible index for the new size
-    setLayouterSize(size, sizeType);
-    const int newFirst = m_layouter->firstVisibleIndex();
-    const int newLast = m_layouter->lastVisibleIndex();
-
-    if ((currentFirst != newFirst) || (currentLast != newLast)) {
-        // At least one index has been changed. Assure that widgets for all possible
-        // visible items get created so that a move-animation can be started later.
-        const int maxVisibleItems = m_layouter->maximumVisibleItems();
-        int minFirst = qMin(newFirst, currentFirst);
-        const int maxLast = qMax(newLast, currentLast);
-
-        if (maxLast - minFirst + 1 < maxVisibleItems) {
-            // Increasing the size might result in a smaller KItemListView::offset().
-            // Decrease the first visible index in a way that at least the maximum
-            // visible items are shown.
-            minFirst = qMax(0, maxLast - maxVisibleItems + 1);
-        }
-
-        if (maxLast - minFirst > maxVisibleItems  + maxVisibleItems / 2) {
-            // The creating of widgets is quite expensive. Assure that never more
-            // than 50 % of the maximum visible items get created for the animations.
-            return;
-        }
-
-        setLayouterSize(currentSize, sizeType);
-        for (int i = minFirst; i <= maxLast; ++i) {
-            if (!m_visibleItems.contains(i)) {
-                KItemListWidget* widget = createWidget(i);
-                const QRectF itemRect = m_layouter->itemRect(i);
-                widget->setPos(itemRect.topLeft());
-                widget->resize(itemRect.size());
-            }
-        }
-        setLayouterSize(size, sizeType);
-    }
-}
-
 void KItemListView::setLayouterSize(const QSizeF& size, SizeType sizeType)
 {
     switch (sizeType) {
index e4f1cd0d9972acfe7be357699990de855aefca51..e4466993669d64b50c32863d6dba1ede798b559e 100644 (file)
@@ -366,17 +366,6 @@ private:
     void recycleWidget(KItemListWidget* widget);
     void setWidgetIndex(KItemListWidget* widget, int index);
 
-    /**
-     * Helper method for setGeometry() and setItemSize(): Calling both methods might result
-     * in a changed number of visible items. To assure that currently invisible items can
-     * get animated from the old position to the new position prepareLayoutForIncreasedItemCount()
-     * takes care to create all item widgets that are visible with the old or the new size.
-     * @param size     Size of the layouter or the item dependent on \p sizeType.
-     * @param sizeType LayouterSize: KItemListLayouter::setSize() is used.
-     *                 ItemSize: KItemListLayouter::setItemSize() is used.
-     */
-    void prepareLayoutForIncreasedItemCount(const QSizeF& size, SizeType sizeType);
-
     /**
      * Helper method for prepareLayoutForIncreasedItemCount().
      */
index 38adfde64f51f676a7a6e1d1b3c037bcb7432207..7c32f982a839ada24d70ee8a8eab7e5300d17ff8 100644 (file)
@@ -209,7 +209,7 @@ void DolphinItemListContainer::updateGridSize()
     switch (itemLayout()) {
     case KFileItemListView::IconsLayout: {
         const int minItemWidth = 64;
-        itemWidth = minItemWidth + IconsModeSettings::textWidthIndex() * 64; // TODO:
+        itemWidth = minItemWidth + IconsModeSettings::textWidthIndex() * 64;
         if (itemWidth < iconSize + innerMargin * 2) {
             itemWidth = iconSize + innerMargin * 2;
         }
@@ -217,7 +217,7 @@ void DolphinItemListContainer::updateGridSize()
         break;
     }
     case KFileItemListView::CompactLayout: {
-        itemWidth = innerMargin * 2;
+        itemWidth = innerMargin * 4 + iconSize + styleOption.fontMetrics.height() * 5;
         const int textLinesCount = m_fileItemListView->visibleRoles().count();
         itemHeight = innerMargin * 2 + qMax(iconSize, textLinesCount * styleOption.fontMetrics.height());
         break;