From 29a620fa974b6771b2585e4310e0a2e098a1c6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com> Date: Wed, 8 Apr 2009 14:32:31 +0200 Subject: [PATCH] Made font of search results match text editor font Before it would use Courier on all platforms, which didn't always look nice. Now it uses the configured text editor font. The file paths are now also normal size, at least personally I don't see why they should use a larger font. --- .../find/searchresulttreeitemdelegate.cpp | 12 +++--- src/plugins/find/searchresulttreeitemroles.h | 4 +- src/plugins/find/searchresulttreemodel.cpp | 20 +++++----- src/plugins/find/searchresulttreemodel.h | 12 ++++-- src/plugins/find/searchresulttreeview.cpp | 8 +++- src/plugins/find/searchresulttreeview.h | 2 + src/plugins/find/searchresultwindow.cpp | 37 +++++++++++-------- src/plugins/find/searchresultwindow.h | 4 +- src/plugins/texteditor/texteditorplugin.cpp | 16 +++++++- src/plugins/texteditor/texteditorplugin.h | 6 +++ 10 files changed, 80 insertions(+), 41 deletions(-) diff --git a/src/plugins/find/searchresulttreeitemdelegate.cpp b/src/plugins/find/searchresulttreeitemdelegate.cpp index 533b47e5c91..d72ca5c2b0f 100644 --- a/src/plugins/find/searchresulttreeitemdelegate.cpp +++ b/src/plugins/find/searchresulttreeitemdelegate.cpp @@ -72,7 +72,7 @@ void SearchResultTreeItemDelegate::paint(QPainter *painter, const QStyleOptionVi } int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyleOptionViewItemV3 &option, - const QModelIndex &index) const + const QModelIndex &index) const { static const int lineNumberAreaHorizontalPadding = 4; const bool isSelected = option.state & QStyle::State_Selected; @@ -90,10 +90,10 @@ int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyle else if (!(option.state & QStyle::State_Enabled)) cg = QPalette::Disabled; - painter->fillRect(lineNumberAreaRect, QBrush(isSelected? - option.palette.brush(cg, QPalette::Highlight):QBrush(qRgb(230, 230, 230)))); - painter->setPen(isSelected? - option.palette.color(cg, QPalette::HighlightedText):Qt::darkGray); + painter->fillRect(lineNumberAreaRect, QBrush(isSelected ? + option.palette.brush(cg, QPalette::Highlight) : QBrush(qRgb(230, 230, 230)))); + painter->setPen(isSelected ? + option.palette.color(cg, QPalette::HighlightedText) : Qt::darkGray); painter->drawText(lineNumberAreaRect.adjusted(0, 0, -lineNumberAreaHorizontalPadding, 0), Qt::AlignRight, QString::number(lineNumber)); @@ -101,7 +101,7 @@ int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyle } void SearchResultTreeItemDelegate::drawMarker(QPainter *painter, const QModelIndex &index, const QString text, - const QRect &rect) const + const QRect &rect) const { const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; int searchTermStart = index.model()->data(index, ItemDataRoles::SearchTermStartRole).toInt(); diff --git a/src/plugins/find/searchresulttreeitemroles.h b/src/plugins/find/searchresulttreeitemroles.h index fd9450e6c0b..486e7907c6f 100644 --- a/src/plugins/find/searchresulttreeitemroles.h +++ b/src/plugins/find/searchresulttreeitemroles.h @@ -34,7 +34,7 @@ namespace Find { namespace Internal { namespace ItemDataRoles { -enum roles +enum Roles { TypeRole = Qt::UserRole, FileNameRole, @@ -49,6 +49,6 @@ enum roles } // namespace Internal } // namespace Find -} // namespace itemDataRoles +} // namespace ItemDataRoles #endif // SEARCHRESULTTREEITEMROLES_H diff --git a/src/plugins/find/searchresulttreemodel.cpp b/src/plugins/find/searchresulttreemodel.cpp index 0ae10d50594..68beb2afb8f 100644 --- a/src/plugins/find/searchresulttreemodel.cpp +++ b/src/plugins/find/searchresulttreemodel.cpp @@ -37,9 +37,11 @@ using namespace Find::Internal; SearchResultTreeModel::SearchResultTreeModel(QObject *parent) - : QAbstractItemModel(parent), m_lastAppendedResultFile(0) + : QAbstractItemModel(parent) + , m_lastAppendedResultFile(0) { m_rootItem = new SearchResultTreeItem(); + m_textEditorFont = QFont("Courier"); } SearchResultTreeModel::~SearchResultTreeModel() @@ -47,6 +49,11 @@ SearchResultTreeModel::~SearchResultTreeModel() delete m_rootItem; } +void SearchResultTreeModel::setTextEditorFont(const QFont &font) +{ + m_textEditorFont = font; +} + QModelIndex SearchResultTreeModel::index(int row, int column, const QModelIndex &parent) const { @@ -135,7 +142,7 @@ QVariant SearchResultTreeModel::data(const SearchResultTextRow *row, int role) c result = row->rowText().trimmed(); break; case Qt::FontRole: - result = QFont("courier"); + result = m_textEditorFont; break; case ItemDataRoles::ResultLineRole: case Qt::DisplayRole: @@ -179,13 +186,6 @@ QVariant SearchResultTreeModel::data(const SearchResultFile *file, int role) con case Qt::BackgroundRole: result = QColor(qRgb(245, 245, 245)); break; - case Qt::FontRole: - { - QFont font; - font.setPointSize(font.pointSize() + 1); - result = font; - break; - } case Qt::DisplayRole: result = file->fileName() + " (" + QString::number(file->childrenCount()) + ")"; break; @@ -241,7 +241,7 @@ void SearchResultTreeModel::appendResultLine(int index, int lineNumber, const QS } void SearchResultTreeModel::appendResultLine(int index, const QString &fileName, int lineNumber, const QString &rowText, - int searchTermStart, int searchTermLength) + int searchTermStart, int searchTermLength) { if (!m_lastAppendedResultFile || (m_lastAppendedResultFile->fileName() != fileName)) appendResultFile(fileName); diff --git a/src/plugins/find/searchresulttreemodel.h b/src/plugins/find/searchresulttreemodel.h index 3a1ac87efc7..b4036c0e7b6 100644 --- a/src/plugins/find/searchresulttreemodel.h +++ b/src/plugins/find/searchresulttreemodel.h @@ -31,6 +31,7 @@ #define SEARCHRESULTTREEMODEL_H #include <QtCore/QAbstractItemModel> +#include <QtGui/QFont> namespace Find { namespace Internal { @@ -47,6 +48,8 @@ public: SearchResultTreeModel(QObject *parent = 0); ~SearchResultTreeModel(); + void setTextEditorFont(const QFont &font); + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex parent(const QModelIndex &child) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; @@ -61,10 +64,10 @@ signals: public slots: void clear(); - void appendResultLine(int index, int lineNumber, const QString &rowText, int searchTermStart, - int searchTermLength); - void appendResultLine(int index, const QString &fileName, int lineNumber, const QString &rowText, int searchTermStart, - int searchTermLength); + void appendResultLine(int index, int lineNumber, const QString &rowText, + int searchTermStart, int searchTermLength); + void appendResultLine(int index, const QString &fileName, int lineNumber, const QString &rowText, + int searchTermStart, int searchTermLength); private: void appendResultFile(const QString &fileName); @@ -75,6 +78,7 @@ private: SearchResultTreeItem *m_rootItem; SearchResultFile *m_lastAppendedResultFile; + QFont m_textEditorFont; }; } // namespace Internal diff --git a/src/plugins/find/searchresulttreeview.cpp b/src/plugins/find/searchresulttreeview.cpp index 5b20a763997..b12e3f15885 100644 --- a/src/plugins/find/searchresulttreeview.cpp +++ b/src/plugins/find/searchresulttreeview.cpp @@ -37,7 +37,8 @@ using namespace Find::Internal; SearchResultTreeView::SearchResultTreeView(QWidget *parent) - : QTreeView(parent), m_autoExpandResults(false) + : QTreeView(parent) + , m_autoExpandResults(false) { m_model = new SearchResultTreeModel(this); setModel(m_model); @@ -54,6 +55,11 @@ void SearchResultTreeView::setAutoExpandResults(bool expand) m_autoExpandResults = expand; } +void SearchResultTreeView::setTextEditorFont(const QFont &font) +{ + m_model->setTextEditorFont(font); +} + void SearchResultTreeView::clear() { m_model->clear(); diff --git a/src/plugins/find/searchresulttreeview.h b/src/plugins/find/searchresulttreeview.h index be1420b3438..1fcf03599f4 100644 --- a/src/plugins/find/searchresulttreeview.h +++ b/src/plugins/find/searchresulttreeview.h @@ -44,7 +44,9 @@ class SearchResultTreeView : public QTreeView public: SearchResultTreeView(QWidget *parent = 0); + void setAutoExpandResults(bool expand); + void setTextEditorFont(const QFont &font); signals: void jumpToSearchResult(int index, const QString &fileName, int lineNumber, diff --git a/src/plugins/find/searchresultwindow.cpp b/src/plugins/find/searchresultwindow.cpp index 323d26bf3ba..19c252a4177 100644 --- a/src/plugins/find/searchresultwindow.cpp +++ b/src/plugins/find/searchresultwindow.cpp @@ -82,22 +82,6 @@ SearchResultWindow::~SearchResultWindow() m_items.clear(); } -bool SearchResultWindow::hasFocus() -{ - return m_searchResultTreeView->hasFocus(); -} - -bool SearchResultWindow::canFocus() -{ - return !m_items.isEmpty(); -} - -void SearchResultWindow::setFocus() -{ - if (!m_items.isEmpty()) - m_searchResultTreeView->setFocus(); -} - void SearchResultWindow::visibilityChanged(bool /*visible*/) { } @@ -135,6 +119,27 @@ int SearchResultWindow::numberOfResults() const return m_searchResultTreeView->model()->rowCount(); } +bool SearchResultWindow::hasFocus() +{ + return m_searchResultTreeView->hasFocus(); +} + +bool SearchResultWindow::canFocus() +{ + return !m_items.isEmpty(); +} + +void SearchResultWindow::setFocus() +{ + if (!m_items.isEmpty()) + m_searchResultTreeView->setFocus(); +} + +void SearchResultWindow::setTextEditorFont(const QFont &font) +{ + m_searchResultTreeView->setTextEditorFont(font); +} + void SearchResultWindow::handleJumpToSearchResult(int index, const QString &fileName, int lineNumber, int searchTermStart, int searchTermLength) { diff --git a/src/plugins/find/searchresultwindow.h b/src/plugins/find/searchresultwindow.h index a6f4b705a98..da371971cf7 100644 --- a/src/plugins/find/searchresultwindow.h +++ b/src/plugins/find/searchresultwindow.h @@ -75,11 +75,13 @@ public: bool canFocus(); void setFocus(); + void setTextEditorFont(const QFont &font); + public slots: void clearContents(); void showNoMatchesFound(); ResultWindowItem *addResult(const QString &fileName, int lineNumber, const QString &lineText, - int searchTermStart, int searchTermLength); + int searchTermStart, int searchTermLength); private slots: void handleExpandCollapseToolButton(bool checked); diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index 12e3ef92825..d1e4ce5c8fd 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -48,6 +48,7 @@ #include <coreplugin/editormanager/editormanager.h> #include <extensionsystem/pluginmanager.h> #include <texteditor/texteditoractionhandler.h> +#include <find/searchresultwindow.h> #include <utils/qtcassert.h> #include <QtCore/QtPlugin> @@ -63,7 +64,8 @@ TextEditorPlugin::TextEditorPlugin() : m_settings(0), m_wizard(0), m_editorFactory(0), - m_lineNumberFilter(0) + m_lineNumberFilter(0), + m_searchResultWindow(0) { QTC_ASSERT(!m_instance, return); m_instance = this; @@ -137,6 +139,13 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe void TextEditorPlugin::extensionsInitialized() { m_editorFactory->actionHandler()->initializeActions(); + + m_searchResultWindow = ExtensionSystem::PluginManager::instance()->getObject<Find::SearchResultWindow>(); + + connect(m_settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)), + this, SLOT(updateSearchResultsFont(TextEditor::FontSettings))); + + updateSearchResultsFont(m_settings->fontSettings()); } void TextEditorPlugin::initializeEditor(PlainTextEditor *editor) @@ -155,5 +164,10 @@ void TextEditorPlugin::invokeCompletion() editor->triggerCompletions(); } +void TextEditorPlugin::updateSearchResultsFont(const FontSettings &settings) +{ + if (m_searchResultWindow) + m_searchResultWindow->setTextEditorFont(QFont(settings.family(), settings.fontSize())); +} Q_EXPORT_PLUGIN(TextEditorPlugin) diff --git a/src/plugins/texteditor/texteditorplugin.h b/src/plugins/texteditor/texteditorplugin.h index 73fb4538bb0..17f601dd24c 100644 --- a/src/plugins/texteditor/texteditorplugin.h +++ b/src/plugins/texteditor/texteditorplugin.h @@ -32,6 +32,10 @@ #include <extensionsystem/iplugin.h> +namespace Find { +class SearchResultWindow; +} + namespace TextEditor { class FontSettings; @@ -65,6 +69,7 @@ public: private slots: void invokeCompletion(); + void updateSearchResultsFont(const TextEditor::FontSettings &); private: static TextEditorPlugin *m_instance; @@ -72,6 +77,7 @@ private: TextFileWizard *m_wizard; PlainTextEditorFactory *m_editorFactory; LineNumberFilter *m_lineNumberFilter; + Find::SearchResultWindow *m_searchResultWindow; }; } // namespace Internal -- GitLab