helper.h 3.04 KB
Newer Older
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 7 8
*/
#ifndef EVENTVIEWS_HELPER_H
#define EVENTVIEWS_HELPER_H

9 10
#include "eventviews_export.h"

11 12 13
#include <QColor>
#include <QSharedPointer>

Laurent Montel's avatar
Laurent Montel committed
14
namespace Akonadi {
15 16 17 18 19 20 21
class Collection;
class Item;
}

class QPixmap;
class QDate;

22 23 24 25 26
// This include file declares static methods that are useful to all views.
/**
 * Namespace EventViews provides facilities for displaying incidences,
 * including events, to-dos, and journal entries.
 */
Laurent Montel's avatar
Laurent Montel committed
27
namespace EventViews {
28 29 30 31 32 33
class Prefs;
typedef QSharedPointer<Prefs> PrefsPtr;

/**
 Returns a nice QColor for text, give the input color &c.
*/
Laurent Montel's avatar
Laurent Montel committed
34
Q_REQUIRED_RESULT QColor getTextColor(const QColor &c);
35

36 37 38 39 40 41 42 43 44
/**
 * Determines if the @p color is "dark" or "light" by looking at its luminance.
 * idea taken from:
 * https://stackoverflow.com/questions/9780632/how-do-i-determine-if-a-color-is-closer-to-white-or-black
 *
 * @return true if the specified color is closer to black than white.
 */
Q_REQUIRED_RESULT bool isColorDark(const QColor &color);

45 46
/**
  This method returns the proper resource / subresource color for the view.
47 48 49
  If a value is stored in the preferences, we use it, else we try to find a
  CollectionColorAttribute in the collection. If everything else fails, a
  random color can be set.
Allen Winter's avatar
Allen Winter committed
50
  It is preferred to use this function instead of the
51
  EventViews::Prefs::resourceColor function.
52 53 54 55 56 57
  @return The resource color for the incidence. If the incidence belongs
  to a subresource, the color for the subresource is returned (if set).
  @param calendar the calendar for which the resource color should be obtained
  @param incidence the incidence for which the color is needed (to
                   determine which  subresource needs to be used)
*/
Laurent Montel's avatar
Laurent Montel committed
58
Q_REQUIRED_RESULT EVENTVIEWS_EXPORT QColor resourceColor(const Akonadi::Item &incidence, const PrefsPtr &preferences);
59

Laurent Montel's avatar
Laurent Montel committed
60
Q_REQUIRED_RESULT EVENTVIEWS_EXPORT QColor resourceColor(const Akonadi::Collection &collection, const PrefsPtr &preferences);
61

62
/**
63 64
  This method sets the resource color as an Akonadi collection attribute and
  in the local preferences. It is preferred to use this
65 66 67 68 69
  instead of the EventViews::Prefs::setResourceColor function.
  @param collection the collection for which the resource color should be stored
  @param color the color to stored
  @param preferences a pointer to the EventViews::Prefs to use
*/
Laurent Montel's avatar
Laurent Montel committed
70
EVENTVIEWS_EXPORT void setResourceColor(const Akonadi::Collection &collection, const QColor &color, const PrefsPtr &preferences);
71

72 73 74 75
/**
  Returns the number of years between the @p start QDate and the @p end QDate
  (i.e. the difference in the year number of both dates)
*/
Laurent Montel's avatar
Laurent Montel committed
76
Q_REQUIRED_RESULT int yearDiff(const QDate &start, const QDate &end);
77 78 79 80 81 82 83 84

/**
   Equivalent to SmallIcon( name ), but uses QPixmapCache.
   KIconLoader already uses a cache, but it's 20x slower on my tests.

   @return A new pixmap if it isn't yet in cache, otherwise returns the
           cached one.
*/
Laurent Montel's avatar
Laurent Montel committed
85
Q_REQUIRED_RESULT QPixmap cachedSmallIcon(const QString &name);
86 87 88
}

#endif