7#include "textfindreplacewidget.h"
8#include <KStatefulBrush>
10#include <KColorScheme>
11#include <KLocalizedString>
18#include <QRegularExpression>
21using namespace TextCustomEditor;
23TextReplaceWidget::TextReplaceWidget(
QWidget *parent)
27 , mReplaceAllBtn(new
QPushButton(
i18nc(
"@action:button",
"Replace All"), this))
31 lay->addWidget(label);
32 const int marg1 = lay->contentsMargins().left();
33 const int marg2 = lay->contentsMargins().right();
34 lay->setContentsMargins(marg1, 0, marg2, 0);
36 mReplace->setClearButtonEnabled(
true);
37 lay->addWidget(mReplace);
39 mReplace->setObjectName(QStringLiteral(
"mReplace"));
40 mReplaceBtn->setObjectName(QStringLiteral(
"mReplaceBtn"));
41 mReplaceAllBtn->setObjectName(QStringLiteral(
"mReplaceAllBtn"));
44 lay->addWidget(mReplaceBtn);
47 lay->addWidget(mReplaceAllBtn);
50TextReplaceWidget::~TextReplaceWidget() =
default;
52QLineEdit *TextReplaceWidget::replaceLineEdit()
const
57void TextReplaceWidget::slotSearchStringEmpty(
bool isEmpty)
63TextFindWidget::TextFindWidget(
QWidget *parent)
66 , mFindPrevBtn(new
QPushButton(
QIcon::fromTheme(QStringLiteral(
"go-up-search")),
i18nc(
"Find and go to the previous search match",
"Previous"), this))
67 , mFindNextBtn(new
QPushButton(
QIcon::fromTheme(QStringLiteral(
"go-down-search")),
i18nc(
"Find and go to the next search match",
"Next"), this))
70 const int marg1 = lay->contentsMargins().left();
71 const int marg2 = lay->contentsMargins().right();
72 lay->setContentsMargins(marg1, 0, marg2, 0);
74 lay->addWidget(label);
76 mSearch->setToolTip(
i18nc(
"@info:tooltip",
"Text to search for"));
77 mSearch->setClearButtonEnabled(
true);
78 mSearch->setObjectName(QStringLiteral(
"mSearch"));
79 label->setBuddy(mSearch);
80 lay->addWidget(mSearch);
82 mFindNextBtn->setToolTip(
i18nc(
"@info:tooltip",
"Jump to next match"));
83 lay->addWidget(mFindNextBtn);
84 mFindNextBtn->setEnabled(
false);
85 mFindNextBtn->setObjectName(QStringLiteral(
"mFindNextBtn"));
87 mFindPrevBtn->setToolTip(
i18nc(
"@info:tooltip",
"Jump to previous match"));
88 lay->addWidget(mFindPrevBtn);
89 mFindPrevBtn->setEnabled(
false);
90 mFindPrevBtn->setObjectName(QStringLiteral(
"mFindPrevBtn"));
93 optionsBtn->setText(
i18n(
"Options"));
94 optionsBtn->setToolTip(
i18nc(
"@info:tooltip",
"Modify search behavior"));
95 optionsBtn->setObjectName(QStringLiteral(
"optionsBtn"));
96 auto optionsMenu =
new QMenu(optionsBtn);
97 mCaseSensitiveAct = optionsMenu->addAction(
i18n(
"Case sensitive"));
98 mCaseSensitiveAct->setCheckable(
true);
100 mWholeWordAct = optionsMenu->addAction(
i18n(
"Whole word"));
101 mWholeWordAct->setCheckable(
true);
103 mRegularExpressionAct = optionsMenu->addAction(
i18n(
"Regular Expression"));
104 mRegularExpressionAct->setCheckable(
true);
106 mRespectDiacriticAct = optionsMenu->addAction(
i18n(
"Respect Diacritic and Accents"));
107 mRespectDiacriticAct->setCheckable(
true);
108 mRespectDiacriticAct->setChecked(
true);
110 optionsBtn->setMenu(optionsMenu);
111 lay->addWidget(optionsBtn);
123TextFindWidget::~TextFindWidget() =
default;
125void TextFindWidget::slotRegularExpressionChanged(
bool b)
128 Q_EMIT updateSearchOptions();
131void TextFindWidget::setFoundMatch(
bool match)
133#ifndef QT_NO_STYLE_STYLESHEET
136 if (!mSearch->
text().isEmpty()) {
147 styleSheet = QStringLiteral(
"QLineEdit{ background-color:%1 }").arg(bgBrush.brush(mSearch->
palette()).color().name());
154void TextFindWidget::slotAutoSearch(
const QString &str)
156 const bool isNotEmpty = (!str.
isEmpty());
159 Q_EMIT searchStringEmpty(!isNotEmpty);
166QLineEdit *TextFindWidget::searchLineEdit()
const
171bool TextFindWidget::isRegularExpression()
const
173 return mRegularExpressionAct->
isChecked();
176QString TextFindWidget::searchText()
const
178 return mSearch->
text();
189 searchTextString =
"\\b"_L1 + searchTextString +
"\\b"_L1;
199 opt |= TextEditFindBarBase::FindCaseSensitively;
202 opt |= TextEditFindBarBase::FindWholeWords;
205 opt |= TextEditFindBarBase::FindRespectDiacritics;
210#include "moc_textfindreplacewidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QString label(StandardShortcut id)
bool isChecked() const const
void toggled(bool checked)
void textChanged(const QString &text)
void setPattern(const QString &pattern)
void setPatternOptions(PatternOptions options)
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)