Eventviews

calendardecoration.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Loïc Corbasson <loic.corbasson@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#include "calendardecoration.h"
7
8using namespace EventViews::CalendarDecoration;
9
10Element::Element(const QString &id)
11 : mId(id)
12{
13}
14
15Element::~Element() = default;
16
18{
19 return mId;
20}
21
23{
24 return {};
25}
26
28{
29 return {};
30}
31
33{
34 return {};
35}
36
38{
39 return {};
40}
41
43{
44 return {};
45}
46
48{
49 return {};
50}
51
52////////////////////////////////////////////////////////////////////////////////
53
54StoredElement::StoredElement(const QString &id)
55 : Element(id)
56{
57}
58
59StoredElement::StoredElement(const QString &id, const QString &shortText)
60 : Element(id)
61 , mShortText(shortText)
62{
63}
64
65StoredElement::StoredElement(const QString &id, const QString &shortText, const QString &longText)
66 : Element(id)
67 , mShortText(shortText)
68 , mLongText(longText)
69{
70}
71
72StoredElement::StoredElement(const QString &id, const QString &shortText, const QString &longText, const QString &extensiveText)
73 : Element(id)
74 , mShortText(shortText)
75 , mLongText(longText)
76 , mExtensiveText(extensiveText)
77{
78}
79
80StoredElement::StoredElement(const QString &id, const QPixmap &pixmap)
81 : Element(id)
82 , mPixmap(pixmap)
83{
84}
85
86void StoredElement::setShortText(const QString &t)
87{
88 mShortText = t;
89}
90
92{
93 return mShortText;
94}
95
96void StoredElement::setLongText(const QString &t)
97{
98 mLongText = t;
99}
100
102{
103 return mLongText;
104}
105
106void StoredElement::setExtensiveText(const QString &t)
107{
108 mExtensiveText = t;
109}
110
112{
113 return mExtensiveText;
114}
115
116void StoredElement::setPixmap(const QPixmap &p)
117{
118 mPixmap = p;
119}
120
121QPixmap StoredElement::pixmap() const
122{
123 return mPixmap;
124}
125
126void StoredElement::setUrl(const QUrl &u)
127{
128 mUrl = u;
129}
130
132{
133 return mUrl;
134}
135
136////////////////////////////////////////////////////////////////////////////////
137
138Decoration::Decoration(QObject *parent, const QVariantList &args)
139 : QObject(parent)
140{
141 Q_UNUSED(args)
142}
143
144Decoration::~Decoration()
145{
146 // Deleted by label directly.
147#if 0
148 for (Element::List lst : std::as_const(mDayElements)) {
149 qDeleteAll(lst);
150 lst.clear();
151 }
152 for (Element::List lst : std::as_const(mWeekElements)) {
153 qDeleteAll(lst);
154 lst.clear();
155 }
156 for (Element::List lst : std::as_const(mMonthElements)) {
157 qDeleteAll(lst);
158 lst.clear();
159 }
160 for (Element::List lst : std::as_const(mYearElements)) {
161 qDeleteAll(lst);
162 lst.clear();
163 }
164#endif
165 mDayElements.clear();
166 mWeekElements.clear();
167 mMonthElements.clear();
168 mYearElements.clear();
169}
170
172{
174 it = mDayElements.constFind(date);
175 if (it == mDayElements.constEnd()) {
176 return registerDayElements(createDayElements(date), date);
177 } else {
178 return *it;
179 }
180}
181
183{
184 QDate date = weekDate(d);
186 it = mWeekElements.constFind(date);
187 if (it == mWeekElements.constEnd()) {
188 return registerWeekElements(createWeekElements(date), date);
189 } else {
190 return *it;
191 }
192}
193
195{
196 QDate date = monthDate(d);
198 it = mMonthElements.constFind(date);
199 if (it == mMonthElements.constEnd()) {
200 return registerMonthElements(createMonthElements(date), date);
201 } else {
202 return *it;
203 }
204}
205
207{
208 QDate date = yearDate(d);
210 it = mYearElements.constFind(date);
211 if (it == mYearElements.constEnd()) {
212 return registerYearElements(createYearElements(date), date);
213 } else {
214 return *it;
215 }
216}
217
219{
220 mDayElements.insert(d, e);
221 return e;
222}
223
225{
226 mWeekElements.insert(weekDate(d), e);
227 return e;
228}
229
231{
232 mMonthElements.insert(monthDate(d), e);
233 return e;
234}
235
237{
238 mYearElements.insert(yearDate(d), e);
239 return e;
240}
241
243{
244 return {};
245}
246
248{
249 return {};
250}
251
253{
254 return {};
255}
256
258{
259 return {};
260}
261
262void Decoration::configure(QWidget *)
263{
264}
265
267{
268 QDate result = date;
269 return result.addDays(date.dayOfWeek() - 1);
270}
271
273{
274 return {date.year(), date.month(), 1};
275}
276
278{
279 return {date.year(), 1, 1};
280}
281
282#include "moc_calendardecoration.cpp"
QDate monthDate(QDate date)
Map all dates of the same month to a single date.
virtual Element::List yearElements(const QDate &d)
Return all elements for the year the given date belongs to.
virtual Element::List monthElements(const QDate &d)
Return all elements for the month the given date belongs to.
virtual Element::List createDayElements(const QDate &)
Create day elements for given date.
QDate yearDate(QDate date)
Map all dates of the same year to a single date.
virtual Element::List weekElements(const QDate &d)
Return all elements for the week the given date belongs to.
Element::List registerDayElements(const Element::List &e, const QDate &d)
Register the given elements for the given date.
virtual Element::List createYearElements(const QDate &)
Create elements for the year the given date belongs to.
virtual Element::List createMonthElements(const QDate &)
Create elements for the month the given date belongs to.
virtual Element::List dayElements(const QDate &date)
Return all Elements for the given day.
Element::List registerWeekElements(const Element::List &e, const QDate &d)
Register the given elements for the week the given date belongs to.
Element::List registerYearElements(const Element::List &e, const QDate &d)
Register the given elements for the year the given date belongs to.
virtual Element::List createWeekElements(const QDate &)
Create elements for the week the given date belongs to.
QDate weekDate(QDate date)
Map all dates of the same week to a single date.
Element::List registerMonthElements(const Element::List &e, const QDate &d)
Register the given elements for the month the given date belongs to.
Class for calendar decoration elements.
virtual QString shortText() const
Return a short text for a given date, usually only a few words.
virtual QString longText() const
Return a long text for a given date.
virtual QUrl url() const
Return a URL pointing to more information about the content of the element.
virtual QPixmap newPixmap(const QSize &)
Return a pixmap for a given date and a given size.
virtual QString extensiveText() const
Return an extensive text for a given date.
virtual QString elementInfo() const
Description of element.
virtual QString id() const
Return a name for easy identification.
QUrl url() const override
Return a URL pointing to more information about the content of the element.
QString longText() const override
Return a long text for a given date.
QString extensiveText() const override
Return an extensive text for a given date.
QString shortText() const override
Return a short text for a given date, usually only a few words.
QDate addDays(qint64 ndays) const const
int dayOfWeek() const const
int month() const const
int year() const const
ConstIterator
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.