]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Compact view: Padding- and margin-improvements for grouped alignments
authorPeter Penz <peter.penz19@gmail.com>
Thu, 16 Feb 2012 14:13:23 +0000 (15:13 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 16 Feb 2012 15:23:00 +0000 (16:23 +0100)
src/kitemviews/kitemlistgroupheader.cpp
src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemlistviewlayouter.cpp

index 4482bab570a0d2df4a5c8d2c4438945e57cbda79..e197acc6a48793d6418af51f824f91519a50a0a5 100644 (file)
@@ -131,15 +131,17 @@ void KItemListGroupHeader::paint(QPainter* painter, const QStyleOptionGraphicsIt
         updateCache();
     }
 
+    if (m_itemIndex == 0) {
+        // No top- or left-line should be drawn for the first group-header
+        return;
+    }
+    
+    painter->setPen(m_lineColor);
+    
     if (m_scrollOrientation == Qt::Horizontal) {
-        painter->setPen(m_lineColor);
-        const qreal x = m_roleBounds.x() - 2 * m_styleOption.padding;
-        painter->drawLine(x, 0, x, size().height() - 1);
-
-    } else if (m_itemIndex > 0) {
-        painter->setPen(m_lineColor);
-        const qreal y = m_roleBounds.y() - m_styleOption.padding;
-        painter->drawLine(0, y, size().width() - 1, y);
+        painter->drawLine(0, 0, 0, size().height() - 1);
+    } else {
+        painter->drawLine(0, 0, size().width() - 1, 0);
     }
 }
 
@@ -202,22 +204,17 @@ void KItemListGroupHeader::updateCache()
     m_lineColor = mixedColor(c1, c2, 10);
     m_roleColor = mixedColor(c1, c2, 70);
 
-    int padding = m_styleOption.padding;
-    int horizontalMargin = 0;
-    if (m_scrollOrientation == Qt::Vertical) {
-        // The x-position of the group-header-widget will always be 0,
-        // Add a minimum margin.
-        horizontalMargin = qMax(2, m_styleOption.horizontalMargin);
-    } else {
-        padding *= 2;
-    }
+    const int padding = qMax(1, m_styleOption.padding);
+    const int horizontalMargin = qMax(2, m_styleOption.horizontalMargin);
 
     const QFontMetrics fontMetrics(m_styleOption.font);
     const qreal roleHeight = fontMetrics.height();
+    
+    const int y = (m_scrollOrientation == Qt::Vertical) ? padding : horizontalMargin;
 
     m_roleBounds = QRectF(horizontalMargin + padding,
-                          size().height() - roleHeight - padding,
-                          size().width() - 2 * (horizontalMargin + padding),
+                          y,
+                          size().width() - 2 * padding - horizontalMargin,
                           roleHeight);
 
     m_dirtyCache = false;
index 4f0d68d2e69643d8cca4d5d406b556b18c8b43c2..b7d4c247097577ea8759832e57138b1f26397d43 100644 (file)
@@ -1720,7 +1720,7 @@ void KItemListView::updateGroupHeaderLayout(KItemListWidget* widget)
         groupHeader->setPos(-widget->x(), -groupHeaderRect.height());
         groupHeader->resize(size().width(), groupHeaderRect.size().height());
     } else {
-        groupHeader->setPos(groupHeaderRect.x() - itemRect.x(), -groupHeaderRect.height());
+        groupHeader->setPos(groupHeaderRect.x() - itemRect.x(), -widget->y());
         groupHeader->resize(groupHeaderRect.size());
     }
 }
