Messagelib

searchstatusbuttons.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 "searchstatusbuttons.h"
8#include "messagelist_debug.h"
9#include <KLocalizedString>
10#include <QButtonGroup>
11#include <QHBoxLayout>
12#include <QToolButton>
13using namespace MessageList::Core;
14SearchStatusButtons::SearchStatusButtons(QWidget *parent)
15 : QWidget{parent}
16 , mButtonGroup(new QButtonGroup(this))
17 , mMainLayout(new QHBoxLayout(this))
18{
19 mMainLayout->setObjectName(QStringLiteral("mainLayout"));
20 mMainLayout->setContentsMargins({});
21 mMainLayout->setSpacing(0);
22
23 mButtonGroup->setObjectName(QStringLiteral("mButtonGroup"));
24 mButtonGroup->setExclusive(false);
25
26 connect(mButtonGroup, &QButtonGroup::idClicked, this, &SearchStatusButtons::updateFilters);
27 createAction();
28}
29
30SearchStatusButtons::~SearchStatusButtons() = default;
31
32void SearchStatusButtons::createAction()
33{
34 createFilterAction(QIcon::fromTheme(QStringLiteral("mail-unread")),
35 i18nc("@action:inmenu Status of a message", "Unread"),
37
38 createFilterAction(QIcon::fromTheme(QStringLiteral("mail-replied")),
39 i18nc("@action:inmenu Status of a message", "Replied"),
41
42 createFilterAction(QIcon::fromTheme(QStringLiteral("mail-forwarded")),
43 i18nc("@action:inmenu Status of a message", "Forwarded"),
45
46 createFilterAction(QIcon::fromTheme(QStringLiteral("mail-mark-important")),
47 i18nc("@action:inmenu Status of a message", "Important"),
49
50 createFilterAction(QIcon::fromTheme(QStringLiteral("mail-task")),
51 i18nc("@action:inmenu Status of a message", "Action Item"),
53
54 createFilterAction(QIcon::fromTheme(QStringLiteral("mail-thread-watch")),
55 i18nc("@action:inmenu Status of a message", "Watched"),
57
58 createFilterAction(QIcon::fromTheme(QStringLiteral("mail-thread-ignored")),
59 i18nc("@action:inmenu Status of a message", "Ignored"),
61
62 createFilterAction(QIcon::fromTheme(QStringLiteral("mail-attachment")),
63 i18nc("@action:inmenu Status of a message", "Has Attachment"),
65
66 createFilterAction(QIcon::fromTheme(QStringLiteral("mail-invitation")),
67 i18nc("@action:inmenu Status of a message", "Has Invitation"),
69
70 createFilterAction(QIcon::fromTheme(QStringLiteral("mail-mark-junk")),
71 i18nc("@action:inmenu Status of a message", "Spam"),
73
74 createFilterAction(QIcon::fromTheme(QStringLiteral("mail-mark-notjunk")),
75 i18nc("@action:inmenu Status of a message", "Ham"),
77}
78
79void SearchStatusButtons::createFilterAction(const QIcon &icon, const QString &text, int value)
80{
81 auto toolButton = new QToolButton(this);
82 toolButton->setCheckable(true);
83 toolButton->setAutoRaise(true);
84 toolButton->setIcon(icon);
85 toolButton->setToolTip(text);
86 mButtonGroup->addButton(toolButton, value);
87 mMainLayout->addWidget(toolButton, 0, Qt::AlignTop);
88}
89
90void SearchStatusButtons::clearFilter()
91{
92 for (auto button : mButtonGroup->buttons()) {
93 button->setChecked(false);
94 }
95}
96
97void SearchStatusButtons::updateFilters()
98{
100
101 for (auto button : mButtonGroup->buttons()) {
102 if (button->isChecked()) {
104 status.fromQInt32(static_cast<qint32>(mButtonGroup->id(button)));
105 lstStatus.append(status);
106 }
107 }
108 Q_EMIT filterStatusChanged(lstStatus);
109}
110
111void SearchStatusButtons::setFilterMessageStatus(const QList<Akonadi::MessageStatus> &newLstStatus)
112{
113 for (const Akonadi::MessageStatus &status : newLstStatus) {
114 if (!mButtonGroup->button(status.toQInt32())) {
115 qCWarning(MESSAGELIST_LOG) << " status not found " << status.toQInt32();
116 } else {
117 mButtonGroup->button(status.toQInt32())->setChecked(true);
118 }
119 }
120}
121#include "moc_searchstatusbuttons.cpp"
void fromQInt32(qint32 status)
static const MessageStatus statusUnread()
static const MessageStatus statusHasAttachment()
static const MessageStatus statusSpam()
static const MessageStatus statusHasInvitation()
static const MessageStatus statusReplied()
static const MessageStatus statusImportant()
static const MessageStatus statusWatched()
static const MessageStatus statusForwarded()
static const MessageStatus statusToAct()
static const MessageStatus statusIgnored()
static const MessageStatus statusHam()
Q_SCRIPTABLE CaptureState status()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
The implementation independent part of the MessageList library.
Definition aggregation.h:22
void setChecked(bool)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void addButton(QAbstractButton *button, int id)
QAbstractButton * button(int id) const const
QList< QAbstractButton * > buttons() const const
int id(QAbstractButton *button) const const
void idClicked(int id)
QIcon fromTheme(const QString &name)
void append(QList< T > &&value)
Q_EMITQ_EMIT
void setObjectName(QAnyStringView name)
AlignTop
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.