2 This file is part of KOrganizer.
4 Copyright (C) 2005 Reinhold Kainhofer <reinhold@kainhofer.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution.
26 #include "prefs/koprefs.h"
28 #include <CalendarSupport/KCalPrefs>
30 #include <KMessageBox>
32 QColor
KOHelper::getTextColor(const QColor
&c
)
34 double luminance
= (c
.red() * 0.299) + (c
.green() * 0.587) + (c
.blue() * 0.114);
35 return (luminance
> 128.0) ? QColor(0, 0, 0) : QColor(255, 255, 255);
38 QColor
KOHelper::resourceColor(const Akonadi::Collection
&coll
)
40 if (!coll
.isValid()) {
44 const QString id
= QString::number(coll
.id());
45 return KOPrefs::instance()->resourceColor(id
);
48 QColor
KOHelper::resourceColorKnown(const Akonadi::Collection
&coll
)
50 if (!coll
.isValid()) {
54 const QString id
= QString::number(coll
.id());
55 return KOPrefs::instance()->resourceColorKnown(id
);
58 void KOHelper::setResourceColor(const Akonadi::Collection
&collection
, const QColor
&color
)
60 if (collection
.isValid()) {
61 const QString id
= QString::number(collection
.id());
62 return KOPrefs::instance()->setResourceColor(id
, color
);
66 QColor
KOHelper::resourceColor(const Akonadi::Item
&item
)
68 if (!item
.isValid()) {
72 const QString id
= QString::number(item
.storageCollectionId());
73 return KOPrefs::instance()->resourceColor(id
);
76 int KOHelper::yearDiff(const QDate
&start
, const QDate
&end
)
78 return end
.year() - start
.year();
81 bool KOHelper::isStandardCalendar(Akonadi::Collection::Id id
)
83 return id
== CalendarSupport::KCalPrefs::instance()->defaultCalendarId();
86 void KOHelper::showSaveIncidenceErrorMsg(QWidget
*parent
,
87 const KCalCore::Incidence::Ptr
&incidence
)
91 i18n("Unable to save %1 \"%2\".",
92 i18n(incidence
->typeStr()), incidence
->summary()));