@@ -1976,15 +1976,21 @@ bool KItemListView::scrollBarRequired(const QSizeF& size) const
 
 void KItemListView::updateGroupHeaderHeight()
 {
-    const qreal groupHeaderHeight = m_styleOption.fontMetrics.height() + m_styleOption.padding * 2;
-
+    qreal groupHeaderHeight = m_styleOption.fontMetrics.height();
     qreal groupHeaderMargin = 0;
+    
     if (scrollOrientation() == Qt::Horizontal) {
+        // The vertical margin above and below the header should be
+        // equal to the horizontal margin, not the vertical margin
+        // from m_styleOption.
+        groupHeaderHeight += 2 * m_styleOption.horizontalMargin;
         groupHeaderMargin = m_styleOption.horizontalMargin;
     } else if (m_itemSize.isEmpty()){
-        groupHeaderMargin = groupHeaderHeight / 2;
+        groupHeaderHeight += 2 * m_styleOption.padding;
+        groupHeaderMargin = m_styleOption.iconSize / 2;
     } else {
-        groupHeaderMargin = m_styleOption.verticalMargin * 2;
+        groupHeaderHeight += 2 * m_styleOption.padding;
+        groupHeaderMargin = m_styleOption.iconSize / 4;
     }
     m_layouter->setGroupHeaderHeight(groupHeaderHeight);
     m_layouter->setGroupHeaderMargin(groupHeaderMargin);
index a9b59051dcf3f987d628dc264ee99cb3bfcb7c4c..de78b763677bdfb3b5a937d2a6d50780fd419576 100644 (file)
@@ -257,14 +257,36 @@ QRectF KItemListViewLayouter::groupHeaderRect(int index) const
         return QRectF();
     }
 
-    pos.ry() -= m_groupHeaderHeight;
-
     QSizeF size;
     if (m_scrollOrientation == Qt::Vertical) {
         pos.rx() = 0;
+        pos.ry() -= m_groupHeaderHeight;
         size = QSizeF(m_size.width(), m_groupHeaderHeight);
     } else {
-        size = QSizeF(minimumGroupHeaderWidth(), m_groupHeaderHeight);
+        pos.rx() -= m_itemMargin.width();
+        pos.ry() = 0;
+        
+        // Determine the maximum width used in the
+        // current column. As the scroll-direction is
+        // Qt::Horizontal and m_itemRects is accessed directly,
+        // the logical height represents the visual width.
+        qreal width = minimumGroupHeaderWidth();
+        const qreal y = m_itemRects[index].y();
+        const int maxIndex = m_itemRects.count() - 1;
+        while (index <= maxIndex) {
+            QRectF bounds = m_itemRects[index];
+            if (bounds.y() != y) {
+                break;
+            }
+            
+            if (bounds.height() > width) {
+                width = bounds.height();
+            }
+            
+            ++index;           
+        }
+        
+        size = QSizeF(width, m_size.height());
     }
     return QRectF(pos, size);
 }
@@ -324,7 +346,7 @@ void KItemListViewLayouter::doLayout()
                 // In the horizontal scrolling case all groups are aligned
                 // at the top, which decreases the available height. For the
                 // flipped data this means that the width must be decreased.
-                size.rwidth() -= m_groupHeaderMargin + m_groupHeaderHeight;
+                size.rwidth() -= m_groupHeaderHeight;
             }
         }
 
@@ -363,10 +385,10 @@ void KItemListViewLayouter::doLayout()
                 if (horizontalScrolling) {
                     // All group headers will always be aligned on the top and not
                     // flipped like the other properties
-                    x +=  m_groupHeaderMargin + m_groupHeaderHeight;
+                    x += m_groupHeaderHeight;
                 }
 
-                if (m_groupItemIndexes.contains(index) && !horizontalScrolling) {
+                if (m_groupItemIndexes.contains(index)) {
                     // The item is the first item of a group.
                     // Increase the y-position to provide space
                     // for the group header.
@@ -378,7 +400,10 @@ void KItemListViewLayouter::doLayout()
                         // group already before
                         y += m_groupHeaderMargin;
                     }
-                    y += m_groupHeaderHeight;
+                    
+                    if (!horizontalScrolling) {
+                        y += m_groupHeaderHeight;
+                    }
                 }
             }
 
@@ -561,7 +586,7 @@ bool KItemListViewLayouter::createGroupHeaders()
 
 qreal KItemListViewLayouter::minimumGroupHeaderWidth() const
 {
-    return m_groupHeaderHeight * 15 / 2;
+    return 100;
 }
 
 #include "kitemlistviewlayouter_p.moc"