From 83974d89142dfb6235ebb76612fea80c12f6d4db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com>
Date: Tue, 1 Sep 2009 14:31:17 +0200
Subject: [PATCH] Adapt a few hardcoded background colors in search results

Make the background of the files and line numbers adapt to the
background color. Making it darker only works nicely for non-dark
backgrounds, but it's better than hardcoding a light background.

The highlight of the search results still has to be fixed.
---
 src/plugins/find/searchresulttreeitemdelegate.cpp |  3 ++-
 src/plugins/find/searchresulttreemodel.cpp        | 13 +++++++++----
 src/plugins/find/searchresulttreeview.cpp         |  4 ++--
 src/plugins/find/searchresultwindow.cpp           |  1 -
 4 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/plugins/find/searchresulttreeitemdelegate.cpp b/src/plugins/find/searchresulttreeitemdelegate.cpp
index 10a04538ece..35eab26cadc 100644
--- a/src/plugins/find/searchresulttreeitemdelegate.cpp
+++ b/src/plugins/find/searchresulttreeitemdelegate.cpp
@@ -91,7 +91,8 @@ int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyle
         cg = QPalette::Disabled;
 
     painter->fillRect(lineNumberAreaRect, QBrush(isSelected ?
-        option.palette.brush(cg, QPalette::Highlight) : QBrush(qRgb(230, 230, 230))));
+        option.palette.brush(cg, QPalette::Highlight) :
+        option.palette.color(cg, QPalette::Base).darker(111)));
     painter->setPen(isSelected ?
         option.palette.color(cg, QPalette::HighlightedText) : Qt::darkGray);
     painter->drawText(lineNumberAreaRect.adjusted(0, 0, -lineNumberAreaHorizontalPadding, 0),
diff --git a/src/plugins/find/searchresulttreemodel.cpp b/src/plugins/find/searchresulttreemodel.cpp
index a4fd5e21e3f..5c3d5eb36ab 100644
--- a/src/plugins/find/searchresulttreemodel.cpp
+++ b/src/plugins/find/searchresulttreemodel.cpp
@@ -31,8 +31,10 @@
 #include "searchresulttreeitems.h"
 #include "searchresulttreeitemroles.h"
 
+#include <QtGui/QApplication>
 #include <QtGui/QFont>
 #include <QtGui/QColor>
+#include <QtGui/QPalette>
 #include <QtCore/QDir>
 
 using namespace Find::Internal;
@@ -186,9 +188,11 @@ QVariant SearchResultTreeModel::data(const SearchResultFile *file, int role) con
 
     switch (role)
     {
-    case Qt::BackgroundRole:
-        result = QColor(qRgb(245, 245, 245));
+    case Qt::BackgroundRole: {
+        const QColor baseColor = QApplication::palette().base().color();
+        result = baseColor.darker(105);
         break;
+    }
     case Qt::DisplayRole:
         result = QString(QDir::toNativeSeparators(file->fileName())
             + " (" + QString::number(file->childrenCount()) + ")");
@@ -212,7 +216,7 @@ QVariant SearchResultTreeModel::data(const SearchResultFile *file, int role) con
 }
 
 QVariant SearchResultTreeModel::headerData(int section, Qt::Orientation orientation,
-                               int role) const
+                                           int role) const
 {
     Q_UNUSED(section)
     Q_UNUSED(orientation)
@@ -224,7 +228,8 @@ void SearchResultTreeModel::appendResultFile(const QString &fileName)
 {
     m_lastAppendedResultFile = new SearchResultFile(fileName, m_rootItem);
 
-    beginInsertRows(QModelIndex(), m_rootItem->childrenCount(), m_rootItem->childrenCount());
+    const int childrenCount = m_rootItem->childrenCount();
+    beginInsertRows(QModelIndex(), childrenCount, childrenCount);
     m_rootItem->appendChild(m_lastAppendedResultFile);
     endInsertRows();
 }
diff --git a/src/plugins/find/searchresulttreeview.cpp b/src/plugins/find/searchresulttreeview.cpp
index 49181495a07..c5317c0fdb7 100644
--- a/src/plugins/find/searchresulttreeview.cpp
+++ b/src/plugins/find/searchresulttreeview.cpp
@@ -38,13 +38,13 @@ using namespace Find::Internal;
 
 SearchResultTreeView::SearchResultTreeView(QWidget *parent)
     : QTreeView(parent)
+    , m_model(new SearchResultTreeModel(this))
     , m_autoExpandResults(false)
 {
-    m_model = new SearchResultTreeModel(this);
     setModel(m_model);
     setItemDelegate(new SearchResultTreeItemDelegate(this));
-
     setIndentation(14);
+    setUniformRowHeights(true);
     header()->hide();
 
     connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(emitJumpToSearchResult(QModelIndex)));
diff --git a/src/plugins/find/searchresultwindow.cpp b/src/plugins/find/searchresultwindow.cpp
index cdae2e48c7c..6e44c7c8a94 100644
--- a/src/plugins/find/searchresultwindow.cpp
+++ b/src/plugins/find/searchresultwindow.cpp
@@ -51,7 +51,6 @@ SearchResultWindow::SearchResultWindow()
     m_widget->setWindowTitle(name());
 
     m_searchResultTreeView = new SearchResultTreeView(m_widget);
-    m_searchResultTreeView->setUniformRowHeights(true);
     m_searchResultTreeView->setFrameStyle(QFrame::NoFrame);
     m_searchResultTreeView->setAttribute(Qt::WA_MacShowFocusRect, false);
     m_widget->addWidget(m_searchResultTreeView);
-- 
GitLab