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

KDE's Doxygen guidelines are available online.