]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincategorydrawer.cpp
Enable Dolphin to show the revision states of files that are under revision control...
[dolphin.git] / src / dolphincategorydrawer.cpp
index 9996672d718d4367a74776aac8dede0cb6f6fc1a..00af90d63e155f75cbdcf4b2a6b7c1f4dd95e0af 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
   * This file is part of the KDE project
   * Copyright (C) 2007 Rafael Fernández López <ereslibre@kde.org>
   *
   */
 
 #include "dolphincategorydrawer.h"
-#include "ratingpainter.h"
+
+#include <config-nepomuk.h>
+
 #include <QPainter>
 #include <QFile>
 #include <QDir>
+#include <QApplication>
+#include <QStyleOption>
+
+#ifdef HAVE_NEPOMUK
+#include <nepomuk/kratingpainter.h>
+#endif
 
 #include <kiconloader.h>
 #include <kcategorizedsortfilterproxymodel.h>
 #include <qimageblitz.h>
 #include <kuser.h>
 
-#include <config-nepomuk.h>
-#ifdef HAVE_NEPOMUK
-#include <nepomuk/global.h>
-#include <nepomuk/resource.h>
-#include <nepomuk/tag.h>
-#endif
-
 #include "dolphinview.h"
 #include "dolphinmodel.h"
 
+#define HORIZONTAL_HINT 3
+
 DolphinCategoryDrawer::DolphinCategoryDrawer()
 {
 }
@@ -50,6 +53,8 @@ DolphinCategoryDrawer::~DolphinCategoryDrawer()
 void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
                                          const QStyleOption &option, QPainter *painter) const
 {
+    Q_UNUSED(sortRole);
+
     QRect starRect = option.rect;
 
     int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small);
@@ -79,37 +84,19 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
     QStyleOptionButton opt;
 
     opt.rect = option.rect;
+    opt.rect.setLeft(opt.rect.left() + HORIZONTAL_HINT);
+    opt.rect.setRight(opt.rect.right() - HORIZONTAL_HINT);
     opt.palette = option.palette;
     opt.direction = option.direction;
     opt.text = category;
 
-    if (option.state & QStyle::State_Selected)
-    {
-        QColor selected = option.palette.color(QPalette::Highlight);
-
-        QLinearGradient gradient(option.rect.topLeft(),
-                                 option.rect.bottomRight());
-        gradient.setColorAt(option.direction == Qt::LeftToRight ? 0
-                                                                : 1, selected);
-        gradient.setColorAt(option.direction == Qt::LeftToRight ? 1
-                                                                : 0, Qt::transparent);
-
-        painter->fillRect(option.rect, gradient);
-    }
-    else if (option.state & QStyle::State_MouseOver)
-    {
-        QColor hover = option.palette.color(QPalette::Highlight);
-        hover.setAlpha(88);
-
-        QLinearGradient gradient(option.rect.topLeft(),
-                                 option.rect.bottomRight());
-        gradient.setColorAt(option.direction == Qt::LeftToRight ? 0
-                                                                : 1, hover);
-        gradient.setColorAt(option.direction == Qt::LeftToRight ? 1
-                                                                : 0, Qt::transparent);
-
-        painter->fillRect(option.rect, gradient);
-    }
+    QStyleOptionViewItemV4 viewOptions;
+    viewOptions.rect = option.rect;
+    viewOptions.palette = option.palette;
+    viewOptions.direction = option.direction;
+    viewOptions.state = option.state;
+    viewOptions.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
+    QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewOptions, painter, 0);
 
     QFont painterFont = painter->font();
     painterFont.setWeight(QFont::Bold);
@@ -118,9 +105,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 +121,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;
@@ -177,7 +164,7 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
             }
             else
             {
-                icon = KIconLoader::global()->loadIcon("user", KIconLoader::NoGroup, option.fontMetrics.height());
+                icon = KIconLoader::global()->loadIcon("user-identity", KIconLoader::NoGroup, option.fontMetrics.height());
             }
 
             opt.rect.setTop(opt.rect.top() - icon.height());
@@ -206,49 +193,30 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
             break;
         }
 
-#ifdef HAVE_NEPOMUK
-        case DolphinModel::Rating: {
-            paintText = false;
-            paintIcon = false;
-
-            painter->setLayoutDirection( option.direction );
-            QRect ratingRect( option.rect );
-            ratingRect.setTop(option.rect.top() + (option.rect.height() / 2) - (iconSize / 2));
-            ratingRect.setHeight( iconSize );
-            Nepomuk::RatingPainter::drawRating( painter, ratingRect, Qt::AlignLeft, category.toInt() );
-            break;
-        }
-
-        case DolphinModel::Tags:
+        case DolphinModel::Revision:
             paintIcon = false;
             break;
-#endif
     }
 
     if (paintIcon) {
         painter->drawPixmap(QRect(option.direction == Qt::LeftToRight ? opt.rect.left()
                                                                       : opt.rect.right() - icon.width() + (iconSize / 4), opt.rect.top(), icon.width(), icon.height()), icon);
 
-        if (option.direction == Qt::LeftToRight)
-        {
+        if (option.direction == Qt::LeftToRight) {
             opt.rect.setLeft(opt.rect.left() + icon.width() + (iconSize / 4));
-        }
-        else
-        {
+        } else {
             opt.rect.setRight(opt.rect.right() + (iconSize / 4));
         }
     }
 
     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)
+        if (option.direction == Qt::RightToLeft) {
+            textRect.setWidth(textRect.width() - (paintIcon ? icon.width() + (iconSize / 4)
                                                             : -(iconSize / 4)));
         }
 
@@ -259,9 +227,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;
+
+    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 qMax(option.fontMetrics.height() + (iconSize / 4) * 2 + 2, iconSize + (iconSize / 4) * 2 + 2) /* 2 gradient */;
+    return heightWithoutIcon;
 }