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
This commit is contained in:
Thorbjørn Lindeijer
2009-11-10 18:12:36 +01:00
parent 6a9e7ab0f4
commit 3cd7f49e71
2 changed files with 12 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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);