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:
@@ -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();
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
@@ -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
|
||||
|
@@ -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();
|
||||
|
@@ -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,
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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);
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user