]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kcategorydrawer.cpp
Follow David's advice and use 'delete' instead of 'deleteLater()'. Disconnecting...
[dolphin.git] / src / kcategorydrawer.cpp
index 4c59864a09c3c4c6de615c2f6ffd79fe48430427..d0c671915459f12a38e166c92d35f4b565943383 100644 (file)
@@ -1,6 +1,6 @@
 /**
   * This file is part of the KDE project
-  * Copyright (C) 2007 Rafael Fernández López <ereslibre@gmail.com>
+  * Copyright (C) 2007 Rafael Fernández López <ereslibre@kde.org>
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Library General Public
@@ -38,9 +38,18 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
                                    const QStyleOption &option,
                                    QPainter *painter) const
 {
-    const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryRole).toString();
+    const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).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);
@@ -52,18 +61,30 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
     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)
     {
-        const QPalette::ColorGroup group =
-                                          option.state & QStyle::State_Enabled ?
-                                          QPalette::Normal : QPalette::Disabled;
+        QColor hover = option.palette.color(QPalette::Highlight).light();
+        hover.setAlpha(88);
 
         QLinearGradient gradient(option.rect.topLeft(),
                                  option.rect.bottomRight());
-        gradient.setColorAt(0,
-                            option.palette.color(group,
-                                                 QPalette::Highlight).light());
-        gradient.setColorAt(1, Qt::transparent);
+        gradient.setColorAt(option.direction == Qt::LeftToRight ? 0
+                                                                : 1, hover);
+        gradient.setColorAt(option.direction == Qt::LeftToRight ? 1
+                                                                : 0, Qt::transparent);
 
         painter->fillRect(option.rect, gradient);
     }