french -> French
[kdepim.git] / calendarviews / helper.cpp
blob50d868d6f684338ad7cb55070da3cfff470e4ab1
1 /*
2 Copyright (C) 2005 Reinhold Kainhofer <reinhold@kainhofer.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 As a special exception, permission is given to link this program
19 with any edition of Qt, and distribute the resulting executable,
20 without including the source code for Qt in the source distribution.
23 #include "helper.h"
24 #include "prefs.h"
26 #include <Akonadi/Collection>
27 #include <Akonadi/Item>
29 #include <KIconLoader>
31 #include <QPixmap>
32 #include <QPixmapCache>
34 QColor EventViews::getTextColor( const QColor &c )
36 double luminance = ( c.red() * 0.299 ) + ( c.green() * 0.587 ) + ( c.blue() * 0.114 );
37 return ( luminance > 128.0 ) ? QColor( 0, 0, 0 ) : QColor( 255, 255, 255 );
40 QColor EventViews::resourceColor( const Akonadi::Collection &coll, const PrefsPtr &preferences )
42 if ( !coll.isValid() ) {
43 return QColor();
45 const QString id = QString::number( coll.id() );
46 return preferences->resourceColor( id );
49 QColor EventViews::resourceColor( const Akonadi::Item &item, const PrefsPtr &preferences )
51 if ( !item.isValid() ) {
52 return QColor();
54 const QString id = QString::number( item.storageCollectionId() );
55 return preferences->resourceColor( id );
58 int EventViews::yearDiff( const QDate &start, const QDate &end )
60 return end.year() - start.year();
63 QPixmap EventViews::cachedSmallIcon( const QString &name )
65 QPixmap p;
66 if ( !QPixmapCache::find( name, &p ) ) {
67 p = SmallIcon( name );
70 return p;