]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kcategorydrawer.cpp
Optimize PNG files again.
[dolphin.git] / src / kcategorydrawer.cpp
index 56c538d4e7ced426c098697ac2c5e1d36e132c22..53cf059f1f12e522e2899c678e25b99cd03d162f 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
@@ -23,6 +23,7 @@
 #include <QPainter>
 #include <QStyleOption>
 
+#include <kiconloader.h>
 #include <kcategorizedsortfilterproxymodel.h>
 
 KCategoryDrawer::KCategoryDrawer()
@@ -38,7 +39,7 @@ 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;
 
@@ -61,6 +62,17 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
     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);
@@ -113,7 +125,7 @@ void KCategoryDrawer::drawCategory(const QModelIndex &index,
 
     painter->setPen(color);
 
-    painter->drawText(option.rect, Qt::AlignVCenter | Qt::AlignLeft,
+    painter->drawText(opt.rect, Qt::AlignVCenter | Qt::AlignLeft,
     metrics.elidedText(category, Qt::ElideRight, option.rect.width()));
 
     painter->restore();