7#include "texteditfindbarbase.h"
10#include "textcustomeditor_debug.h"
11#include "widgets/textfindreplacewidget.h"
12#include <KLocalizedString>
22using namespace TextCustomEditor;
24TextEditFindBarBase::TextEditFindBarBase(
QWidget *parent)
26 , mFindWidget(new TextFindWidget(this))
27 , mReplaceWidget(new TextReplaceWidget(this))
35 closeBtn->setIconSize(
QSize(16, 16));
36 closeBtn->setToolTip(
i18nc(
"@info:tooltip",
"Close"));
38#ifndef QT_NO_ACCESSIBILITY
39 closeBtn->setAccessibleName(
i18n(
"Close"));
42 closeBtn->setAutoRaise(
true);
43 lay->addWidget(closeBtn);
45 lay->addWidget(mFindWidget);
47 topLayout->addWidget(mReplaceWidget);
48 mReplaceWidget->hide();
51 connect(mFindWidget, &TextFindWidget::findNext,
this, &TextEditFindBarBase::findNext);
52 connect(mFindWidget, &TextFindWidget::findPrev,
this, &TextEditFindBarBase::findPrev);
53 connect(mFindWidget, &TextFindWidget::updateSearchOptions,
this, &TextEditFindBarBase::slotUpdateSearchOptions);
54 connect(mFindWidget, &TextFindWidget::autoSearch,
this, &TextEditFindBarBase::autoSearch);
55 connect(mFindWidget, &TextFindWidget::clearSearch,
this, &TextEditFindBarBase::slotClearSearch);
56 connect(mFindWidget, &TextFindWidget::searchStringEmpty, mReplaceWidget, &TextReplaceWidget::slotSearchStringEmpty);
57 connect(mReplaceWidget, &TextReplaceWidget::replaceText,
this, &TextEditFindBarBase::slotReplaceText);
58 connect(mReplaceWidget, &TextReplaceWidget::replaceAllText,
this, &TextEditFindBarBase::slotReplaceAllText);
63TextEditFindBarBase::~TextEditFindBarBase() =
default;
65void TextEditFindBarBase::showFind()
67 if (documentIsEmpty()) {
70 mReplaceWidget->slotSearchStringEmpty(mFindWidget->searchText().
isEmpty());
73 mReplaceWidget->
hide();
78void TextEditFindBarBase::setHideWhenClose(
bool hide)
80 mHideWhenClose =
hide;
83void TextEditFindBarBase::showReplace()
85 if (viewIsReadOnly()) {
88 if (documentIsEmpty()) {
91 mReplaceWidget->slotSearchStringEmpty(mFindWidget->searchText().
isEmpty());
94 mReplaceWidget->
show();
99void TextEditFindBarBase::setText(
const QString &text)
101 mFindWidget->searchLineEdit()->
setText(text);
104QString TextEditFindBarBase::text()
const
106 return mFindWidget->searchText();
109void TextEditFindBarBase::focusAndSetCursor()
112 mFindWidget->searchLineEdit()->
selectAll();
113 mFindWidget->searchLineEdit()->
setFocus();
116void TextEditFindBarBase::slotClearSearch()
121void TextEditFindBarBase::autoSearch(
const QString &str)
123 const bool isNotEmpty = (!str.
isEmpty());
133void TextEditFindBarBase::messageInfo(
bool backward,
bool isAutoSearch,
bool found)
136 if (!found && !isAutoSearch) {
142 Q_EMIT displayMessageIndicator(
i18n(
"End of message reached.\nPhrase '%1' could not be found.", str));
146bool TextEditFindBarBase::searchText(
bool backward,
bool isAutoSearch)
148 mLastSearchStr = mFindWidget->searchText();
149 mLastSearchRegExp = mFindWidget->searchRegularExpression();
152 searchOptions |= TextEditFindBarBase::FindBackward;
156 autoSearchMoveCursor();
157 }
else if (mFindWidget->isRegularExpression()) {
164 if (mFindWidget->isRegularExpression()) {
165 found = searchInDocument(mLastSearchRegExp, searchOptions);
167 found = searchInDocument(mLastSearchStr, searchOptions);
169 mFindWidget->setFoundMatch(found);
170 messageInfo(backward, isAutoSearch, found);
174void TextEditFindBarBase::findNext()
176 searchText(
false,
false);
179void TextEditFindBarBase::findPrev()
181 searchText(
true,
false);
184void TextEditFindBarBase::slotUpdateSearchOptions()
187 mLastSearchStr = mFindWidget->searchText();
188 mLastSearchRegExp = mFindWidget->searchRegularExpression();
189 if (mFindWidget->isRegularExpression()) {
190 searchInDocument(mLastSearchRegExp, searchOptions);
192 searchInDocument(mLastSearchStr, searchOptions);
196void TextEditFindBarBase::clearSelections()
198 mFindWidget->setFoundMatch(
false);
201void TextEditFindBarBase::closeBar()
207 mReplaceWidget->
hide();
209 if (mHideWhenClose) {
215bool TextEditFindBarBase::event(
QEvent *e)
225 if (shortCutOverride) {
234 if (shortCutOverride) {
237 if (mFindWidget->searchText().
isEmpty()) {
252#include "moc_texteditfindbarbase.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void addLayout(QLayout *layout, int stretch)
QIcon fromTheme(const QString &name)
void setText(const QString &)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype length() const const
void truncate(qsizetype position)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)