]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincategorydrawer.cpp
Whenever we are trying to sort, bypass lessThanGeneralPurpose when is not allowed...
[dolphin.git] / src / dolphincategorydrawer.cpp
index 2479f2755044fe2ae277e553509dafb5c5eea077..4bb408babffaf54add1d0b7999f91a3cc6a3401f 100644 (file)
@@ -52,7 +52,7 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
 {
     QRect starRect = option.rect;
 
-    int iconSize =  KIconLoader::global()->currentSize(K3Icon::Small);
+    int iconSize = KIconLoader::global()->currentSize(K3Icon::Small);
     QVariant categoryVariant = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryRole);
 
     if (!categoryVariant.isValid())
@@ -62,7 +62,16 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
 
     const QString category = categoryVariant.toString();
 
-    QColor color = option.palette.color(QPalette::Text);
+    QColor color;
+
+    if (option.state & QStyle::State_Selected)
+    {
+        color = option.palette.color(QPalette::HighlightedText);
+    }
+    else
+    {
+        color = option.palette.color(QPalette::Text);
+    }
 
     painter->save();
     painter->setRenderHint(QPainter::Antialiasing);
@@ -74,7 +83,20 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
     opt.direction = option.direction;
     opt.text = category;
 
-    if (option.state & QStyle::State_MouseOver)
+    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).light();
         hover.setAlpha(88);
@@ -145,16 +167,21 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
             break;
 
         case KDirModel::Owner: {
-            opt.rect.setTop(option.rect.top() + (iconSize / 4));
+            opt.rect.setTop(option.rect.bottom() - (iconSize / 4));
             KUser user(category);
-            if (QFile::exists(user.homeDir() + QDir::separator() + ".face.icon"))
+            QString faceIconPath = user.faceIconPath();
+
+            if (!faceIconPath.isEmpty())
             {
-                icon = QPixmap::fromImage(QImage(user.homeDir() + QDir::separator() + ".face.icon")).scaled(iconSize, iconSize);
+                icon = QPixmap::fromImage(QImage(faceIconPath).scaledToHeight(KIconLoader::global()->currentSize(K3Icon::MainToolbar), Qt::SmoothTransformation));
             }
             else
             {
-                icon = KIconLoader::global()->loadIcon("user", K3Icon::Small);
+                icon = KIconLoader::global()->loadIcon("user", K3Icon::MainToolbar, option.fontMetrics.height());
             }
+
+            opt.rect.setTop(opt.rect.top() - icon.height());
+
             break;
         }
 
@@ -163,7 +190,7 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
             break;
 
         case KDirModel::Type: {
-            opt.rect.setTop(option.rect.top() + (option.rect.height() / 2) - (iconSize / 2));
+            opt.rect.setTop(option.rect.bottom() - (iconSize / 4));
             const KCategorizedSortFilterProxyModel *proxyModel = static_cast<const KCategorizedSortFilterProxyModel*>(index.model());
             const DolphinModel *model = static_cast<const DolphinModel*>(proxyModel->sourceModel());
             KFileItem item = model->itemForIndex(proxyModel->mapToSource(index));
@@ -172,7 +199,10 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
             // so the group icon drawn is that one particularly. This way assures the drawn
             // icon is the one of the mimetype of the group itself. (ereslibre)
             icon = KIconLoader::global()->loadMimeTypeIcon(item.mimeTypePtr()->iconName(),
-                                                           K3Icon::Small);
+                                                           K3Icon::MainToolbar);
+
+            opt.rect.setTop(opt.rect.top() - icon.height());
+
             break;
         }
 
@@ -211,14 +241,12 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
                 if (option.direction == Qt::RightToLeft)
                 {
                     starRect.setLeft(starRect.left() + (iconSize / 2) /* separator between stars */);
-                    //starRect.setRight(starRect.right() + (iconSize / 2) /* separator between stars */);
                 }
 
                 starRect.setTop(option.rect.top() + (option.rect.height() / 2) - (iconSize / 4));
                 starRect.setSize(QSize(iconSize / 2, iconSize / 2));
                 painter->drawPixmap(starRect, smallPixmap);
                 starRect.setTop(opt.rect.top() + (option.rect.height() / 2) - (iconSize / 2));
-                //starRect.setSize(QSize(iconSize / 2, iconSize / 2));
 
                 if (option.direction == Qt::LeftToRight)
                 {
@@ -266,11 +294,15 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
 
     if (paintIcon) {
         painter->drawPixmap(QRect(option.direction == Qt::LeftToRight ? opt.rect.left()
-                                                                      : opt.rect.right() - iconSize, opt.rect.top(), iconSize, iconSize), icon);
+                                                                      : opt.rect.right() - icon.width() + (iconSize / 4), opt.rect.top(), icon.width(), icon.height()), icon);
 
         if (option.direction == Qt::LeftToRight)
         {
-            opt.rect.setLeft(opt.rect.left() + iconSize + (iconSize / 4));
+            opt.rect.setLeft(opt.rect.left() + icon.width() + (iconSize / 4));
+        }
+        else
+        {
+            opt.rect.setRight(opt.rect.right() + (iconSize / 4));
         }
     }
 
@@ -283,8 +315,8 @@ void DolphinCategoryDrawer::drawCategory(const QModelIndex &index, int sortRole,
 
         if (option.direction == Qt::RightToLeft)
         {
-            textRect.setWidth(textRect.width() - (paintIcon ? iconSize + (iconSize / 4)
-                                                            : (iconSize / 4)));
+            textRect.setWidth(textRect.width() - (paintIcon ? icon.width() + (iconSize / 2)
+                                                            : -(iconSize / 4)));
         }
 
         painter->drawText(textRect, Qt::AlignVCenter | Qt::AlignLeft,