Akonadi

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

KDE's Doxygen guidelines are available online.