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 Akonadi::TagAttributePrivate
14 {
15 public:
16  QString name;
17  QString icon;
18  QColor backgroundColor;
19  QColor textColor;
20  QString font;
21  bool inToolbar = false;
23  int priority = -1;
24 };
25 
26 TagAttribute::TagAttribute()
27  : d(new TagAttributePrivate())
28 {
29 }
30 
31 TagAttribute::~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 
102 static 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  QVector<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 
143 QColor TagAttribute::backgroundColor() const
144 {
145  return d->backgroundColor;
146 }
147 
148 void TagAttribute::setBackgroundColor(const QColor &color)
149 {
150  d->backgroundColor = color;
151 }
152 
153 void TagAttribute::setTextColor(const QColor &color)
154 {
155  d->textColor = color;
156 }
157 
158 QColor TagAttribute::textColor() const
159 {
160  return d->textColor;
161 }
162 
163 void TagAttribute::setFont(const QString &font)
164 {
165  d->font = font;
166 }
167 
168 QString TagAttribute::font() const
169 {
170  return d->font;
171 }
172 
173 void TagAttribute::setInToolbar(bool inToolbar)
174 {
175  d->inToolbar = inToolbar;
176 }
177 
178 bool TagAttribute::inToolbar() const
179 {
180  return d->inToolbar;
181 }
182 
183 void TagAttribute::setShortcut(const QString &shortcut)
184 {
185  d->shortcut = shortcut;
186 }
187 
188 QString TagAttribute::shortcut() const
189 {
190  return d->shortcut;
191 }
192 
193 void TagAttribute::setPriority(int priority)
194 {
195  d->priority = priority;
196 }
197 
199 {
200  return d->priority;
201 }
QString number(int n, int base)
const QList< QKeySequence > & shortcut(StandardShortcut id)
QString fromUtf8(const char *str, int size)
void setPriority(int priority)
Sets the priority of the tag.
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().
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.
QString displayName() const
Returns the name that should be used for display.
void reserve(int alloc)
int size() const const
const T & at(int i) const const
QByteArray toUtf8() const const
const T & at(int i) const const
int toInt(bool *ok, int base) const const
void reserve(int size)
int toInt(bool *ok, int base) const const
QString name(StandardShortcut id)
void setIconName(const QString &name)
Sets the icon name for the default icon.
TagAttribute * clone() const override
Creates a copy of this attribute.
QByteArray type() const override
Returns the type of the attribute.
Attribute that stores the properties that are used to display a tag.
Definition: tagattribute.h:26
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.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:47 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.