]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Improve group-header layout
authorPeter Penz <peter.penz19@gmail.com>
Sun, 23 Oct 2011 19:30:40 +0000 (21:30 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 23 Oct 2011 19:32:35 +0000 (21:32 +0200)
- Apply a dynamic width
- Use a height that depends on the style
- Cleanup some interfaces and replace xxxBoundingRect() by
  xxxRect()

src/kitemviews/kfileitemlistwidget.cpp
src/kitemviews/kfileitemlistwidget.h
src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemlistview.h
src/kitemviews/kitemlistviewlayouter.cpp
src/kitemviews/kitemlistviewlayouter_p.h
src/kitemviews/kitemlistwidget.cpp
src/kitemviews/kitemlistwidget.h
src/views/dolphinview.cpp

index 3d47285215eec6d6681046afcb1271b3aa434976..f6039b7a59153c23e6ff69bbb0d311253bdc09dd 100644 (file)
@@ -53,7 +53,7 @@ KFileItemListWidget::KFileItemListWidget(QGraphicsItem* parent) :
     m_hoverPixmap(),
     m_textPos(),
     m_text(),
-    m_textBoundingRect(),
+    m_textRect(),
     m_sortedVisibleRoles(),
     m_expansionArea(),
     m_customTextColor(),
@@ -150,7 +150,7 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte
 #endif
 }
 
-QRectF KFileItemListWidget::iconBoundingRect() const
+QRectF KFileItemListWidget::iconRect() const
 {
     const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing();
 
@@ -160,10 +160,10 @@ QRectF KFileItemListWidget::iconBoundingRect() const
     return bounds;
 }
 
-QRectF KFileItemListWidget::textBoundingRect() const
+QRectF KFileItemListWidget::textRect() const
 {
     const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing();
-    return m_textBoundingRect;
+    return m_textRect;
 }
 
 QRectF KFileItemListWidget::expansionToggleRect() const
@@ -531,7 +531,7 @@ void KFileItemListWidget::updateIconsLayoutTextCache()
 
     m_text[Name].setTextWidth(maxWidth);
     m_textPos[Name] = QPointF(option.margin, widgetHeight - textLinesCount * fontHeight - option.margin);
-    m_textBoundingRect = QRectF(option.margin + (maxWidth - requiredWidthForName) / 2,
+    m_textRect = QRectF(option.margin + (maxWidth - requiredWidthForName) / 2,
                                  m_textPos[Name].y(),
                                  requiredWidthForName,
                                  m_text[Name].size().height());
@@ -570,15 +570,15 @@ void KFileItemListWidget::updateIconsLayoutTextCache()
         m_textPos[textId] = QPointF(option.margin, y);
         m_text[textId].setTextWidth(maxWidth);
 
-        const QRectF textBoundingRect(option.margin + (maxWidth - requiredWidth) / 2, y, requiredWidth, fontHeight);
-        m_textBoundingRect |= textBoundingRect;
+        const QRectF textRect(option.margin + (maxWidth - requiredWidth) / 2, y, requiredWidth, fontHeight);
+        m_textRect |= textRect;
 
         y += fontHeight;
     }
 
-    // Add a margin to the text bounding rectangle
+    // Add a margin to the text rectangle
     const qreal margin = option.margin;
-    m_textBoundingRect.adjust(-margin, -margin, margin, margin);
+    m_textRect.adjust(-margin, -margin, margin, margin);
 }
 
 void KFileItemListWidget::updateCompactLayoutTextCache()
@@ -620,7 +620,7 @@ void KFileItemListWidget::updateCompactLayoutTextCache()
         y += fontHeight;
     }
 
-    m_textBoundingRect = QRectF(x - option.margin, 0, maximumRequiredTextWidth + 2 * option.margin, widgetHeight);
+    m_textRect = QRectF(x - option.margin, 0, maximumRequiredTextWidth + 2 * option.margin, widgetHeight);
 }
 
 void KFileItemListWidget::updateDetailsLayoutTextCache()
