Changeset View
Changeset View
Standalone View
Standalone View
korganizer/kohelper.cpp
Show All 20 Lines | /* | ||||
with any edition of Qt, and distribute the resulting executable, | with any edition of Qt, and distribute the resulting executable, | ||||
without including the source code for Qt in the source distribution. | without including the source code for Qt in the source distribution. | ||||
*/ | */ | ||||
#include "kohelper.h" | #include "kohelper.h" | ||||
#include "koprefs.h" | #include "koprefs.h" | ||||
#include <calendarsupport/kcalprefs.h> | #include <calendarsupport/kcalprefs.h> | ||||
#include <akonadi/collectioncolorattribute.h> | |||||
#include <KMessageBox> | #include <KMessageBox> | ||||
QColor KOHelper::getTextColor( const QColor &c ) | QColor KOHelper::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 KOHelper::resourceColor( const Akonadi::Collection &coll ) | QColor KOHelper::resourceColor( const Akonadi::Collection &coll ) | ||||
{ | { | ||||
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 KOPrefs::instance()->resourceColor( id ); | return KOPrefs::instance()->resourceColor( id ); | ||||
} | } | ||||
QColor KOHelper::resourceColorKnown( const Akonadi::Collection &coll ) | QColor KOHelper::resourceColorKnown( const Akonadi::Collection &coll ) | ||||
{ | { | ||||
if ( !coll.isValid() ) { | if ( !coll.isValid() ) { | ||||
return QColor(); | return QColor(); | ||||
} | } | ||||
const QString id = QString::number( coll.id() ); | Akonadi::CollectionColorAttribute *colorAttribute = coll.attribute<Akonadi::CollectionColorAttribute>(); | ||||
return KOPrefs::instance()->resourceColorKnown( id ); | if (colorAttribute) { | ||||
return colorAttribute->color(); | |||||
} | |||||
} | } | ||||
void KOHelper::setResourceColor(const Akonadi::Collection &collection, const QColor &color) | void KOHelper::setResourceColor(Akonadi::Collection &collection, const QColor &color) | ||||
{ | { | ||||
if ( collection.isValid() ) { | if ( collection.isValid() ) { | ||||
const QString id = QString::number( collection.id() ); | collection.attribute<Akonadi::CollectionColorAttribute>(Akonadi::Collection::AddIfMissing)->setColor(color); | ||||
return KOPrefs::instance()->setResourceColor(id, color); | |||||
} | } | ||||
} | } | ||||
QColor KOHelper::resourceColor( const Akonadi::Item &item ) | QColor KOHelper::resourceColor( const Akonadi::Item &item ) | ||||
{ | { | ||||
if ( !item.isValid() ) { | if ( !item.isValid() ) { | ||||
return QColor(); | return QColor(); | ||||
} | } | ||||
const QString id = QString::number( item.storageCollectionId() ); | return resourceColor(item.parentCollection()); | ||||
return KOPrefs::instance()->resourceColor( id ); | |||||
} | } | ||||
int KOHelper::yearDiff( const QDate &start, const QDate &end ) | int KOHelper::yearDiff( const QDate &start, const QDate &end ) | ||||
{ | { | ||||
return end.year() - start.year(); | return end.year() - start.year(); | ||||
} | } | ||||
bool KOHelper::isStandardCalendar( const Akonadi::Entity::Id &id ) | bool KOHelper::isStandardCalendar( const Akonadi::Entity::Id &id ) | ||||
Show All 13 Lines |