Akonadi

tagattribute.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "tagattribute.h"
8
9#include "private/imapparser_p.h"
10
11using namespace Akonadi;
12
13class Akonadi::TagAttributePrivate
14{
15public:
16 QString name;
17 QString icon;
18 QColor backgroundColor;
19 QColor textColor;
20 QString font;
21 bool inToolbar = false;
22 QString shortcut;
23 int priority = -1;
24};
25
26TagAttribute::TagAttribute()
27 : d(new TagAttributePrivate())
28{
29}
30
31TagAttribute::~TagAttribute() = default;
32
34{
35 return d->name;
36}
37
39{
40 d->name = name;
41}
42
44{
45 return d->icon;
46}
47
49{
50 d->icon = icon;
51}
52
54{
55 static const QByteArray sType("TAG");
56 return sType;
57}
58
60{
61 auto attr = new TagAttribute();
62 attr->d->name = d->name;
63 attr->d->icon = d->icon;
64 attr->d->backgroundColor = d->backgroundColor;
65 attr->d->textColor = d->textColor;
66 attr->d->font = d->font;
67 attr->d->inToolbar = d->inToolbar;
68 attr->d->shortcut = d->shortcut;
69 attr->d->priority = d->priority;
70 return attr;
71}
72
74{
76 l.reserve(8);
77 l << ImapParser::quote(d->name.toUtf8());
78 l << ImapParser::quote(d->icon.toUtf8());
79 l << ImapParser::quote(d->font.toUtf8());
80 l << ImapParser::quote(d->shortcut.toUtf8());
81 l << ImapParser::quote(QString::number(d->inToolbar).toUtf8());
82 {
83 QList<QByteArray> components;
84 if (d->backgroundColor.isValid()) {
85 components = QList<QByteArray>() << QByteArray::number(d->backgroundColor.red()) << QByteArray::number(d->backgroundColor.green())
86 << QByteArray::number(d->backgroundColor.blue()) << QByteArray::number(d->backgroundColor.alpha());
87 }
88 l << '(' + ImapParser::join(components, " ") + ')';
89 }
90 {
91 QList<QByteArray> components;
92 if (d->textColor.isValid()) {
93 components = QList<QByteArray>() << QByteArray::number(d->textColor.red()) << QByteArray::number(d->textColor.green())
94 << QByteArray::number(d->textColor.blue()) << QByteArray::number(d->textColor.alpha());
95 }
96 l << '(' + ImapParser::join(components, " ") + ')';
97 }
98 l << ImapParser::quote(QString::number(d->priority).toUtf8());
99 return '(' + ImapParser::join(l, " ") + ')';
100}
101
102static QColor parseColor(const QByteArray &data)
103{
104 QList<QByteArray> componentData;
105 ImapParser::parseParenthesizedList(data, componentData);
106 if (componentData.size() != 4) {
107 return QColor();
108 }
109 QList<int> components;
110 components.reserve(4);
111 bool ok;
112 for (int i = 0; i <= 3; ++i) {
113 components << componentData.at(i).toInt(&ok);
114 if (!ok) {
115 return QColor();
116 }
117 }
118 return QColor(components.at(0), components.at(1), components.at(2), components.at(3));
119}
120
122{
124 ImapParser::parseParenthesizedList(data, l);
125 int size = l.size();
126 Q_ASSERT(size >= 7);
127 d->name = QString::fromUtf8(l[0]);
128 d->icon = QString::fromUtf8(l[1]);
129 d->font = QString::fromUtf8(l[2]);
130 d->shortcut = QString::fromUtf8(l[3]);
131 d->inToolbar = QString::fromUtf8(l[4]).toInt();
132 if (!l[5].isEmpty()) {
133 d->backgroundColor = parseColor(l[5]);
134 }
135 if (!l[6].isEmpty()) {
136 d->textColor = parseColor(l[6]);
137 }
138 if (l.size() >= 8) {
139 d->priority = QString::fromUtf8(l[7]).toInt();
140 }
141}
142
143QColor TagAttribute::backgroundColor() const
144{
145 return d->backgroundColor;
146}
147
148void TagAttribute::setBackgroundColor(const QColor &color)
149{
150 d->backgroundColor = color;
151}
152
153void TagAttribute::setTextColor(const QColor &color)
154{
155 d->textColor = color;
156}
157
158QColor TagAttribute::textColor() const
159{
160 return d->textColor;
161}
162
163void TagAttribute::setFont(const QString &font)
164{
165 d->font = font;
166}
167
168QString TagAttribute::font() const
169{
170 return d->font;
171}
172
173void TagAttribute::setInToolbar(bool inToolbar)
174{
175 d->inToolbar = inToolbar;
176}
177
178bool TagAttribute::inToolbar() const
179{
180 return d->inToolbar;
181}
182
183void TagAttribute::setShortcut(const QString &shortcut)
184{
185 d->shortcut = shortcut;
186}
187
188QString TagAttribute::shortcut() const
189{
190 return d->shortcut;
191}
192
194{
195 d->priority = priority;
196}
197
199{
200 return d->priority;
201}
Attribute that stores the properties that are used to display a tag.
QString displayName() const
Returns the name that should be used for display.
TagAttribute * clone() const override
Creates a copy of this attribute.
void setDisplayName(const QString &name)
Sets the name that should be used for display.
QByteArray serialized() const override
Returns a QByteArray representation of the attribute which will be storaged.
void setIconName(const QString &name)
Sets the icon name for the default icon.
QByteArray type() const override
Returns the type of the attribute.
void setPriority(int priority)
Sets the priority of the tag.
QString iconName() const
Returns the icon name of the icon returned by icon().
int priority() const
Returns the priority of the tag.
void deserialize(const QByteArray &data) override
Sets the data of this attribute, using the same encoding as returned by toByteArray().
Helper integration between Akonadi and Qt.
const QList< QKeySequence > & shortcut(StandardShortcut id)
QByteArray number(double n, char format, int precision)
const_reference at(qsizetype i) const const
void reserve(qsizetype size)
qsizetype size() const const
QString fromUtf8(QByteArrayView str)
QString number(double n, char format, int precision)
int toInt(bool *ok, int base) const const
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.