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 showNewEventPopupSignal();
205
206protected:
207 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
208 void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
209 void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
210 void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
211 void wheelEvent(QGraphicsSceneWheelEvent *wheelEvent) override;
212 void timerEvent(QTimerEvent *e) override;
213 void helpEvent(QGraphicsSceneHelpEvent *helpEvent) override;
214 /**
215 Scrolls all incidences in cells up
216 */
217 virtual void scrollCellsUp();
218
219 /**
220 Scrolls all incidences in cells down
221 */
222 virtual void scrollCellsDown();
223
224 /**
225 A click on a scroll indicator has occurred
226 TODO : move this handler to the scrollindicator
227 */
228 virtual void clickOnScrollIndicator(ScrollIndicator *scrollItem);
229
230 /**
231 Handles drag and drop events. Called from eventFilter.
232 */
233 // virtual bool eventFilter_drag( QObject *, QDropEvent * );
234
235 /**
236 Returns true if the last item is visible in the given @p cell.
237 */
238 bool lastItemFit(MonthCell *cell);
239
240private:
241 /**
242 * Returns the height of the header of the view
243 */
244 [[nodiscard]] int headerHeight() const;
245
246 [[nodiscard]] int availableWidth() const;
247
248 /**
249 * Height available to draw the cells. Doesn't include header.
250 */
251 [[nodiscard]] int availableHeight() const;
252
253 /**
254 * Removes all the margins, frames, etc. to give the
255 * X coordinate in the MonthGrid.
256 */
257 [[nodiscard]] int sceneXToMonthGridX(int xScene);
258
259 /**
260 * Removes all the margins, frames, headers etc. to give the
261 * Y coordinate in the MonthGrid.
262 */
263 int sceneYToMonthGridY(int yScene);
264
265 /**
266 * Given a pos in the scene coordinates,
267 * returns the cell containing @p pos.
268 */
269 MonthCell *getCellFromPos(QPointF pos);
270
271 /**
272 Returns true if (x, y) is in the monthgrid, false else.
273 */
274 bool isInMonthGrid(int x, int y) const;
275
276 bool mInitialized;
277
278 // User interaction.
279 MonthItem *mClickedItem = nullptr; // todo ini in ctor
280 MonthItem *mActionItem = nullptr;
281 bool mActionInitiated;
282
283 MonthItem *mSelectedItem = nullptr;
284 QDate mSelectedCellDate;
285 MonthCell *mStartCell = nullptr; // start cell when dragging
286 MonthCell *mPreviousCell = nullptr; // the cell before that one during dragging
287
288 ActionType mActionType;
289 ResizeType mResizeType;
290
291 // The item height at the top of the cell. This is generally 0 unless
292 // the user scroll the view when there are too many items.
293 int mStartHeight;
294
295 // icons to draw in front of the events
296 QPixmap mEventPixmap;
297 QPixmap mBirthdayPixmap;
298 QPixmap mAnniversaryPixmap;
299 QPixmap mTodoPixmap;
300 QPixmap mTodoDonePixmap;
301 QPixmap mJournalPixmap;
302 QPixmap mAlarmPixmap;
303 QPixmap mRecurPixmap;
304 QPixmap mReadonlyPixmap;
305 QPixmap mReplyPixmap;
306 QPixmap mHolidayPixmap;
307 QBasicTimer repeatTimer;
308 ScrollIndicator *mCurrentIndicator = nullptr;
309 friend class MonthGraphicsView;
310};
311
312/**
313 * Renders a MonthScene
314 */
316{
318public:
320
321 /**
322 Draws the cells.
323 */
324 void drawBackground(QPainter *painter, const QRectF &rect) override;
325
326 void setScene(MonthScene *scene);
327
328 /**
329 Change the cursor according to @p actionType.
330 */
331 void setActionCursor(MonthScene::ActionType actionType);
332
333protected:
334 void resizeEvent(QResizeEvent *) override;
335
336private:
337 MonthScene *mScene = nullptr;
338 MonthView *mMonthView = nullptr;
339};
340}
Renders a MonthScene.
Definition monthscene.h:316
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 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.