Core: Inline findwidget.ui

A lot of unusual stuff where LayoutBuilder doesn't shine...

Change-Id: I06259e0913fade2d70ebfbab3f438cb8f7e96bf3
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2022-09-29 12:12:29 +02:00
parent 01ddb61ab7
commit 38f88f6310
6 changed files with 238 additions and 400 deletions

View File

@@ -67,7 +67,6 @@ add_qtc_plugin(Core
find/findplugin.cpp find/findplugin.h
find/findtoolbar.cpp find/findtoolbar.h
find/findtoolwindow.cpp find/findtoolwindow.h
find/findwidget.ui
find/highlightscrollbarcontroller.cpp find/highlightscrollbarcontroller.h
find/ifindfilter.cpp find/ifindfilter.h
find/ifindsupport.cpp find/ifindsupport.h

View File

@@ -298,7 +298,6 @@ Project {
"findtoolbar.h",
"findtoolwindow.cpp",
"findtoolwindow.h",
"findwidget.ui",
"highlightscrollbarcontroller.cpp",
"highlightscrollbarcontroller.h",
"ifindfilter.cpp",

View File

@@ -23,6 +23,7 @@
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QApplication>
#include <QMenu>
#include <QStringListModel>
#include <QVector>

View File

@@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "findtoolbar.h"
#include "ifindfilter.h"
#include "findplugin.h"
#include "optionspopup.h"
@@ -16,31 +17,40 @@
#include <coreplugin/findplaceholder.h>
#include <utils/hostosinfo.h>
#include <utils/fancylineedit.h>
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
#include <utils/stylehelper.h>
#include <utils/theme/theme.h>
#include <utils/utilsicons.h>
#include <QDebug>
#include <QSettings>
#include <QAbstractItemView>
#include <QApplication>
#include <QCheckBox>
#include <QClipboard>
#include <QCompleter>
#include <QDebug>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QKeyEvent>
#include <QLabel>
#include <QMenu>
#include <QPainter>
#include <QSettings>
#include <QSpacerItem>
#include <QStringListModel>
#include <QToolButton>
#include <QVBoxLayout>
Q_DECLARE_METATYPE(QStringList)
Q_DECLARE_METATYPE(Core::IFindFilter*)
static const int MINIMUM_WIDTH_FOR_COMPLEX_LAYOUT = 150;
static const int FINDBUTTON_SPACER_WIDTH = 20;
using namespace Utils;
namespace Core {
namespace Internal {
namespace Core::Internal {
const int MINIMUM_WIDTH_FOR_COMPLEX_LAYOUT = 150;
const int FINDBUTTON_SPACER_WIDTH = 20;
FindToolBar::FindToolBar(CurrentDocumentFind *currentDocumentFind)
: m_currentDocumentFind(currentDocumentFind),
@@ -49,80 +59,176 @@ FindToolBar::FindToolBar(CurrentDocumentFind *currentDocumentFind)
m_findIncrementalTimer(this),
m_findStepTimer(this)
{
//setup ui
m_ui.setupUi(this);
// compensate for a vertically expanding spacer below the label
m_ui.replaceLabel->setMinimumHeight(m_ui.replaceEdit->sizeHint().height());
m_ui.mainLayout->setColumnStretch(1, 10);
setWindowTitle(QCoreApplication::translate("Core::Internal::FindWidget", "Find", nullptr));
setFocusProxy(m_ui.findEdit);
m_findLabel = new QLabel;
m_findLabel->setText(QCoreApplication::translate("Core::Internal::FindWidget", "Find:", nullptr));
m_findEdit = new FancyLineEdit;
m_findEdit->setMinimumWidth(100);
m_findEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
m_findPreviousButton = new QToolButton;
m_findNextButton = new QToolButton;
m_selectAllButton = new QToolButton;
m_horizontalSpacer = new QSpacerItem(40, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
m_close = new QToolButton;
auto findButtonsWidget = new QWidget;
m_findButtonLayout = new QHBoxLayout(findButtonsWidget);
m_findButtonLayout->setSpacing(3);
m_findButtonLayout->setContentsMargins(0, 0, 0, 0);
m_findButtonLayout->addWidget(m_findPreviousButton);
m_findButtonLayout->addWidget(m_findNextButton);
m_findButtonLayout->addWidget(m_selectAllButton);
m_findButtonLayout->addItem(m_horizontalSpacer);
m_findButtonLayout->addWidget(m_close);
m_replaceEdit = new FancyLineEdit(this);
m_replaceEdit->setMinimumWidth(100);
m_replaceEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
m_replaceEdit->setFiltering(true);
m_replaceLabel = new QLabel;
m_replaceLabel->setText(QCoreApplication::translate("Core::Internal::FindWidget", "Replace with:"));
// compensate for a vertically expanding spacer below the label
m_replaceLabel->setMinimumHeight(m_replaceEdit->sizeHint().height());
m_replaceButtonsWidget = new QWidget;
m_replaceButtonsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_replaceButton = new QToolButton;
m_replaceButton->setText(QCoreApplication::translate("Core::Internal::FindWidget", "Replace"));
m_replaceButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
m_replaceButton->setArrowType(Qt::LeftArrow);
m_replaceNextButton = new QToolButton;
m_replaceNextButton->setText(QCoreApplication::translate("Core::Internal::FindWidget", "Replace && Find"));
m_replaceNextButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
m_replaceNextButton->setArrowType(Qt::RightArrow);
m_replaceAllButton = new QToolButton;
m_replaceAllButton->setText(QCoreApplication::translate("Core::Internal::FindWidget", "Replace All"));
m_replaceAllButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
m_advancedButton = new QToolButton;
m_advancedButton->setText(QCoreApplication::translate("Core::Internal::FindWidget", "Advanced..."));
m_advancedButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
QWidget::setTabOrder(m_findEdit, m_replaceEdit);
QWidget::setTabOrder(m_replaceEdit, m_findPreviousButton);
QWidget::setTabOrder(m_findPreviousButton, m_findNextButton);
QWidget::setTabOrder(m_findNextButton, m_replaceButton);
QWidget::setTabOrder(m_replaceButton, m_replaceNextButton);
QWidget::setTabOrder(m_replaceNextButton, m_replaceAllButton);
QWidget::setTabOrder(m_replaceAllButton, m_advancedButton);
QWidget::setTabOrder(m_advancedButton, m_close);
auto replaceButtonsLayout = new QHBoxLayout(m_replaceButtonsWidget);
replaceButtonsLayout->setSpacing(3);
replaceButtonsLayout->setContentsMargins(0, 0, 0, 0);
replaceButtonsLayout->addWidget(m_replaceButton);
replaceButtonsLayout->addWidget(m_replaceNextButton);
replaceButtonsLayout->addWidget(m_replaceAllButton);
auto verticalLayout_3 = new QVBoxLayout();
verticalLayout_3->setSpacing(0);
verticalLayout_3->addWidget(m_advancedButton);
verticalLayout_3->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
auto gridLayout = new QGridLayout();
gridLayout->setHorizontalSpacing(3);
gridLayout->setVerticalSpacing(0);
gridLayout->addWidget(m_replaceButtonsWidget, 0, 0, 1, 1);
gridLayout->addLayout(verticalLayout_3, 0, 1, 1, 1);
using namespace Layouting;
Grid {
m_findLabel,
m_findEdit,
findButtonsWidget,
br,
Column { m_replaceLabel, st }.setSpacing(0),
Column { m_replaceEdit, st }.setSpacing(0),
gridLayout,
}.attachTo(this);
auto mainLayout = static_cast<QGridLayout *>(layout());
mainLayout->setHorizontalSpacing(3);
mainLayout->setVerticalSpacing(1);
mainLayout->setContentsMargins(5, 2, 0, 1);
mainLayout->setColumnStretch(1, 10);
setFocusProxy(m_findEdit);
setProperty("topBorder", true);
setSingleRow(false);
m_ui.findEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
m_ui.replaceEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
m_ui.replaceEdit->setFiltering(true);
connect(m_ui.findEdit, &Utils::FancyLineEdit::editingFinished,
connect(m_findEdit, &Utils::FancyLineEdit::editingFinished,
this, &FindToolBar::invokeResetIncrementalSearch);
connect(m_ui.findEdit, &Utils::FancyLineEdit::textChanged,
connect(m_findEdit, &Utils::FancyLineEdit::textChanged,
this, &FindToolBar::updateFindReplaceEnabled);
connect(m_ui.close, &QToolButton::clicked,
connect(m_close, &QToolButton::clicked,
this, &FindToolBar::hideAndResetFocus);
m_findCompleter->setModel(Find::findCompletionModel());
m_replaceCompleter->setModel(Find::replaceCompletionModel());
m_ui.findEdit->setSpecialCompleter(m_findCompleter);
m_ui.replaceEdit->setSpecialCompleter(m_replaceCompleter);
m_findEdit->setSpecialCompleter(m_findCompleter);
m_replaceEdit->setSpecialCompleter(m_replaceCompleter);
m_ui.findEdit->setButtonVisible(Utils::FancyLineEdit::Left, true);
m_ui.findEdit->setFiltering(true);
m_ui.findEdit->setPlaceholderText(QString());
m_ui.findEdit->button(Utils::FancyLineEdit::Left)->setFocusPolicy(Qt::TabFocus);
m_ui.findEdit->setValidationFunction([this](Utils::FancyLineEdit *, QString *) {
m_findEdit->setButtonVisible(Utils::FancyLineEdit::Left, true);
m_findEdit->setFiltering(true);
m_findEdit->setPlaceholderText(QString());
m_findEdit->button(Utils::FancyLineEdit::Left)->setFocusPolicy(Qt::TabFocus);
m_findEdit->setValidationFunction([this](Utils::FancyLineEdit *, QString *) {
return m_lastResult != IFindSupport::NotFound;
});
m_ui.replaceEdit->setPlaceholderText(QString());
m_replaceEdit->setPlaceholderText(QString());
connect(m_ui.findEdit, &Utils::FancyLineEdit::textChanged,
connect(m_findEdit, &Utils::FancyLineEdit::textChanged,
this, &FindToolBar::invokeFindIncremental);
connect(m_ui.findEdit, &Utils::FancyLineEdit::leftButtonClicked,
connect(m_findEdit, &Utils::FancyLineEdit::leftButtonClicked,
this, &FindToolBar::findEditButtonClicked);
// invoke{Find,Replace}Helper change the completion model. QueuedConnection is used to perform these
// changes only after the completer's activated() signal is handled (QTCREATORBUG-8408)
connect(m_ui.findEdit, &Utils::FancyLineEdit::returnPressed,
connect(m_findEdit, &Utils::FancyLineEdit::returnPressed,
this, &FindToolBar::invokeFindEnter, Qt::QueuedConnection);
connect(m_ui.replaceEdit, &Utils::FancyLineEdit::returnPressed,
connect(m_replaceEdit, &Utils::FancyLineEdit::returnPressed,
this, &FindToolBar::invokeReplaceEnter, Qt::QueuedConnection);
connect(m_findCompleter, QOverload<const QModelIndex &>::of(&QCompleter::activated),
this, &FindToolBar::findCompleterActivated);
auto shiftEnterAction = new QAction(m_ui.findEdit);
auto shiftEnterAction = new QAction(m_findEdit);
shiftEnterAction->setShortcut(QKeySequence(tr("Shift+Enter")));
shiftEnterAction->setShortcutContext(Qt::WidgetShortcut);
connect(shiftEnterAction, &QAction::triggered,
this, &FindToolBar::invokeFindPrevious);
m_ui.findEdit->addAction(shiftEnterAction);
auto shiftReturnAction = new QAction(m_ui.findEdit);
m_findEdit->addAction(shiftEnterAction);
auto shiftReturnAction = new QAction(m_findEdit);
shiftReturnAction->setShortcut(QKeySequence(tr("Shift+Return")));
shiftReturnAction->setShortcutContext(Qt::WidgetShortcut);
connect(shiftReturnAction, &QAction::triggered,
this, &FindToolBar::invokeFindPrevious);
m_ui.findEdit->addAction(shiftReturnAction);
m_findEdit->addAction(shiftReturnAction);
auto shiftEnterReplaceAction = new QAction(m_ui.replaceEdit);
auto shiftEnterReplaceAction = new QAction(m_replaceEdit);
shiftEnterReplaceAction->setShortcut(QKeySequence(tr("Shift+Enter")));
shiftEnterReplaceAction->setShortcutContext(Qt::WidgetShortcut);
connect(shiftEnterReplaceAction, &QAction::triggered,
this, &FindToolBar::invokeReplacePrevious);
m_ui.replaceEdit->addAction(shiftEnterReplaceAction);
auto shiftReturnReplaceAction = new QAction(m_ui.replaceEdit);
m_replaceEdit->addAction(shiftEnterReplaceAction);
auto shiftReturnReplaceAction = new QAction(m_replaceEdit);
shiftReturnReplaceAction->setShortcut(QKeySequence(tr("Shift+Return")));
shiftReturnReplaceAction->setShortcutContext(Qt::WidgetShortcut);
connect(shiftReturnReplaceAction, &QAction::triggered,
this, &FindToolBar::invokeReplacePrevious);
m_ui.replaceEdit->addAction(shiftReturnReplaceAction);
m_replaceEdit->addAction(shiftReturnReplaceAction);
// need to make sure QStringList is registered as metatype
QMetaTypeId<QStringList>::qt_metatype_id();
@@ -137,9 +243,9 @@ FindToolBar::FindToolBar(CurrentDocumentFind *currentDocumentFind)
Command *advancedCmd = ActionManager::command(Constants::ADVANCED_FIND);
if (advancedCmd)
advancedCmd->augmentActionWithShortcutToolTip(advancedAction);
m_ui.advancedButton->setDefaultAction(advancedAction);
m_advancedButton->setDefaultAction(advancedAction);
connect(advancedAction, &QAction::triggered, this, [this] {
Find::openFindDialog(nullptr, m_ui.findEdit->text());
Find::openFindDialog(nullptr, m_findEdit->text());
});
m_goToCurrentFindAction = new QAction(this);
@@ -182,7 +288,7 @@ FindToolBar::FindToolBar(CurrentDocumentFind *currentDocumentFind)
cmd = ActionManager::registerAction(m_localFindNextAction, Constants::FIND_NEXT, findcontext);
cmd->augmentActionWithShortcutToolTip(m_localFindNextAction);
connect(m_localFindNextAction, &QAction::triggered, this, &FindToolBar::invokeFindNext);
m_ui.findNextButton->setDefaultAction(m_localFindNextAction);
m_findNextButton->setDefaultAction(m_localFindNextAction);
m_findPreviousAction = new QAction(tr("Find Previous"), this);
cmd = ActionManager::registerAction(m_findPreviousAction, Constants::FIND_PREVIOUS);
@@ -193,7 +299,7 @@ FindToolBar::FindToolBar(CurrentDocumentFind *currentDocumentFind)
cmd = ActionManager::registerAction(m_localFindPreviousAction, Constants::FIND_PREVIOUS, findcontext);
cmd->augmentActionWithShortcutToolTip(m_localFindPreviousAction);
connect(m_localFindPreviousAction, &QAction::triggered, this, &FindToolBar::invokeFindPrevious);
m_ui.findPreviousButton->setDefaultAction(m_localFindPreviousAction);
m_findPreviousButton->setDefaultAction(m_localFindPreviousAction);
m_findNextSelectedAction = new QAction(tr("Find Next (Selected)"), this);
cmd = ActionManager::registerAction(m_findNextSelectedAction, Constants::FIND_NEXT_SELECTED);
@@ -217,7 +323,7 @@ FindToolBar::FindToolBar(CurrentDocumentFind *currentDocumentFind)
cmd = ActionManager::registerAction(m_localSelectAllAction, Constants::FIND_SELECT_ALL, findcontext);
cmd->augmentActionWithShortcutToolTip(m_localSelectAllAction);
connect(m_localSelectAllAction, &QAction::triggered, this, &FindToolBar::selectAll);
m_ui.selectAllButton->setDefaultAction(m_localSelectAllAction);
m_selectAllButton->setDefaultAction(m_localSelectAllAction);
m_replaceAction = new QAction(tr("Replace"), this);
cmd = ActionManager::registerAction(m_replaceAction, Constants::REPLACE);
@@ -228,7 +334,7 @@ FindToolBar::FindToolBar(CurrentDocumentFind *currentDocumentFind)
cmd = ActionManager::registerAction(m_localReplaceAction, Constants::REPLACE, findcontext);
cmd->augmentActionWithShortcutToolTip(m_localReplaceAction);
connect(m_localReplaceAction, &QAction::triggered, this, &FindToolBar::invokeReplace);
m_ui.replaceButton->setDefaultAction(m_localReplaceAction);
m_replaceButton->setDefaultAction(m_localReplaceAction);
m_replaceNextAction = new QAction(tr("Replace && Find"), this);
cmd = ActionManager::registerAction(m_replaceNextAction, Constants::REPLACE_NEXT);
@@ -240,7 +346,7 @@ FindToolBar::FindToolBar(CurrentDocumentFind *currentDocumentFind)
cmd = ActionManager::registerAction(m_localReplaceNextAction, Constants::REPLACE_NEXT, findcontext);
cmd->augmentActionWithShortcutToolTip(m_localReplaceNextAction);
connect(m_localReplaceNextAction, &QAction::triggered, this, &FindToolBar::invokeReplaceNext);
m_ui.replaceNextButton->setDefaultAction(m_localReplaceNextAction);
m_replaceNextButton->setDefaultAction(m_localReplaceNextAction);
m_replacePreviousAction = new QAction(tr("Replace && Find Previous"), this);
cmd = ActionManager::registerAction(m_replacePreviousAction, Constants::REPLACE_PREVIOUS);
@@ -261,7 +367,7 @@ FindToolBar::FindToolBar(CurrentDocumentFind *currentDocumentFind)
cmd = ActionManager::registerAction(m_localReplaceAllAction, Constants::REPLACE_ALL, findcontext);
cmd->augmentActionWithShortcutToolTip(m_localReplaceAllAction);
connect(m_localReplaceAllAction, &QAction::triggered, this, &FindToolBar::invokeReplaceAll);
m_ui.replaceAllButton->setDefaultAction(m_localReplaceAllAction);
m_replaceAllButton->setDefaultAction(m_localReplaceAllAction);
m_caseSensitiveAction = new QAction(tr("Case Sensitive"), this);
m_caseSensitiveAction->setIcon(Icons::FIND_CASE_INSENSITIVELY.icon());
@@ -328,8 +434,8 @@ void FindToolBar::installEventFilters()
{
if (!m_eventFiltersInstalled) {
m_findCompleter->popup()->installEventFilter(this);
m_ui.findEdit->installEventFilter(this);
m_ui.replaceEdit->installEventFilter(this);
m_findEdit->installEventFilter(this);
m_replaceEdit->installEventFilter(this);
this->installEventFilter(this);
m_eventFiltersInstalled = true;
}
@@ -340,19 +446,19 @@ bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
if (event->type() == QEvent::KeyPress) {
auto ke = static_cast<QKeyEvent *>(event);
if (ke->key() == Qt::Key_Down) {
if (obj == m_ui.findEdit) {
if (m_ui.findEdit->text().isEmpty())
if (obj == m_findEdit) {
if (m_findEdit->text().isEmpty())
m_findCompleter->setCompletionPrefix(QString());
m_findCompleter->complete();
} else if (obj == m_ui.replaceEdit) {
if (m_ui.replaceEdit->text().isEmpty())
} else if (obj == m_replaceEdit) {
if (m_replaceEdit->text().isEmpty())
m_replaceCompleter->setCompletionPrefix(QString());
m_replaceCompleter->complete();
}
}
}
if ((obj == m_ui.findEdit || obj == m_findCompleter->popup())
if ((obj == m_findEdit || obj == m_findCompleter->popup())
&& event->type() == QEvent::KeyPress) {
auto ke = static_cast<QKeyEvent *>(event);
if (ke->key() == Qt::Key_Space && (ke->modifiers() & Utils::HostOsInfo::controlModifier())) {
@@ -413,34 +519,34 @@ void FindToolBar::updateToolBar()
m_wholeWordAction->setEnabled(enabled);
m_regularExpressionAction->setEnabled(enabled);
m_preserveCaseAction->setEnabled(replaceEnabled && !hasFindFlag(FindRegularExpression));
bool replaceFocus = m_ui.replaceEdit->hasFocus();
bool replaceFocus = m_replaceEdit->hasFocus();
m_ui.findLabel->setEnabled(enabled);
m_ui.findLabel->setVisible(showAllControls);
m_ui.findEdit->setEnabled(enabled);
m_ui.findEdit->setPlaceholderText(showAllControls ? QString() : tr("Search for..."));
m_ui.findPreviousButton->setEnabled(enabled);
m_ui.findPreviousButton->setVisible(showAllControls);
m_ui.findNextButton->setEnabled(enabled);
m_ui.findNextButton->setVisible(showAllControls);
m_ui.selectAllButton->setVisible(style == ControlStyle::Text
m_findLabel->setEnabled(enabled);
m_findLabel->setVisible(showAllControls);
m_findEdit->setEnabled(enabled);
m_findEdit->setPlaceholderText(showAllControls ? QString() : tr("Search for..."));
m_findPreviousButton->setEnabled(enabled);
m_findPreviousButton->setVisible(showAllControls);
m_findNextButton->setEnabled(enabled);
m_findNextButton->setVisible(showAllControls);
m_selectAllButton->setVisible(style == ControlStyle::Text
&& m_currentDocumentFind->supportsSelectAll());
m_ui.horizontalSpacer->changeSize((showAllControls ? FINDBUTTON_SPACER_WIDTH : 0), 0,
m_horizontalSpacer->changeSize((showAllControls ? FINDBUTTON_SPACER_WIDTH : 0), 0,
QSizePolicy::Expanding, QSizePolicy::Ignored);
m_ui.findButtonLayout->invalidate(); // apply spacer change
m_findButtonLayout->invalidate(); // apply spacer change
m_ui.replaceLabel->setEnabled(replaceEnabled);
m_ui.replaceLabel->setVisible(replaceEnabled && showAllControls);
m_ui.replaceEdit->setEnabled(replaceEnabled);
m_ui.replaceEdit->setPlaceholderText(showAllControls ? QString() : tr("Replace with..."));
m_ui.replaceEdit->setVisible(replaceEnabled);
m_ui.replaceButtonsWidget->setVisible(replaceEnabled && showAllControls);
m_ui.advancedButton->setVisible(replaceEnabled && showAllControls);
m_replaceLabel->setEnabled(replaceEnabled);
m_replaceLabel->setVisible(replaceEnabled && showAllControls);
m_replaceEdit->setEnabled(replaceEnabled);
m_replaceEdit->setPlaceholderText(showAllControls ? QString() : tr("Replace with..."));
m_replaceEdit->setVisible(replaceEnabled);
m_replaceButtonsWidget->setVisible(replaceEnabled && showAllControls);
m_advancedButton->setVisible(replaceEnabled && showAllControls);
layout()->invalidate();
if (!replaceEnabled && enabled && replaceFocus)
m_ui.findEdit->setFocus();
m_findEdit->setFocus();
updateIcons();
updateFlagMenus();
}
@@ -502,29 +608,29 @@ void FindToolBar::invokeGlobalFindPrevious()
QString FindToolBar::getFindText()
{
return m_ui.findEdit->text();
return m_findEdit->text();
}
QString FindToolBar::getReplaceText()
{
return m_ui.replaceEdit->text();
return m_replaceEdit->text();
}
void FindToolBar::setFindText(const QString &text)
{
disconnect(m_ui.findEdit, &Utils::FancyLineEdit::textChanged,
disconnect(m_findEdit, &Utils::FancyLineEdit::textChanged,
this, &FindToolBar::invokeFindIncremental);
if (hasFindFlag(FindRegularExpression))
m_ui.findEdit->setText(QRegularExpression::escape(text));
m_findEdit->setText(QRegularExpression::escape(text));
else
m_ui.findEdit->setText(text);
connect(m_ui.findEdit, &Utils::FancyLineEdit::textChanged,
m_findEdit->setText(text);
connect(m_findEdit, &Utils::FancyLineEdit::textChanged,
this, &FindToolBar::invokeFindIncremental);
}
void FindToolBar::selectFindText()
{
m_ui.findEdit->selectAll();
m_findEdit->selectAll();
}
void FindToolBar::invokeFindStep()
@@ -644,7 +750,7 @@ void FindToolBar::putSelectionToFindClipboard()
void FindToolBar::updateFromFindClipboard()
{
if (QApplication::clipboard()->supportsFindBuffer()) {
QSignalBlocker blocker(m_ui.findEdit);
QSignalBlocker blocker(m_findEdit);
setFindText(QApplication::clipboard()->text(QClipboard::FindBuffer));
}
}
@@ -660,7 +766,7 @@ void FindToolBar::findFlagsChanged()
void FindToolBar::findEditButtonClicked()
{
auto popup = new OptionsPopup(m_ui.findEdit, {Constants::CASE_SENSITIVE, Constants::WHOLE_WORDS,
auto popup = new OptionsPopup(m_findEdit, {Constants::CASE_SENSITIVE, Constants::WHOLE_WORDS,
Constants::REGULAR_EXPRESSIONS, Constants::PRESERVE_CASE});
popup->show();
}
@@ -674,9 +780,9 @@ void FindToolBar::updateIcons()
bool preserveCase = effectiveFlags & FindPreserveCase;
if (!casesensitive && !wholewords && !regexp && !preserveCase) {
const QIcon icon = Utils::Icons::MAGNIFIER.icon();
m_ui.findEdit->setButtonIcon(Utils::FancyLineEdit::Left, icon);
m_findEdit->setButtonIcon(Utils::FancyLineEdit::Left, icon);
} else {
m_ui.findEdit->setButtonIcon(Utils::FancyLineEdit::Left,
m_findEdit->setButtonIcon(Utils::FancyLineEdit::Left,
IFindFilter::pixmapForFindFlags(effectiveFlags));
}
}
@@ -754,27 +860,27 @@ bool FindToolBar::toolBarHasFocus() const
FindToolBar::ControlStyle FindToolBar::controlStyle(bool replaceIsVisible)
{
const Qt::ToolButtonStyle currentFindButtonStyle = m_ui.findNextButton->toolButtonStyle();
const Qt::ToolButtonStyle currentFindButtonStyle = m_findNextButton->toolButtonStyle();
const int fullWidth = width();
if (replaceIsVisible) {
// Since the replace buttons do not collapse to icons, they have precedence, here.
const int replaceFixedWidth = m_ui.replaceLabel->sizeHint().width()
+ m_ui.replaceButton->sizeHint().width()
+ m_ui.replaceNextButton->sizeHint().width()
+ m_ui.replaceAllButton->sizeHint().width()
+ m_ui.advancedButton->sizeHint().width();
const int replaceFixedWidth = m_replaceLabel->sizeHint().width()
+ m_replaceButton->sizeHint().width()
+ m_replaceNextButton->sizeHint().width()
+ m_replaceAllButton->sizeHint().width()
+ m_advancedButton->sizeHint().width();
return fullWidth - replaceFixedWidth >= MINIMUM_WIDTH_FOR_COMPLEX_LAYOUT ?
ControlStyle::Text : ControlStyle::Hidden;
}
const auto findWidth = [this] {
const int selectAllWidth = m_currentDocumentFind->supportsSelectAll() ?
m_ui.selectAllButton->sizeHint().width() : 0;
return m_ui.findLabel->sizeHint().width() + m_ui.findNextButton->sizeHint().width()
+ m_ui.findPreviousButton->sizeHint().width()
m_selectAllButton->sizeHint().width() : 0;
return m_findLabel->sizeHint().width() + m_findNextButton->sizeHint().width()
+ m_findPreviousButton->sizeHint().width()
+ selectAllWidth + FINDBUTTON_SPACER_WIDTH
+ m_ui.close->sizeHint().width();
+ m_close->sizeHint().width();
};
setFindButtonStyle(Qt::ToolButtonTextOnly);
const int findWithTextWidth = findWidth();
@@ -791,8 +897,8 @@ FindToolBar::ControlStyle FindToolBar::controlStyle(bool replaceIsVisible)
void FindToolBar::setFindButtonStyle(Qt::ToolButtonStyle style)
{
m_ui.findPreviousButton->setToolButtonStyle(style);
m_ui.findNextButton->setToolButtonStyle(style);
m_findPreviousButton->setToolButtonStyle(style);
m_findNextButton->setToolButtonStyle(style);
}
/*!
@@ -819,7 +925,7 @@ void FindToolBar::acceptCandidateAndMoveToolBar()
void FindToolBar::indicateSearchState(IFindSupport::Result searchState)
{
m_lastResult = searchState;
m_ui.findEdit->validate();
m_findEdit->validate();
}
void FindToolBar::openFind(bool focus)
@@ -888,15 +994,15 @@ void FindToolBar::selectAll()
bool FindToolBar::focusNextPrevChild(bool next)
{
QAbstractButton *optionsButton = m_ui.findEdit->button(Utils::FancyLineEdit::Left);
QAbstractButton *optionsButton = m_findEdit->button(Utils::FancyLineEdit::Left);
// close tab order
if (next && m_ui.advancedButton->hasFocus())
if (next && m_advancedButton->hasFocus())
optionsButton->setFocus(Qt::TabFocusReason);
else if (next && optionsButton->hasFocus())
m_ui.findEdit->setFocus(Qt::TabFocusReason);
m_findEdit->setFocus(Qt::TabFocusReason);
else if (!next && optionsButton->hasFocus())
m_ui.advancedButton->setFocus(Qt::TabFocusReason);
else if (!next && m_ui.findEdit->hasFocus())
m_advancedButton->setFocus(Qt::TabFocusReason);
else if (!next && m_findEdit->hasFocus())
optionsButton->setFocus(Qt::TabFocusReason);
else
return Utils::StyledBar::focusNextPrevChild(next);
@@ -1005,7 +1111,7 @@ void FindToolBar::setLightColoredIcon(bool lightColored)
: Utils::Icons::NEXT_TOOLBAR.icon());
m_localFindPreviousAction->setIcon(lightColored ? Utils::Icons::PREV.icon()
: Utils::Icons::PREV_TOOLBAR.icon());
m_ui.close->setIcon(lightColored ? Utils::Icons::CLOSE_FOREGROUND.icon()
m_close->setIcon(lightColored ? Utils::Icons::CLOSE_FOREGROUND.icon()
: Utils::Icons::CLOSE_TOOLBAR.icon());
}
@@ -1040,5 +1146,4 @@ void FindToolBar::updateReplaceEnabled()
m_replacePreviousAction->setEnabled(globalsEnabled);
}
} // namespace Internal
} // namespace Core
} // Core::Internal

View File

@@ -3,7 +3,6 @@
#pragma once
#include "ui_findwidget.h"
#include "currentdocumentfind.h"
#include <utils/id.h>
@@ -11,6 +10,16 @@
#include <QTimer>
QT_BEGIN_NAMESPACE
class QCompleter;
class QHBoxLayout;
class QLabel;
class QSpacerItem;
class QToolButton;
QT_END_NAMESPACE
namespace Utils { class FancyLineEdit; }
namespace Core {
class FindToolBarPlaceHolder;
@@ -122,7 +131,7 @@ private:
void updateReplaceEnabled();
CurrentDocumentFind *m_currentDocumentFind = nullptr;
Ui::FindWidget m_ui;
QCompleter *m_findCompleter = nullptr;
QCompleter *m_replaceCompleter = nullptr;
QAction *m_goToCurrentFindAction = nullptr;
@@ -150,6 +159,21 @@ private:
QAction *m_localReplacePreviousAction = nullptr;
QAction *m_localReplaceAllAction = nullptr;
QLabel *m_findLabel;
Utils::FancyLineEdit *m_findEdit;
QHBoxLayout *m_findButtonLayout;
QToolButton *m_findPreviousButton;
QToolButton *m_findNextButton;
QToolButton *m_selectAllButton;
QSpacerItem *m_horizontalSpacer;
QToolButton *m_close;
QLabel *m_replaceLabel;
Utils::FancyLineEdit *m_replaceEdit;
QWidget *m_replaceButtonsWidget;
QToolButton *m_replaceButton;
QToolButton *m_replaceNextButton;
QToolButton *m_replaceAllButton;
QToolButton *m_advancedButton;
FindFlags m_findFlags;
QTimer m_findIncrementalTimer;

View File

@@ -1,290 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Core::Internal::FindWidget</class>
<widget class="QWidget" name="Core::Internal::FindWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>681</width>
<height>88</height>
</rect>
</property>
<property name="windowTitle">
<string>Find</string>
</property>
<layout class="QGridLayout" name="mainLayout">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<property name="horizontalSpacing">
<number>3</number>
</property>
<property name="verticalSpacing">
<number>1</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="findLabel">
<property name="text">
<string>Find:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Utils::FancyLineEdit" name="findEdit">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QWidget" name="findButtonsWidget" native="true">
<layout class="QHBoxLayout" name="findButtonLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="findPreviousButton"/>
</item>
<item>
<widget class="QToolButton" name="findNextButton"/>
</item>
<item>
<widget class="QToolButton" name="selectAllButton">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="close"/>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="replaceLabel">
<property name="text">
<string>Replace with:</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="Utils::FancyLineEdit" name="replaceEdit">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="2">
<layout class="QGridLayout" name="gridLayout">
<property name="horizontalSpacing">
<number>3</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QWidget" name="replaceButtonsWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="replaceButtonsLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="replaceButton">
<property name="text">
<string>Replace</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
<property name="arrowType">
<enum>Qt::LeftArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="replaceNextButton">
<property name="font">
<font/>
</property>
<property name="text">
<string>Replace &amp;&amp; Find</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
<property name="arrowType">
<enum>Qt::RightArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="replaceAllButton">
<property name="font">
<font/>
</property>
<property name="text">
<string>Replace All</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="advancedButton">
<property name="text">
<string>Advanced...</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::FancyLineEdit</class>
<extends>QLineEdit</extends>
<header location="global">utils/fancylineedit.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>findEdit</tabstop>
<tabstop>replaceEdit</tabstop>
<tabstop>findPreviousButton</tabstop>
<tabstop>findNextButton</tabstop>
<tabstop>replaceButton</tabstop>
<tabstop>replaceNextButton</tabstop>
<tabstop>replaceAllButton</tabstop>
<tabstop>advancedButton</tabstop>
<tabstop>close</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>