]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Better looking categories. Thanks to Aurélien Gâteau for the original patch.
authorRafael Fernández López <ereslibre@kde.org>
Wed, 2 Jan 2008 01:21:39 +0000 (01:21 +0000)
committerRafael Fernández López <ereslibre@kde.org>
Wed, 2 Jan 2008 01:21:39 +0000 (01:21 +0000)
CCMAIL: kde-core-devel@kde.org

svn path=/trunk/KDE/kdebase/apps/; revision=755674

src/dolphincategorydrawer.cpp
src/dolphincategorydrawer.h
src/kcategorizedview.cpp
src/kcategorydrawer.cpp
src/kcategorydrawer.h

index 7f82a215f5589aa825a10cbeff1876bfe35b2a06..8148a7b8ed02f0ab8f1d1bd50cf267998786ab76 100644 (file)
@@ -118,9 +118,9 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
 
     QPainterPath path;
     path.addRect(option.rect.left(),
-                 option.rect.bottom() - 2,
+                 option.rect.bottom() - 1,
                  option.rect.width(),
-                 2);
+                 1);
 
     QLinearGradient gradient(option.rect.topLeft(),
                              option.rect.bottomRight());
@@ -134,15 +134,15 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
 
     if (option.direction == Qt::LeftToRight)
     {
-        opt.rect.setLeft(opt.rect.left() + (iconSize / 4));
-        starRect.setLeft(starRect.left() + (iconSize / 4));
-        starRect.setRight(starRect.right() + (iconSize / 4));
+        opt.rect.setLeft(opt.rect.left());
+        starRect.setLeft(starRect.left());
+        starRect.setRight(starRect.right());
     }
     else
     {
-        opt.rect.setRight(opt.rect.width() - (iconSize / 4));
-        starRect.setLeft(starRect.width() - iconSize);
-        starRect.setRight(starRect.width() - (iconSize / 4));
+        opt.rect.setRight(opt.rect.width());
+        starRect.setLeft(starRect.width());
+        starRect.setRight(starRect.width());
     }
 
     bool paintIcon = true;
@@ -241,14 +241,14 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
 
     if (paintText) {
         opt.rect.setTop(option.rect.top() + (iconSize / 4));
-        opt.rect.setBottom(opt.rect.bottom() - 2);
+        opt.rect.setBottom(opt.rect.bottom() - 1);
         painter->setPen(color);
 
         QRect textRect = opt.rect;
 
         if (option.direction == Qt::RightToLeft)
         {
-            textRect.setWidth(textRect.width() - (paintIcon ? icon.width() + (iconSize / 2)
+            textRect.setWidth(textRect.width() - (paintIcon ? icon.width() + (iconSize / 4)
                                                             : -(iconSize / 4)));
         }
 
@@ -259,9 +259,23 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
     painter->restore();
 }
 
-int DolphinCategoryDrawer::categoryHeight(const QStyleOption &option) const
+int DolphinCategoryDrawer::categoryHeight(const QModelIndex &index, const QStyleOption &option) const
 {
     int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small);
+    int heightWithoutIcon = option.fontMetrics.height() + (iconSize / 4) * 2 + 1; /* 1 pixel-width gradient */
+    bool paintIcon;
 
-    return qMax(option.fontMetrics.height() + (iconSize / 4) * 2 + 2, iconSize + (iconSize / 4) * 2 + 2) /* 2 gradient */;
+    switch (index.column()) {
+        case KDirModel::Owner:
+        case KDirModel::Type:
+            paintIcon = true;
+            break;
+        default:
+            paintIcon = false;
+    }
+
+    if (paintIcon)
+        return qMax(heightWithoutIcon, iconSize + (iconSize / 4) * 2 + 1) /* 1 pixel-width gradient */;
+
+    return heightWithoutIcon;
 }
index a8e196b0de4637673189e76de66b5be6fba58896..ea70a922bb382f848aa67d094cd37c8b4aba52c1 100644 (file)
@@ -39,7 +39,7 @@ public:
     virtual void drawCategory(const QModelIndex &index, int sortRole,
                               const QStyleOption &option, QPainter *painter) const;
 
-    virtual int categoryHeight(const QStyleOption &option) const;
+    virtual int categoryHeight(const QModelIndex &index, const QStyleOption &option) const;
 };
 
 #endif // DOLPHINCATEGORYDRAWER_H
index b2504a14bdb2411ee2422ff26fda00992d14dfde..51b4a000bd5e57ff3fc5a406f06dce49c9ca4f5e 100644 (file)
@@ -129,12 +129,12 @@ QRect KCategorizedView::Private::visualRectInViewport(const QModelIndex &index)
     if (listView->layoutDirection() == Qt::LeftToRight)
     {
         retRect = QRect(listView->spacing(), listView->spacing() * 2 +
-                        categoryDrawer->categoryHeight(listView->viewOptions()), 0, 0);
+                        categoryDrawer->categoryHeight(index, listView->viewOptions()), 0, 0);
     }
     else
     {
         retRect = QRect(listView->viewport()->width() - listView->spacing(), listView->spacing() * 2 +
-                        categoryDrawer->categoryHeight(listView->viewOptions()), 0, 0);
+                        categoryDrawer->categoryHeight(index, listView->viewOptions()), 0, 0);
     }
 
     int viewportWidth = listView->viewport()->width() - listView->spacing();
