forked from qt-creator/qt-creator
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.
This commit is contained in:
@@ -90,10 +90,10 @@ int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyle
|
|||||||
else if (!(option.state & QStyle::State_Enabled))
|
else if (!(option.state & QStyle::State_Enabled))
|
||||||
cg = QPalette::Disabled;
|
cg = QPalette::Disabled;
|
||||||
|
|
||||||
painter->fillRect(lineNumberAreaRect, QBrush(isSelected?
|
painter->fillRect(lineNumberAreaRect, QBrush(isSelected ?
|
||||||
option.palette.brush(cg, QPalette::Highlight):QBrush(qRgb(230, 230, 230))));
|
option.palette.brush(cg, QPalette::Highlight) : QBrush(qRgb(230, 230, 230))));
|
||||||
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, QString::number(lineNumber));
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ namespace Find {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
namespace ItemDataRoles {
|
namespace ItemDataRoles {
|
||||||
|
|
||||||
enum roles
|
enum Roles
|
||||||
{
|
{
|
||||||
TypeRole = Qt::UserRole,
|
TypeRole = Qt::UserRole,
|
||||||
FileNameRole,
|
FileNameRole,
|
||||||
@@ -49,6 +49,6 @@ enum roles
|
|||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Find
|
} // namespace Find
|
||||||
} // namespace itemDataRoles
|
} // namespace ItemDataRoles
|
||||||
|
|
||||||
#endif // SEARCHRESULTTREEITEMROLES_H
|
#endif // SEARCHRESULTTREEITEMROLES_H
|
||||||
|
@@ -37,9 +37,11 @@
|
|||||||
using namespace Find::Internal;
|
using namespace Find::Internal;
|
||||||
|
|
||||||
SearchResultTreeModel::SearchResultTreeModel(QObject *parent)
|
SearchResultTreeModel::SearchResultTreeModel(QObject *parent)
|
||||||
: QAbstractItemModel(parent), m_lastAppendedResultFile(0)
|
: QAbstractItemModel(parent)
|
||||||
|
, m_lastAppendedResultFile(0)
|
||||||
{
|
{
|
||||||
m_rootItem = new SearchResultTreeItem();
|
m_rootItem = new SearchResultTreeItem();
|
||||||
|
m_textEditorFont = QFont("Courier");
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchResultTreeModel::~SearchResultTreeModel()
|
SearchResultTreeModel::~SearchResultTreeModel()
|
||||||
@@ -47,6 +49,11 @@ SearchResultTreeModel::~SearchResultTreeModel()
|
|||||||
delete m_rootItem;
|
delete m_rootItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SearchResultTreeModel::setTextEditorFont(const QFont &font)
|
||||||
|
{
|
||||||
|
m_textEditorFont = font;
|
||||||
|
}
|
||||||
|
|
||||||
QModelIndex SearchResultTreeModel::index(int row, int column,
|
QModelIndex SearchResultTreeModel::index(int row, int column,
|
||||||
const QModelIndex &parent) const
|
const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
@@ -135,7 +142,7 @@ QVariant SearchResultTreeModel::data(const SearchResultTextRow *row, int role) c
|
|||||||
result = row->rowText().trimmed();
|
result = row->rowText().trimmed();
|
||||||
break;
|
break;
|
||||||
case Qt::FontRole:
|
case Qt::FontRole:
|
||||||
result = QFont("courier");
|
result = m_textEditorFont;
|
||||||
break;
|
break;
|
||||||
case ItemDataRoles::ResultLineRole:
|
case ItemDataRoles::ResultLineRole:
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
@@ -179,13 +186,6 @@ QVariant SearchResultTreeModel::data(const SearchResultFile *file, int role) con
|
|||||||
case Qt::BackgroundRole:
|
case Qt::BackgroundRole:
|
||||||
result = QColor(qRgb(245, 245, 245));
|
result = QColor(qRgb(245, 245, 245));
|
||||||
break;
|
break;
|
||||||
case Qt::FontRole:
|
|
||||||
{
|
|
||||||
QFont font;
|
|
||||||
font.setPointSize(font.pointSize() + 1);
|
|
||||||
result = font;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
result = file->fileName() + " (" + QString::number(file->childrenCount()) + ")";
|
result = file->fileName() + " (" + QString::number(file->childrenCount()) + ")";
|
||||||
break;
|
break;
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#define SEARCHRESULTTREEMODEL_H
|
#define SEARCHRESULTTREEMODEL_H
|
||||||
|
|
||||||
#include <QtCore/QAbstractItemModel>
|
#include <QtCore/QAbstractItemModel>
|
||||||
|
#include <QtGui/QFont>
|
||||||
|
|
||||||
namespace Find {
|
namespace Find {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -47,6 +48,8 @@ public:
|
|||||||
SearchResultTreeModel(QObject *parent = 0);
|
SearchResultTreeModel(QObject *parent = 0);
|
||||||
~SearchResultTreeModel();
|
~SearchResultTreeModel();
|
||||||
|
|
||||||
|
void setTextEditorFont(const QFont &font);
|
||||||
|
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||||
QModelIndex parent(const QModelIndex &child) const;
|
QModelIndex parent(const QModelIndex &child) const;
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
@@ -61,10 +64,10 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void clear();
|
void clear();
|
||||||
void appendResultLine(int index, int lineNumber, const QString &rowText, int searchTermStart,
|
void appendResultLine(int index, int lineNumber, const QString &rowText,
|
||||||
int searchTermLength);
|
int searchTermStart, int searchTermLength);
|
||||||
void appendResultLine(int index, const QString &fileName, int lineNumber, const QString &rowText, int searchTermStart,
|
void appendResultLine(int index, const QString &fileName, int lineNumber, const QString &rowText,
|
||||||
int searchTermLength);
|
int searchTermStart, int searchTermLength);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void appendResultFile(const QString &fileName);
|
void appendResultFile(const QString &fileName);
|
||||||
@@ -75,6 +78,7 @@ private:
|
|||||||
|
|
||||||
SearchResultTreeItem *m_rootItem;
|
SearchResultTreeItem *m_rootItem;
|
||||||
SearchResultFile *m_lastAppendedResultFile;
|
SearchResultFile *m_lastAppendedResultFile;
|
||||||
|
QFont m_textEditorFont;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -37,7 +37,8 @@
|
|||||||
using namespace Find::Internal;
|
using namespace Find::Internal;
|
||||||
|
|
||||||
SearchResultTreeView::SearchResultTreeView(QWidget *parent)
|
SearchResultTreeView::SearchResultTreeView(QWidget *parent)
|
||||||
: QTreeView(parent), m_autoExpandResults(false)
|
: QTreeView(parent)
|
||||||
|
, m_autoExpandResults(false)
|
||||||
{
|
{
|
||||||
m_model = new SearchResultTreeModel(this);
|
m_model = new SearchResultTreeModel(this);
|
||||||
setModel(m_model);
|
setModel(m_model);
|
||||||
@@ -54,6 +55,11 @@ void SearchResultTreeView::setAutoExpandResults(bool expand)
|
|||||||
m_autoExpandResults = expand;
|
m_autoExpandResults = expand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SearchResultTreeView::setTextEditorFont(const QFont &font)
|
||||||
|
{
|
||||||
|
m_model->setTextEditorFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
void SearchResultTreeView::clear()
|
void SearchResultTreeView::clear()
|
||||||
{
|
{
|
||||||
m_model->clear();
|
m_model->clear();
|
||||||
|
@@ -44,7 +44,9 @@ class SearchResultTreeView : public QTreeView
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
SearchResultTreeView(QWidget *parent = 0);
|
SearchResultTreeView(QWidget *parent = 0);
|
||||||
|
|
||||||
void setAutoExpandResults(bool expand);
|
void setAutoExpandResults(bool expand);
|
||||||
|
void setTextEditorFont(const QFont &font);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void jumpToSearchResult(int index, const QString &fileName, int lineNumber,
|
void jumpToSearchResult(int index, const QString &fileName, int lineNumber,
|
||||||
|
@@ -82,22 +82,6 @@ SearchResultWindow::~SearchResultWindow()
|
|||||||
m_items.clear();
|
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*/)
|
void SearchResultWindow::visibilityChanged(bool /*visible*/)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -135,6 +119,27 @@ int SearchResultWindow::numberOfResults() const
|
|||||||
return m_searchResultTreeView->model()->rowCount();
|
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,
|
void SearchResultWindow::handleJumpToSearchResult(int index, const QString &fileName, int lineNumber,
|
||||||
int searchTermStart, int searchTermLength)
|
int searchTermStart, int searchTermLength)
|
||||||
{
|
{
|
||||||
|
@@ -75,6 +75,8 @@ public:
|
|||||||
bool canFocus();
|
bool canFocus();
|
||||||
void setFocus();
|
void setFocus();
|
||||||
|
|
||||||
|
void setTextEditorFont(const QFont &font);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void clearContents();
|
void clearContents();
|
||||||
void showNoMatchesFound();
|
void showNoMatchesFound();
|
||||||
|
@@ -48,6 +48,7 @@
|
|||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <texteditor/texteditoractionhandler.h>
|
#include <texteditor/texteditoractionhandler.h>
|
||||||
|
#include <find/searchresultwindow.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QtCore/QtPlugin>
|
#include <QtCore/QtPlugin>
|
||||||
@@ -63,7 +64,8 @@ TextEditorPlugin::TextEditorPlugin()
|
|||||||
: m_settings(0),
|
: m_settings(0),
|
||||||
m_wizard(0),
|
m_wizard(0),
|
||||||
m_editorFactory(0),
|
m_editorFactory(0),
|
||||||
m_lineNumberFilter(0)
|
m_lineNumberFilter(0),
|
||||||
|
m_searchResultWindow(0)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!m_instance, return);
|
QTC_ASSERT(!m_instance, return);
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
@@ -137,6 +139,13 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
|
|||||||
void TextEditorPlugin::extensionsInitialized()
|
void TextEditorPlugin::extensionsInitialized()
|
||||||
{
|
{
|
||||||
m_editorFactory->actionHandler()->initializeActions();
|
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)
|
void TextEditorPlugin::initializeEditor(PlainTextEditor *editor)
|
||||||
@@ -155,5 +164,10 @@ void TextEditorPlugin::invokeCompletion()
|
|||||||
editor->triggerCompletions();
|
editor->triggerCompletions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditorPlugin::updateSearchResultsFont(const FontSettings &settings)
|
||||||
|
{
|
||||||
|
if (m_searchResultWindow)
|
||||||
|
m_searchResultWindow->setTextEditorFont(QFont(settings.family(), settings.fontSize()));
|
||||||
|
}
|
||||||
|
|
||||||
Q_EXPORT_PLUGIN(TextEditorPlugin)
|
Q_EXPORT_PLUGIN(TextEditorPlugin)
|
||||||
|
@@ -32,6 +32,10 @@
|
|||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
|
namespace Find {
|
||||||
|
class SearchResultWindow;
|
||||||
|
}
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
class FontSettings;
|
class FontSettings;
|
||||||
@@ -65,6 +69,7 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void invokeCompletion();
|
void invokeCompletion();
|
||||||
|
void updateSearchResultsFont(const TextEditor::FontSettings &);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static TextEditorPlugin *m_instance;
|
static TextEditorPlugin *m_instance;
|
||||||
@@ -72,6 +77,7 @@ private:
|
|||||||
TextFileWizard *m_wizard;
|
TextFileWizard *m_wizard;
|
||||||
PlainTextEditorFactory *m_editorFactory;
|
PlainTextEditorFactory *m_editorFactory;
|
||||||
LineNumberFilter *m_lineNumberFilter;
|
LineNumberFilter *m_lineNumberFilter;
|
||||||
|
Find::SearchResultWindow *m_searchResultWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user