Messagelib

filternamewidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "filternamewidget.h"
8 #include <KIconButton>
9 #include <KLocalizedString>
10 #include <Libkdepim/LineEditCatchReturnKey>
11 #include <QHBoxLayout>
12 #include <QLabel>
13 #include <QLineEdit>
14 
15 using namespace MessageList::Core;
16 FilterNameWidget::FilterNameWidget(QWidget *parent)
17  : QWidget(parent)
18  , mName(new QLineEdit(this))
19  , mIconButton(new KIconButton(this))
20 {
21  auto mainLayout = new QHBoxLayout(this);
22  mainLayout->setObjectName(QStringLiteral("mainLayout"));
23  mainLayout->setContentsMargins({});
24 
25  mName->setObjectName(QStringLiteral("mName"));
26  mName->setClearButtonEnabled(true);
27  mIconButton->setObjectName(QStringLiteral("mIconButton"));
28  mIconButton->setFixedSize(32, 32);
29  new KPIM::LineEditCatchReturnKey(mName, this);
30 
31  auto label = new QLabel(i18n("Name:"), this);
32  label->setObjectName(QStringLiteral("label"));
33 
34  mainLayout->addWidget(label);
35  mainLayout->addWidget(mName);
36  mainLayout->addWidget(mIconButton);
37  connect(mName, &QLineEdit::textChanged, this, [this](const QString &str) {
38  const QString trimmedStr = str.trimmed();
39  Q_EMIT updateOkButton(!trimmedStr.isEmpty() && !mFilterListNames.contains(trimmedStr));
40  });
41 }
42 
43 FilterNameWidget::~FilterNameWidget() = default;
44 
45 void FilterNameWidget::setFilterName(const QString &str)
46 {
47  mName->setText(str);
48 }
49 
50 void FilterNameWidget::setIconName(const QString &icon)
51 {
52  mIconButton->setIcon(icon);
53 }
54 
55 QString FilterNameWidget::filterName() const
56 {
57  return mName->text();
58 }
59 
60 QString FilterNameWidget::iconName() const
61 {
62  return mIconButton->icon();
63 }
64 
65 void FilterNameWidget::setExistingFilterNames(const QStringList &lst)
66 {
67  mFilterListNames = lst;
68 }
void textChanged(const QString &text)
The implementation independent part of the MessageList library.
Definition: aggregation.h:21
QString label(StandardShortcut id)
bool isEmpty() const const
QString trimmed() const const
QString i18n(const char *text, const TYPE &arg...)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 23:04:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.