@@ -189,7 +189,7 @@ QRect KCategorizedView::Private::visualRectInViewport(const QModelIndex &index)
 
         retRect.setTop(retRect.top() +
                        (rowsInt * itemHeight) +
-                       categoryDrawer->categoryHeight(listView->viewOptions()) +
+                       categoryDrawer->categoryHeight(index, listView->viewOptions()) +
                        listView->spacing() * 2);
 
         if (listView->gridSize().isEmpty())
@@ -273,7 +273,7 @@ QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &cat
 
         retRect.setTop(retRect.top() +
                        (rowsInt * itemHeight) +
-                       categoryDrawer->categoryHeight(listView->viewOptions()) +
+                       categoryDrawer->categoryHeight(index, listView->viewOptions()) +
                        listView->spacing() * 2);
 
         if (listView->gridSize().isEmpty())
@@ -283,7 +283,7 @@ QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &cat
         }
     }
 
-    retRect.setHeight(categoryDrawer->categoryHeight(listView->viewOptions()));
+    retRect.setHeight(categoryDrawer->categoryHeight(index, listView->viewOptions()));
 
     return retRect;
 }
index 53cf059f1f12e522e2899c678e25b99cd03d162f..6d82bf96bbf9a3ec33ca1517566f41f1ff2a30d7 100644 (file)
@@ -35,7 +35,7 @@ KCategoryDrawer::~KCategoryDrawer()
 }
 
 void KCategoryDrawer::drawCategory(const QModelIndex &index,
-                                   int sortRole,
+                                   int /*sortRole*/,
                                    const QStyleOption &option,
                                    QPainter *painter) const
 {
@@ -55,24 +55,6 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
     painter->save();
     painter->setRenderHint(QPainter::Antialiasing);
 
-    QStyleOptionButton opt;
-
-    opt.rect = option.rect;
-    opt.palette = option.palette;
-    opt.direction = option.direction;
-    opt.text = category;
-
-    int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small);
-
-    if (option.direction == Qt::LeftToRight)
-    {
-        opt.rect.setLeft(opt.rect.left() + (iconSize / 4));
-    }
-    else
-    {
-        opt.rect.setRight(opt.rect.width() - (iconSize / 4));
-    }
-
     if (option.state & QStyle::State_Selected)
     {
         QColor selected = option.palette.color(QPalette::Highlight);
@@ -103,15 +85,13 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
 
     QFont painterFont = painter->font();
     painterFont.setWeight(QFont::Bold);
-    painterFont.setPointSize(painterFont.pointSize() + 2);
     QFontMetrics metrics(painterFont);
     painter->setFont(painterFont);
 
-    QPainterPath path;
-    path.addRect(option.rect.left(),
-                 option.rect.bottom() - 2,
-                 option.rect.width(),
-                 2);
+    QRect lineRect(option.rect.left(),
+                   option.rect.bottom() - 1,
+                   option.rect.width(),
+                   1);
 
     QLinearGradient gradient(option.rect.topLeft(),
                              option.rect.bottomRight());
@@ -120,18 +100,19 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
     gradient.setColorAt(option.direction == Qt::LeftToRight ? 1
                                                             : 0, Qt::transparent);
 
-    painter->setBrush(gradient);
-    painter->fillPath(path, gradient);
+    painter->fillRect(lineRect, gradient);
 
     painter->setPen(color);
 
-    painter->drawText(opt.rect, Qt::AlignVCenter | Qt::AlignLeft,
+    painter->drawText(option.rect, Qt::AlignVCenter | Qt::AlignLeft,
     metrics.elidedText(category, Qt::ElideRight, option.rect.width()));
 
     painter->restore();
 }
 
-int KCategoryDrawer::categoryHeight(const QStyleOption &option) const
+int KCategoryDrawer::categoryHeight(const QModelIndex &index, const QStyleOption &option) const
 {
-    return option.fontMetrics.height() + 6 /* 4 separator; 2 gradient */;
+    Q_UNUSED(index);
+
+    return option.fontMetrics.height() + 4 /* 3 separator; 1 gradient */;
 }
index 743dafa9057daaafa5b5dfd4e425f174bd12c1f0..6af0d73cd25c2b4b2eee62d5b1bd70888d94214e 100644 (file)
@@ -46,7 +46,7 @@ public:
                               const QStyleOption &option,
                               QPainter *painter) const;
 
-    virtual int categoryHeight(const QStyleOption &option) const;
+    virtual int categoryHeight(const QModelIndex &index, const QStyleOption &option) const;
 };
 
 #endif // KCATEGORYDRAWER_H