From 3cd7f49e71f263a5cc80cac90d5b15a2bbde0b56 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com>
Date: Tue, 10 Nov 2009 18:12:36 +0100
Subject: [PATCH] Fixed search results handling of font height

This patch makes sure that the rows that show the file and the rows that
show the results are the same height, to satisfy the uniform row heights
setting.

Also, a layout changed signal is now emitted when the font is changed.
This makes active search results update correctly when the text editor
font is changed.

Reviewed-by: con
---
 src/plugins/find/searchresulttreeitemdelegate.cpp |  2 +-
 src/plugins/find/searchresulttreemodel.cpp        | 13 +++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/plugins/find/searchresulttreeitemdelegate.cpp b/src/plugins/find/searchresulttreeitemdelegate.cpp
index 5502069a177..88ac8d05535 100644
--- a/src/plugins/find/searchresulttreeitemdelegate.cpp
+++ b/src/plugins/find/searchresulttreeitemdelegate.cpp
@@ -109,7 +109,7 @@ int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyle
     painter->setPen(isSelected ?
         option.palette.color(cg, QPalette::HighlightedText) : Qt::darkGray);
     painter->drawText(lineNumberAreaRect.adjusted(0, 0, -lineNumberAreaHorizontalPadding, 0),
-        Qt::AlignRight, QString::number(lineNumber));
+        Qt::AlignRight | Qt::AlignVCenter, QString::number(lineNumber));
 
     return lineNumberAreaWidth;
 }
diff --git a/src/plugins/find/searchresulttreemodel.cpp b/src/plugins/find/searchresulttreemodel.cpp
index 267022bb437..3afb91d31da 100644
--- a/src/plugins/find/searchresulttreemodel.cpp
+++ b/src/plugins/find/searchresulttreemodel.cpp
@@ -33,6 +33,7 @@
 
 #include <QtGui/QApplication>
 #include <QtGui/QFont>
+#include <QtGui/QFontMetrics>
 #include <QtGui/QColor>
 #include <QtGui/QPalette>
 #include <QtCore/QDir>
@@ -45,7 +46,7 @@ SearchResultTreeModel::SearchResultTreeModel(QObject *parent)
     , m_lastAppendedResultFile(0)
     , m_showReplaceUI(false)
 {
-    m_rootItem = new SearchResultTreeItem();
+    m_rootItem = new SearchResultTreeItem;
     m_textEditorFont = QFont("Courier");
 }
 
@@ -61,7 +62,9 @@ void SearchResultTreeModel::setShowReplaceUI(bool show)
 
 void SearchResultTreeModel::setTextEditorFont(const QFont &font)
 {
+    layoutAboutToBeChanged();
     m_textEditorFont = font;
+    layoutChanged();
 }
 
 Qt::ItemFlags SearchResultTreeModel::flags(const QModelIndex &index) const
@@ -143,7 +146,13 @@ QVariant SearchResultTreeModel::data(const QModelIndex &index, int role) const
 
     QVariant result;
 
-    if (item->itemType() == SearchResultTreeItem::ResultRow)
+    if (role == Qt::SizeHintRole)
+    {
+        const int appFontHeight = QApplication::fontMetrics().height();
+        const int editorFontHeight = QFontMetrics(m_textEditorFont).height();
+        result = QSize(0, qMax(appFontHeight, editorFontHeight));
+    }
+    else if (item->itemType() == SearchResultTreeItem::ResultRow)
     {
         const SearchResultTextRow *row = static_cast<const SearchResultTextRow *>(item);
         result = data(row, role);
-- 
GitLab