korganizer
kohelper.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qcolor.h>
00026
00027 #include <kdebug.h>
00028
00029 #include <libkcal/incidence.h>
00030 #include <libkcal/calendar.h>
00031 #include <libkcal/calendarresources.h>
00032 #include <libkcal/resourcecalendar.h>
00033
00034 #include "koprefs.h"
00035 #include "kohelper.h"
00036
00037 QColor KOHelper::mixColors( const QColor &transparentColor,
00038 double alpha,
00039 const QColor &otherColor )
00040 {
00041 const int red = ( 1 - alpha )*otherColor.red() + alpha*transparentColor.red();
00042 const int green = ( 1 - alpha )*otherColor.green() + alpha*transparentColor.green();
00043 const int blue = ( 1 - alpha )*otherColor.blue() + alpha*transparentColor.blue();
00044
00045 return QColor( red, green, blue );
00046 }
00047
00048 QColor KOHelper::resourceColor( KCal::Calendar*calendar, KCal::Incidence*incidence )
00049 {
00050 QColor resourceColor = QColor();
00051
00052
00053 KCal::CalendarResources *calendarResource = dynamic_cast<KCal::CalendarResources*>( calendar );
00054
00055 if ( calendarResource ) {
00056 KCal::ResourceCalendar *resourceCalendar = calendarResource->resource( incidence );
00057
00058 if( resourceCalendar ) {
00059 QString identifier = resourceCalendar->identifier();
00060 resourceColor = *KOPrefs::instance()->resourceColor( identifier );
00061
00062 if ( !resourceCalendar->subresources().isEmpty() ) {
00063 identifier = resourceCalendar->subresourceIdentifier( incidence );
00064 if ( identifier.isEmpty() )
00065 identifier = resourceCalendar->identifier();
00066 QColor subrescolor( *KOPrefs::instance()->resourceColor( identifier ) );
00067 if ( subrescolor.isValid() )
00068 resourceColor = subrescolor;
00069 }
00070 }
00071
00072
00073 }
00074 return resourceColor;
00075 }
|