Changeset View
Changeset View
Standalone View
Standalone View
src/kohelper.cpp
Show All 19 Lines | 1 | /* | |||
---|---|---|---|---|---|
20 | As a special exception, permission is given to link this program | 20 | As a special exception, permission is given to link this program | ||
21 | with any edition of Qt, and distribute the resulting executable, | 21 | with any edition of Qt, and distribute the resulting executable, | ||
22 | without including the source code for Qt in the source distribution. | 22 | without including the source code for Qt in the source distribution. | ||
23 | */ | 23 | */ | ||
24 | 24 | | |||
25 | #include "kohelper.h" | 25 | #include "kohelper.h" | ||
26 | #include "prefs/koprefs.h" | 26 | #include "prefs/koprefs.h" | ||
27 | 27 | | |||
28 | #include <CalendarSupport/KCalPrefs> | 28 | #include <EventViews/Helper> | ||
29 | 29 | | |||
30 | #include <CalendarSupport/KCalPrefs> | ||||
30 | #include <KMessageBox> | 31 | #include <KMessageBox> | ||
31 | 32 | | |||
32 | QColor KOHelper::getTextColor(const QColor &c) | 33 | QColor KOHelper::getTextColor(const QColor &c) | ||
33 | { | 34 | { | ||
34 | double luminance = (c.red() * 0.299) + (c.green() * 0.587) + (c.blue() * 0.114); | 35 | double luminance = (c.red() * 0.299) + (c.green() * 0.587) + (c.blue() * 0.114); | ||
35 | return (luminance > 128.0) ? QColor(0, 0, 0) : QColor(255, 255, 255); | 36 | return (luminance > 128.0) ? QColor(0, 0, 0) : QColor(255, 255, 255); | ||
36 | } | 37 | } | ||
37 | 38 | | |||
38 | QColor KOHelper::resourceColor(const Akonadi::Collection &coll) | 39 | QColor KOHelper::resourceColor(const Akonadi::Collection &coll) | ||
39 | { | 40 | { | ||
40 | if (!coll.isValid()) { | 41 | return EventViews::resourceColor(coll, KOPrefs::instance()->eventViewsPreferences()); | ||
41 | return QColor(); | | |||
42 | } | | |||
43 | | ||||
44 | const QString id = QString::number(coll.id()); | | |||
45 | return KOPrefs::instance()->resourceColor(id); | | |||
46 | } | 42 | } | ||
47 | 43 | | |||
48 | QColor KOHelper::resourceColorKnown(const Akonadi::Collection &coll) | 44 | QColor KOHelper::resourceColorKnown(const Akonadi::Collection &coll) | ||
49 | { | 45 | { | ||
50 | if (!coll.isValid()) { | 46 | return EventViews::resourceColor(coll, KOPrefs::instance()->eventViewsPreferences()); | ||
51 | return QColor(); | | |||
52 | } | | |||
53 | | ||||
54 | const QString id = QString::number(coll.id()); | | |||
55 | return KOPrefs::instance()->resourceColorKnown(id); | | |||
56 | } | 47 | } | ||
57 | 48 | | |||
58 | void KOHelper::setResourceColor(const Akonadi::Collection &collection, const QColor &color) | 49 | void KOHelper::setResourceColor(const Akonadi::Collection &collection, const QColor &color) | ||
59 | { | 50 | { | ||
60 | if (collection.isValid()) { | 51 | EventViews::setResourceColor(collection, color, KOPrefs::instance()->eventViewsPreferences()); | ||
61 | const QString id = QString::number(collection.id()); | 52 | KOPrefs::instance()->eventViewsPreferences()->writeConfig(); | ||
62 | return KOPrefs::instance()->setResourceColor(id, color); | | |||
63 | } | | |||
64 | } | 53 | } | ||
65 | 54 | | |||
66 | QColor KOHelper::resourceColor(const Akonadi::Item &item) | 55 | QColor KOHelper::resourceColor(const Akonadi::Item &item) | ||
67 | { | 56 | { | ||
68 | if (!item.isValid()) { | 57 | return EventViews::resourceColor(item, KOPrefs::instance()->eventViewsPreferences()); | ||
69 | return QColor(); | | |||
70 | } | | |||
71 | | ||||
72 | const QString id = QString::number(item.storageCollectionId()); | | |||
73 | return KOPrefs::instance()->resourceColor(id); | | |||
74 | } | 58 | } | ||
75 | 59 | | |||
76 | int KOHelper::yearDiff(const QDate &start, const QDate &end) | 60 | int KOHelper::yearDiff(const QDate &start, const QDate &end) | ||
77 | { | 61 | { | ||
78 | return end.year() - start.year(); | 62 | return end.year() - start.year(); | ||
79 | } | 63 | } | ||
80 | 64 | | |||
81 | bool KOHelper::isStandardCalendar(Akonadi::Collection::Id id) | 65 | bool KOHelper::isStandardCalendar(Akonadi::Collection::Id id) | ||
Show All 13 Lines |