aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/coreplugin/find
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/coreplugin/find')
-rw-r--r--src/plugins/coreplugin/find/find.pri2
-rw-r--r--src/plugins/coreplugin/find/findtoolbar.cpp73
-rw-r--r--src/plugins/coreplugin/find/findtoolbar.h19
-rw-r--r--src/plugins/coreplugin/find/findtoolwindow.cpp7
-rw-r--r--src/plugins/coreplugin/find/highlightscrollbarcontroller.cpp2
-rw-r--r--src/plugins/coreplugin/find/optionspopup.cpp110
-rw-r--r--src/plugins/coreplugin/find/optionspopup.h59
-rw-r--r--src/plugins/coreplugin/find/searchresulttreeitemdelegate.cpp150
-rw-r--r--src/plugins/coreplugin/find/searchresulttreeitemdelegate.h15
-rw-r--r--src/plugins/coreplugin/find/searchresulttreemodel.cpp2
-rw-r--r--src/plugins/coreplugin/find/searchresulttreeview.cpp9
-rw-r--r--src/plugins/coreplugin/find/searchresulttreeview.h1
-rw-r--r--src/plugins/coreplugin/find/searchresultwidget.cpp4
-rw-r--r--src/plugins/coreplugin/find/searchresultwindow.cpp5
14 files changed, 307 insertions, 151 deletions
diff --git a/src/plugins/coreplugin/find/find.pri b/src/plugins/coreplugin/find/find.pri
index 41005912fb..811f20a5c0 100644
--- a/src/plugins/coreplugin/find/find.pri
+++ b/src/plugins/coreplugin/find/find.pri
@@ -8,6 +8,7 @@ HEADERS += \
$$PWD/ifindfilter.h \
$$PWD/ifindsupport.h \
$$PWD/itemviewfind.h \
+ $$PWD/optionspopup.h \
$$PWD/searchresultcolor.h \
$$PWD/searchresulttreeitemdelegate.h \
$$PWD/searchresulttreeitemroles.h \
@@ -29,6 +30,7 @@ SOURCES += \
$$PWD/ifindfilter.cpp \
$$PWD/ifindsupport.cpp \
$$PWD/itemviewfind.cpp \
+ $$PWD/optionspopup.cpp \
$$PWD/searchresulttreeitemdelegate.cpp \
$$PWD/searchresulttreeitems.cpp \
$$PWD/searchresulttreemodel.cpp \
diff --git a/src/plugins/coreplugin/find/findtoolbar.cpp b/src/plugins/coreplugin/find/findtoolbar.cpp
index 4307ba388d..72a2d23e3c 100644
--- a/src/plugins/coreplugin/find/findtoolbar.cpp
+++ b/src/plugins/coreplugin/find/findtoolbar.cpp
@@ -26,6 +26,7 @@
#include "findtoolbar.h"
#include "ifindfilter.h"
#include "findplugin.h"
+#include "optionspopup.h"
#include <coreplugin/coreicons.h>
#include <coreplugin/coreplugin.h>
@@ -118,8 +119,7 @@ FindToolBar::FindToolBar(CurrentDocumentFind *currentDocumentFind)
this, &FindToolBar::invokeFindEnter, Qt::QueuedConnection);
connect(m_ui.replaceEdit, &Utils::FancyLineEdit::returnPressed,
this, &FindToolBar::invokeReplaceEnter, Qt::QueuedConnection);
- connect(m_findCompleter,
- static_cast<void (QCompleter::*)(const QModelIndex &)>(&QCompleter::activated),
+ connect(m_findCompleter, QOverload<const QModelIndex &>::of(&QCompleter::activated),
this, &FindToolBar::findCompleterActivated);
auto shiftEnterAction = new QAction(m_ui.findEdit);
@@ -660,7 +660,8 @@ void FindToolBar::findFlagsChanged()
void FindToolBar::findEditButtonClicked()
{
- auto popup = new OptionsPopup(m_ui.findEdit);
+ auto popup = new OptionsPopup(m_ui.findEdit, {Constants::CASE_SENSITIVE, Constants::WHOLE_WORDS,
+ Constants::REGULAR_EXPRESSIONS, Constants::PRESERVE_CASE});
popup->show();
}
@@ -1015,71 +1016,5 @@ void FindToolBar::updateReplaceEnabled()
m_replacePreviousAction->setEnabled(globalsEnabled);
}
-OptionsPopup::OptionsPopup(QWidget *parent)
- : QWidget(parent, Qt::Popup)
-{
- setAttribute(Qt::WA_DeleteOnClose);
- auto layout = new QVBoxLayout(this);
- layout->setContentsMargins(2, 2, 2, 2);
- layout->setSpacing(2);
- setLayout(layout);
- QCheckBox *firstCheckBox = createCheckboxForCommand(Constants::CASE_SENSITIVE);
- layout->addWidget(firstCheckBox);
- layout->addWidget(createCheckboxForCommand(Constants::WHOLE_WORDS));
- layout->addWidget(createCheckboxForCommand(Constants::REGULAR_EXPRESSIONS));
- layout->addWidget(createCheckboxForCommand(Constants::PRESERVE_CASE));
- firstCheckBox->setFocus();
- move(parent->mapToGlobal(QPoint(0, -sizeHint().height())));
-}
-
-bool OptionsPopup::event(QEvent *ev)
-{
- if (ev->type() == QEvent::ShortcutOverride) {
- auto ke = static_cast<QKeyEvent *>(ev);
- if (ke->key() == Qt::Key_Escape && !ke->modifiers()) {
- ev->accept();
- return true;
- }
- }
- return QWidget::event(ev);
-}
-
-bool OptionsPopup::eventFilter(QObject *obj, QEvent *ev)
-{
- auto checkbox = qobject_cast<QCheckBox *>(obj);
- if (ev->type() == QEvent::KeyPress && checkbox) {
- auto ke = static_cast<QKeyEvent *>(ev);
- if (!ke->modifiers() && (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return)) {
- checkbox->click();
- ev->accept();
- return true;
- }
- }
- return QWidget::eventFilter(obj, ev);
-}
-
-void OptionsPopup::actionChanged()
-{
- auto action = qobject_cast<QAction *>(sender());
- QTC_ASSERT(action, return);
- QCheckBox *checkbox = m_checkboxMap.value(action);
- QTC_ASSERT(checkbox, return);
- checkbox->setEnabled(action->isEnabled());
-}
-
-QCheckBox *OptionsPopup::createCheckboxForCommand(Id id)
-{
- QAction *action = ActionManager::command(id)->action();
- QCheckBox *checkbox = new QCheckBox(action->text());
- checkbox->setToolTip(action->toolTip());
- checkbox->setChecked(action->isChecked());
- checkbox->setEnabled(action->isEnabled());
- checkbox->installEventFilter(this); // enter key handling
- QObject::connect(checkbox, &QCheckBox::clicked, action, &QAction::setChecked);
- QObject::connect(action, &QAction::changed, this, &OptionsPopup::actionChanged);
- m_checkboxMap.insert(action, checkbox);
- return checkbox;
-}
-
} // namespace Internal
} // namespace Core
diff --git a/src/plugins/coreplugin/find/findtoolbar.h b/src/plugins/coreplugin/find/findtoolbar.h
index 8d6a9b77a4..f2fb494905 100644
--- a/src/plugins/coreplugin/find/findtoolbar.h
+++ b/src/plugins/coreplugin/find/findtoolbar.h
@@ -43,25 +43,6 @@ class FindToolBarPlaceHolder;
namespace Internal {
-class OptionsPopup : public QWidget
-{
- Q_OBJECT
-
-public:
- explicit OptionsPopup(QWidget *parent);
-
-protected:
- bool event(QEvent *ev) override;
- bool eventFilter(QObject *obj, QEvent *ev) override;
-
-private:
- void actionChanged();
-
- QCheckBox *createCheckboxForCommand(Id id);
-
- QMap<QAction *, QCheckBox *> m_checkboxMap;
-};
-
class FindToolBar : public Utils::StyledBar
{
Q_OBJECT
diff --git a/src/plugins/coreplugin/find/findtoolwindow.cpp b/src/plugins/coreplugin/find/findtoolwindow.cpp
index 04f138a151..0490e8481f 100644
--- a/src/plugins/coreplugin/find/findtoolwindow.cpp
+++ b/src/plugins/coreplugin/find/findtoolwindow.cpp
@@ -77,14 +77,13 @@ FindToolWindow::FindToolWindow(QWidget *parent)
connect(m_ui.matchCase, &QAbstractButton::toggled, Find::instance(), &Find::setCaseSensitive);
connect(m_ui.wholeWords, &QAbstractButton::toggled, Find::instance(), &Find::setWholeWord);
connect(m_ui.regExp, &QAbstractButton::toggled, Find::instance(), &Find::setRegularExpression);
- connect(m_ui.filterList, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
- this, static_cast<void (FindToolWindow::*)(int)>(&FindToolWindow::setCurrentFilter));
+ connect(m_ui.filterList, QOverload<int>::of(&QComboBox::activated),
+ this, QOverload<int>::of(&FindToolWindow::setCurrentFilter));
m_findCompleter->setModel(Find::findCompletionModel());
m_ui.searchTerm->setSpecialCompleter(m_findCompleter);
m_ui.searchTerm->installEventFilter(this);
- connect(m_findCompleter,
- static_cast<void (QCompleter::*)(const QModelIndex &)>(&QCompleter::activated),
+ connect(m_findCompleter, QOverload<const QModelIndex &>::of(&QCompleter::activated),
this, &FindToolWindow::findCompleterActivated);
m_ui.searchTerm->setValidationFunction(validateRegExp);
diff --git a/src/plugins/coreplugin/find/highlightscrollbarcontroller.cpp b/src/plugins/coreplugin/find/highlightscrollbarcontroller.cpp
index 2ea32798de..b9d07b70da 100644
--- a/src/plugins/coreplugin/find/highlightscrollbarcontroller.cpp
+++ b/src/plugins/coreplugin/find/highlightscrollbarcontroller.cpp
@@ -92,7 +92,7 @@ void HighlightScrollBarOverlay::scheduleUpdate()
return;
m_isCacheUpdateScheduled = true;
- QTimer::singleShot(0, this, static_cast<void (QWidget::*)()>(&QWidget::update));
+ QTimer::singleShot(0, this, QOverload<>::of(&QWidget::update));
}
void HighlightScrollBarOverlay::paintEvent(QPaintEvent *paintEvent)
diff --git a/src/plugins/coreplugin/find/optionspopup.cpp b/src/plugins/coreplugin/find/optionspopup.cpp
new file mode 100644
index 0000000000..d7274f87e0
--- /dev/null
+++ b/src/plugins/coreplugin/find/optionspopup.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "optionspopup.h"
+
+#include <coreplugin/actionmanager/actionmanager.h>
+
+#include <utils/qtcassert.h>
+
+#include <QAction>
+#include <QCheckBox>
+#include <QEvent>
+#include <QKeyEvent>
+#include <QVBoxLayout>
+
+namespace Core {
+
+OptionsPopup::OptionsPopup(QWidget *parent, const QVector<Id> &commands)
+ : QWidget(parent, Qt::Popup)
+{
+ setAttribute(Qt::WA_DeleteOnClose);
+ auto layout = new QVBoxLayout(this);
+ layout->setContentsMargins(2, 2, 2, 2);
+ layout->setSpacing(2);
+ setLayout(layout);
+
+ bool first = true;
+ for (const Id &command : commands) {
+ QCheckBox *checkBox = createCheckboxForCommand(command);
+ if (first) {
+ checkBox->setFocus();
+ first = false;
+ }
+ layout->addWidget(checkBox);
+ }
+ move(parent->mapToGlobal(QPoint(0, -sizeHint().height())));
+}
+
+bool OptionsPopup::event(QEvent *ev)
+{
+ if (ev->type() == QEvent::ShortcutOverride) {
+ auto ke = static_cast<QKeyEvent *>(ev);
+ if (ke->key() == Qt::Key_Escape && !ke->modifiers()) {
+ ev->accept();
+ return true;
+ }
+ }
+ return QWidget::event(ev);
+}
+
+bool OptionsPopup::eventFilter(QObject *obj, QEvent *ev)
+{
+ auto checkbox = qobject_cast<QCheckBox *>(obj);
+ if (ev->type() == QEvent::KeyPress && checkbox) {
+ auto ke = static_cast<QKeyEvent *>(ev);
+ if (!ke->modifiers() && (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return)) {
+ checkbox->click();
+ ev->accept();
+ return true;
+ }
+ }
+ return QWidget::eventFilter(obj, ev);
+}
+
+void OptionsPopup::actionChanged()
+{
+ auto action = qobject_cast<QAction *>(sender());
+ QTC_ASSERT(action, return);
+ QCheckBox *checkbox = m_checkboxMap.value(action);
+ QTC_ASSERT(checkbox, return);
+ checkbox->setEnabled(action->isEnabled());
+}
+
+QCheckBox *OptionsPopup::createCheckboxForCommand(Id id)
+{
+ QAction *action = ActionManager::command(id)->action();
+ QCheckBox *checkbox = new QCheckBox(action->text());
+ checkbox->setToolTip(action->toolTip());
+ checkbox->setChecked(action->isChecked());
+ checkbox->setEnabled(action->isEnabled());
+ checkbox->installEventFilter(this); // enter key handling
+ QObject::connect(checkbox, &QCheckBox::clicked, action, &QAction::setChecked);
+ QObject::connect(action, &QAction::changed, this, &OptionsPopup::actionChanged);
+ m_checkboxMap.insert(action, checkbox);
+ return checkbox;
+}
+
+} // namespace Core
diff --git a/src/plugins/coreplugin/find/optionspopup.h b/src/plugins/coreplugin/find/optionspopup.h
new file mode 100644
index 0000000000..003280eb36
--- /dev/null
+++ b/src/plugins/coreplugin/find/optionspopup.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <coreplugin/id.h>
+
+#include <QMap>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QCheckBox;
+QT_END_NAMESPACE
+
+namespace Core {
+
+class CORE_EXPORT OptionsPopup : public QWidget
+{
+ Q_OBJECT
+
+public:
+ OptionsPopup(QWidget *parent, const QVector<Id> &commands);
+
+protected:
+ bool event(QEvent *ev) override;
+ bool eventFilter(QObject *obj, QEvent *ev) override;
+
+private:
+ void actionChanged();
+
+ QCheckBox *createCheckboxForCommand(Id id);
+
+ QMap<QAction *, QCheckBox *> m_checkboxMap;
+};
+
+} // namespace Core
diff --git a/src/plugins/coreplugin/find/searchresulttreeitemdelegate.cpp b/src/plugins/coreplugin/find/searchresulttreeitemdelegate.cpp
index 81ec2541c6..9351387c5b 100644
--- a/src/plugins/coreplugin/find/searchresulttreeitemdelegate.cpp
+++ b/src/plugins/coreplugin/find/searchresulttreeitemdelegate.cpp
@@ -40,59 +40,101 @@ SearchResultTreeItemDelegate::SearchResultTreeItemDelegate(int tabWidth, QObject
setTabWidth(tabWidth);
}
-void SearchResultTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
-{
- static const int iconSize = 16;
+const int lineNumberAreaHorizontalPadding = 4;
+const int minimumLineNumberDigits = 6;
- painter->save();
+static std::pair<int, QString> lineNumberInfo(const QStyleOptionViewItem &option,
+ const QModelIndex &index)
+{
+ const int lineNumber = index.data(ItemDataRoles::ResultBeginLineNumberRole).toInt();
+ if (lineNumber < 1)
+ return {0, {}};
+ const QString lineNumberText = QString::number(lineNumber);
+ const int lineNumberDigits = qMax(minimumLineNumberDigits, lineNumberText.count());
+ const int fontWidth = option.fontMetrics.horizontalAdvance(QString(lineNumberDigits, QLatin1Char('0')));
+ const QStyle *style = option.widget ? option.widget->style() : QApplication::style();
+ return {lineNumberAreaHorizontalPadding + fontWidth + lineNumberAreaHorizontalPadding
+ + style->pixelMetric(QStyle::PM_FocusFrameHMargin),
+ lineNumberText};
+}
- QStyleOptionViewItem opt = setOptions(index, option);
- painter->setFont(opt.font);
+static QString itemText(const QModelIndex &index)
+{
+ const QString text = index.data(Qt::DisplayRole).toString();
+ // show number of subresults in displayString
+ if (index.model()->hasChildren(index)) {
+ return text + QLatin1String(" (") + QString::number(index.model()->rowCount(index))
+ + QLatin1Char(')');
+ }
+ return text;
+}
- QItemDelegate::drawBackground(painter, opt, index);
+LayoutInfo SearchResultTreeItemDelegate::getLayoutInfo(const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ static const int iconSize = 16;
- // ---- do the layout
- QRect checkRect;
- QRect pixmapRect;
- QRect textRect;
+ LayoutInfo info;
+ info.option = setOptions(index, option);
// check mark
- bool checkable = (index.model()->flags(index) & Qt::ItemIsUserCheckable);
- Qt::CheckState checkState = Qt::Unchecked;
+ const bool checkable = (index.model()->flags(index) & Qt::ItemIsUserCheckable);
+ info.checkState = Qt::Unchecked;
if (checkable) {
QVariant checkStateData = index.data(Qt::CheckStateRole);
- checkState = static_cast<Qt::CheckState>(checkStateData.toInt());
- checkRect = doCheck(opt, opt.rect, checkStateData);
+ info.checkState = static_cast<Qt::CheckState>(checkStateData.toInt());
+ info.checkRect = doCheck(info.option, info.option.rect, checkStateData);
}
// icon
- QIcon icon = index.model()->data(index, ItemDataRoles::ResultIconRole).value<QIcon>();
- if (!icon.isNull()) {
- const QSize size = icon.actualSize(QSize(iconSize, iconSize));
- pixmapRect = QRect(0, 0, size.width(), size.height());
+ info.icon = index.data(ItemDataRoles::ResultIconRole).value<QIcon>();
+ if (!info.icon.isNull()) {
+ const QSize size = info.icon.actualSize(QSize(iconSize, iconSize));
+ info.pixmapRect = QRect(0, 0, size.width(), size.height());
}
// text
- textRect = opt.rect.adjusted(0, 0, checkRect.width() + pixmapRect.width(), 0);
+ info.textRect = info.option.rect.adjusted(0,
+ 0,
+ info.checkRect.width() + info.pixmapRect.width(),
+ 0);
+
+ // do basic layout
+ doLayout(info.option, &info.checkRect, &info.pixmapRect, &info.textRect, false);
+
+ // adapt for line numbers
+ const int lineNumberWidth = lineNumberInfo(info.option, index).first;
+ info.lineNumberRect = info.textRect;
+ info.lineNumberRect.setWidth(lineNumberWidth);
+ info.textRect.adjust(lineNumberWidth, 0, 0, 0);
+ return info;
+}
+
+void SearchResultTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ painter->save();
+
+ const LayoutInfo info = getLayoutInfo(option, index);
+
+ painter->setFont(info.option.font);
+
+ QItemDelegate::drawBackground(painter, info.option, index);
- // do layout
- doLayout(opt, &checkRect, &pixmapRect, &textRect, false);
// ---- draw the items
// icon
- if (!icon.isNull())
- icon.paint(painter, pixmapRect, option.decorationAlignment);
+ if (!info.icon.isNull())
+ info.icon.paint(painter, info.pixmapRect, info.option.decorationAlignment);
// line numbers
- int lineNumberAreaWidth = drawLineNumber(painter, opt, textRect, index);
- textRect.adjust(lineNumberAreaWidth, 0, 0, 0);
+ drawLineNumber(painter, info.option, info.lineNumberRect, index);
// text and focus/selection
- drawText(painter, opt, textRect, index);
- QItemDelegate::drawFocus(painter, opt, opt.rect);
+ drawText(painter, info.option, info.textRect, index);
+ QItemDelegate::drawFocus(painter, info.option, info.option.rect);
// check mark
- if (checkable)
- QItemDelegate::drawCheck(painter, opt, checkRect, checkState);
+ if (info.checkRect.isValid())
+ QItemDelegate::drawCheck(painter, info.option, info.checkRect, info.checkState);
painter->restore();
}
@@ -102,22 +144,31 @@ void SearchResultTreeItemDelegate::setTabWidth(int width)
m_tabString = QString(width, QLatin1Char(' '));
}
+QSize SearchResultTreeItemDelegate::sizeHint(const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ const LayoutInfo info = getLayoutInfo(option, index);
+ const int height = index.data(Qt::SizeHintRole).value<QSize>().height();
+ // get text width, see QItemDelegatePrivate::displayRect
+ const QString text = itemText(index).replace('\t', m_tabString);
+ const QRect textMaxRect(0, 0, INT_MAX / 256, height);
+ const QRect textLayoutRect = textRectangle(nullptr, textMaxRect, info.option.font, text);
+ const QRect textRect(info.textRect.x(), info.textRect.y(), textLayoutRect.width(), height);
+ const QRect layoutRect = info.checkRect | info.pixmapRect | info.lineNumberRect | textRect;
+ return QSize(layoutRect.x(), layoutRect.y()) + layoutRect.size();
+}
+
// returns the width of the line number area
int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyleOptionViewItem &option,
const QRect &rect,
const QModelIndex &index) const
{
- static const int lineNumberAreaHorizontalPadding = 4;
- int lineNumber = index.model()->data(index, ItemDataRoles::ResultBeginLineNumberRole).toInt();
- if (lineNumber < 1)
- return 0;
const bool isSelected = option.state & QStyle::State_Selected;
- QString lineText = QString::number(lineNumber);
- int minimumLineNumberDigits = qMax((int)m_minimumLineNumberDigits, lineText.count());
- int fontWidth = painter->fontMetrics().width(QString(minimumLineNumberDigits, QLatin1Char('0')));
- int lineNumberAreaWidth = lineNumberAreaHorizontalPadding + fontWidth + lineNumberAreaHorizontalPadding;
+ const std::pair<int, QString> numberInfo = lineNumberInfo(option, index);
+ if (numberInfo.first == 0)
+ return 0;
QRect lineNumberAreaRect(rect);
- lineNumberAreaRect.setWidth(lineNumberAreaWidth);
+ lineNumberAreaRect.setWidth(numberInfo.first);
QPalette::ColorGroup cg = QPalette::Normal;
if (!(option.state & QStyle::State_Active))
@@ -137,9 +188,9 @@ int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyle
const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, nullptr) + 1;
const QRect rowRect = lineNumberAreaRect.adjusted(-textMargin, 0, textMargin-lineNumberAreaHorizontalPadding, 0);
- QItemDelegate::drawDisplay(painter, opt, rowRect, lineText);
+ QItemDelegate::drawDisplay(painter, opt, rowRect, numberInfo.second);
- return lineNumberAreaWidth;
+ return numberInfo.first;
}
void SearchResultTreeItemDelegate::drawText(QPainter *painter,
@@ -147,18 +198,15 @@ void SearchResultTreeItemDelegate::drawText(QPainter *painter,
const QRect &rect,
const QModelIndex &index) const
{
- QString text = index.model()->data(index, Qt::DisplayRole).toString();
- // show number of subresults in displayString
- if (index.model()->hasChildren(index)) {
- text += QLatin1String(" (")
- + QString::number(index.model()->rowCount(index))
- + QLatin1Char(')');
- }
+ const QString text = itemText(index);
const int searchTermStart = index.model()->data(index, ItemDataRoles::ResultBeginColumnNumberRole).toInt();
int searchTermLength = index.model()->data(index, ItemDataRoles::SearchTermLengthRole).toInt();
if (searchTermStart < 0 || searchTermStart >= text.length() || searchTermLength < 1) {
- QItemDelegate::drawDisplay(painter, option, rect, text.replace(QLatin1Char('\t'), m_tabString));
+ QItemDelegate::drawDisplay(painter,
+ option,
+ rect,
+ QString(text).replace(QLatin1Char('\t'), m_tabString));
return;
}
@@ -168,8 +216,8 @@ void SearchResultTreeItemDelegate::drawText(QPainter *painter,
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);
+ int searchTermStartPixels = painter->fontMetrics().horizontalAdvance(textBefore);
+ int searchTermLengthPixels = painter->fontMetrics().horizontalAdvance(textHighlight);
// rects
QRect beforeHighlightRect(rect);
diff --git a/src/plugins/coreplugin/find/searchresulttreeitemdelegate.h b/src/plugins/coreplugin/find/searchresulttreeitemdelegate.h
index 0551e4c8d7..edb13e98ed 100644
--- a/src/plugins/coreplugin/find/searchresulttreeitemdelegate.h
+++ b/src/plugins/coreplugin/find/searchresulttreeitemdelegate.h
@@ -30,20 +30,31 @@
namespace Core {
namespace Internal {
+struct LayoutInfo
+{
+ QRect checkRect;
+ QRect pixmapRect;
+ QRect textRect;
+ QRect lineNumberRect;
+ QIcon icon;
+ Qt::CheckState checkState;
+ QStyleOptionViewItem option;
+};
+
class SearchResultTreeItemDelegate: public QItemDelegate
{
public:
SearchResultTreeItemDelegate(int tabWidth, QObject *parent = nullptr);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void setTabWidth(int width);
-
+ QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
private:
+ LayoutInfo getLayoutInfo(const QStyleOptionViewItem &option, const QModelIndex &index) const;
int drawLineNumber(QPainter *painter, const QStyleOptionViewItem &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;
};
} // namespace Internal
diff --git a/src/plugins/coreplugin/find/searchresulttreemodel.cpp b/src/plugins/coreplugin/find/searchresulttreemodel.cpp
index 150e9dcc09..3fba0f899d 100644
--- a/src/plugins/coreplugin/find/searchresulttreemodel.cpp
+++ b/src/plugins/coreplugin/find/searchresulttreemodel.cpp
@@ -258,7 +258,7 @@ QVariant SearchResultTreeModel::data(const SearchResultTreeItem *row, int role)
result = row->item.text;
break;
case ItemDataRoles::ResultItemRole:
- result = qVariantFromValue(row->item);
+ result = QVariant::fromValue(row->item);
break;
case ItemDataRoles::ResultBeginLineNumberRole:
result = row->item.mainRange.begin.line;
diff --git a/src/plugins/coreplugin/find/searchresulttreeview.cpp b/src/plugins/coreplugin/find/searchresulttreeview.cpp
index 0ca09fcefd..48d1845053 100644
--- a/src/plugins/coreplugin/find/searchresulttreeview.cpp
+++ b/src/plugins/coreplugin/find/searchresulttreeview.cpp
@@ -44,6 +44,8 @@ SearchResultTreeView::SearchResultTreeView(QWidget *parent)
setIndentation(14);
setUniformRowHeights(true);
setExpandsOnDoubleClick(true);
+ header()->setSectionResizeMode(QHeaderView::ResizeToContents);
+ header()->setStretchLastSection(false);
header()->hide();
connect(this, &SearchResultTreeView::activated,
@@ -93,6 +95,13 @@ void SearchResultTreeView::keyPressEvent(QKeyEvent *event)
TreeView::keyPressEvent(event);
}
+bool SearchResultTreeView::event(QEvent *e)
+{
+ if (e->type() == QEvent::Resize)
+ header()->setMinimumSectionSize(width());
+ return TreeView::event(e);
+}
+
void SearchResultTreeView::emitJumpToSearchResult(const QModelIndex &index)
{
if (model()->data(index, ItemDataRoles::IsGeneratedRole).toBool())
diff --git a/src/plugins/coreplugin/find/searchresulttreeview.h b/src/plugins/coreplugin/find/searchresulttreeview.h
index eb11d29a7d..4809a6887b 100644
--- a/src/plugins/coreplugin/find/searchresulttreeview.h
+++ b/src/plugins/coreplugin/find/searchresulttreeview.h
@@ -50,6 +50,7 @@ public:
void addResults(const QList<SearchResultItem> &items, SearchResult::AddMode mode);
void keyPressEvent(QKeyEvent *event) override;
+ bool event(QEvent *e) override;
signals:
void jumpToSearchResult(const SearchResultItem &item);
diff --git a/src/plugins/coreplugin/find/searchresultwidget.cpp b/src/plugins/coreplugin/find/searchresultwidget.cpp
index 9428a31a1d..5827885802 100644
--- a/src/plugins/coreplugin/find/searchresultwidget.cpp
+++ b/src/plugins/coreplugin/find/searchresultwidget.cpp
@@ -72,8 +72,8 @@ public:
QSize sizeHint() const override
{
QSize sh = QLineEdit::minimumSizeHint();
- sh.rwidth() += qMax(25 * fontMetrics().width(QLatin1Char('x')),
- fontMetrics().width(text()));
+ sh.rwidth() += qMax(25 * fontMetrics().horizontalAdvance(QLatin1Char('x')),
+ fontMetrics().horizontalAdvance(text()));
return sh;
}
};
diff --git a/src/plugins/coreplugin/find/searchresultwindow.cpp b/src/plugins/coreplugin/find/searchresultwindow.cpp
index 7cea0166d1..ec723c8928 100644
--- a/src/plugins/coreplugin/find/searchresultwindow.cpp
+++ b/src/plugins/coreplugin/find/searchresultwindow.cpp
@@ -124,7 +124,7 @@ namespace Internal {
m_recentSearchesBox->setProperty("drawleftborder", true);
m_recentSearchesBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
m_recentSearchesBox->addItem(tr("New Search"));
- connect(m_recentSearchesBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
+ connect(m_recentSearchesBox, QOverload<int>::of(&QComboBox::activated),
this, &SearchResultWindowPrivate::setCurrentIndexWithFocus);
m_widget->setWindowTitle(q->displayName());
@@ -135,7 +135,6 @@ namespace Internal {
m_widget->addWidget(newSearchArea);
m_expandCollapseButton = new QToolButton(m_widget);
- m_expandCollapseButton->setAutoRaise(true);
m_expandCollapseAction->setCheckable(true);
m_expandCollapseAction->setIcon(Utils::Icons::EXPAND_ALL_TOOLBAR.icon());
@@ -167,11 +166,13 @@ namespace Internal {
if (focus)
m_widget->currentWidget()->setFocus();
m_expandCollapseAction->setEnabled(false);
+ m_newSearchButton->setEnabled(false);
} else {
if (focus)
m_searchResultWidgets.at(visibleSearchIndex())->setFocusInternally();
m_searchResultWidgets.at(visibleSearchIndex())->notifyVisibilityChanged(true);
m_expandCollapseAction->setEnabled(true);
+ m_newSearchButton->setEnabled(true);
}
q->navigateStateChanged();
}