diff options
Diffstat (limited to 'src')
10 files changed, 65 insertions, 14 deletions
diff --git a/src/plugins/coreplugin/find/searchresulttreeitemdelegate.cpp b/src/plugins/coreplugin/find/searchresulttreeitemdelegate.cpp index 39164f711d..c9cb263920 100644 --- a/src/plugins/coreplugin/find/searchresulttreeitemdelegate.cpp +++ b/src/plugins/coreplugin/find/searchresulttreeitemdelegate.cpp @@ -39,9 +39,10 @@ using namespace Core::Internal; -SearchResultTreeItemDelegate::SearchResultTreeItemDelegate(QObject *parent) - : QItemDelegate(parent) +SearchResultTreeItemDelegate::SearchResultTreeItemDelegate(int tabWidth, QObject *parent) + : QItemDelegate(parent) { + setTabWidth(tabWidth); } void SearchResultTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const @@ -100,6 +101,11 @@ void SearchResultTreeItemDelegate::paint(QPainter *painter, const QStyleOptionVi painter->restore(); } +void SearchResultTreeItemDelegate::setTabWidth(int width) +{ + m_tabString = QString(width, QLatin1Char(' ')); +} + // returns the width of the line number area int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyleOptionViewItemV3 &option, const QRect &rect, @@ -156,14 +162,18 @@ void SearchResultTreeItemDelegate::drawText(QPainter *painter, const int searchTermStart = index.model()->data(index, ItemDataRoles::SearchTermStartRole).toInt(); int searchTermLength = index.model()->data(index, ItemDataRoles::SearchTermLengthRole).toInt(); if (searchTermStart < 0 || searchTermStart >= text.length() || searchTermLength < 1) { - QItemDelegate::drawDisplay(painter, option, rect, text); + QItemDelegate::drawDisplay(painter, option, rect, text.replace(QLatin1Char('\t'), m_tabString)); return; } + // clip searchTermLength to end of line searchTermLength = qMin(searchTermLength, text.length() - searchTermStart); const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; - int searchTermStartPixels = painter->fontMetrics().width(text.left(searchTermStart)); - int searchTermLengthPixels = painter->fontMetrics().width(text.mid(searchTermStart, searchTermLength)); + const QString textBefore = text.left(searchTermStart).replace(QLatin1Char('\t'), m_tabString); + const QString textHighlight = text.mid(searchTermStart, searchTermLength).replace(QLatin1Char('\t'), m_tabString); + const QString textAfter = text.mid(searchTermStart + searchTermLength).replace(QLatin1Char('\t'), m_tabString); + int searchTermStartPixels = painter->fontMetrics().width(textBefore); + int searchTermLengthPixels = painter->fontMetrics().width(textHighlight); // rects QRect beforeHighlightRect(rect); @@ -203,19 +213,16 @@ void SearchResultTreeItemDelegate::drawText(QPainter *painter, noHighlightOpt.textElideMode = Qt::ElideNone; if (isSelected) noHighlightOpt.palette.setColor(QPalette::Text, noHighlightOpt.palette.color(cg, QPalette::HighlightedText)); - QItemDelegate::drawDisplay(painter, noHighlightOpt, - beforeHighlightRect, text.mid(0, searchTermStart)); + QItemDelegate::drawDisplay(painter, noHighlightOpt, beforeHighlightRect, textBefore); // Highlight text QStyleOptionViewItem highlightOpt = noHighlightOpt; const QColor highlightForeground = index.model()->data(index, ItemDataRoles::ResultHighlightForegroundColor).value<QColor>(); highlightOpt.palette.setColor(QPalette::Text, highlightForeground); - QItemDelegate::drawDisplay(painter, highlightOpt, resultHighlightRect, - text.mid(searchTermStart, searchTermLength)); + QItemDelegate::drawDisplay(painter, highlightOpt, resultHighlightRect, textHighlight); // Text after the Highlight noHighlightOpt.rect = afterHighlightRect; - QItemDelegate::drawDisplay(painter, noHighlightOpt, afterHighlightRect, - text.mid(searchTermStart + searchTermLength)); + QItemDelegate::drawDisplay(painter, noHighlightOpt, afterHighlightRect, textAfter); } diff --git a/src/plugins/coreplugin/find/searchresulttreeitemdelegate.h b/src/plugins/coreplugin/find/searchresulttreeitemdelegate.h index 9dc85c988e..eeca6aafd1 100644 --- a/src/plugins/coreplugin/find/searchresulttreeitemdelegate.h +++ b/src/plugins/coreplugin/find/searchresulttreeitemdelegate.h @@ -39,14 +39,16 @@ namespace Internal { class SearchResultTreeItemDelegate: public QItemDelegate { public: - SearchResultTreeItemDelegate(QObject *parent = 0); + SearchResultTreeItemDelegate(int tabWidth, QObject *parent = 0); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + void setTabWidth(int width); private: int drawLineNumber(QPainter *painter, const QStyleOptionViewItemV3 &option, const QRect &rect, const QModelIndex &index) const; void drawText(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QModelIndex &index) const; + QString m_tabString; static const int m_minimumLineNumberDigits = 6; }; diff --git a/src/plugins/coreplugin/find/searchresulttreeview.cpp b/src/plugins/coreplugin/find/searchresulttreeview.cpp index dbab12e445..1931284b6c 100644 --- a/src/plugins/coreplugin/find/searchresulttreeview.cpp +++ b/src/plugins/coreplugin/find/searchresulttreeview.cpp @@ -45,7 +45,7 @@ SearchResultTreeView::SearchResultTreeView(QWidget *parent) , m_autoExpandResults(false) { setModel(m_model); - setItemDelegate(new SearchResultTreeItemDelegate(this)); + setItemDelegate(new SearchResultTreeItemDelegate(8, this)); setIndentation(14); setUniformRowHeights(true); setExpandsOnDoubleClick(true); @@ -91,6 +91,13 @@ void SearchResultTreeView::emitJumpToSearchResult(const QModelIndex &index) emit jumpToSearchResult(item); } +void SearchResultTreeView::setTabWidth(int tabWidth) +{ + SearchResultTreeItemDelegate *delegate = static_cast<SearchResultTreeItemDelegate *>(itemDelegate()); + delegate->setTabWidth(tabWidth); + doItemsLayout(); +} + SearchResultTreeModel *SearchResultTreeView::model() const { return m_model; diff --git a/src/plugins/coreplugin/find/searchresulttreeview.h b/src/plugins/coreplugin/find/searchresulttreeview.h index ff8b1fb313..9a9641555e 100644 --- a/src/plugins/coreplugin/find/searchresulttreeview.h +++ b/src/plugins/coreplugin/find/searchresulttreeview.h @@ -50,6 +50,7 @@ public: void setAutoExpandResults(bool expand); void setTextEditorFont(const QFont &font, const SearchResultColor &color); + void setTabWidth(int tabWidth); SearchResultTreeModel *model() const; void addResults(const QList<SearchResultItem> &items, SearchResult::AddMode mode); diff --git a/src/plugins/coreplugin/find/searchresultwidget.cpp b/src/plugins/coreplugin/find/searchresultwidget.cpp index a484699ac9..b61799dfa7 100644 --- a/src/plugins/coreplugin/find/searchresultwidget.cpp +++ b/src/plugins/coreplugin/find/searchresultwidget.cpp @@ -354,6 +354,11 @@ void SearchResultWidget::setTextEditorFont(const QFont &font, const SearchResult m_searchResultTreeView->setTextEditorFont(font, color); } +void SearchResultWidget::setTabWidth(int tabWidth) +{ + m_searchResultTreeView->setTabWidth(tabWidth); +} + void SearchResultWidget::setAutoExpandResults(bool expand) { m_searchResultTreeView->setAutoExpandResults(expand); diff --git a/src/plugins/coreplugin/find/searchresultwidget.h b/src/plugins/coreplugin/find/searchresultwidget.h index 1962742e44..d1d58a156c 100644 --- a/src/plugins/coreplugin/find/searchresultwidget.h +++ b/src/plugins/coreplugin/find/searchresultwidget.h @@ -81,6 +81,7 @@ public: void notifyVisibilityChanged(bool visible); void setTextEditorFont(const QFont &font, const SearchResultColor &color); + void setTabWidth(int tabWidth); void setAutoExpandResults(bool expand); void expandAll(); diff --git a/src/plugins/coreplugin/find/searchresultwindow.cpp b/src/plugins/coreplugin/find/searchresultwindow.cpp index 1bd23449a5..930bc906a7 100644 --- a/src/plugins/coreplugin/find/searchresultwindow.cpp +++ b/src/plugins/coreplugin/find/searchresultwindow.cpp @@ -101,6 +101,7 @@ namespace Internal { int m_currentIndex; QFont m_font; SearchResultColor m_color; + int m_tabWidth; public slots: void setCurrentIndex(int index); @@ -109,7 +110,8 @@ namespace Internal { }; SearchResultWindowPrivate::SearchResultWindowPrivate(SearchResultWindow *window) - : q(window) + : q(window), + m_tabWidth(8) { } @@ -406,6 +408,7 @@ SearchResult *SearchResultWindow::startNewSearch(const QString &label, connect(widget, SIGNAL(restarted()), d, SLOT(moveWidgetToTop())); connect(widget, SIGNAL(requestPopup(bool)), d, SLOT(popupRequested(bool))); widget->setTextEditorFont(d->m_font, d->m_color); + widget->setTabWidth(d->m_tabWidth); widget->setSupportPreserveCase(preserveCaseMode == PreserveCaseEnabled); widget->setShowReplaceUI(searchOrSearchAndReplace != SearchOnly); widget->setAutoExpandResults(d->m_expandCollapseAction->isChecked()); @@ -494,6 +497,13 @@ void SearchResultWindow::setTextEditorFont(const QFont &font, widget->setTextEditorFont(font, color); } +void SearchResultWindow::setTabWidth(int tabWidth) +{ + d->m_tabWidth = tabWidth; + foreach (Internal::SearchResultWidget *widget, d->m_searchResultWidgets) + widget->setTabWidth(tabWidth); +} + void SearchResultWindow::openNewSearchPanel() { d->setCurrentIndex(0); diff --git a/src/plugins/coreplugin/find/searchresultwindow.h b/src/plugins/coreplugin/find/searchresultwindow.h index d2827202a3..fd879e8995 100644 --- a/src/plugins/coreplugin/find/searchresultwindow.h +++ b/src/plugins/coreplugin/find/searchresultwindow.h @@ -169,6 +169,7 @@ public: const QColor &textBackgroundColor, const QColor &highlightForegroundColor, const QColor &highlightBackgroundColor); + void setTabWidth(int width); void openNewSearchPanel(); // The search result window owns the returned SearchResult diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index 4430c3b77e..3cdc0ec4dd 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -48,6 +48,10 @@ #include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/externaltoolmanager.h> #include <extensionsystem/pluginmanager.h> + +#include <texteditor/icodestylepreferences.h> +#include <texteditor/tabsettings.h> + #include <utils/qtcassert.h> #include <utils/macroexpander.h> @@ -143,6 +147,11 @@ void TextEditorPlugin::extensionsInitialized() updateSearchResultsFont(m_settings->fontSettings()); + connect(m_settings->codeStyle(), &ICodeStylePreferences::currentTabSettingsChanged, + this, &TextEditorPlugin::updateSearchResultsTabWidth); + + updateSearchResultsTabWidth(m_settings->codeStyle()->currentTabSettings()); + addAutoReleasedObject(new FindInFiles); addAutoReleasedObject(new FindInCurrentFile); addAutoReleasedObject(new FindInOpenFiles); @@ -221,6 +230,12 @@ void TextEditorPlugin::updateSearchResultsFont(const FontSettings &settings) } } +void TextEditorPlugin::updateSearchResultsTabWidth(const TabSettings &tabSettings) +{ + if (auto window = SearchResultWindow::instance()) + window->setTabWidth(tabSettings.m_tabSize); +} + void TextEditorPlugin::updateCurrentSelection(const QString &text) { if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) { diff --git a/src/plugins/texteditor/texteditorplugin.h b/src/plugins/texteditor/texteditorplugin.h index 76ab5f226d..00d447123c 100644 --- a/src/plugins/texteditor/texteditorplugin.h +++ b/src/plugins/texteditor/texteditorplugin.h @@ -36,6 +36,7 @@ namespace TextEditor { class FontSettings; +class TabSettings; class TextEditorSettings; namespace Internal { @@ -62,6 +63,7 @@ public: private slots: void updateSearchResultsFont(const TextEditor::FontSettings &); + void updateSearchResultsTabWidth(const TextEditor::TabSettings &tabSettings); void updateCurrentSelection(const QString &text); private: |