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 "searchlinecommand.h"
9#include "searchlinecommandflowlayout.h"
10#include <KLocalizedString>
11#include <QEvent>
12#include <QPushButton>
13#include <QVBoxLayout>
14using namespace MessageList::Core;
15SearchLineCommandButtonsWidget::SearchLineCommandButtonsWidget(QWidget *parent)
16 : QFrame{parent}
17{
18 auto flowLayout = new SearchLineCommandFlowLayout(this);
19 flowLayout->setObjectName(QStringLiteral("flowLayout"));
20 flowLayout->setContentsMargins({});
21 flowLayout->setSpacing(0);
22 flowLayout->setHorizontalSpacing(0);
23 flowLayout->setVerticalSpacing(0);
24 fillWidgets();
25 Q_ASSERT(!mButtonsList.isEmpty());
26 for (const auto &info : std::as_const(mButtonsList)) {
27 flowLayout->addWidget(createPushButton(info.needSpace, info.i18n, info.identifier));
28 }
29}
30
31SearchLineCommandButtonsWidget::~SearchLineCommandButtonsWidget() = default;
32
33QPushButton *SearchLineCommandButtonsWidget::createPushButton(bool needSpace, const QString &i18nStr, const QString &commandStr)
34{
35 auto pushButton = new QPushButton(i18nStr, this);
36 pushButton->setObjectName(commandStr);
37 pushButton->setToolTip(commandStr);
38 connect(pushButton, &QPushButton::clicked, this, [this, commandStr, needSpace]() {
39 const QString str = commandStr + (needSpace ? QStringLiteral(" ") : QStringLiteral(":"));
40 Q_EMIT insertCommand(str);
41 });
42 return pushButton;
43}
44
45void SearchLineCommandButtonsWidget::fillWidgets()
46{
47 mButtonsList = {
48 {false, SearchLineCommand::searchLineTypeToString(SearchLineCommand::Subject), i18nc("@action:button", "Subject")},
49 {false, SearchLineCommand::searchLineTypeToString(SearchLineCommand::Body), i18nc("@action:button", "Body")},
50 {false, SearchLineCommand::searchLineTypeToString(SearchLineCommand::From), i18nc("@action:button", "From")},
51 {false, SearchLineCommand::searchLineTypeToString(SearchLineCommand::To), i18nc("@action:button", "To")},
52 {false, SearchLineCommand::searchLineTypeToString(SearchLineCommand::Cc), i18nc("@action:button", "Cc")},
53 {false, SearchLineCommand::searchLineTypeToString(SearchLineCommand::Bcc), i18nc("@action:button", "Bcc")},
54 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::HasAttachment), i18nc("@action:button", "Has Attachment")},
55 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::HasInvitation), i18nc("@action:button", "Has Invitation")},
56 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::IsRead), i18nc("@action:button", "Read")},
57 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::IsUnRead), i18nc("@action:button", "Unread")},
58 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::IsImportant), i18nc("@action:button", "Important")},
59 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::IsIgnored), i18nc("@action:button", "Ignored")},
60 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::IsHam), i18nc("@action:button", "Ham")},
61 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::IsSpam), i18nc("@action:button", "Spam")},
62 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::IsWatched), i18nc("@action:button", "Watched")},
63 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::IsReplied), i18nc("@action:button", "Replied")},
64 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::IsForwarded), i18nc("@action:button", "Forwarded")},
65 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::IsEncrypted), i18nc("@action:button", "Encrypted")},
66 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::IsQueued), i18nc("@action:button", "Queued")},
67 {true, SearchLineCommand::searchLineTypeToString(SearchLineCommand::IsSent), i18nc("@action:button", "Sent")},
68#if 0 // Reactivate when we implemented it.
69 {false, QStringLiteral("smaller:"), i18nc("@action:button", "Smaller")},
70 {false, QStringLiteral("larger:"), i18nc("@action:button", "Larger")},
71 {false, QStringLiteral("size:"), i18nc("@action:button", "Size")},
72 {false, QStringLiteral("older_than:"), i18nc("@action:button", "Older")},
73 {false, QStringLiteral("newer_than:"), i18nc("@action:button", "Newer")},
74 {false, QStringLiteral("category:"), i18nc("@action:button", "Category")},
75#endif
76 };
77}
78
79#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 Sat Dec 21 2024 16:59:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.