Messagelib

searchlinecommandwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "searchlinecommandwidget.h"
8#include "searchlinecommandflowlayout.h"
9#include <KLocalizedString>
10#include <QPushButton>
11#include <QVBoxLayout>
12using namespace MessageList::Core;
13SearchLineCommandWidget::SearchLineCommandWidget(QWidget *parent)
14 : QWidget{parent}
15{
16 auto flowLayout = new SearchLineCommandFlowLayout(this);
17 flowLayout->setObjectName(QStringLiteral("flowLayout"));
18 flowLayout->setContentsMargins({});
19 flowLayout->setSpacing(0);
20 fillWidgets();
21 Q_ASSERT(!mButtonsList.isEmpty());
22 for (const auto &info : std::as_const(mButtonsList)) {
23 flowLayout->addWidget(createPushButton(info.needSpace, info.i18n, info.identifier));
24 }
25}
26
27SearchLineCommandWidget::~SearchLineCommandWidget() = default;
28
29QPushButton *SearchLineCommandWidget::createPushButton(bool needSpace, const QString &i18nStr, const QString &commandStr)
30{
31 auto pushButton = new QPushButton(i18nStr, this);
32 pushButton->setObjectName(commandStr);
33 connect(pushButton, &QPushButton::clicked, this, [this, commandStr, needSpace]() {
34 const QString str = commandStr + (needSpace ? QStringLiteral(" ") : QString());
35 Q_EMIT insertCommand(str);
36 });
37 return pushButton;
38}
39
40void SearchLineCommandWidget::fillWidgets()
41{
42 mButtonsList = {
43 {false, QStringLiteral("subject:"), i18n("Subject")},
44 {false, QStringLiteral("from:"), i18n("From")},
45 {false, QStringLiteral("to:"), i18n("To")},
46 {false, QStringLiteral("cc:"), i18n("Cc")},
47 {false, QStringLiteral("bcc:"), i18n("Bcc")},
48 {true, QStringLiteral("has:attachment"), i18n("Has Attachment")},
49 {true, QStringLiteral("has:invitation"), i18n("Has Invitation")},
50 {true, QStringLiteral("is:read"), i18n("Read")},
51 {true, QStringLiteral("is:unread"), i18n("Unread")},
52 {true, QStringLiteral("is:important"), i18n("Important")},
53 {true, QStringLiteral("is:ignored"), i18n("Ignored")},
54 {true, QStringLiteral("is:ham"), i18n("Ham")},
55 {true, QStringLiteral("is:spam"), i18n("Spam")},
56 {true, QStringLiteral("is:watched"), i18n("Watched")},
57 {true, QStringLiteral("is:replied"), i18n("Replied")},
58 {true, QStringLiteral("is:forwarded"), i18n("Forwarded")},
59 };
60}
61
62#include "moc_searchlinecommandwidget.cpp"
QString i18n(const char *text, const TYPE &arg...)
The implementation independent part of the MessageList library.
Definition aggregation.h:22
void clicked(bool checked)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:08:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.