Eventviews

monthscene.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 <Akonadi/Collection>
10#include <Akonadi/CollectionCalendar>
11#include <Akonadi/Item>
12
13#include <QBasicTimer>
14#include <QDate>
15#include <QGraphicsScene>
16#include <QGraphicsView>
17#include <QMap>
18
19namespace Akonadi
20{
21class IncidenceChanger;
22}
23
24namespace EventViews
25{
26class MonthCell;
27class MonthItem;
28class MonthView;
29class ScrollIndicator;
30
31class MonthScene : public QGraphicsScene
32{
34
35 enum ActionType {
36 None,
37 Move,
38 Resize
39 };
40
41public:
42 enum ResizeType {
43 ResizeLeft,
44 ResizeRight
45 };
46
47 explicit MonthScene(MonthView *parent);
48 ~MonthScene() override;
49
50 [[nodiscard]] int columnWidth() const;
51 [[nodiscard]] int rowHeight() const;
52
53 MonthCell *firstCellForMonthItem(MonthItem *manager);
54 [[nodiscard]] int height(MonthItem *manager);
55 [[nodiscard]] int itemHeight();
56 [[nodiscard]] int itemHeightIncludingSpacing();
57 QList<MonthItem *> mManagerList;
58 MonthView *mMonthView = nullptr;
59
60 [[nodiscard]] MonthView *monthView() const
61 {
62 return mMonthView;
63 }
64
65 QMap<QDate, MonthCell *> mMonthCellMap;
66
67 [[nodiscard]] bool initialized() const
68 {
69 return mInitialized;
70 }
71
72 void setInitialized(bool i)
73 {
74 mInitialized = i;
75 }
76
77 void resetAll();
78 Akonadi::IncidenceChanger *incidenceChanger() const;
79
80 [[nodiscard]] int totalHeight();
81
82 /**
83 * Returns the vertical position where the top of the cell should be
84 * painted taking in account margins, rowHeight
85 */
86 [[nodiscard]] int cellVerticalPos(const MonthCell *cell) const;
87
88 /**
89 * Idem, for the horizontal position
90 */
91 [[nodiscard]] int cellHorizontalPos(const MonthCell *cell) const;
92
93 /**
94 Select item. If the argument is 0, the currently selected item gets
95 deselected. This function emits the itemSelected(bool) signal to inform
96 about selection/deselection of events.
97 */
98 void selectItem(MonthItem *);
99 [[nodiscard]] int maxRowCount();
100
101 MonthCell *selectedCell() const;
102 MonthCell *previousCell() const;
103
104 /**
105 Get the space on the right of the cell associated to the date @p date.
106 */
107 [[nodiscard]] int getRightSpan(QDate date) const;
108
109 /**
110 Get the space on the left of the cell associated to the date @p date.
111 */
112 [[nodiscard]] int getLeftSpan(QDate date) const;
113
114 /**
115 Returns the date in the first column of the row given by @p row.
116 */
117 [[nodiscard]] QDate firstDateOnRow(int row) const;
118
119 /**
120 Calls updateGeometry() on each MonthItem
121 */
122 void updateGeometry();
123
124 /**
125 Returns the first height. Used for scrolling
126
127 @see MonthItem::height()
128 */
129 [[nodiscard]] int startHeight() const
130 {
131 return mStartHeight;
132 }
133
134 /**
135 Set the current height using @p height.
136 If height = 0, then the view is not scrolled. Else it will be scrolled
137 by step of one item.
138 */
139 void setStartHeight(int height)
140 {
141 mStartHeight = height;
142 }
143
144 /**
145 Returns the resize type.
146 */
147 [[nodiscard]] ResizeType resizeType() const
148 {
149 return mResizeType;
150 }
151
152 /**
153 Returns the currently selected item.
154 */
155 MonthItem *selectedItem()
156 {
157 return mSelectedItem;
158 }
159
160 [[nodiscard]] QPixmap birthdayPixmap() const
161 {
162 return mBirthdayPixmap;
163 }
164
165 [[nodiscard]] QPixmap anniversaryPixmap() const
166 {
167 return mAnniversaryPixmap;
168 }
169
170 [[nodiscard]] QPixmap alarmPixmap() const
171 {
172 return mAlarmPixmap;
173 }
174
175 [[nodiscard]] QPixmap recurPixmap() const
176 {
177 return mRecurPixmap;
178 }
179
180 [[nodiscard]] QPixmap readonlyPixmap() const
181 {
182 return mReadonlyPixmap;
183 }
184
185 [[nodiscard]] QPixmap replyPixmap() const
186 {
187 return mReplyPixmap;
188 }
189
190 [[nodiscard]] QPixmap holidayPixmap() const
191 {
192 return mHolidayPixmap;
193 }
194
195 /**
196 Removes an incidence from the scene
197 */
198 void removeIncidence(const QString &uid);
199
201 void incidenceSelected(const Akonadi::Item &incidence, const QDate &);
202 void showIncidencePopupSignal(const Akonadi::CollectionCalendar::Ptr &, const Akonadi::Item &, const QDate &);
203 void newEventSignal();
204 void newEventSignal(const QDate &);
205 void showNewEventPopupSignal();
206
207protected:
208 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
209 void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
210 void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
211 void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
212 void wheelEvent(QGraphicsSceneWheelEvent *wheelEvent) override;
213 void timerEvent(QTimerEvent *e) override;
214 void helpEvent(QGraphicsSceneHelpEvent *helpEvent) override;
215 /**
216 Scrolls all incidences in cells up
217 */
218 virtual void scrollCellsUp();
219
220 /**
221 Scrolls all incidences in cells down
222 */
223 virtual void scrollCellsDown();
224
225 /**
226 A click on a scroll indicator has occurred
227 TODO : move this handler to the scrollindicator
228 */
229 virtual void clickOnScrollIndicator(ScrollIndicator *scrollItem);
230
231 /**
232 Handles drag and drop events. Called from eventFilter.
233 */
234 // virtual bool eventFilter_drag( QObject *, QDropEvent * );
235
236 /**
237 Returns true if the last item is visible in the given @p cell.
238 */
239 bool lastItemFit(MonthCell *cell);
240
241private:
242 /**
243 * Returns the height of the header of the view
244 */
245 [[nodiscard]] int headerHeight() const;
246
247 [[nodiscard]] int availableWidth() const;
248
249 /**
250 * Height available to draw the cells. Doesn't include header.
251 */
252 [[nodiscard]] int availableHeight() const;
253
254 /**
255 * Removes all the margins, frames, etc. to give the
256 * X coordinate in the MonthGrid.
257 */
258 [[nodiscard]] int sceneXToMonthGridX(int xScene);
259
260 /**
261 * Removes all the margins, frames, headers etc. to give the
262 * Y coordinate in the MonthGrid.
263 */
264 int sceneYToMonthGridY(int yScene);
265
266 /**
267 * Given a pos in the scene coordinates,
268 * returns the cell containing @p pos.
269 */
270 MonthCell *getCellFromPos(QPointF pos);
271
272 /**
273 Returns true if (x, y) is in the monthgrid, false else.
274 */
275 bool isInMonthGrid(int x, int y) const;
276
277 bool mInitialized;
278
279 // User interaction.
280 MonthItem *mClickedItem = nullptr; // todo ini in ctor
281 MonthItem *mActionItem = nullptr;
282 bool mActionInitiated;
283
284 MonthItem *mSelectedItem = nullptr;
285 QDate mSelectedCellDate;
286 MonthCell *mStartCell = nullptr; // start cell when dragging
287 MonthCell *mPreviousCell = nullptr; // the cell before that one during dragging
288
289 ActionType mActionType;
290 ResizeType mResizeType;
291
292 // The item height at the top of the cell. This is generally 0 unless
293 // the user scroll the view when there are too many items.
294 int mStartHeight;
295
296 // icons to draw in front of the events
297 QPixmap mEventPixmap;
298 QPixmap mBirthdayPixmap;
299 QPixmap mAnniversaryPixmap;
300 QPixmap mTodoPixmap;
301 QPixmap mTodoDonePixmap;
302 QPixmap mJournalPixmap;
303 QPixmap mAlarmPixmap;
304 QPixmap mRecurPixmap;
305 QPixmap mReadonlyPixmap;
306 QPixmap mReplyPixmap;
307 QPixmap mHolidayPixmap;
308 QBasicTimer repeatTimer;
309 ScrollIndicator *mCurrentIndicator = nullptr;
310 friend class MonthGraphicsView;
311};
312
313/**
314 * Renders a MonthScene
315 */
316class MonthGraphicsView : public QGraphicsView
317{
319public:
320 explicit MonthGraphicsView(MonthView *parent);
321
322 /**
323 Draws the cells.
324 */
325 void drawBackground(QPainter *painter, const QRectF &rect) override;
326
327 void setScene(MonthScene *scene);
328
329 /**
330 Change the cursor according to @p actionType.
331 */
332 void setActionCursor(MonthScene::ActionType actionType);
333
334protected:
335 void resizeEvent(QResizeEvent *) override;
336
337private:
338 MonthScene *mScene = nullptr;
339 MonthView *mMonthView = nullptr;
340};
341}
Keeps information about a month cell.
void setActionCursor(MonthScene::ActionType actionType)
Change the cursor according to actionType.
void drawBackground(QPainter *painter, const QRectF &rect) override
Draws the cells.
A month item manages different MonthGraphicsItems.
Definition monthitem.h:27
New month view.
Definition monthview.h:27
Graphics items which indicates that the view can be scrolled to display more events.
QSharedPointer< Calendar > Ptr
Namespace EventViews provides facilities for displaying incidences, including events,...
Definition agenda.h:33
qreal height() const const
QGraphicsView(QGraphicsScene *scene, QWidget *parent)
QGraphicsScene * scene() const const
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 11 2025 11:48:36 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.