20 #include "tagattribute.h"
22 #include "imapparser_p.h"
26 using namespace Akonadi;
28 class TagAttribute::Private
38 QColor backgroundColor;
46 TagAttribute::TagAttribute() :
51 TagAttribute::~TagAttribute()
84 attr->d->name = d->name;
85 attr->d->icon = d->icon;
86 attr->d->backgroundColor = d->backgroundColor;
87 attr->d->textColor = d->textColor;
88 attr->d->font = d->font;
89 attr->d->inToolbar = d->inToolbar;
90 attr->d->shortcut = d->shortcut;
98 l << ImapParser::quote( d->name.toUtf8() );
99 l << ImapParser::quote( d->icon.toUtf8() );
100 l << ImapParser::quote( d->font.toUtf8() );
101 l << ImapParser::quote( d->shortcut.toUtf8() );
102 l << ImapParser::quote( QString::number(d->inToolbar).toUtf8() );
104 QList<QByteArray> components;
105 if ( d->backgroundColor.isValid() ) {
106 components = QList<QByteArray>() << QByteArray::number( d->backgroundColor.red() )
107 << QByteArray::number( d->backgroundColor.green() )
108 << QByteArray::number( d->backgroundColor.blue() )
109 << QByteArray::number( d->backgroundColor.alpha() );
111 l <<
'(' + ImapParser::join( components,
" " ) +
')';
114 QList<QByteArray> components;
115 if ( d->textColor.isValid() ) {
116 components = QList<QByteArray>() << QByteArray::number( d->textColor.red() )
117 << QByteArray::number( d->textColor.green() )
118 << QByteArray::number( d->textColor.blue() )
119 << QByteArray::number( d->textColor.alpha() );
121 l <<
'(' + ImapParser::join( components,
" " ) +
')';
123 l << ImapParser::quote( QString::number(d->priority).toUtf8() );
124 return '(' + ImapParser::join( l,
" " ) +
')';
127 static QColor parseColor(
const QByteArray &data)
129 QList<QByteArray> componentData;
130 ImapParser::parseParenthesizedList( data, componentData );
131 if (componentData.size() != 4) {
134 QList<int> components;
136 for (
int i = 0; i <= 3; ++i) {
137 components << componentData.at(i).toInt(&ok);
142 return QColor( components.at( 0 ), components.at( 1 ), components.at( 2 ), components.at( 3 ) );
148 ImapParser::parseParenthesizedList(data, l);
150 Q_ASSERT( size >= 7);
151 d->name = QString::fromUtf8(l[0]);
152 d->icon = QString::fromUtf8(l[1]);
153 d->font = QString::fromUtf8(l[2]);
154 d->shortcut = QString::fromUtf8(l[3]);
155 d->inToolbar = QString::fromUtf8(l[4]).toInt();
156 if (!l[5].isEmpty()) {
157 d->backgroundColor = parseColor(l[5]);
159 if (!l[6].isEmpty()) {
160 d->textColor = parseColor(l[6]);
163 d->priority = QString::fromUtf8(l[7]).toInt();
167 QColor TagAttribute::backgroundColor()
const
169 return d->backgroundColor;
172 void TagAttribute::setBackgroundColor(
const QColor &color)
174 d->backgroundColor = color;
177 void TagAttribute::setTextColor(
const QColor &color)
179 d->textColor = color;
182 QColor TagAttribute::textColor()
const
187 void TagAttribute::setFont(
const QString& font)
192 QString TagAttribute::font()
const
197 void TagAttribute::setInToolbar(
bool inToolbar)
199 d->inToolbar = inToolbar;
202 bool TagAttribute::inToolbar()
const
207 void TagAttribute::setShortcut(
const QString &shortcut)
209 d->shortcut = shortcut;
212 QString TagAttribute::shortcut()
const
QByteArray type() const
Returns the type of the attribute.
void setPriority(int priority)
Sets the priority of the tag.
QByteArray serialized() const
Returns a QByteArray representation of the attribute which will be storaged.
void setDisplayName(const QString &name)
Sets the name that should be used for display.
int priority() const
Returns the priority of the tag.
QString iconName() const
Returns the icon name of the icon returned by icon().
void deserialize(const QByteArray &data)
Sets the data of this attribute, using the same encoding as returned by toByteArray().
QString displayName() const
Returns the name that should be used for display.
Attribute that stores the properties that are used to display a tag.
void setIconName(const QString &name)
Sets the icon name for the default icon.
TagAttribute * clone() const
Creates a copy of this attribute.