]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Group header fixes
authorPeter Penz <peter.penz19@gmail.com>
Tue, 25 Oct 2011 23:17:57 +0000 (01:17 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 25 Oct 2011 23:18:53 +0000 (01:18 +0200)
- Simplify header for the horizontal scroll direction
- Fix issue that orientation change was not forwarded to the header

src/kitemviews/kitemlistgroupheader.cpp
src/kitemviews/kitemlistgroupheader.h
src/kitemviews/kitemlistview.cpp

index 0cc04dc2554c81d7773646ab8ec029f1cecfb01e..a63ad8d0913c79025a19dc206485020e5265fc3c 100644 (file)
@@ -44,8 +44,7 @@ KItemListGroupHeader::KItemListGroupHeader(QGraphicsWidget* parent) :
 
 KItemListGroupHeader::~KItemListGroupHeader()
 {
-    delete m_leftBorderCache;
-    delete m_rightBorderCache;
+    deleteCache();
 }
 
 void KItemListGroupHeader::setRole(const QByteArray& role)
@@ -96,7 +95,11 @@ void KItemListGroupHeader::setScrollOrientation(Qt::Orientation orientation)
     if (m_scrollOrientation != orientation) {
         const Qt::Orientation previous = m_scrollOrientation;
         m_scrollOrientation = orientation;
-        m_dirtyCache = true;
+        if (orientation == Qt::Vertical) {
+            m_dirtyCache = true;
+        } else {
+            deleteCache();
+        }
         scrollOrientationChanged(orientation, previous);
     }
 }
@@ -108,13 +111,19 @@ Qt::Orientation KItemListGroupHeader::scrollOrientation() const
 
 void KItemListGroupHeader::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
 {
+    Q_UNUSED(option);
+    Q_UNUSED(widget);
+
+    if (m_scrollOrientation == Qt::Horizontal) {
+        Q_ASSERT(!m_leftBorderCache);
+        Q_ASSERT(!m_rightBorderCache);
+        return;
+    }
+
     if (m_dirtyCache) {
         updateCache();
     }
 
-    Q_UNUSED(option);
-    Q_UNUSED(widget);
-
     const int leftBorderX = m_leftBorderCache->width() + 1;
     const int rightBorderX = size().width() - m_rightBorderCache->width() - 2;
 
@@ -161,8 +170,7 @@ void KItemListGroupHeader::updateCache()
 {
     Q_ASSERT(m_dirtyCache);
 
-    delete m_leftBorderCache;
-    delete m_rightBorderCache;
+    deleteCache();
 
     const int length = qMax(int(size().height() - 1), 1);
     m_leftBorderCache = new QPixmap(length, length);
@@ -210,33 +218,34 @@ void KItemListGroupHeader::updateCache()
         QPainter painter(m_rightBorderCache);
         painter.setPen(m_outlineColor);
 
+        // 1. Draw top horizontal line
+        painter.drawLine(0, 0, length - 3, 0);
+
+        // 2. Draw vertical line with gradient
         const int right = length - 1;
-        if (m_scrollOrientation == Qt::Vertical) {
-            // 1. Draw top horizontal line
-            painter.drawLine(0, 0, length - 3, 0);
-
-            // 2. Draw vertical line with gradient
-            const QPoint start(right, 3);
-            QLinearGradient gradient(start, QPoint(right, length));
-            gradient.setColorAt(0, m_outlineColor);
-            gradient.setColorAt(1, Qt::transparent);
-            painter.fillRect(QRect(start, QSize(1, length - start.y())), gradient);
-
-            // 3. Draw arc
-            painter.setRenderHint(QPainter::Antialiasing);
-            QRectF arc(QPointF(length - 5, 0), QSizeF(4, 4));
-            arc.translate(0.5, 0.5);
-            painter.drawArc(arc, 0, 1440);
-        } else {
-            // Draw a horizontal gradiented line
-            QLinearGradient gradient(QPoint(0, 0), QPoint(length, 0));
-            gradient.setColorAt(0, m_outlineColor);
-            gradient.setColorAt(1, Qt::transparent);
-            painter.fillRect(QRect(QPoint(0, 0), QSize(length, 1)), gradient);
-        }
+        const QPoint start(right, 3);
+        QLinearGradient gradient(start, QPoint(right, length));
+        gradient.setColorAt(0, m_outlineColor);
+        gradient.setColorAt(1, Qt::transparent);
+        painter.fillRect(QRect(start, QSize(1, length - start.y())), gradient);
+
+        // 3. Draw arc
+        painter.setRenderHint(QPainter::Antialiasing);
+        QRectF arc(QPointF(length - 5, 0), QSizeF(4, 4));
+        arc.translate(0.5, 0.5);
+        painter.drawArc(arc, 0, 1440);
     }
 
     m_dirtyCache = false;
 }
 
+void KItemListGroupHeader::deleteCache()
+{
+    delete m_leftBorderCache;
+    m_leftBorderCache = 0;
+
+    delete m_rightBorderCache;
+    m_rightBorderCache = 0;
+}
+
 #include "kitemlistgroupheader.moc"
index 20a58cc5b573f16693378a2998c85e8cf4e9b854..8f556afc50a78dadb7984b81d0aa5ff0770a12f7 100644 (file)
@@ -87,6 +87,7 @@ protected:
 
 private:
     void updateCache();
+    void deleteCache();
 
 private:
     bool m_dirtyCache;
index 6b199c1bbb7b1007b4010b64ce075a17f5a90e60..84b8440847f2c35b41f184d06843b0a268f72bda 100644 (file)
@@ -117,6 +117,15 @@ void KItemListView::setScrollOrientation(Qt::Orientation orientation)
     m_layouter->setScrollOrientation(orientation);
     m_animation->setScrollOrientation(orientation);
     m_sizeHintResolver->clearCache();
+
+    if (m_grouped) {
+        QMutableHashIterator<KItemListWidget*, KItemListGroupHeader*> it (m_visibleGroups);
+        while (it.hasNext()) {
+            it.next();
+            it.value()->setScrollOrientation(orientation);
+        }
+    }
+
     updateLayout();
 
     onScrollOrientationChanged(orientation, previousOrientation);
@@ -857,8 +866,7 @@ void KItemListView::slotGroupedSortingChanged(bool current)
         QHashIterator<int, KItemListWidget*> it(m_visibleItems);
         while (it.hasNext()) {
             it.next();
-            KItemListWidget* widget = it.value();
-            updateGroupHeaderForWidget(widget);
+            updateGroupHeaderForWidget(it.value());
         }
     } else {
         // Clear all visible headers