File indexing completed on 2025-03-09 04:45:14
0001 /* 0002 SPDX-FileCopyrightText: 2005 Reinhold Kainhofer <reinhold@kainhofer.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0005 */ 0006 #pragma once 0007 0008 #include "eventviews_export.h" 0009 0010 #include <QColor> 0011 #include <QSharedPointer> 0012 0013 namespace Akonadi 0014 { 0015 class Collection; 0016 class Item; 0017 } 0018 0019 class QPixmap; 0020 class QDate; 0021 0022 // This include file declares static methods that are useful to all views. 0023 /** 0024 * Namespace EventViews provides facilities for displaying incidences, 0025 * including events, to-dos, and journal entries. 0026 */ 0027 namespace EventViews 0028 { 0029 class Prefs; 0030 using PrefsPtr = QSharedPointer<Prefs>; 0031 0032 /** 0033 Returns a nice QColor for text, give the input color &c. 0034 */ 0035 [[nodiscard]] QColor getTextColor(const QColor &c); 0036 0037 /** 0038 * Determines if the @p color is "dark" or "light" by looking at its luminance. 0039 * idea taken from: 0040 * https://stackoverflow.com/questions/9780632/how-do-i-determine-if-a-color-is-closer-to-white-or-black 0041 * 0042 * @return true if the specified color is closer to black than white. 0043 */ 0044 [[nodiscard]] bool isColorDark(const QColor &color); 0045 0046 /** 0047 This method returns the proper resource / subresource color for the view. 0048 If a value is stored in the preferences, we use it, else we try to find a 0049 CollectionColorAttribute in the collection. If everything else fails, a 0050 random color can be set. 0051 It is preferred to use this function instead of the 0052 EventViews::Prefs::resourceColor function. 0053 @return The resource color for the incidence. If the incidence belongs 0054 to a subresource, the color for the subresource is returned (if set). 0055 @param calendar the calendar for which the resource color should be obtained 0056 @param incidence the incidence for which the color is needed (to 0057 determine which subresource needs to be used) 0058 */ 0059 [[nodiscard]] EVENTVIEWS_EXPORT QColor resourceColor(const Akonadi::Item &incidence, const PrefsPtr &preferences); 0060 0061 [[nodiscard]] EVENTVIEWS_EXPORT QColor resourceColor(const Akonadi::Collection &collection, const PrefsPtr &preferences); 0062 0063 /** 0064 This method sets the resource color as an Akonadi collection attribute and 0065 in the local preferences. It is preferred to use this 0066 instead of the EventViews::Prefs::setResourceColor function. 0067 @param collection the collection for which the resource color should be stored 0068 @param color the color to stored 0069 @param preferences a pointer to the EventViews::Prefs to use 0070 */ 0071 EVENTVIEWS_EXPORT void setResourceColor(const Akonadi::Collection &collection, const QColor &color, const PrefsPtr &preferences); 0072 0073 /** 0074 Returns the number of years between the @p start QDate and the @p end QDate 0075 (i.e. the difference in the year number of both dates) 0076 */ 0077 [[nodiscard]] int yearDiff(QDate start, QDate end); 0078 0079 /** 0080 Equivalent to SmallIcon( name ), but uses QPixmapCache. 0081 KIconLoader already uses a cache, but it's 20x slower on my tests. 0082 0083 @return A new pixmap if it isn't yet in cache, otherwise returns the 0084 cached one. 0085 */ 0086 [[nodiscard]] QPixmap cachedSmallIcon(const QString &name); 0087 }