8#include "quicksearchline.h"
9#include "messagelistsettings.h"
10#include <KStringHandler>
12#include "core/filter.h"
13#include "searchlinestatus.h"
14#include "searchstatusbuttons.h"
15#include <KLocalizedString>
17#include "core/widgets/searchlinecommandwidget.h"
22#include <QStandardPaths>
24QuickSearchLine::QuickSearchLine(
QWidget *parent)
26 , mSearchEdit(new SearchLineStatus(this))
27 , mSearchStatusButtons(new SearchStatusButtons(this))
28 , mSearchMessageByButtons(new SearchMessageByButtons(this))
29 , mSearchLineCommandWidget(new SearchLineCommandWidget(this))
33 vbox->setContentsMargins({});
38 hbox->setContentsMargins({});
42 vbox->addWidget(mSearchMessageByButtons);
43 mSearchMessageByButtons->setVisible(
false);
44 vbox->addWidget(mSearchLineCommandWidget);
45 mSearchLineCommandWidget->setVisible(
false);
46 connect(mSearchEdit, &SearchLineStatus::searchCommandActionRequested,
this, [
this]() {
47 mSearchLineCommandWidget->setVisible(!mSearchLineCommandWidget->isVisible());
49 connect(mSearchLineCommandWidget, &SearchLineCommandWidget::insertCommand, mSearchEdit, &SearchLineStatus::slotInsertCommand);
52 MessageList::Core::SearchLineCommand c;
53 c.parseSearchLineCommand(str);
54 mSearchLineCommandWidget->setLabel(c.generateCommadLineStr());
57 connect(mSearchEdit, &SearchLineStatus::forceLostFocus,
this, &QuickSearchLine::forceLostFocus);
58 mSearchEdit->setPlaceholderText(
i18nc(
"Search for messages.",
"Search"));
60 mSearchEdit->setClearButtonEnabled(
true);
61 connect(mSearchMessageByButtons, &SearchMessageByButtons::searchOptionChanged,
this, [
this]() {
62 mSearchEdit->filterAdded();
63 Q_EMIT searchOptionChanged();
67 connect(mSearchEdit, &SearchLineStatus::clearButtonClicked,
this, &QuickSearchLine::slotClearButtonClicked);
68 connect(mSearchEdit, &SearchLineStatus::saveFilter,
this, &QuickSearchLine::saveFilter);
69 connect(mSearchEdit, &SearchLineStatus::activateFilter,
this, &QuickSearchLine::activateFilter);
71 hbox->addWidget(mSearchEdit);
73 hbox->addWidget(mSearchStatusButtons);
74 connect(mSearchStatusButtons, &SearchStatusButtons::filterStatusChanged,
this, &QuickSearchLine::slotFilterActionChanged);
78 mTagFilterCombo->setMaximumWidth(300);
79 mTagFilterCombo->setMaximumWidth(200);
80 mTagFilterCombo->hide();
81 hbox->addWidget(mTagFilterCombo);
84 mSearchEdit->setEnabled(
false);
85 mTagFilterCombo->setEnabled(
false);
87 installEventFilter(
this);
88 mTagFilterCombo->installEventFilter(
this);
89 changeQuicksearchVisibility(MessageListSettings::self()->showQuickSearch());
92QuickSearchLine::~QuickSearchLine() =
default;
94void QuickSearchLine::slotSearchEditTextEdited(
const QString &text)
96 int minimumStringLength = 3;
98 minimumStringLength = 5;
100 if (!text.trimmed().
isEmpty()) {
103 Q_EMIT searchEditTextEdited(text);
106 slotClearButtonClicked();
110void QuickSearchLine::slotClearButtonClicked()
115 mSearchEdit->clearFilterButtonClicked();
116 mSearchStatusButtons->clearFilter();
117 mSearchMessageByButtons->clearFilter();
119 Q_EMIT clearButtonClicked();
124 mSearchMessageByButtons->setSearchOptions(opts);
126 mSearchEdit->filterAdded();
131 return mSearchMessageByButtons->searchOptions();
134void QuickSearchLine::focusQuickSearch(
const QString &selectedText)
137 mSearchEdit->
setText(selectedText);
142QComboBox *QuickSearchLine::tagFilterComboBox()
const
144 return mTagFilterCombo;
147SearchLineStatus *QuickSearchLine::searchEdit()
const
152void QuickSearchLine::resetFilter()
157 mSearchEdit->clearFilterButtonClicked();
158 mSearchEdit->setLocked(
false);
159 mSearchStatusButtons->clearFilter();
165 mSearchEdit->filterAdded();
166 Q_EMIT statusButtonsClicked();
171 mLstStatus = newLstStatus;
172 mSearchEdit->filterAdded();
173 mSearchStatusButtons->setFilterMessageStatus(mLstStatus);
181bool QuickSearchLine::containsOutboundMessages()
const
183 return mSearchMessageByButtons->containsOutboundMessages();
186void QuickSearchLine::setContainsOutboundMessages(
bool containsOutboundMessages)
188 mSearchMessageByButtons->setContainsOutboundMessages(containsOutboundMessages);
191void QuickSearchLine::updateComboboxVisibility()
199 if (shortCutOverride) {
206void QuickSearchLine::changeQuicksearchVisibility(
bool show)
213void QuickSearchLine::addCompletionItem(
const QString &str)
215 mSearchEdit->addCompletionItem(str);
218#include "moc_quicksearchline.cpp"
constexpr bool isEmpty() const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KCOREADDONS_EXPORT int logicalLength(const QString &text)
The implementation independent part of the MessageList library.
void setCurrentIndex(int index)
void setText(const QString &)
void textChanged(const QString &text)
virtual bool eventFilter(QObject *watched, QEvent *event)
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)