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))
32 lay->addWidget(label);
33 const int marg1 = lay->contentsMargins().
left();
34 const int marg2 = lay->contentsMargins().
right();
35 lay->setContentsMargins(marg1, 0, marg2, 0);
37 mReplace->setClearButtonEnabled(
true);
38 lay->addWidget(mReplace);
40 mReplace->setObjectName(QStringLiteral(
"mReplace"));
41 mReplaceBtn->setObjectName(QStringLiteral(
"mReplaceBtn"));
42 mReplaceAllBtn->setObjectName(QStringLiteral(
"mReplaceAllBtn"));
45 lay->addWidget(mReplaceBtn);
48 lay->addWidget(mReplaceAllBtn);
51TextReplaceWidget::~TextReplaceWidget() =
default;
53QLineEdit *TextReplaceWidget::replaceLineEdit()
const
58void TextReplaceWidget::slotSearchStringEmpty(
bool isEmpty)
61 mReplaceAllBtn->setDisabled(isEmpty);
64TextFindWidget::TextFindWidget(QWidget *parent)
66 , mSearch(new QLineEdit(this))
67 , mFindPrevBtn(new QPushButton(QIcon::fromTheme(QStringLiteral(
"go-up-search")),
i18nc(
"Find and go to the previous search match",
"Previous"), this))
68 , mFindNextBtn(new QPushButton(QIcon::fromTheme(QStringLiteral(
"go-down-search")),
i18nc(
"Find and go to the next search match",
"Next"), this))
71 const int marg1 = lay->contentsMargins().left();
72 const int marg2 = lay->contentsMargins().right();
73 lay->setContentsMargins(marg1, 0, marg2, 0);
76 lay->addWidget(label);
78 mSearch->setToolTip(
i18nc(
"@info:tooltip",
"Text to search for"));
79 mSearch->setClearButtonEnabled(
true);
80 mSearch->setObjectName(QStringLiteral(
"mSearch"));
81 label->setBuddy(mSearch);
82 lay->addWidget(mSearch);
84 mFindNextBtn->setToolTip(
i18nc(
"@info:tooltip",
"Jump to next match"));
85 lay->addWidget(mFindNextBtn);
86 mFindNextBtn->setEnabled(
false);
87 mFindNextBtn->setObjectName(QStringLiteral(
"mFindNextBtn"));
89 mFindPrevBtn->setToolTip(
i18nc(
"@info:tooltip",
"Jump to previous match"));
90 lay->addWidget(mFindPrevBtn);
91 mFindPrevBtn->setEnabled(
false);
92 mFindPrevBtn->setObjectName(QStringLiteral(
"mFindPrevBtn"));
95 optionsBtn->setText(
i18n(
"Options"));
96 optionsBtn->setToolTip(
i18nc(
"@info:tooltip",
"Modify search behavior"));
97 optionsBtn->setObjectName(QStringLiteral(
"optionsBtn"));
98 auto optionsMenu =
new QMenu(optionsBtn);
99 mCaseSensitiveAct = optionsMenu->addAction(
i18n(
"Case sensitive"));
100 mCaseSensitiveAct->setCheckable(
true);
102 mWholeWordAct = optionsMenu->addAction(
i18n(
"Whole word"));
103 mWholeWordAct->setCheckable(
true);
105 mRegularExpressionAct = optionsMenu->addAction(
i18n(
"Regular Expression"));
106 mRegularExpressionAct->setCheckable(
true);
108 mRespectDiacriticAct = optionsMenu->addAction(
i18n(
"Respect Diacritic and Accents"));
109 mRespectDiacriticAct->setCheckable(
true);
110 mRespectDiacriticAct->setChecked(
true);
112 optionsBtn->setMenu(optionsMenu);
113 lay->addWidget(optionsBtn);
125TextFindWidget::~TextFindWidget() =
default;
127void TextFindWidget::slotRegularExpressionChanged(
bool b)
129 mRespectDiacriticAct->setEnabled(!b);
130 Q_EMIT updateSearchOptions();
133void TextFindWidget::setFoundMatch(
bool match)
135#ifndef QT_NO_STYLE_STYLESHEET
138 if (!mSearch->text().isEmpty()) {
149 styleSheet = QStringLiteral(
"QLineEdit{ background-color:%1 }").arg(bgBrush.brush(mSearch->palette()).color().name());
156void TextFindWidget::slotAutoSearch(
const QString &str)
158 const bool isNotEmpty = (!str.
isEmpty());
159 mFindPrevBtn->setEnabled(isNotEmpty);
160 mFindNextBtn->setEnabled(isNotEmpty);
161 Q_EMIT searchStringEmpty(!isNotEmpty);
168QLineEdit *TextFindWidget::searchLineEdit()
const
173bool TextFindWidget::isRegularExpression()
const
175 return mRegularExpressionAct->isChecked();
178QString TextFindWidget::searchText()
const
180 return mSearch->text();
183QRegularExpression TextFindWidget::searchRegularExpression()
const
185 QRegularExpression reg;
186 if (!mCaseSensitiveAct->isChecked()) {
189 QString searchTextString = mSearch->text();
190 if (mWholeWordAct->isChecked()) {
191 searchTextString =
"\\b"_L1 + searchTextString +
"\\b"_L1;
197TextEditFindBarBase::FindFlags TextFindWidget::searchOptions()
const
199 TextEditFindBarBase::FindFlags opt = {};
200 if (mCaseSensitiveAct->isChecked()) {
201 opt |= TextEditFindBarBase::FindCaseSensitively;
203 if (mWholeWordAct->isChecked()) {
204 opt |= TextEditFindBarBase::FindWholeWords;
206 if (mRespectDiacriticAct->isChecked()) {
207 opt |= TextEditFindBarBase::FindRespectDiacritics;
212#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)
void toggled(bool checked)
void textChanged(const QString &text)
void setPattern(const QString &pattern)
void setPatternOptions(PatternOptions options)
bool isEmpty() const const
QString left(qsizetype n) const const
QString right(qsizetype n) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)