@@ -631,7 +631,7 @@ void KFileItemListWidget::updateDetailsLayoutTextCache()
     // +------+
     // | Icon |  Name role   Additional role 1   Additional role 2
     // +------+
-    m_textBoundingRect = QRectF();
+    m_textRect = QRectF();
 
     const KItemListStyleOption& option = styleOption();
     const QHash<QByteArray, QVariant> values = data();
@@ -669,7 +669,7 @@ void KFileItemListWidget::updateDetailsLayoutTextCache()
 
         switch (textId) {
         case Name: {
-            m_textBoundingRect = QRectF(m_textPos[textId].x() - option.margin, 0,
+            m_textRect = QRectF(m_textPos[textId].x() - option.margin, 0,
                                         requiredWidth + 2 * option.margin, size().height());
 
             // The column after the name should always be aligned on the same x-position independent
index 71c57ea73c3d30756bcebab1f38d5846ab00eb33..bebc3e168e7efa0f1b140efda57b32b64739a5b2 100644 (file)
@@ -48,8 +48,8 @@ public:
 
     virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
 
-    virtual QRectF iconBoundingRect() const;
-    virtual QRectF textBoundingRect() const;
+    virtual QRectF iconRect() const;
+    virtual QRectF textRect() const;
     virtual QRectF expansionToggleRect() const;
 
     /**
@@ -132,7 +132,7 @@ private:
 
     QPointF m_textPos[TextIdCount];
     QStaticText m_text[TextIdCount];
-    QRectF m_textBoundingRect;
+    QRectF m_textRect;
 
     QList<QByteArray> m_sortedVisibleRoles;
 
index deefe8e3c8ca430447546db0fe06016cdf561c55..a9885f285321a7dae18bb4019e52ba84417e1b32 100644 (file)
@@ -693,10 +693,10 @@ void KItemListController::slotRubberBandChanged()
     foreach (const KItemListWidget* widget, m_view->visibleItemListWidgets()) {
         const int index = widget->index();
 
-        const QRectF widgetRect = m_view->itemBoundingRect(index);
+        const QRectF widgetRect = m_view->itemRect(index);
         if (widgetRect.intersects(rubberBandRect)) {
-            const QRectF iconRect = widget->iconBoundingRect().translated(widgetRect.topLeft());
-            const QRectF textRect = widget->textBoundingRect().translated(widgetRect.topLeft());
+            const QRectF iconRect = widget->iconRect().translated(widgetRect.topLeft());
+            const QRectF textRect = widget->textRect().translated(widgetRect.topLeft());
             if (iconRect.intersects(rubberBandRect) || textRect.intersects(rubberBandRect)) {
                 selectedItems.insert(index);
             }
@@ -712,7 +712,7 @@ void KItemListController::slotRubberBandChanged()
     int index = increaseIndex ? m_view->lastVisibleIndex() + 1 : m_view->firstVisibleIndex() - 1;
     bool selectionFinished = false;
     do {
-        const QRectF widgetRect = m_view->itemBoundingRect(index);
+        const QRectF widgetRect = m_view->itemRect(index);
         if (widgetRect.intersects(rubberBandRect)) {
             selectedItems.insert(index);
         }
index e8d5243b64e91adb3ff9a65690f9854a341e1f15..05a2d30c10e7a2903d97b2aa0c6a026fdb6bbafd 100644 (file)
@@ -395,9 +395,9 @@ QHash<QByteArray, QSizeF> KItemListView::visibleRolesSizes(const KItemRangeList&
     return QHash<QByteArray, QSizeF>();
 }
 
-QRectF KItemListView::itemBoundingRect(int index) const
+QRectF KItemListView::itemRect(int index) const
 {
-    return m_layouter->itemBoundingRect(index);
+    return m_layouter->itemRect(index);
 }
 
 int KItemListView::itemsPerOffset() const
@@ -848,6 +848,11 @@ void KItemListView::slotGroupedSortingChanged(bool current)
 {
     m_grouped = current;
     if (m_grouped) {
+        // Apply the height of the header to the layouter
+        const qreal groupHeaderHeight = m_styleOption.fontMetrics.height() +
+                                        m_styleOption.margin * 2;
+        m_layouter->setGroupHeaderHeight(groupHeaderHeight);
+
         // Assure that headers from already visible items get created
         QHashIterator<int, KItemListWidget*> it(m_visibleItems);
         while (it.hasNext()) {
@@ -886,24 +891,24 @@ void KItemListView::slotCurrentChanged(int current, int previous)
     }
 
     const QRectF viewGeometry = geometry();
-    const QRectF currentBoundingRect = itemBoundingRect(current);
+    const QRectF currentRect = itemRect(current);
 
-    if (!viewGeometry.contains(currentBoundingRect)) {
+    if (!viewGeometry.contains(currentRect)) {
         // Make sure that the new current item is fully visible in the view.
         qreal newOffset = scrollOffset();
-        if (currentBoundingRect.top() < viewGeometry.top()) {
+        if (currentRect.top() < viewGeometry.top()) {
             Q_ASSERT(scrollOrientation() == Qt::Vertical);
-            newOffset += currentBoundingRect.top() - viewGeometry.top();
-        } else if ((currentBoundingRect.bottom() > viewGeometry.bottom())) {
+            newOffset += currentRect.top() - viewGeometry.top();
+        } else if ((currentRect.bottom() > viewGeometry.bottom())) {
             Q_ASSERT(scrollOrientation() == Qt::Vertical);
-            newOffset += currentBoundingRect.bottom() - viewGeometry.bottom();
-        } else if (currentBoundingRect.left() < viewGeometry.left()) {
+            newOffset += currentRect.bottom() - viewGeometry.bottom();
+        } else if (currentRect.left() < viewGeometry.left()) {
             if (scrollOrientation() == Qt::Horizontal) {
-                newOffset += currentBoundingRect.left() - viewGeometry.left();
+                newOffset += currentRect.left() - viewGeometry.left();
             }
-        } else if ((currentBoundingRect.right() > viewGeometry.right())) {
+        } else if ((currentRect.right() > viewGeometry.right())) {
             if (scrollOrientation() == Qt::Horizontal) {
-                newOffset += currentBoundingRect.right() - viewGeometry.right();
+                newOffset += currentRect.right() - viewGeometry.right();
             }
         }
 
@@ -1209,7 +1214,7 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha
         bool applyNewPos = true;
         bool wasHidden = false;
 
-        const QRectF itemBounds = m_layouter->itemBoundingRect(i);
+        const QRectF itemBounds = m_layouter->itemRect(i);
         const QPointF newPos = itemBounds.topLeft();
         KItemListWidget* widget = m_visibleItems.value(i);
         if (!widget) {
@@ -1228,13 +1233,13 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha
             if (animate && changedCount < 0) {
                 // Items have been deleted, move the created item to the
                 // imaginary old position.
-                const QRectF itemBoundingRect = m_layouter->itemBoundingRect(i - changedCount);
-                if (itemBoundingRect.isEmpty()) {
+                const QRectF itemRect = m_layouter->itemRect(i - changedCount);
+                if (itemRect.isEmpty()) {
                     const QPointF invisibleOldPos = (scrollOrientation() == Qt::Vertical)
                                                     ? QPointF(0, size().height()) : QPointF(size().width(), 0);
                     widget->setPos(invisibleOldPos);
                 } else {
-                    widget->setPos(itemBoundingRect.topLeft());
+                    widget->setPos(itemRect.topLeft());
                 }
                 applyNewPos = false;
             }
@@ -1290,6 +1295,15 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha
         recycleWidget(m_visibleItems.value(index));
     }
 
+    if (m_grouped) {
+        // Update the layout of all visible group headers
+        QHashIterator<KItemListWidget*, KItemListGroupHeader*> it(m_visibleGroups);
+        while (it.hasNext()) {
+            it.next();
+            updateGroupHeaderLayout(it.key());
+        }
+    }
+
     emitOffsetChanges();
 }
 
@@ -1397,7 +1411,7 @@ void KItemListView::prepareLayoutForIncreasedItemCount(const QSizeF& size, SizeT
         for (int i = minFirst; i <= maxLast; ++i) {
             if (!m_visibleItems.contains(i)) {
                 KItemListWidget* widget = createWidget(i);
-                const QPointF pos = m_layouter->itemBoundingRect(i).topLeft();
+                const QPointF pos = m_layouter->itemRect(i).topLeft();
                 widget->setPos(pos);
             }
         }
@@ -1447,12 +1461,6 @@ void KItemListView::updateGroupHeaderForWidget(KItemListWidget* widget)
     }
     Q_ASSERT(header->parentItem() == widget);
 
-    // TODO:
-    header->show();
-    header->setPos(0, -50);
-    header->resize(200, 50);
-    header->setRole(model()->sortRole());
-
     // Determine the shown data for the header by doing a binary
     // search in the groups-list
     const QList<QPair<int, QVariant> > groups = model()->groups();
@@ -1467,7 +1475,28 @@ void KItemListView::updateGroupHeaderForWidget(KItemListWidget* widget)
             max = mid - 1;
         }
     } while (groups.at(mid).first != index && min <= max);
+
     header->setData(groups.at(mid).second);
+    header->setRole(model()->sortRole());
+
+    header->show();
+}
+
+void KItemListView::updateGroupHeaderLayout(KItemListWidget* widget)
+{
+    KItemListGroupHeader* header = m_visibleGroups.value(widget);
+    Q_ASSERT(header);
+
+    const int index = widget->index();
+    const QRectF groupHeaderRect = m_layouter->groupHeaderRect(index);
+    const QRectF itemRect = m_layouter->itemRect(index);
+
+    // The group-header is a child of the itemlist widget. Translate the
+    // group header position to the relative position.
+    const QPointF groupHeaderPos(groupHeaderRect.x() - itemRect.x(),
+                                 - groupHeaderRect.height());
+    header->setPos(groupHeaderPos);
+    header->resize(groupHeaderRect.size());
 }
 
 void KItemListView::recycleGroupHeaderForWidget(KItemListWidget* widget)
index 985b7c2780ebd262298eb2691b4d2e7b276115f7..fd2f286dbfe27cc96baa2c6b2289349f3cc04e9b 100644 (file)
@@ -162,10 +162,10 @@ public:
     virtual QHash<QByteArray, QSizeF> visibleRolesSizes(const KItemRangeList& itemRanges) const;
 
     /**
-     * @return The bounding rectangle of the item relative to the top/left of
+     * @return The rectangle of the item relative to the top/left of
      *         the currently visible area (see KItemListView::offset()).
      */
-    QRectF itemBoundingRect(int index) const;
+    QRectF itemRect(int index) const;
 
     /**
      * @return The number of items that can be shown in parallel for one offset.
@@ -335,6 +335,13 @@ private:
      */
     void updateGroupHeaderForWidget(KItemListWidget* widget);
 
+    /**
+     * Updates the position and size of the group-header that belongs
+     * to the itemlist widget \a widget. The given widget must represent
+     * the first item of a group.
+     */
+    void updateGroupHeaderLayout(KItemListWidget* widget);
+
     /**
      * Recycles the group-header from the widget.
      */
index 4aae66f63d2f60fd658fc53557f08e7a076f519f..6bd9a6e27a1686331ee945d6b884c30d3bf1d13e 100644 (file)
 
 #define KITEMLISTVIEWLAYOUTER_DEBUG
 
-namespace {
-    // TODO: Calculate dynamically
-    const int GroupHeaderHeight = 50;
-};
-
 KItemListViewLayouter::KItemListViewLayouter(QObject* parent) :
     QObject(parent),
     m_dirty(true),
@@ -50,9 +45,9 @@ KItemListViewLayouter::KItemListViewLayouter(QObject* parent) :
     m_columnWidth(0),
     m_xPosInc(0),
     m_columnCount(0),
-    m_groups(),
-    m_groupIndexes(),
-    m_itemBoundingRects()
+    m_groupItemIndexes(),
+    m_groupHeaderHeight(0),
+    m_itemRects()
 {
 }
 
@@ -112,6 +107,19 @@ qreal KItemListViewLayouter::headerHeight() const
     return m_headerHeight;
 }
 
+void KItemListViewLayouter::setGroupHeaderHeight(qreal height)
+{
+    if (m_groupHeaderHeight != height) {
+        m_groupHeaderHeight = height;
+        m_dirty = true;
+    }
+}
+
+qreal KItemListViewLayouter::groupHeaderHeight() const
+{
+    return m_groupHeaderHeight;
+}
+
 void KItemListViewLayouter::setScrollOffset(qreal offset)
 {
     if (m_scrollOffset != offset) {
@@ -188,17 +196,17 @@ int KItemListViewLayouter::lastVisibleIndex() const
     return m_lastVisibleIndex;
 }
 
-QRectF KItemListViewLayouter::itemBoundingRect(int index) const
+QRectF KItemListViewLayouter::itemRect(int index) const
 {
     const_cast<KItemListViewLayouter*>(this)->doLayout();
-    if (index < 0 || index >= m_itemBoundingRects.count()) {
+    if (index < 0 || index >= m_itemRects.count()) {
         return QRectF();
     }
 
     if (m_scrollOrientation == Qt::Horizontal) {
         // Rotate the logical direction which is always vertical by 90°
         // to get the physical horizontal direction
-        const QRectF& b = m_itemBoundingRects[index];
+        const QRectF& b = m_itemRects[index];
         QRectF bounds(b.y(), b.x(), b.height(), b.width());
         QPointF pos = bounds.topLeft();
         pos.rx() -= m_scrollOffset;
@@ -206,11 +214,31 @@ QRectF KItemListViewLayouter::itemBoundingRect(int index) const
         return bounds;
     }
 
-    QRectF bounds = m_itemBoundingRects[index];
+    QRectF bounds = m_itemRects[index];
     bounds.moveTo(bounds.topLeft() - QPointF(m_itemOffset, m_scrollOffset));
     return bounds;
 }
 
+QRectF KItemListViewLayouter::groupHeaderRect(int index) const
+{
+    const QRectF firstItemRect = itemRect(index);
+    QPointF pos = firstItemRect.topLeft();
+    if (pos.isNull()) {
+        return QRectF();
+    }
+
+    pos.ry() -= m_groupHeaderHeight;
+
+    QSizeF size;
+    if (m_scrollOrientation == Qt::Vertical) {
+        pos.rx() = 0;
+        size = QSizeF(m_size.width(), m_groupHeaderHeight);
+    } else {
+        size = QSizeF(firstItemRect.width(), m_groupHeaderHeight);
+    }
+    return QRectF(pos, size);
+}
+
 int KItemListViewLayouter::maximumVisibleItems() const
 {
     const_cast<KItemListViewLayouter*>(this)->doLayout();
@@ -232,7 +260,7 @@ int KItemListViewLayouter::itemsPerOffset() const
 
 bool KItemListViewLayouter::isFirstGroupItem(int itemIndex) const
 {
-    return m_groupIndexes.contains(itemIndex);
+    return m_groupItemIndexes.contains(itemIndex);
 }
 
 void KItemListViewLayouter::markAsDirty()
@@ -280,14 +308,12 @@ void KItemListViewLayouter::doLayout()
             ++rowCount;
         }
 
-        m_itemBoundingRects.reserve(itemCount);
+        m_itemRects.reserve(itemCount);
 
         qreal y = m_headerHeight;
         int rowIndex = 0;
 
         const bool grouped = createGroupHeaders();
-        int groupIndex = 0;
-        int firstItemIndexOfGroup = 0;
 
         int index = 0;
         while (index < itemCount) {
@@ -298,24 +324,15 @@ void KItemListViewLayouter::doLayout()
                 if (horizontalScrolling) {
                     // All group headers will always be aligned on the top and not
                     // flipped like the other properties
-                    x += GroupHeaderHeight;
+                    x += m_groupHeaderHeight;
                 }
 
-                if (index == firstItemIndexOfGroup) {
+                if (m_groupItemIndexes.contains(index)) {
                     if (!horizontalScrolling) {
                         // The item is the first item of a group.
                         // Increase the y-position to provide space
                         // for the group header.
-                        y += GroupHeaderHeight;
-                    }
-
-                    // Calculate the index of the first item for
-                    // the next group
-                    ++groupIndex;
-                    if (groupIndex < m_groups.count()) {
-                        firstItemIndexOfGroup = m_groups.at(groupIndex);
-                    } else {
-                        firstItemIndexOfGroup = -1;
+                        y += m_groupHeaderHeight;
                     }
                 }
             }
@@ -332,10 +349,10 @@ void KItemListViewLayouter::doLayout()
                 }
 
                 const QRectF bounds(x, y, itemSize.width(), requiredItemHeight);
-                if (index < m_itemBoundingRects.count()) {
-                    m_itemBoundingRects[index] = bounds;
+                if (index < m_itemRects.count()) {
+                    m_itemRects[index] = bounds;
                 } else {
-                    m_itemBoundingRects.append(bounds);
+                    m_itemRects.append(bounds);
                 }
 
                 maxItemHeight = qMax(maxItemHeight, requiredItemHeight);
@@ -343,7 +360,7 @@ void KItemListViewLayouter::doLayout()
                 ++index;
                 ++column;
 
-                if (grouped && index == firstItemIndexOfGroup) {
+                if (grouped && m_groupItemIndexes.contains(index)) {
                     // The item represents the first index of a group
                     // and must aligned in the first column
                     break;
@@ -353,13 +370,13 @@ void KItemListViewLayouter::doLayout()
             y += maxItemHeight;
             ++rowIndex;
         }
-        if (m_itemBoundingRects.count() > itemCount) {
-            m_itemBoundingRects.erase(m_itemBoundingRects.begin() + itemCount,
-                                      m_itemBoundingRects.end());
+        if (m_itemRects.count() > itemCount) {
+            m_itemRects.erase(m_itemRects.begin() + itemCount,
+                                      m_itemRects.end());
         }
 
         if (itemCount > 0) {
-            m_maximumScrollOffset = m_itemBoundingRects.last().bottom();
+            m_maximumScrollOffset = m_itemRects.last().bottom();
             m_maximumItemOffset = m_columnCount * m_columnWidth;
         } else {
             m_maximumScrollOffset = 0;
@@ -398,14 +415,14 @@ void KItemListViewLayouter::updateVisibleIndexes()
     int mid = 0;
     do {
         mid = (min + max) / 2;
-        if (m_itemBoundingRects[mid].bottom() < m_scrollOffset) {
+        if (m_itemRects[mid].bottom() < m_scrollOffset) {
             min = mid + 1;
         } else {
             max = mid - 1;
         }
     } while (min <= max);
 
-    while (mid < maxIndex && m_itemBoundingRects[mid].bottom() < m_scrollOffset) {
+    while (mid < maxIndex && m_itemRects[mid].bottom() < m_scrollOffset) {
         ++mid;
     }
     m_firstVisibleIndex = mid;
@@ -414,21 +431,21 @@ void KItemListViewLayouter::updateVisibleIndexes()
     const int visibleHeight = (m_scrollOrientation == Qt::Horizontal) ? m_size.width() : m_size.height();
     qreal bottom = m_scrollOffset + visibleHeight;
     if (m_model->groupedSorting()) {
-        bottom += GroupHeaderHeight;
+        bottom += m_groupHeaderHeight;
     }
 
     min = m_firstVisibleIndex;
     max = maxIndex;
     do {
         mid = (min + max) / 2;
-        if (m_itemBoundingRects[mid].y() <= bottom) {
+        if (m_itemRects[mid].y() <= bottom) {
             min = mid + 1;
         } else {
             max = mid - 1;
         }
     } while (min <= max);
 
-    while (mid > 0 && m_itemBoundingRects[mid].y() > bottom) {
+    while (mid > 0 && m_itemRects[mid].y() > bottom) {
         --mid;
     }
     m_lastVisibleIndex = mid;
@@ -442,19 +459,16 @@ bool KItemListViewLayouter::createGroupHeaders()
         return false;
     }
 
-    m_groups.clear();
-    m_groupIndexes.clear();
+    m_groupItemIndexes.clear();
 
     const QList<QPair<int, QVariant> > groups = m_model->groups();
     if (groups.isEmpty()) {
         return false;
     }
 
-    m_groups.reserve(groups.count());
     for (int i = 0; i < groups.count(); ++i) {
         const int firstItemIndex = groups.at(i).first;
-        m_groups.append(firstItemIndex);
-        m_groupIndexes.insert(firstItemIndex);
+        m_groupItemIndexes.insert(firstItemIndex);
     }
 
     return true;
index 255db91884db41a5c52aaa49f5124bcaaab6235e..109528c634d56ed08d491dc28379585c9eca8f50 100644 (file)
@@ -55,6 +55,13 @@ public:
     void setHeaderHeight(qreal height);
     qreal headerHeight() const;
 
+    /**
+     * Sets the height of the group header that is used
+     * to indicate a new item group.
+     */
+    void setGroupHeaderHeight(qreal height);
+    qreal groupHeaderHeight() const;
+
     // TODO: add note that offset can be < 0 or > maximumOffset!
     void setScrollOffset(qreal scrollOffset);
     qreal scrollOffset() const;
@@ -72,17 +79,39 @@ public:
     void setSizeHintResolver(const KItemListSizeHintResolver* sizeHintResolver);
     const KItemListSizeHintResolver* sizeHintResolver() const;
 
-
-    // TODO: mention that return value is -1 if count == 0
+    /**
+     * @return The first (at least partly) visible index. -1 is returned
+     *         if the item count is 0.
+     */
     int firstVisibleIndex() const;
 
-    // TODO: mention that return value is -1 if count == 0
+    /**
+     * @return The last (at least partly) visible index. -1 is returned
+     *         if the item count is 0.
+     */
     int lastVisibleIndex() const;
 
-    QRectF itemBoundingRect(int index) const;
+    /**
+     * @return Rectangle of the item with the index \a index.
+     *         The top/left of the bounding rectangle is related to
+     *         the top/left of the KItemListView. An empty rectangle
+     *         is returned if an invalid index is given.
+     */
+    QRectF itemRect(int index) const;
 
+    QRectF groupHeaderRect(int index) const;
+
+    /**
+     * @return Maximum number of (at least partly) visible items for
+     *         the given size.
+     */
     int maximumVisibleItems() const;
 
+    /**
+     * @return Maximum number of items that can be shown in the same row
+     *          (= vertical scrolldirection) or same column
+     *          (= horizontal scrolldirection).
+     */
     int itemsPerOffset() const;
 
     /**
@@ -123,13 +152,12 @@ private:
     qreal m_xPosInc;
     int m_columnCount;
 
-    QList<int> m_groups;
-
     // Stores all item indexes that are the first item of a group.
     // Assures fast access for KItemListViewLayouter::isFirstGroupItem().
-    QSet<int> m_groupIndexes;
+    QSet<int> m_groupItemIndexes;
+    qreal m_groupHeaderHeight;
 
-    QList<QRectF> m_itemBoundingRects;
+    QList<QRectF> m_itemRects;
 };
 
 #endif
index 025b8e883f6fab59842384c5f1b02076edb6d800..21bfe707fc711549c46d6a4aec12c04da911b013 100644 (file)
@@ -104,7 +104,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
         painter->fillRect(backgroundRect, backgroundColor);
     }
 
-    const QRect iconBounds = iconBoundingRect().toRect();
+    const QRect iconBounds = iconRect().toRect();
     if (m_selected) {
         QStyleOptionViewItemV4 viewItemOption;
         viewItemOption.initFrom(widget);
@@ -119,7 +119,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
     if (isCurrent()) {
         QStyleOptionViewItemV4 viewItemOption;
         viewItemOption.initFrom(widget);
-        viewItemOption.rect = textBoundingRect().toRect();
+        viewItemOption.rect = textRect().toRect();
         viewItemOption.state = QStyle::State_Enabled | QStyle::State_Item;
         viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
         style()->drawPrimitive(QStyle::PE_FrameFocusRect, &viewItemOption, painter, widget);
@@ -271,8 +271,8 @@ bool KItemListWidget::contains(const QPointF& point) const
         return false;
     }
 
-    return iconBoundingRect().contains(point) ||
-           textBoundingRect().contains(point) ||
+    return iconRect().contains(point) ||
+           textRect().contains(point) ||
            expansionToggleRect().contains(point) ||
            selectionToggleRect().contains(point);
 }
@@ -366,7 +366,7 @@ void KItemListWidget::drawTextBackground(QPainter* painter)
 {
     const qreal opacity = painter->opacity();
 
-    QRectF textBounds = textBoundingRect();
+    QRectF textBounds = textRect();
     const qreal marginDiff = m_styleOption.margin / 2;
     textBounds.adjust(marginDiff, marginDiff, -marginDiff, -marginDiff);
     painter->setOpacity(opacity * 0.1);
index eae4c39dabc92de9bd565cf8e45d37c1bb531d84..2df19a610028b33589551e08429aade8785e24dd 100644 (file)
@@ -53,7 +53,7 @@ public:
     QHash<QByteArray, QVariant> data() const;
 
     /**
-     * Draws the hover-bounding-rectangle if the item is hovered. Overwrite this method
+     * Draws the hover-rectangle if the item is hovered. Overwrite this method
      * to show the data of the custom model provided by KItemListWidget::data().
      * @reimp
      */
@@ -81,22 +81,22 @@ public:
     bool alternatingBackgroundColors() const;
 
     /**
-     * @return True if \a point is inside KItemListWidget::hoverBoundingRect(),
-     *         KItemListWidget::textBoundingRect(), KItemListWidget::selectionToggleRect()
+     * @return True if \a point is inside KItemListWidget::hoverRect(),
+     *         KItemListWidget::textRect(), KItemListWidget::selectionToggleRect()
      *         or KItemListWidget::expansionToggleRect().
      * @reimp
      */
     virtual bool contains(const QPointF& point) const;
 
     /**
-     * @return Bounding rectangle for the area that shows the icon.
+     * @return Rectangle for the area that shows the icon.
      */
-    virtual QRectF iconBoundingRect() const = 0;
+    virtual QRectF iconRect() const = 0;
 
     /**
-     * @return Bounding rectangle for the area that contains the text-properties.
+     * @return Rectangle for the area that contains the text-properties.
      */
-    virtual QRectF textBoundingRect() const = 0;
+    virtual QRectF textRect() const = 0;
 
     /**
      * @return Rectangle for the selection-toggle that is used to select or deselect an item.
index 5ff3cb26d70168e294bd44096287f537a92d96fc..961651b698594263c237ba9710e985ad099d34cd 100644 (file)
@@ -846,7 +846,7 @@ void DolphinView::slotItemHovered(int index)
     const KFileItem item = fileItemModel()->fileItem(index);
 
     if (GeneralSettings::showToolTips()) {
-        QRectF itemRect = m_container->controller()->view()->itemBoundingRect(index);
+        QRectF itemRect = m_container->controller()->view()->itemRect(index);
         const QPoint pos = m_container->mapToGlobal(itemRect.topLeft().toPoint());
         itemRect.moveTo(pos);