8#include <Akonadi/TagAttribute>
10#include <QGuiApplication>
15Tag::Ptr Tag::createDefaultTag(
const QString &name)
17 Tag::Ptr tag(
new Tag());
19 tag->iconName = QStringLiteral(
"mail-tagged");
22 tag->inToolbar =
false;
23 tag->isImmutable =
false;
25 tag->isItalic =
false;
29Tag::Ptr Tag::fromAkonadi(
const Akonadi::Tag &akonadiTag)
31 Tag::Ptr tag(
new Tag());
32 tag->tagName = akonadiTag.name();
33 tag->mTag = akonadiTag;
35 tag->iconName = QStringLiteral(
"mail-tagged");
36 tag->inToolbar =
false;
38 const auto *attr = akonadiTag.
attribute<Akonadi::TagAttribute>();
40 if (!attr->iconName().isEmpty()) {
41 tag->iconName = attr->iconName();
43 tag->inToolbar = attr->inToolbar();
44 tag->shortcut = QKeySequence(attr->shortcut());
45 tag->textColor = attr->textColor();
46 tag->backgroundColor = attr->backgroundColor();
47 if (!attr->font().isEmpty()) {
50 tag->isBold = font.
bold();
51 tag->isItalic = font.
italic();
53 tag->priority = attr->priority();
58Akonadi::Tag Tag::saveToAkonadi(Tag::SaveFlags saveFlags)
const
60 Akonadi::Tag tag = mTag;
61 if (tag.gid().isEmpty()) {
70 attr->setDisplayName(tagName);
71 attr->setIconName(iconName);
72 attr->setInToolbar(inToolbar);
73 attr->setShortcut(shortcut.toString());
74 attr->setPriority(priority);
76 if (textColor.isValid() && (saveFlags & TextColor)) {
77 attr->setTextColor(textColor);
79 attr->setTextColor(QColor());
82 if (backgroundColor.isValid() && (saveFlags & BackgroundColor)) {
83 attr->setBackgroundColor(backgroundColor);
85 attr->setBackgroundColor(QColor());
88 if (saveFlags & Font) {
95 tag.addAttribute(attr);
99bool Tag::compare(
const Tag::Ptr &tag1,
const Tag::Ptr &tag2)
101 if (tag1->priority < tag2->priority) {
103 }
else if (tag1->priority == tag2->priority) {
104 return tag1->tagName < tag2->tagName;
110bool Tag::compareName(
const Tag::Ptr &tag1,
const Tag::Ptr &tag2)
112 return tag1->tagName < tag2->tagName;
115bool Tag::operator==(
const Tag &other)
const
118 if (mTag.isValid()) {
119 return id() == other.id();
122 return tagName == other.tagName && textColor == other.textColor && backgroundColor == other.backgroundColor && isBold == other.isBold
123 && isItalic == other.isItalic && iconName == other.iconName && inToolbar == other.inToolbar && shortcut.toString() == other.shortcut.
toString()
124 && priority == other.priority;
127bool Tag::operator!=(
const Tag &other)
const
129 return !(*
this == other);
132qint64 Tag::id()
const
137QString Tag::name()
const
142Akonadi::Tag Tag::tag()
const
147#include "moc_tag.cpp"
static const char GENERIC[]
const T * attribute() const
static const char PLAIN[]
bool fromString(const QString &descrip)
bool italic() const const
void setBold(bool enable)
void setItalic(bool enable)
QString toString() const const
QString toString(SequenceFormat format) const const