From 3bc20dbb60775e1e6a37b358f531ce83ec9cd2fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com>
Date: Thu, 27 May 2010 13:49:36 +0200
Subject: [PATCH] Fixed vertical alignment of line numbers in search results on
 Mac

Due to different text positioning logic between the QItemDelegate and
the way SearchResultTreeItemDelegate drew the line numbers, the line
numbers did not align properly to the line of text next to it.

This was fixed by relying on QItemDelegate::drawDisplay for drawing the
line numbers, so that the same positioning logic is used.

This exposed a small right-alignment bug in QTextLayout, for which a fix
is coming to Qt.

Done-with: Erik Verbruggen
---
 src/plugins/find/searchresulttreeitemdelegate.cpp | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/plugins/find/searchresulttreeitemdelegate.cpp b/src/plugins/find/searchresulttreeitemdelegate.cpp
index e294c5cd26e..bec2da78391 100644
--- a/src/plugins/find/searchresulttreeitemdelegate.cpp
+++ b/src/plugins/find/searchresulttreeitemdelegate.cpp
@@ -106,10 +106,16 @@ int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyle
     painter->fillRect(lineNumberAreaRect, QBrush(isSelected ?
         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),
-        Qt::AlignRight | Qt::AlignVCenter, QString::number(lineNumber));
+
+    QStyleOptionViewItemV3 opt = option;
+    opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
+    opt.palette.setColor(cg, QPalette::Text, Qt::darkGray);
+
+    const QStyle *style = QApplication::style();
+    const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1;
+
+    const QRect rowRect = lineNumberAreaRect.adjusted(-textMargin, 0, textMargin-lineNumberAreaHorizontalPadding, 0);
+    QItemDelegate::drawDisplay(painter, opt, rowRect, QString::number(lineNumber));
 
     return lineNumberAreaWidth;
 }
-- 
GitLab