Changeset View
Changeset View
Standalone View
Standalone View
src/helper.cpp
Show All 31 Lines | |||||
32 | #include <QPixmap> | 32 | #include <QPixmap> | ||
33 | 33 | | |||
34 | QColor EventViews::getTextColor(const QColor &c) | 34 | QColor EventViews::getTextColor(const QColor &c) | ||
35 | { | 35 | { | ||
36 | double luminance = (c.red() * 0.299) + (c.green() * 0.587) + (c.blue() * 0.114); | 36 | double luminance = (c.red() * 0.299) + (c.green() * 0.587) + (c.blue() * 0.114); | ||
37 | return (luminance > 128.0) ? QColor(0, 0, 0) : QColor(255, 255, 255); | 37 | return (luminance > 128.0) ? QColor(0, 0, 0) : QColor(255, 255, 255); | ||
38 | } | 38 | } | ||
39 | 39 | | |||
40 | static QString keyForCollectionColor(const Akonadi::Collection &coll) | ||||
41 | { | ||||
42 | if (coll.remoteId().isEmpty()) { | ||||
43 | qCDebug(CALENDARVIEW_LOG) << "Missing remoteId on collection" << coll.id() << coll.name() << "falling back to id"; | ||||
44 | return QString::number(coll.id()); | ||||
45 | } | ||||
46 | return coll.remoteId(); | ||||
47 | } | ||||
48 | | ||||
40 | void EventViews::setResourceColor(const Akonadi::Collection &coll, const QColor &color, const PrefsPtr &preferences) | 49 | void EventViews::setResourceColor(const Akonadi::Collection &coll, const QColor &color, const PrefsPtr &preferences) | ||
41 | { | 50 | { | ||
42 | if (!coll.isValid()) { | 51 | if (!coll.isValid()) { | ||
43 | return; | 52 | return; | ||
44 | } | 53 | } | ||
45 | 54 | | |||
46 | const QString id = QString::number(coll.id()); | 55 | const QString id = keyForCollectionColor(coll); | ||
47 | if (coll.hasAttribute<Akonadi::CollectionColorAttribute>()) { | 56 | if (coll.hasAttribute<Akonadi::CollectionColorAttribute>()) { | ||
48 | Akonadi::CollectionColorAttribute *colorAttr | 57 | Akonadi::CollectionColorAttribute *colorAttr | ||
49 | = coll.attribute<Akonadi::CollectionColorAttribute>(); | 58 | = coll.attribute<Akonadi::CollectionColorAttribute>(); | ||
50 | if (colorAttr && colorAttr->color().isValid() && (colorAttr->color() == color)) { | 59 | if (colorAttr && colorAttr->color().isValid() && (colorAttr->color() == color)) { | ||
51 | // It's the same color: we save an invalid color | 60 | // It's the same color: we save an invalid color | ||
52 | preferences->setResourceColor(id, QColor()); | 61 | preferences->setResourceColor(id, QColor()); | ||
53 | } | 62 | } | ||
54 | } | 63 | } | ||
55 | // in all other cases, we save the resourceColor | 64 | // in all other cases, we save the resourceColor | ||
56 | preferences->setResourceColor(id, color); | 65 | preferences->setResourceColor(id, color); | ||
57 | } | 66 | } | ||
58 | 67 | | |||
59 | QColor EventViews::resourceColor(const Akonadi::Collection &coll, const PrefsPtr &preferences) | 68 | QColor EventViews::resourceColor(const Akonadi::Collection &coll, const PrefsPtr &preferences) | ||
60 | { | 69 | { | ||
61 | if (!coll.isValid()) { | 70 | if (!coll.isValid()) { | ||
62 | return QColor(); | 71 | return QColor(); | ||
63 | } | 72 | } | ||
64 | const QString id = QString::number(coll.id()); | 73 | const QString id = keyForCollectionColor(coll); | ||
65 | // Color stored in eventviewsrc (and in memory) | 74 | // Color stored in eventviewsrc (and in memory) | ||
66 | QColor color = preferences->resourceColorKnown(id); | 75 | QColor color = preferences->resourceColorKnown(id); | ||
67 | if (color.isValid()) { | 76 | if (color.isValid()) { | ||
68 | return color; | 77 | return color; | ||
69 | } | 78 | } | ||
79 | // Fallback for old config files which use ID instead of RemoteID | ||||
80 | color = preferences->resourceColorKnown(QString::number(coll.id())); | ||||
81 | if (color.isValid()) { | ||||
82 | return color; | ||||
83 | } | ||||
70 | // Color stored in akonadi | 84 | // Color stored in akonadi | ||
71 | if (coll.hasAttribute<Akonadi::CollectionColorAttribute>()) { | 85 | if (coll.hasAttribute<Akonadi::CollectionColorAttribute>()) { | ||
72 | Akonadi::CollectionColorAttribute *colorAttr | 86 | Akonadi::CollectionColorAttribute *colorAttr | ||
73 | = coll.attribute<Akonadi::CollectionColorAttribute>(); | 87 | = coll.attribute<Akonadi::CollectionColorAttribute>(); | ||
74 | if (colorAttr && colorAttr->color().isValid()) { | 88 | if (colorAttr && colorAttr->color().isValid()) { | ||
75 | return colorAttr->color(); | 89 | return colorAttr->color(); | ||
76 | } | 90 | } | ||
77 | } | 91 | } | ||
Show All 21 Lines |