Eventviews

agendaitem.h
1/*
2 SPDX-FileCopyrightText: 2000, 2001, 2003 Cornelius Schumacher <schumacher@kde.org>
3 SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
4
5 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
6*/
7#pragma once
8
9#include "viewcalendar.h"
10
11#include <CalendarSupport/CellItem>
12
13#include <Akonadi/Item>
14
15#include <QDateTime>
16#include <QPointer>
17#include <QWidget>
18
19namespace EventViews
20{
21class AgendaItem;
22class EventView;
23
24struct MultiItemInfo {
25 int mStartCellXLeft, mStartCellXRight;
26 int mStartCellYTop, mStartCellYBottom;
27 QPointer<AgendaItem> mFirstMultiItem;
28 QPointer<AgendaItem> mPrevMultiItem;
29 QPointer<AgendaItem> mNextMultiItem;
30 QPointer<AgendaItem> mLastMultiItem;
31};
32
33/**
34 @class AgendaItem
35
36 @brief This class describes the widgets that represent the various calendar
37 items in the agenda view
38
39 The AgendaItem has to make sure that it receives all mouse events, which
40 are to be used for dragging and resizing. That means it has to be installed
41 as event filter for its children, if it has children, and it has to pass
42 mouse events from the children to itself. See eventFilter().
43
44 Some comments on the movement of multi-day items:
45 Basically, the agenda items are arranged in two implicit double-linked lists.
46 The mMultiItemInfo works like before to describe the currently viewed
47 multi-item.
48 When moving, new events might need to be added to the beginning or the end of
49 the multi-item sequence, or events might need to be hidden. I cannot just
50 delete this items, since I have to restore/show them if the move is reset
51 (i.e. if a drag started). So internally, I keep another doubly-linked list
52 which is longer than the one defined by mMultiItemInfo, but includes the
53 multi-item sequence, too.
54
55 The mStartMoveInfo stores the first and last item of the multi-item sequence
56 when the move started. The prev and next members of mStartMoveInfo are used
57 for that longer sequence including all (shown and hidden) items.
58*/
59
60class AgendaItem : public QWidget, public CalendarSupport::CellItem
61{
63public:
65 using List = QList<QPtr>;
66
67 AgendaItem(EventView *eventView,
68 const MultiViewCalendar::Ptr &calendar,
69 const KCalendarCore::Incidence::Ptr &incidence,
70 int itemPos,
71 int itemCount,
72 const QDateTime &qd,
73 bool isSelected,
75 ~AgendaItem() override;
76
77 [[nodiscard]] int cellXLeft() const
78 {
79 return mCellXLeft;
80 }
81
82 [[nodiscard]] int cellXRight() const
83 {
84 return mCellXRight;
85 }
86
87 [[nodiscard]] int cellYTop() const
88 {
89 return mCellYTop;
90 }
91
92 [[nodiscard]] int cellYBottom() const
93 {
94 return mCellYBottom;
95 }
96
97 [[nodiscard]] int cellHeight() const;
98 [[nodiscard]] int cellWidth() const;
99
100 [[nodiscard]] int itemPos() const
101 {
102 return mItemPos;
103 }
104
105 [[nodiscard]] int itemCount() const
106 {
107 return mItemCount;
108 }
109
110 void setCellXY(int X, int YTop, int YBottom);
111 void setCellY(int YTop, int YBottom);
112 void setCellX(int XLeft, int XRight);
113 void setCellXRight(int XRight);
114
115 /** Start movement */
116 void startMove();
117
118 /** Reset to original values */
119 void resetMove();
120
121 /** End the movement (i.e. clean up) */
122 void endMove();
123
124 void moveRelative(int dx, int dy);
125
126 /**
127 * Expands the item's top.
128 *
129 * @param dy delta y, number of units to be added to mCellYTop
130 * @param allowOverLimit If false, the new mCellYTop can't be bigger than
131 * mCellYBottom, instead, it gets mCellYBottom's value.
132 * If true, @p dy is always added, regardless if mCellYTop
133 * becomes bigger than mCellYBottom, this is useful when
134 * moving items because it guarantees expandTop and the
135 * following expandBottom call add the same value.
136 */
137 void expandTop(int dy, const bool allowOverLimit = false);
138 void expandBottom(int dy);
139 void expandLeft(int dx);
140 void expandRight(int dx);
141
142 [[nodiscard]] bool isMultiItem() const;
143
144 AgendaItem::QPtr prevMoveItem() const
145 {
146 return (mStartMoveInfo) ? (mStartMoveInfo->mPrevMultiItem) : nullptr;
147 }
148
149 AgendaItem::QPtr nextMoveItem() const
150 {
151 return (mStartMoveInfo) ? (mStartMoveInfo->mNextMultiItem) : nullptr;
152 }
153
154 MultiItemInfo *moveInfo() const
155 {
156 return mStartMoveInfo;
157 }
158
159 void setMultiItem(const AgendaItem::QPtr &first, const AgendaItem::QPtr &prev, const AgendaItem::QPtr &next, const AgendaItem::QPtr &last);
160
161 AgendaItem::QPtr prependMoveItem(const AgendaItem::QPtr &);
162
163 AgendaItem::QPtr appendMoveItem(const AgendaItem::QPtr &);
164
165 AgendaItem::QPtr removeMoveItem(const AgendaItem::QPtr &);
166
167 AgendaItem::QPtr firstMultiItem() const
168 {
169 return (mMultiItemInfo) ? (mMultiItemInfo->mFirstMultiItem) : nullptr;
170 }
171
172 AgendaItem::QPtr prevMultiItem() const
173 {
174 return (mMultiItemInfo) ? (mMultiItemInfo->mPrevMultiItem) : nullptr;
175 }
176
177 AgendaItem::QPtr nextMultiItem() const
178 {
179 return (mMultiItemInfo) ? (mMultiItemInfo->mNextMultiItem) : nullptr;
180 }
181
182 AgendaItem::QPtr lastMultiItem() const
183 {
184 return (mMultiItemInfo) ? (mMultiItemInfo->mLastMultiItem) : nullptr;
185 }
186
187 [[nodiscard]] bool dissociateFromMultiItem();
188
189 void setIncidence(const KCalendarCore::Incidence::Ptr &incidence);
190
191 const KCalendarCore::Incidence::Ptr &incidence() const
192 {
193 return mIncidence;
194 }
195
196 [[nodiscard]] QDateTime occurrenceDateTime() const
197 {
198 return mOccurrenceDateTime;
199 }
200
201 [[nodiscard]] QDate occurrenceDate() const;
202
203 // /** Update the date of this item's occurrence (not in the event) */
204 void setOccurrenceDateTime(const QDateTime &qd);
205
206 void setText(const QString &text)
207 {
208 mLabelText = text;
209 }
210
211 [[nodiscard]] QString text() const
212 {
213 return mLabelText;
214 }
215
216 QList<AgendaItem::QPtr> &conflictItems();
217 void setConflictItems(const QList<AgendaItem::QPtr> &);
218 void addConflictItem(const AgendaItem::QPtr &ci);
219
220 [[nodiscard]] QString label() const override;
221
222 /** Tells whether this item overlaps item @p o */
223 bool overlaps(CellItem *o) const override;
224
225 void setResourceColor(const QColor &color)
226 {
227 mResourceColor = color;
228 }
229
230 [[nodiscard]] QColor resourceColor() const
231 {
232 return mResourceColor;
233 }
234
236 void removeAgendaItem(const AgendaItem::QPtr &);
237 void showAgendaItem(const AgendaItem::QPtr &);
238
239public Q_SLOTS:
240 void updateIcons();
241 void select(bool selected = true);
242 void addAttendee(const QString &);
243
244protected:
245 bool eventFilter(QObject *obj, QEvent *event) override;
246 bool event(QEvent *event) override;
247 void dragEnterEvent(QDragEnterEvent *e) override;
248 void dropEvent(QDropEvent *e) override;
249 void paintEvent(QPaintEvent *e) override;
250
251 /** private movement functions. startMove needs to be called of only one of
252 * the multitems. it will then loop through the whole series using
253 * startMovePrivate. Same for resetMove and endMove */
254 void startMovePrivate();
255 void resetMovePrivate();
256 void endMovePrivate();
257
258 // Variables to remember start position
259 MultiItemInfo *mStartMoveInfo = nullptr;
260 // Color of the resource
261 QColor mResourceColor;
262
263private:
264 void paintIcon(QPainter *p, int &x, int y, int ft);
265
266 // paint all visible icons
267 void paintIcons(QPainter *p, int &x, int y, int ft);
268
269 void drawRoundedRect(QPainter *p,
270 QRect rect,
271 bool selected,
272 const QColor &bgColor,
273 const QColor &frameColor,
274 bool frame,
275 int ft,
276 bool roundTop,
277 bool roundBottom);
278
279 [[nodiscard]] QColor getCategoryColor() const;
280 [[nodiscard]] QColor getFrameColor(const QColor &resourceColor, const QColor &categoryColor) const;
281 [[nodiscard]] QColor getBackgroundColor(const QColor &resourceColor, const QColor &categoryColor) const;
282
283 int mCellXLeft, mCellXRight;
284 int mCellYTop, mCellYBottom;
285
286 EventView *const mEventView;
287 MultiViewCalendar::Ptr mCalendar;
289 QDateTime mOccurrenceDateTime;
290 bool mValid = true;
291 bool mCloned = false;
292 QString mLabelText;
293 bool mSelected;
294 bool mIconAlarm;
295 bool mIconRecur;
296 bool mIconReadonly;
297 bool mIconReply;
298 bool mIconGroup;
299 bool mIconGroupTent;
300 bool mIconOrganizer;
301 bool mSpecialEvent;
302
303 // For incidences that expand through more than 1 day
304 // Will be 1 for single day incidences
305 int mItemPos;
306 int mItemCount;
307
308 // Multi item pointers
309 MultiItemInfo *mMultiItemInfo = nullptr;
310
311 QList<AgendaItem::QPtr> mConflictItems;
312
313 static QPixmap *alarmPxmp;
314 static QPixmap *recurPxmp;
315 static QPixmap *readonlyPxmp;
316 static QPixmap *replyPxmp;
317 static QPixmap *groupPxmp;
318 static QPixmap *groupPxmpTent;
319 static QPixmap *organizerPxmp;
320 static QPixmap *eventPxmp;
321 static QPixmap *todoPxmp;
322 static QPixmap *completedPxmp;
323};
324}
This class describes the widgets that represent the various calendar items in the agenda view.
Definition agendaitem.h:61
void setOccurrenceDateTime(const QDateTime &qd)
Update the date of this item's occurrence (not in the event)
bool overlaps(CellItem *o) const override
Tells whether this item overlaps item o.
void endMove()
End the movement (i.e.
void expandTop(int dy, const bool allowOverLimit=false)
Expands the item's top.
void startMovePrivate()
private movement functions.
void resetMove()
Reset to original values.
void startMove()
Start movement.
EventView is the abstract base class from which all other calendar views for event data are derived.
Definition eventview.h:69
Namespace EventViews provides facilities for displaying incidences, including events,...
Definition agenda.h:33
EVENTVIEWS_EXPORT QColor resourceColor(const Akonadi::Collection &collection, const PrefsPtr &preferences)
This method returns the proper resource / subresource color for the view.
Definition helper.cpp:56
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.