korganizer

kohelper.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2005 Reinhold Kainhofer <reinhold@kainhofer.com>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
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(); //Default invalid color
00051   //FIXME: dynamic_cast are dirty, Better We implements interface to get the color
00052   // from the calendar
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 //   } else {
00072 //     kdDebug(5850) << "resourceColor: Calendar is not a CalendarResources" <<endl;
00073   }
00074   return resourceColor;
00075 }
KDE Home | KDE Accessibility Home | Description of Access Keys