From 757b314631919d67b3319dc9924bdb2b4e47174f Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Tue, 10 Aug 2010 16:23:28 +0200
Subject: [PATCH] QmlJSOutline: Show the type icons again in the outline

They got kicked out when I added a custom style delegate.
---
 .../qmljseditor/qmljsoutlinetreeview.cpp      | 30 ++++++++++---------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/src/plugins/qmljseditor/qmljsoutlinetreeview.cpp b/src/plugins/qmljseditor/qmljsoutlinetreeview.cpp
index 23aaa208b9d..05db59af11b 100644
--- a/src/plugins/qmljseditor/qmljsoutlinetreeview.cpp
+++ b/src/plugins/qmljseditor/qmljsoutlinetreeview.cpp
@@ -20,7 +20,7 @@ QSize QmlJSOutlineItemDelegate::sizeHint(const QStyleOptionViewItem &option, con
 
     const QString annotation = index.data(QmlOutlineModel::AnnotationRole).toString();
     if (!annotation.isEmpty())
-        opt.text += "   " + annotation;
+        opt.text += "     " + annotation;
 
     QStyle *style = QApplication::style();
     return style->sizeFromContents(QStyle::CT_ItemViewItem, &opt, QSize(), 0);
@@ -40,22 +40,24 @@ void QmlJSOutlineItemDelegate::paint(QPainter *painter, const QStyleOptionViewIt
 
     QStyle *style = QApplication::style();
 
-    // paint type name
-    QRect typeRect = style->itemTextRect(opt.fontMetrics, opt.rect, Qt::AlignLeft, true, typeString);
+    style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, 0);
 
-    QPalette::ColorRole textColorRole = QPalette::Text;
-    if (option.state & QStyle::State_Selected) {
-        textColorRole = QPalette::HighlightedText;
-    }
-
-    style->drawItemText(painter, typeRect, Qt::AlignLeft, opt.palette, true, typeString, textColorRole);
-
-    // paint annotation (e.g. id)
     if (!annotationString.isEmpty()) {
-        QRect annotationRect = style->itemTextRect(opt.fontMetrics, opt.rect, Qt::AlignLeft, true,
+        QPalette::ColorRole textColorRole = QPalette::Text;
+        if (option.state & QStyle::State_Selected) {
+            textColorRole = QPalette::HighlightedText;
+        }
+
+        // calculate sizes of icon, type.
+        QPixmap iconPixmap = opt.icon.pixmap(opt.rect.size());
+        QRect iconRect = style->itemPixmapRect(opt.rect, Qt::AlignLeft, iconPixmap);
+        QRect typeRect = style->itemTextRect(opt.fontMetrics, opt.rect, Qt::AlignLeft, true, typeString);
+        QRect annotationRect = style->itemTextRect(opt.fontMetrics, opt.rect, Qt::AlignLeft | Qt::AlignBottom, true,
                                                    annotationString);
-        static int space = opt.fontMetrics.width("   ");
-        annotationRect.adjust(typeRect.width() + space, 0, typeRect.width() + space, 0);
+
+        static int space = opt.fontMetrics.width("     ");
+        annotationRect.adjust(iconRect.width() + typeRect.width() + space, 0,
+                              iconRect.width() + typeRect.width() + space, 0);
 
         QPalette disabledPalette(opt.palette);
         disabledPalette.setCurrentColorGroup(QPalette::Disabled);
-- 
GitLab