File indexing completed on 2024-11-24 04:41:33
0001 /* 0002 SPDX-FileCopyrightText: 2007 Loïc Corbasson <loic.corbasson@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #pragma once 0007 0008 #include "eventviews_export.h" 0009 0010 #include <QUrl> 0011 0012 #include <QDate> 0013 #include <QMap> 0014 #include <QPixmap> 0015 #include <QVariant> 0016 0017 namespace EventViews 0018 { 0019 namespace CalendarDecoration 0020 { 0021 /** 0022 @class Element 0023 0024 @brief Class for calendar decoration elements 0025 0026 It provides entities like texts and pictures for a given date. 0027 Implementations can implement all functions or only a subset. 0028 */ 0029 class EVENTVIEWS_EXPORT Element : public QObject 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 using List = QList<Element *>; 0035 0036 explicit Element(const QString &id); 0037 ~Element() override; 0038 0039 /** 0040 Return a name for easy identification. 0041 This will be used for example for internal configuration (position, etc.), 0042 so don't i18n it and make it unique for your decoration. 0043 */ 0044 [[nodiscard]] virtual QString id() const; 0045 0046 /** 0047 Description of element. 0048 */ 0049 [[nodiscard]] virtual QString elementInfo() const; 0050 0051 /** 0052 Return a short text for a given date, 0053 usually only a few words. 0054 */ 0055 [[nodiscard]] virtual QString shortText() const; 0056 0057 /** 0058 Return a long text for a given date. 0059 This text can be of any length, 0060 but usually it will have one or a few lines. 0061 0062 Can for example be used as a tool tip. 0063 */ 0064 [[nodiscard]] virtual QString longText() const; 0065 0066 /** 0067 Return an extensive text for a given date. 0068 This text can be of any length, 0069 but usually it will have one or a few paragraphs. 0070 */ 0071 [[nodiscard]] virtual QString extensiveText() const; 0072 0073 /** 0074 Return a pixmap for a given date and a given size. 0075 */ 0076 [[nodiscard]] virtual QPixmap newPixmap(const QSize &); 0077 0078 /** 0079 Return a URL pointing to more information about the content of the 0080 element. 0081 */ 0082 [[nodiscard]] virtual QUrl url() const; 0083 0084 Q_SIGNALS: 0085 void gotNewPixmap(const QPixmap &); 0086 void gotNewShortText(const QString &); 0087 void gotNewLongText(const QString &); 0088 void gotNewExtensiveText(const QString &); 0089 void gotNewUrl(const QUrl &); 0090 0091 protected: 0092 QString mId; 0093 }; 0094 0095 /** 0096 This class provides a stored element, which contains all data for the given 0097 date/month/year. 0098 */ 0099 class EVENTVIEWS_EXPORT StoredElement : public Element 0100 { 0101 Q_OBJECT 0102 public: 0103 explicit StoredElement(const QString &id); 0104 StoredElement(const QString &id, const QString &shortText); 0105 StoredElement(const QString &id, const QString &shortText, const QString &longText); 0106 StoredElement(const QString &id, const QString &shortText, const QString &longText, const QString &extensiveText); 0107 StoredElement(const QString &id, const QPixmap &pixmap); 0108 0109 virtual void setShortText(const QString &t); 0110 [[nodiscard]] QString shortText() const override; 0111 0112 virtual void setLongText(const QString &t); 0113 [[nodiscard]] QString longText() const override; 0114 0115 virtual void setExtensiveText(const QString &t); 0116 [[nodiscard]] QString extensiveText() const override; 0117 0118 virtual void setPixmap(const QPixmap &p); 0119 [[nodiscard]] virtual QPixmap pixmap() const; 0120 0121 virtual void setUrl(const QUrl &u); 0122 [[nodiscard]] QUrl url() const override; 0123 0124 protected: 0125 QString mShortText; 0126 QString mLongText; 0127 QString mExtensiveText; 0128 QPixmap mPixmap; 0129 QUrl mUrl; 0130 }; 0131 0132 /** 0133 @class Decoration 0134 0135 @brief This class provides the interface for a date dependent decoration. 0136 0137 The decoration is made of various decoration elements, 0138 which show a defined text/picture/widget for a given date. 0139 */ 0140 class EVENTVIEWS_EXPORT Decoration : public QObject 0141 { 0142 Q_OBJECT 0143 0144 public: 0145 using List = QList<Decoration *>; 0146 0147 Decoration(QObject *parent = nullptr, const QVariantList &args = {}); 0148 ~Decoration() override; 0149 0150 /** 0151 Return all Elements for the given day. 0152 */ 0153 virtual Element::List dayElements(const QDate &date); 0154 0155 /** 0156 Return all elements for the week the given date belongs to. 0157 */ 0158 virtual Element::List weekElements(const QDate &d); 0159 0160 /** 0161 Return all elements for the month the given date belongs to. 0162 */ 0163 virtual Element::List monthElements(const QDate &d); 0164 0165 /** 0166 Return all elements for the year the given date belongs to. 0167 */ 0168 virtual Element::List yearElements(const QDate &d); 0169 0170 virtual void configure(QWidget *); 0171 0172 virtual QString info() const = 0; 0173 0174 protected: 0175 /** 0176 Register the given elements for the given date. They will be deleted when 0177 this object is destroyed. 0178 */ 0179 Element::List registerDayElements(const Element::List &e, const QDate &d); 0180 0181 /** 0182 Register the given elements for the week the given date belongs to. They 0183 will be deleted when this object is destroyed. 0184 */ 0185 Element::List registerWeekElements(const Element::List &e, const QDate &d); 0186 0187 /** 0188 Register the given elements for the month the given date belongs to. They 0189 will be deleted when this object is destroyed. 0190 */ 0191 Element::List registerMonthElements(const Element::List &e, const QDate &d); 0192 0193 /** 0194 Register the given elements for the year the given date belongs to. They 0195 will be deleted when this object is destroyed. 0196 */ 0197 Element::List registerYearElements(const Element::List &e, const QDate &d); 0198 0199 /** 0200 Create day elements for given date. 0201 */ 0202 virtual Element::List createDayElements(const QDate &); 0203 0204 /** 0205 Create elements for the week the given date belongs to. 0206 */ 0207 virtual Element::List createWeekElements(const QDate &); 0208 0209 /** 0210 Create elements for the month the given date belongs to. 0211 */ 0212 virtual Element::List createMonthElements(const QDate &); 0213 0214 /** 0215 Create elements for the year the given date belongs to. 0216 */ 0217 virtual Element::List createYearElements(const QDate &); 0218 0219 /** 0220 Map all dates of the same week to a single date. 0221 */ 0222 QDate weekDate(QDate date); 0223 0224 /** 0225 Map all dates of the same month to a single date. 0226 */ 0227 QDate monthDate(QDate date); 0228 0229 /** 0230 Map all dates of the same year to a single date. 0231 */ 0232 QDate yearDate(QDate date); 0233 0234 private: 0235 QMap<QDate, Element::List> mDayElements; 0236 QMap<QDate, Element::List> mWeekElements; 0237 QMap<QDate, Element::List> mMonthElements; 0238 QMap<QDate, Element::List> mYearElements; 0239 }; 0240 0241 } 0242 }