diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.0) -set(PIM_VERSION "5.6.40") +set(PIM_VERSION "5.6.41") project(eventviews VERSION ${PIM_VERSION}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -115,6 +115,7 @@ ecm_generate_headers(eventviews_CamelCase_HEADERS HEADER_NAMES + Helper Prefs EventView REQUIRED_HEADERS eventviews_CamelCase_HEADERS diff --git a/src/helper.h b/src/helper.h --- a/src/helper.h +++ b/src/helper.h @@ -22,6 +22,9 @@ #ifndef EVENTVIEWS_HELPER_H #define EVENTVIEWS_HELPER_H +#include "eventviews_export.h" + + #include #include @@ -49,18 +52,34 @@ /** This method returns the proper resource / subresource color for the view. + If a value is stored in the preferences, we use it, else we try to find a + CollectionColorAttribute in the collection. If everything else fails, a + random color can be set. + It is prefered to use this function instead of the + EventViews::Prefs::resourceColor function. @return The resource color for the incidence. If the incidence belongs to a subresource, the color for the subresource is returned (if set). @param calendar the calendar for which the resource color should be obtained @param incidence the incidence for which the color is needed (to determine which subresource needs to be used) */ -QColor resourceColor(const Akonadi::Item &incidence, +EVENTVIEWS_EXPORT QColor resourceColor(const Akonadi::Item &incidence, const PrefsPtr &preferences); -QColor resourceColor(const Akonadi::Collection &collection, +EVENTVIEWS_EXPORT QColor resourceColor(const Akonadi::Collection &collection, const PrefsPtr &preferences); +/** + This method sets the resource color in the preferences, only if it is + different from the CollectionColorAttribute. It is prefered to use this + instead of the EventViews::Prefs::setResourceColor function. + @param collection the collection for which the resource color should be stored + @param color the color to stored + @param preferences a pointer to the EventViews::Prefs to use +*/ +EVENTVIEWS_EXPORT void setResourceColor(const Akonadi::Collection &collection, + const QColor &color, const PrefsPtr &preferences); + /** Returns the number of years between the @p start QDate and the @p end QDate (i.e. the difference in the year number of both dates) diff --git a/src/helper.cpp b/src/helper.cpp --- a/src/helper.cpp +++ b/src/helper.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include #include @@ -35,22 +37,60 @@ return (luminance > 128.0) ? QColor(0, 0, 0) : QColor(255, 255, 255); } +void EventViews::setResourceColor(const Akonadi::Collection &coll, const QColor &color, const PrefsPtr &preferences) +{ + if (!coll.isValid()) { + return; + } + + const QString id = QString::number(coll.id()); + if (coll.hasAttribute()) { + Akonadi::CollectionColorAttribute *colorAttr = coll.attribute(); + if (colorAttr && colorAttr->color().isValid() && (colorAttr->color() == color)) { + // It's the same color: we save an invalid color + preferences->setResourceColor(id, QColor()); + } + } + // in all other cases, we save the resourceColor + preferences->setResourceColor(id, color); +} + + QColor EventViews::resourceColor(const Akonadi::Collection &coll, const PrefsPtr &preferences) { if (!coll.isValid()) { return QColor(); } const QString id = QString::number(coll.id()); - return preferences->resourceColor(id); + QColor color = preferences->resourceColorKnown(id); + if (!color.isValid() && coll.hasAttribute()) { + Akonadi::CollectionColorAttribute *colorAttr = coll.attribute(); + if (colorAttr && colorAttr->color().isValid()) { + color = colorAttr->color(); + } else { + return preferences->resourceColor(id); + } + } + return color; } QColor EventViews::resourceColor(const Akonadi::Item &item, const PrefsPtr &preferences) { if (!item.isValid()) { return QColor(); } const QString id = QString::number(item.parentCollection().id()); - return preferences->resourceColor(id); + + QColor color = preferences->resourceColorKnown(id); + if (!color.isValid() && item.parentCollection().hasAttribute()) { + Akonadi::CollectionColorAttribute *colorAttr = item.parentCollection().attribute(); + if (colorAttr && colorAttr->color().isValid()) { + color = colorAttr->color(); + } else { + return preferences->resourceColor(id); + } + } + return color; } int EventViews::yearDiff(const QDate &start, const QDate &end) diff --git a/src/prefs.cpp b/src/prefs.cpp --- a/src/prefs.cpp +++ b/src/prefs.cpp @@ -30,6 +30,9 @@ #include "calendarview_debug.h" #include +#include +#include + using namespace EventViews; QSet iconArrayToSet(const QByteArray &array) @@ -499,10 +502,14 @@ Prefs::Prefs() : d(new Private(this)) { + // necessary to use CollectionColorAttribute in the EventViews::resourceColor and EventViews::setResourceColor + Akonadi::AttributeFactory::registerAttribute(); } Prefs::Prefs(KCoreConfigSkeleton *appConfig) : d(new Private(this, appConfig)) { + // necessary to use CollectionColorAttribute in the EventViews::resourceColor and EventViews::setResourceColor + Akonadi::AttributeFactory::registerAttribute(); } Prefs::~Prefs()