clazy: fix QString(QLatin1String(...))
[trojita.git] / src / Gui / TagWidget.cpp
blob30e1860969c50ae3a0064baf849ad7f4cc7fa599
1 /* Copyright (C) 2012 Mildred <mildred-pub@mildred.fr>
2 Copyright (C) 2015 Erik Quaeghebeur <trojita@equaeghe.nospammail.net>
3 Copyright (C) 2006 - 2015 Jan Kundrát <jkt@kde.org>
5 This file is part of the Trojita Qt IMAP e-mail client,
6 http://trojita.flaska.net/
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License or (at your option) version 3 or any later version
12 accepted by the membership of KDE e.V. (or its successor approved
13 by the membership of KDE e.V.), which shall act as a proxy
14 defined in Section 14 of version 3 of the license.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <QEvent>
26 #include <QPair>
28 #include "TagWidget.h"
30 namespace Gui
33 TagWidget::TagWidget(const Mode mode, const QString &tagName, const QString &backgroundColor):
34 QLabel(),
35 m_tagName(tagName),
36 m_mode(mode)
38 setStyleSheet(QString::fromLatin1("border: 1px solid black; border-radius: 4px; background-color: %1;").arg(backgroundColor));
41 TagWidget *TagWidget::addingWidget()
43 auto res = new TagWidget(Mode::AddingWidget, QString(), QStringLiteral("lightgreen"));
44 res->setText(QStringLiteral("+"));
45 return res;
48 TagWidget *TagWidget::userKeyword(const QString &tagName)
50 auto res = new TagWidget(Mode::UserKeyword, tagName, QStringLiteral("lightyellow"));
51 res->setText(tagName + QLatin1String(" | x"));
52 return res;
55 TagWidget *TagWidget::systemFlag(const QString &flagName)
57 auto res = new TagWidget(Mode::SystemFlag, flagName, QStringLiteral("lightgrey"));
58 res->setText(flagName);
59 return res;
62 bool TagWidget::event(QEvent *e)
64 if (e->type() == QEvent::MouseButtonPress) {
65 switch (m_mode) {
66 case Mode::AddingWidget:
67 emit addingClicked();
68 return true;
69 case Mode::UserKeyword:
70 Q_ASSERT(!m_tagName.isEmpty());
71 emit removeClicked(m_tagName);
72 return true;
73 case Mode::SystemFlag:
74 // do nothing -- this is just an indicator
75 break;
79 return QLabel::event(e);
82 QString TagWidget::tagName() const
84 return m_tagName;
87 } // namespace Gui