diff --git a/src/plugins/find/searchresulttreeitemdelegate.cpp b/src/plugins/find/searchresulttreeitemdelegate.cpp index 533b47e5c91694b8c1fe25992ba47a948e4d826f..d72ca5c2b0fa5842c9403e9c3f14dec0268044e5 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 fd9450e6c0bd3475c60eab9031520ea96eb7d4a5..486e7907c6f45e89c96ae6db127fd062c81603e9 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 0ae10d50594fb7058ae125455eef356b370c4359..68beb2afb8f3ace34b4a9fa0fbd5f25ae9d03962 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 3a1ac87efc74afb42b980e1bbaf9fb9f296f5f8d..b4036c0e7b64b91525292d328399100af3ab3957 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 5b20a763997b25c02d43076f3766a0dcbe43252c..b12e3f15885a0f33c8f5833132eb9b2ed7dcaf4e 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 be1420b3438e991c9202e04828040ba8fb8d5175..1fcf03599f4d148b2ebe414da3f02d5e45afc1e9 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 323d26bf3bae102078e8a38942d73b76218b5bfe..19c252a417792f8054bd6c7eda754a37f6ea32fe 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 a6f4b705a98c8cd292cb6ce71147da8ae409bae5..da371971cf795910ca7880f139381461512ed3bc 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 12e3ef9282520cf58b9af4c1625562085398df30..d1e4ce5c8fd4546a2294f63992b43e6ad5ffd55e 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 73fb4538bb0aef572adcf82c8aa8602eab789580..17f601dd24cf9651ae6ceec569331820769cb946 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