Messagelib

quicksearchwarning.cpp
1 /*
2  SPDX-FileCopyrightText: 2015-2023 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "quicksearchwarning.h"
8 #include "messagelistsettings.h"
9 #include <KLocalizedString>
10 #include <QAction>
11 using namespace MessageList::Core;
12 
13 QuickSearchWarning::QuickSearchWarning(QWidget *parent)
14  : KMessageWidget(parent)
15 {
16  setVisible(false);
17  setCloseButtonVisible(true);
18  setMessageType(Warning);
19  setWordWrap(true);
20  setText(i18n("The words less than 3 letters are ignored."));
21  auto action = new QAction(i18n("Do not show again"), this);
22  action->setObjectName(QStringLiteral("donotshowagain"));
23  connect(action, &QAction::triggered, this, &QuickSearchWarning::slotDoNotRememberIt);
24  addAction(action);
25 }
26 
27 QuickSearchWarning::~QuickSearchWarning() = default;
28 
29 void QuickSearchWarning::setSearchText(const QString &text)
30 {
31  if (!MessageList::MessageListSettings::quickSearchWarningDoNotShowAgain()) {
32  const QStringList lstText = text.split(QLatin1Char(' '), Qt::SkipEmptyParts);
33  bool foundLessThanThreeCharacters = false;
34  for (const QString &splitText : lstText) {
35  if (splitText.trimmed().size() < 3) {
36  foundLessThanThreeCharacters = true;
37  break;
38  }
39  }
40  if (foundLessThanThreeCharacters) {
41  animatedShow();
42  } else {
43  animatedHide();
44  }
45  }
46 }
47 
48 void QuickSearchWarning::slotDoNotRememberIt()
49 {
50  MessageList::MessageListSettings::setQuickSearchWarningDoNotShowAgain(true);
51  animatedHide();
52 }
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual void setVisible(bool visible)
QString i18n(const char *text, const TYPE &arg...)
SkipEmptyParts
void triggered(bool checked)
void addAction(QAction *action)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Mar 22 2023 04:07:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.