forked from qt-creator/qt-creator
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:
@@ -109,7 +109,7 @@ int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyle
|
|||||||
painter->setPen(isSelected ?
|
painter->setPen(isSelected ?
|
||||||
option.palette.color(cg, QPalette::HighlightedText) : Qt::darkGray);
|
option.palette.color(cg, QPalette::HighlightedText) : Qt::darkGray);
|
||||||
painter->drawText(lineNumberAreaRect.adjusted(0, 0, -lineNumberAreaHorizontalPadding, 0),
|
painter->drawText(lineNumberAreaRect.adjusted(0, 0, -lineNumberAreaHorizontalPadding, 0),
|
||||||
Qt::AlignRight, QString::number(lineNumber));
|
Qt::AlignRight | Qt::AlignVCenter, QString::number(lineNumber));
|
||||||
|
|
||||||
return lineNumberAreaWidth;
|
return lineNumberAreaWidth;
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
#include <QtGui/QFont>
|
#include <QtGui/QFont>
|
||||||
|
#include <QtGui/QFontMetrics>
|
||||||
#include <QtGui/QColor>
|
#include <QtGui/QColor>
|
||||||
#include <QtGui/QPalette>
|
#include <QtGui/QPalette>
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
@@ -45,7 +46,7 @@ SearchResultTreeModel::SearchResultTreeModel(QObject *parent)
|
|||||||
, m_lastAppendedResultFile(0)
|
, m_lastAppendedResultFile(0)
|
||||||
, m_showReplaceUI(false)
|
, m_showReplaceUI(false)
|
||||||
{
|
{
|
||||||
m_rootItem = new SearchResultTreeItem();
|
m_rootItem = new SearchResultTreeItem;
|
||||||
m_textEditorFont = QFont("Courier");
|
m_textEditorFont = QFont("Courier");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +62,9 @@ void SearchResultTreeModel::setShowReplaceUI(bool show)
|
|||||||
|
|
||||||
void SearchResultTreeModel::setTextEditorFont(const QFont &font)
|
void SearchResultTreeModel::setTextEditorFont(const QFont &font)
|
||||||
{
|
{
|
||||||
|
layoutAboutToBeChanged();
|
||||||
m_textEditorFont = font;
|
m_textEditorFont = font;
|
||||||
|
layoutChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags SearchResultTreeModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags SearchResultTreeModel::flags(const QModelIndex &index) const
|
||||||
@@ -143,7 +146,13 @@ QVariant SearchResultTreeModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
QVariant result;
|
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);
|
const SearchResultTextRow *row = static_cast<const SearchResultTextRow *>(item);
|
||||||
result = data(row, role);
|
result = data(row, role);
|
||||||
|
Reference in New Issue
Block a user