Eventviews

helper.h
1/*
2 SPDX-FileCopyrightText: 2005 Reinhold Kainhofer <reinhold@kainhofer.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
5*/
6#pragma once
7
8#include "eventviews_export.h"
9
10#include <QColor>
11#include <QSharedPointer>
12
13namespace Akonadi
14{
15class Collection;
16class Item;
17}
18
19class QPixmap;
20class QDate;
21
22// This include file declares static methods that are useful to all views.
23/**
24 * Namespace EventViews provides facilities for displaying incidences,
25 * including events, to-dos, and journal entries.
26 */
27namespace EventViews
28{
29class Prefs;
30using PrefsPtr = QSharedPointer<Prefs>;
31
32/**
33 Returns a nice QColor for text, give the input color &c.
34*/
35[[nodiscard]] QColor getTextColor(const QColor &c);
36
37/**
38 * Determines if the @p color is "dark" or "light" by looking at its luminance.
39 * idea taken from:
40 * https://stackoverflow.com/questions/9780632/how-do-i-determine-if-a-color-is-closer-to-white-or-black
41 *
42 * @return true if the specified color is closer to black than white.
43 */
44[[nodiscard]] bool isColorDark(const QColor &color);
45
46/**
47 This method returns the proper resource / subresource color for the view.
48 If a value is stored in the preferences, we use it, else we try to find a
49 CollectionColorAttribute in the collection. If everything else fails, a
50 random color can be set.
51 It is preferred to use this function instead of the
52 EventViews::Prefs::resourceColor function.
53 @return The resource color for the incidence. If the incidence belongs
54 to a subresource, the color for the subresource is returned (if set).
55 @param calendar the calendar for which the resource color should be obtained
56 @param incidence the incidence for which the color is needed (to
57 determine which subresource needs to be used)
58*/
59[[nodiscard]] EVENTVIEWS_EXPORT QColor resourceColor(const Akonadi::Collection &collection, const PrefsPtr &preferences);
60
61/**
62 This method sets the resource color as an Akonadi collection attribute and
63 in the local preferences. It is preferred to use this
64 instead of the EventViews::Prefs::setResourceColor function.
65 @param collection the collection for which the resource color should be stored
66 @param color the color to stored
67 @param preferences a pointer to the EventViews::Prefs to use
68*/
69EVENTVIEWS_EXPORT void setResourceColor(const Akonadi::Collection &collection, const QColor &color, const PrefsPtr &preferences);
70
71/**
72 Returns the number of years between the @p start QDate and the @p end QDate
73 (i.e. the difference in the year number of both dates)
74*/
75[[nodiscard]] int yearDiff(QDate start, QDate end);
76
77/**
78 Equivalent to SmallIcon( name ), but uses QPixmapCache.
79 KIconLoader already uses a cache, but it's 20x slower on my tests.
80
81 @return A new pixmap if it isn't yet in cache, otherwise returns the
82 cached one.
83*/
84[[nodiscard]] QPixmap cachedSmallIcon(const QString &name);
85}
Q_SCRIPTABLE Q_NOREPLY void start()
Namespace EventViews provides facilities for displaying incidences, including events,...
Definition agenda.h:33
bool isColorDark(const QColor &color)
Determines if the color is "dark" or "light" by looking at its luminance.
Definition helper.cpp:20
EVENTVIEWS_EXPORT QColor resourceColor(const Akonadi::Collection &collection, const PrefsPtr &preferences)
This method returns the proper resource / subresource color for the view.
Definition helper.cpp:56
QPixmap cachedSmallIcon(const QString &name)
Equivalent to SmallIcon( name ), but uses QPixmapCache.
Definition helper.cpp:83
int yearDiff(QDate start, QDate end)
Returns the number of years between the start QDate and the end QDate (i.e.
Definition helper.cpp:78
EVENTVIEWS_EXPORT void setResourceColor(const Akonadi::Collection &collection, const QColor &color, const PrefsPtr &preferences)
This method sets the resource color as an Akonadi collection attribute and in the local preferences.
Definition helper.cpp:31
QColor getTextColor(const QColor &c)
Returns a nice QColor for text, give the input color &c.
Definition helper.cpp:26
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:12:29 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.