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>
21#include <QStandardPaths>
22#if USE_SEARCH_COMMAND_LINE
23#include "core/widgets/searchlinecommandwidget.h"
26QuickSearchLine::QuickSearchLine(
QWidget *parent)
28 , mSearchEdit(new SearchLineStatus(this))
29 , mSearchStatusButtons(new SearchStatusButtons(this))
30 , mSearchMessageByButtons(new SearchMessageByButtons(this))
31#if USE_SEARCH_COMMAND_LINE
32 , mSearchLineCommandWidget(new SearchLineCommandWidget(this))
37 vbox->setContentsMargins({});
42 hbox->setContentsMargins({});
46 vbox->addWidget(mSearchMessageByButtons);
47 mSearchMessageByButtons->setVisible(
false);
48#if USE_SEARCH_COMMAND_LINE
49 vbox->addWidget(mSearchLineCommandWidget);
50 mSearchLineCommandWidget->setVisible(
false);
51 connect(mSearchEdit, &SearchLineStatus::searchCommandActionRequested,
this, [
this]() {
52 mSearchLineCommandWidget->setVisible(!mSearchLineCommandWidget->isVisible());
54 connect(mSearchLineCommandWidget, &SearchLineCommandWidget::insertCommand, mSearchEdit, &SearchLineStatus::slotInsertCommand);
57 MessageList::Core::SearchLineCommand c;
58 c.parseSearchLineCommand(str);
59 mSearchLineCommandWidget->setLabel(c.generateCommadLineStr());
63 connect(mSearchEdit, &SearchLineStatus::forceLostFocus,
this, &QuickSearchLine::forceLostFocus);
64 mSearchEdit->setPlaceholderText(
i18nc(
"Search for messages.",
"Search"));
66 mSearchEdit->setClearButtonEnabled(
true);
67 connect(mSearchMessageByButtons, &SearchMessageByButtons::searchOptionChanged,
this, [
this]() {
68 mSearchEdit->filterAdded();
69 Q_EMIT searchOptionChanged();
73 connect(mSearchEdit, &SearchLineStatus::clearButtonClicked,
this, &QuickSearchLine::slotClearButtonClicked);
74 connect(mSearchEdit, &SearchLineStatus::saveFilter,
this, &QuickSearchLine::saveFilter);
75 connect(mSearchEdit, &SearchLineStatus::activateFilter,
this, &QuickSearchLine::activateFilter);
77 hbox->addWidget(mSearchEdit);
79 hbox->addWidget(mSearchStatusButtons);
80 connect(mSearchStatusButtons, &SearchStatusButtons::filterStatusChanged,
this, &QuickSearchLine::slotFilterActionChanged);
84 mTagFilterCombo->setMaximumWidth(300);
85 mTagFilterCombo->setMaximumWidth(200);
86 mTagFilterCombo->hide();
87 hbox->addWidget(mTagFilterCombo);
90 mSearchEdit->setEnabled(
false);
91 mTagFilterCombo->setEnabled(
false);
93 installEventFilter(
this);
94 mTagFilterCombo->installEventFilter(
this);
95 changeQuicksearchVisibility(MessageListSettings::self()->showQuickSearch());
98QuickSearchLine::~QuickSearchLine() =
default;
100void QuickSearchLine::slotSearchEditTextEdited(
const QString &text)
102 int minimumStringLength = 3;
104 minimumStringLength = 5;
106 if (!text.trimmed().
isEmpty()) {
109 Q_EMIT searchEditTextEdited(text);
112 slotClearButtonClicked();
116void QuickSearchLine::slotClearButtonClicked()
121 mSearchEdit->clearFilterButtonClicked();
122 mSearchStatusButtons->clearFilter();
123 mSearchMessageByButtons->clearFilter();
125 Q_EMIT clearButtonClicked();
130 mSearchMessageByButtons->setSearchOptions(opts);
132 mSearchEdit->filterAdded();
137 return mSearchMessageByButtons->searchOptions();
140void QuickSearchLine::focusQuickSearch(
const QString &selectedText)
143 mSearchEdit->
setText(selectedText);
148QComboBox *QuickSearchLine::tagFilterComboBox()
const
150 return mTagFilterCombo;
153SearchLineStatus *QuickSearchLine::searchEdit()
const
158void QuickSearchLine::resetFilter()
163 mSearchEdit->clearFilterButtonClicked();
164 mSearchEdit->setLocked(
false);
165 mSearchStatusButtons->clearFilter();
171 mSearchEdit->filterAdded();
172 Q_EMIT statusButtonsClicked();
177 mLstStatus = newLstStatus;
178 mSearchEdit->filterAdded();
179 mSearchStatusButtons->setFilterMessageStatus(mLstStatus);
187bool QuickSearchLine::containsOutboundMessages()
const
189 return mSearchMessageByButtons->containsOutboundMessages();
192void QuickSearchLine::setContainsOutboundMessages(
bool containsOutboundMessages)
194 mSearchMessageByButtons->setContainsOutboundMessages(containsOutboundMessages);
197void QuickSearchLine::updateComboboxVisibility()
205 if (shortCutOverride) {
212void QuickSearchLine::changeQuicksearchVisibility(
bool show)
219void QuickSearchLine::addCompletionItem(
const QString &str)
221 mSearchEdit->addCompletionItem(str);
224#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)