Messagelib

filternamewidget.cpp
1/*
2 SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "filternamewidget.h"
8#include <KIconButton>
9#include <KLineEditEventHandler>
10#include <KLocalizedString>
11#include <QHBoxLayout>
12#include <QLabel>
13#include <QLineEdit>
14
15using namespace MessageList::Core;
16FilterNameWidget::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(QLatin1StringView("mainLayout"));
23 mainLayout->setContentsMargins({});
24
25 mName->setObjectName(QLatin1StringView("mName"));
26 mName->setClearButtonEnabled(true);
27 mIconButton->setObjectName(QLatin1StringView("mIconButton"));
28 mIconButton->setButtonIconSize(24);
29 mIconButton->setFixedSize(32, 32);
31
32 auto label = new QLabel(i18nc("@label:textbox", "Name:"), this);
33 label->setObjectName(QLatin1StringView("label"));
34
35 mainLayout->addWidget(label);
36 mainLayout->addWidget(mName);
37 mainLayout->addWidget(mIconButton);
38 connect(mName, &QLineEdit::textChanged, this, [this](const QString &str) {
39 const QString trimmedStr = str.trimmed();
40 Q_EMIT updateOkButton(!trimmedStr.isEmpty() && !mFilterListNames.contains(trimmedStr));
41 });
42}
43
44FilterNameWidget::~FilterNameWidget() = default;
45
46void FilterNameWidget::setFilterName(const QString &str)
47{
48 mName->setText(str);
49}
50
51void FilterNameWidget::setIconName(const QString &icon)
52{
53 mIconButton->setIcon(icon);
54}
55
56QString FilterNameWidget::filterName() const
57{
58 return mName->text();
59}
60
61QString FilterNameWidget::iconName() const
62{
63 return mIconButton->icon();
64}
65
66void FilterNameWidget::setExistingFilterNames(const QStringList &lst)
67{
68 mFilterListNames = lst;
69}
70
71#include "moc_filternamewidget.cpp"
void setIcon(const QString &icon)
const QString & icon() const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void catchReturnKey(QObject *lineEdit)
QString label(StandardShortcut id)
The implementation independent part of the MessageList library.
Definition aggregation.h:22
void setText(const QString &)
void textChanged(const QString &text)
bool isEmpty() const const
QString trimmed() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.