Messagelib

searchlinecommandbuttonswidget.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 "searchlinecommandbuttonswidget.h"
8#include "searchlinecommandflowlayout.h"
9#include <KLocalizedString>
10#include <QEvent>
11#include <QPushButton>
12#include <QVBoxLayout>
13using namespace MessageList::Core;
14SearchLineCommandButtonsWidget::SearchLineCommandButtonsWidget(QWidget *parent)
15 : QFrame{parent}
16{
17 auto flowLayout = new SearchLineCommandFlowLayout(this);
18 flowLayout->setObjectName(QStringLiteral("flowLayout"));
19 flowLayout->setContentsMargins({});
20 flowLayout->setSpacing(0);
21 flowLayout->setHorizontalSpacing(0);
22 flowLayout->setVerticalSpacing(0);
23 fillWidgets();
24 Q_ASSERT(!mButtonsList.isEmpty());
25 for (const auto &info : std::as_const(mButtonsList)) {
26 flowLayout->addWidget(createPushButton(info.needSpace, info.i18n, info.identifier));
27 }
28}
29
30SearchLineCommandButtonsWidget::~SearchLineCommandButtonsWidget() = default;
31
32QPushButton *SearchLineCommandButtonsWidget::createPushButton(bool needSpace, const QString &i18nStr, const QString &commandStr)
33{
34 auto pushButton = new QPushButton(i18nStr, this);
35 pushButton->setObjectName(commandStr);
36 pushButton->setToolTip(commandStr);
37 connect(pushButton, &QPushButton::clicked, this, [this, commandStr, needSpace]() {
38 const QString str = commandStr + (needSpace ? QStringLiteral(" ") : QString());
39 Q_EMIT insertCommand(str);
40 });
41 return pushButton;
42}
43
44void SearchLineCommandButtonsWidget::fillWidgets()
45{
46 mButtonsList = {
47 {false, QStringLiteral("subject:"), i18nc("@action:button", "Subject")},
48 {false, QStringLiteral("body:"), i18nc("@action:button", "Body")},
49 {false, QStringLiteral("from:"), i18nc("@action:button", "From")},
50 {false, QStringLiteral("to:"), i18nc("@action:button", "To")},
51 {false, QStringLiteral("cc:"), i18nc("@action:button", "Cc")},
52 {false, QStringLiteral("bcc:"), i18nc("@action:button", "Bcc")},
53 {true, QStringLiteral("has:attachment"), i18nc("@action:button", "Has Attachment")},
54 {true, QStringLiteral("has:invitation"), i18nc("@action:button", "Has Invitation")},
55 {true, QStringLiteral("is:read"), i18nc("@action:button", "Read")},
56 {true, QStringLiteral("is:unread"), i18nc("@action:button", "Unread")},
57 {true, QStringLiteral("is:important"), i18nc("@action:button", "Important")},
58 {true, QStringLiteral("is:ignored"), i18nc("@action:button", "Ignored")},
59 {true, QStringLiteral("is:ham"), i18nc("@action:button", "Ham")},
60 {true, QStringLiteral("is:spam"), i18nc("@action:button", "Spam")},
61 {true, QStringLiteral("is:watched"), i18nc("@action:button", "Watched")},
62 {true, QStringLiteral("is:replied"), i18nc("@action:button", "Replied")},
63 {true, QStringLiteral("is:forwarded"), i18nc("@action:button", "Forwarded")},
64#if 0 // Reactivate when we implemented it.
65 {false, QStringLiteral("smaller:"), i18nc("@action:button", "Smaller")},
66 {false, QStringLiteral("larger:"), i18nc("@action:button", "Larger")},
67 {false, QStringLiteral("size:"), i18nc("@action:button", "Size")},
68 {false, QStringLiteral("older_than:"), i18nc("@action:button", "Older")},
69 {false, QStringLiteral("newer_than:"), i18nc("@action:button", "Newer")},
70 {false, QStringLiteral("category:"), i18nc("@action:button", "Category")},
71#endif
72 };
73}
74
75#include "moc_searchlinecommandbuttonswidget.cpp"
QString i18nc(const char *context, 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 Mon Nov 18 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.