Eventviews

monthitem.h
1/*
2 SPDX-FileCopyrightText: 2008 Bruno Virlet <bruno.virlet@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
5*/
6
7#pragma once
8
9#include "eventviews_export.h"
10
11#include <Akonadi/CollectionCalendar>
12#include <Akonadi/Item>
13#include <KCalendarCore/Incidence>
14
15#include <QDate>
16#include <QObject>
17
18namespace EventViews
19{
20class MonthGraphicsItem;
21class MonthScene;
22
23/**
24 * A month item manages different MonthGraphicsItems.
25 */
26class EVENTVIEWS_EXPORT MonthItem : public QObject
27{
28 Q_OBJECT
29
30public:
31 explicit MonthItem(MonthScene *monthWidget);
32 ~MonthItem() override;
33
34 [[nodiscard]] QWidget *parentWidget() const;
35
36 /**
37 Compares two items to decide which to place in the view first.
38
39 The month view displays a list of items. When loading (which occurs each
40 time there is a change), the items are sorted in an order intended to
41 avoid unsightly gaps:
42 - biggest durations first
43 - earliest date
44 - finally, time in the day
45 Holidays are sorted before events with the same start date and length,
46 so they appear at the top of the day's box.
47 */
48 static bool greaterThan(const MonthItem *e1, const MonthItem *e2);
49
50 /**
51 Compare this event with a second one, if the former function is not
52 able to sort them.
53 */
54 virtual bool greaterThanFallback(const MonthItem *other) const;
55
56 /**
57 The start date of the incidence, generally realStartDate. But it
58 reflect changes, even during move.
59 */
60 [[nodiscard]] QDate startDate() const;
61
62 /**
63 The end date of the incidence, generally realEndDate. But it
64 reflect changes, even during move.
65 */
66 [[nodiscard]] QDate endDate() const;
67
68 /**
69 The number of days this item spans.
70 */
71 [[nodiscard]] int daySpan() const;
72
73 /**
74 This is the real start date, usually the start date of the incidence.
75 */
76 virtual QDate realStartDate() const = 0;
77
78 /**
79 This is the real end date, usually the end date of the incidence.
80 */
81 virtual QDate realEndDate() const = 0;
82
83 /**
84 True if this item last all the day.
85 */
86 virtual bool allDay() const = 0;
87
88 /**
89 Updates geometry of all MonthGraphicsItems.
90 */
91 void updateGeometry();
92
93 /**
94 Find the lowest possible position for this item.
95
96 The position of an item in a cell is it's vertical position. This is used
97 to avoid overlapping of items. An item keeps the same position in every
98 cell it crosses. The position is measured from top to bottom.
99 */
100 void updatePosition();
101
102 /**
103 Returns true if this item is selected.
104 */
105 [[nodiscard]] bool selected() const
106 {
107 return mSelected;
108 }
109
110 /**
111 Returns the position of the item ( > 0 ).
112 */
113 [[nodiscard]] int position() const
114 {
115 return mPosition;
116 }
117
118 /**
119 Returns the associated month scene to this item.
120 */
121 [[nodiscard]] MonthScene *monthScene() const
122 {
123 return mMonthScene;
124 }
125
126 /**
127 Begin a move.
128 */
129 void beginMove();
130
131 /**
132 End a move.
133 */
134 void endMove();
135
136 /**
137 Begin a resize.
138 */
139 void beginResize();
140
141 /**
142 End a resize.
143 */
144 void endResize();
145
146 /**
147 Called during move to move the item a bit, relative to the previous
148 move step.
149 */
150 void moveBy(int offsetFromPreviousDate);
151
152 /**
153 * Called during a drag to move the item to a particular date.
154 * An invalid date indicates a drag outside the month grid.
155 */
156 void moveTo(QDate date);
157
158 /**
159 Called during resize to resize the item a bit, relative to the previous
160 resize step.
161 */
162 bool resizeBy(int offsetFromPreviousDate);
163
164 /**
165 Returns true if the item is being moved.
166 */
167 [[nodiscard]] bool isMoving() const
168 {
169 return mMoving;
170 }
171
172 /**
173 Returns true if the item is being resized.
174 */
175 [[nodiscard]] bool isResizing() const
176 {
177 return mResizing;
178 }
179
180 /**
181 Returns true if the item can be moved.
182 */
183 virtual bool isMoveable() const = 0;
184
185 /**
186 Returns true if the item can be resized.
187 */
188 virtual bool isResizable() const = 0;
189
190 /**
191 Deletes all MonthGraphicsItem this item handles. Clear the list.
192 */
193 void deleteAll();
194
195 /**
196 Update the monthgraphicsitems
197
198 This basically deletes and rebuild all the MonthGraphicsItems but tries
199 to do it wisely:
200 - If there is a moving item, it won't be deleted because then the
201 new item won't receive anymore the MouseMove events.
202 - If there is an item on a line where the new state needs an item,
203 it is used and not deleted. This will avoid flickers.
204 */
205 void updateMonthGraphicsItems();
206
207 /**
208 Sets the selection state of this item.
209 */
210 void setSelected(bool selected)
211 {
212 mSelected = selected;
213 }
214
215 // METHODS NEEDED TO PAINT ITEMS
216
217 /**
218 Returns the text to draw in an item.
219
220 @param end True if the text at the end of an item should be returned.
221 */
222 virtual QString text(bool end) const = 0;
223
224 /**
225 Returns the text for the tooltip of the item
226 */
227 virtual QString toolTipText(const QDate &date) const = 0;
228
229 /**
230 Returns the background color of the item.
231 */
232 [[nodiscard]] virtual QColor bgColor() const = 0;
233
234 /**
235 Returns the frame color of the item.
236 */
237 [[nodiscard]] virtual QColor frameColor() const = 0;
238
239 /**
240 Returns a list of pixmaps to draw next to the items.
241 */
242 virtual QList<QPixmap> icons() const = 0;
243
244 QList<MonthGraphicsItem *> monthGraphicsItems() const;
245
246protected:
247 /**
248 Called after a move operation.
249 */
250 virtual void finalizeMove(const QDate &newStartDate) = 0;
251
252 /**
253 Called after a resize operation.
254 */
255 virtual void finalizeResize(const QDate &newStartDate, const QDate &newEndDate) = 0;
256
257private:
258 /**
259 Sets the value of all MonthGraphicsItem to @param z.
260 */
261 EVENTVIEWS_NO_EXPORT void setZValue(qreal z);
262
263 QList<MonthGraphicsItem *> mMonthGraphicsItemList;
264
265 MonthScene *mMonthScene = nullptr;
266
267 bool mSelected = false;
268 bool mMoving = false; // during move
269 bool mResizing = false; // during resize
270 QDate mOverrideStartDate;
271 int mOverrideDaySpan;
272
273 int mPosition;
274};
275
276class EVENTVIEWS_EXPORT IncidenceMonthItem : public MonthItem
277{
278 Q_OBJECT
279
280public:
281 IncidenceMonthItem(MonthScene *monthScene,
282 const Akonadi::CollectionCalendar::Ptr &calendar,
283 const Akonadi::Item &item,
284 const KCalendarCore::Incidence::Ptr &incidence,
285 QDate recurStartDate = QDate());
286
287 ~IncidenceMonthItem() override;
288
289 KCalendarCore::Incidence::Ptr incidence() const;
290 Akonadi::Item akonadiItem() const;
291 Akonadi::Item::Id akonadiItemId() const;
292 Akonadi::CollectionCalendar::Ptr calendar() const;
293
294 bool greaterThanFallback(const MonthItem *other) const override;
295
296 QDate realStartDate() const override;
297 QDate realEndDate() const override;
298 bool allDay() const override;
299
300 bool isMoveable() const override;
301 bool isResizable() const override;
302
303 QString text(bool end) const override;
304 QString toolTipText(const QDate &date) const override;
305
306 QColor bgColor() const override;
307 QColor frameColor() const override;
308
309 QList<QPixmap> icons() const override;
310
311protected:
312 void finalizeMove(const QDate &newStartDate) override;
313 void finalizeResize(const QDate &newStartDate, const QDate &newEndDate) override;
314
315protected Q_SLOTS:
316 /**
317 Update the selected state of this item.
318 If will be selected if incidence is the incidence managed by this item.
319 Else it will be deselected.
320 */
321 void updateSelection(const Akonadi::Item &incidence, QDate date);
322
323private:
324 EVENTVIEWS_NO_EXPORT void updateDates(int startOffset, int endOffset);
325
326 EVENTVIEWS_NO_EXPORT void setNewDates(const KCalendarCore::Incidence::Ptr &incidence, int startOffset, int endOffset);
327
328 /**
329 Returns the category color for this incidence.
330 */
331 QColor catColor() const;
332
335 Akonadi::Item::Id mAkonadiItemId;
336 int mRecurDayOffset;
337 bool mIsEvent, mIsTodo, mIsJournal;
338};
339
340class EVENTVIEWS_EXPORT HolidayMonthItem : public MonthItem
341{
342 Q_OBJECT
343
344public:
345 HolidayMonthItem(MonthScene *monthScene, QDate date, const QString &name);
346 HolidayMonthItem(MonthScene *monthScene, QDate startDate, QDate endDate, const QString &name);
347 ~HolidayMonthItem() override;
348
349 bool greaterThanFallback(const MonthItem *other) const override;
350
351 QDate realStartDate() const override
352 {
353 return mStartDate;
354 }
355
356 QDate realEndDate() const override
357 {
358 return mEndDate;
359 }
360
361 bool allDay() const override
362 {
363 return true;
364 }
365
366 bool isMoveable() const override
367 {
368 return false;
369 }
370
371 bool isResizable() const override
372 {
373 return false;
374 }
375
376 QString text(bool end) const override
377 {
378 Q_UNUSED(end)
379 return mName;
380 }
381
382 QString toolTipText(const QDate &) const override
383 {
384 return mName;
385 }
386
387 QColor bgColor() const override;
388 QColor frameColor() const override;
389
390 QList<QPixmap> icons() const override;
391
392protected:
393 void finalizeMove(const QDate &newStartDate) override;
394 void finalizeResize(const QDate &newStartDate, const QDate &newEndDate) override;
395
396private:
397 QDate mStartDate;
398 QDate mEndDate;
399 QString mName;
400};
401}
A month item manages different MonthGraphicsItems.
Definition monthitem.h:27
int position() const
Returns the position of the item ( > 0 ).
Definition monthitem.h:113
void setSelected(bool selected)
Sets the selection state of this item.
Definition monthitem.h:210
virtual void finalizeResize(const QDate &newStartDate, const QDate &newEndDate)=0
Called after a resize operation.
bool isMoving() const
Returns true if the item is being moved.
Definition monthitem.h:167
virtual QColor frameColor() const =0
Returns the frame color of the item.
MonthScene * monthScene() const
Returns the associated month scene to this item.
Definition monthitem.h:121
virtual bool allDay() const =0
True if this item last all the day.
virtual bool isMoveable() const =0
Returns true if the item can be moved.
virtual QDate realEndDate() const =0
This is the real end date, usually the end date of the incidence.
virtual QColor bgColor() const =0
Returns the background color of the item.
virtual QString toolTipText(const QDate &date) const =0
Returns the text for the tooltip of the item.
bool selected() const
Returns true if this item is selected.
Definition monthitem.h:105
virtual QList< QPixmap > icons() const =0
Returns a list of pixmaps to draw next to the items.
bool isResizing() const
Returns true if the item is being resized.
Definition monthitem.h:175
virtual QString text(bool end) const =0
Returns the text to draw in an item.
virtual void finalizeMove(const QDate &newStartDate)=0
Called after a move operation.
virtual bool isResizable() const =0
Returns true if the item can be resized.
virtual QDate realStartDate() const =0
This is the real start date, usually the start date of the incidence.
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.