Changeset View
Changeset View
Standalone View
Standalone View
calendarviews/helper.cpp
Show All 19 Lines | /* | ||||
without including the source code for Qt in the source distribution. | without including the source code for Qt in the source distribution. | ||||
*/ | */ | ||||
#include "helper.h" | #include "helper.h" | ||||
#include "prefs.h" | #include "prefs.h" | ||||
#include <Akonadi/Collection> | #include <Akonadi/Collection> | ||||
#include <Akonadi/Item> | #include <Akonadi/Item> | ||||
#include <akonadi/collectioncolorattribute.h> | |||||
#include <KIconLoader> | #include <KIconLoader> | ||||
#include <QPixmap> | #include <QPixmap> | ||||
#include <QPixmapCache> | #include <QPixmapCache> | ||||
QColor EventViews::getTextColor( const QColor &c ) | QColor EventViews::getTextColor( const QColor &c ) | ||||
{ | { | ||||
double luminance = ( c.red() * 0.299 ) + ( c.green() * 0.587 ) + ( c.blue() * 0.114 ); | double luminance = ( c.red() * 0.299 ) + ( c.green() * 0.587 ) + ( c.blue() * 0.114 ); | ||||
return ( luminance > 128.0 ) ? QColor( 0, 0, 0 ) : QColor( 255, 255, 255 ); | return ( luminance > 128.0 ) ? QColor( 0, 0, 0 ) : QColor( 255, 255, 255 ); | ||||
} | } | ||||
QColor EventViews::resourceColor( const Akonadi::Collection &coll, const PrefsPtr &preferences ) | QColor EventViews::resourceColor( const Akonadi::Collection &coll, const PrefsPtr &preferences ) | ||||
{ | { | ||||
if ( !coll.isValid() ) { | if ( !coll.isValid() ) { | ||||
return QColor(); | return QColor(); | ||||
} | } | ||||
Akonadi::CollectionColorAttribute *colorAttribute = coll.attribute<Akonadi::CollectionColorAttribute>(); | |||||
if (colorAttribute) { | |||||
return colorAttribute->color(); | |||||
} | |||||
const QString id = QString::number( coll.id() ); | const QString id = QString::number( coll.id() ); | ||||
return preferences->resourceColor( id ); | return preferences->resourceColor( id ); | ||||
} | } | ||||
QColor EventViews::resourceColor( const Akonadi::Item &item, const PrefsPtr &preferences ) | QColor EventViews::resourceColor( const Akonadi::Item &item, const PrefsPtr &preferences ) | ||||
{ | { | ||||
if ( !item.isValid() ) { | if ( !item.isValid() ) { | ||||
return QColor(); | return QColor(); | ||||
} | } | ||||
const QString id = QString::number( item.parentCollection().id() ); | return resourceColor(item.parentCollection(), preferences); | ||||
return preferences->resourceColor( id ); | |||||
} | } | ||||
int EventViews::yearDiff( const QDate &start, const QDate &end ) | int EventViews::yearDiff( const QDate &start, const QDate &end ) | ||||
{ | { | ||||
return end.year() - start.year(); | return end.year() - start.year(); | ||||
} | } | ||||
QPixmap EventViews::cachedSmallIcon( const QString &name ) | QPixmap EventViews::cachedSmallIcon( const QString &name ) | ||||
{ | { | ||||
QPixmap p; | QPixmap p; | ||||
if ( !QPixmapCache::find( name, &p ) ) { | if ( !QPixmapCache::find( name, &p ) ) { | ||||
p = SmallIcon( name ); | p = SmallIcon( name ); | ||||
} | } | ||||
return p; | return p; | ||||
} | } |