Eventviews

calendardecoration.h
1/*
2 SPDX-FileCopyrightText: 2007 Loïc Corbasson <loic.corbasson@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#pragma once
7
8#include "eventviews_export.h"
9
10#include <QUrl>
11
12#include <QDate>
13#include <QMap>
14#include <QPixmap>
15#include <QVariant>
16
17namespace EventViews
18{
19namespace CalendarDecoration
20{
21/**
22 @class Element
23
24 @brief Class for calendar decoration elements
25
26 It provides entities like texts and pictures for a given date.
27 Implementations can implement all functions or only a subset.
28 */
29class EVENTVIEWS_EXPORT Element : public QObject
30{
31 Q_OBJECT
32
33public:
34 using List = QList<Element *>;
35
36 explicit Element(const QString &id);
37 ~Element() override;
38
39 /**
40 Return a name for easy identification.
41 This will be used for example for internal configuration (position, etc.),
42 so don't i18n it and make it unique for your decoration.
43 */
44 [[nodiscard]] virtual QString id() const;
45
46 /**
47 Description of element.
48 */
49 [[nodiscard]] virtual QString elementInfo() const;
50
51 /**
52 Return a short text for a given date,
53 usually only a few words.
54 */
55 [[nodiscard]] virtual QString shortText() const;
56
57 /**
58 Return a long text for a given date.
59 This text can be of any length,
60 but usually it will have one or a few lines.
61
62 Can for example be used as a tool tip.
63 */
64 [[nodiscard]] virtual QString longText() const;
65
66 /**
67 Return an extensive text for a given date.
68 This text can be of any length,
69 but usually it will have one or a few paragraphs.
70 */
71 [[nodiscard]] virtual QString extensiveText() const;
72
73 /**
74 Return a pixmap for a given date and a given size.
75 */
76 [[nodiscard]] virtual QPixmap newPixmap(const QSize &);
77
78 /**
79 Return a URL pointing to more information about the content of the
80 element.
81 */
82 [[nodiscard]] virtual QUrl url() const;
83
84Q_SIGNALS:
85 void gotNewPixmap(const QPixmap &);
86 void gotNewShortText(const QString &);
87 void gotNewLongText(const QString &);
88 void gotNewExtensiveText(const QString &);
89 void gotNewUrl(const QUrl &);
90
91protected:
92 QString mId;
93};
94
95/**
96 This class provides a stored element, which contains all data for the given
97 date/month/year.
98*/
99class EVENTVIEWS_EXPORT StoredElement : public Element
100{
101 Q_OBJECT
102public:
103 explicit StoredElement(const QString &id);
104 StoredElement(const QString &id, const QString &shortText);
105 StoredElement(const QString &id, const QString &shortText, const QString &longText);
106 StoredElement(const QString &id, const QString &shortText, const QString &longText, const QString &extensiveText);
107 StoredElement(const QString &id, const QPixmap &pixmap);
108
109 virtual void setShortText(const QString &t);
110 [[nodiscard]] QString shortText() const override;
111
112 virtual void setLongText(const QString &t);
113 [[nodiscard]] QString longText() const override;
114
115 virtual void setExtensiveText(const QString &t);
116 [[nodiscard]] QString extensiveText() const override;
117
118 virtual void setPixmap(const QPixmap &p);
119 [[nodiscard]] virtual QPixmap pixmap() const;
120
121 virtual void setUrl(const QUrl &u);
122 [[nodiscard]] QUrl url() const override;
123
124protected:
125 QString mShortText;
126 QString mLongText;
127 QString mExtensiveText;
128 QPixmap mPixmap;
129 QUrl mUrl;
130};
131
132/**
133 @class Decoration
134
135 @brief This class provides the interface for a date dependent decoration.
136
137 The decoration is made of various decoration elements,
138 which show a defined text/picture/widget for a given date.
139 */
140class EVENTVIEWS_EXPORT Decoration : public QObject
141{
142 Q_OBJECT
143
144public:
146
147 Decoration(QObject *parent = nullptr, const QVariantList &args = {});
148 ~Decoration() override;
149
150 /**
151 Return all Elements for the given day.
152 */
153 virtual Element::List dayElements(const QDate &date);
154
155 /**
156 Return all elements for the week the given date belongs to.
157 */
158 virtual Element::List weekElements(const QDate &d);
159
160 /**
161 Return all elements for the month the given date belongs to.
162 */
163 virtual Element::List monthElements(const QDate &d);
164
165 /**
166 Return all elements for the year the given date belongs to.
167 */
168 virtual Element::List yearElements(const QDate &d);
169
170 virtual void configure(QWidget *);
171
172 virtual QString info() const = 0;
173
174protected:
175 /**
176 Register the given elements for the given date. They will be deleted when
177 this object is destroyed.
178 */
179 Element::List registerDayElements(const Element::List &e, const QDate &d);
180
181 /**
182 Register the given elements for the week the given date belongs to. They
183 will be deleted when this object is destroyed.
184 */
185 Element::List registerWeekElements(const Element::List &e, const QDate &d);
186
187 /**
188 Register the given elements for the month the given date belongs to. They
189 will be deleted when this object is destroyed.
190 */
191 Element::List registerMonthElements(const Element::List &e, const QDate &d);
192
193 /**
194 Register the given elements for the year the given date belongs to. They
195 will be deleted when this object is destroyed.
196 */
197 Element::List registerYearElements(const Element::List &e, const QDate &d);
198
199 /**
200 Create day elements for given date.
201 */
202 virtual Element::List createDayElements(const QDate &);
203
204 /**
205 Create elements for the week the given date belongs to.
206 */
207 virtual Element::List createWeekElements(const QDate &);
208
209 /**
210 Create elements for the month the given date belongs to.
211 */
212 virtual Element::List createMonthElements(const QDate &);
213
214 /**
215 Create elements for the year the given date belongs to.
216 */
217 virtual Element::List createYearElements(const QDate &);
218
219 /**
220 Map all dates of the same week to a single date.
221 */
222 [[nodiscard]] QDate weekDate(QDate date);
223
224 /**
225 Map all dates of the same month to a single date.
226 */
227 [[nodiscard]] QDate monthDate(QDate date);
228
229 /**
230 Map all dates of the same year to a single date.
231 */
232 [[nodiscard]] QDate yearDate(QDate date);
233
234private:
235 QMap<QDate, Element::List> mDayElements;
236 QMap<QDate, Element::List> mWeekElements;
237 QMap<QDate, Element::List> mMonthElements;
238 QMap<QDate, Element::List> mYearElements;
239};
240
241}
242}
This class provides the interface for a date dependent decoration.
Class for calendar decoration elements.
This class provides a stored element, which contains all data for the given date/month/year.
Namespace EventViews provides facilities for displaying incidences, including events,...
Definition agenda.h:33
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:55 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.