Eventviews

agenda.h
1/*
2 SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org>
3 SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
4 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
5 SPDX-FileContributor: Kevin Krammer <krake@kdab.com>
6
7 Marcus Bains line.
8 SPDX-FileCopyrightText: 2001 Ali Rahimi <ali@mit.edu>
9
10 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
11*/
12#pragma once
13
14#include "agendaitem.h"
15#include "eventviews_export.h"
16#include "viewcalendar.h"
17
18#include <Akonadi/Item>
19
20#include <KCalendarCore/Todo>
21
22#include <QFrame>
23#include <QScrollArea>
24
25#include <memory>
26
27namespace Akonadi
28{
29class IncidenceChanger;
30}
31
32namespace EventViews
33{
34class Agenda;
35class AgendaItem;
36class AgendaView;
37
38class MarcusBainsPrivate;
39
40class MarcusBains : public QFrame
41{
43public:
44 explicit MarcusBains(EventView *eventView, Agenda *agenda = nullptr);
45 void updateLocationRecalc(bool recalculate = false);
46 ~MarcusBains() override;
47
48public Q_SLOTS:
49 void updateLocation();
50
51private:
52 std::unique_ptr<MarcusBainsPrivate> const d;
53};
54
55class AgendaPrivate;
56
57class EVENTVIEWS_EXPORT Agenda : public QWidget
58{
59 Q_OBJECT
60public:
61 Agenda(AgendaView *agendaView, QScrollArea *scrollArea, int columns, int rows, int rowSize, bool isInteractive);
62
63 Agenda(AgendaView *agendaView, QScrollArea *scrollArea, int columns, bool isInteractive);
64
65 ~Agenda() override;
66
67 [[nodiscard]] KCalendarCore::Incidence::Ptr selectedIncidence() const;
68 [[nodiscard]] QDate selectedIncidenceDate() const;
69 QSize sizeHint() const override;
70 QSize minimumSizeHint() const override;
71 QSize minimumSize() const;
72 int minimumHeight() const;
73 // QSizePolicy sizePolicy() const;
74 [[nodiscard]] int contentsY() const
75 {
76 return -y();
77 }
78
79 [[nodiscard]] int contentsX() const
80 {
81 return x();
82 }
83
84 [[nodiscard]] QScrollBar *verticalScrollBar() const;
85
86 [[nodiscard]] QScrollArea *scrollArea() const;
87
88 [[nodiscard]] AgendaItem::List agendaItems(const QString &uid) const;
89
90 /**
91 Returns the uid of the last incidence that was selected. This
92 persists across reloads and clear, so that if the same uid
93 reappears, it can be reselected.
94 */
95 [[nodiscard]] QString lastSelectedItemUid() const;
96
97 bool eventFilter(QObject *, QEvent *) override;
98
99 void paintEvent(QPaintEvent *) override;
100
101 [[nodiscard]] QPoint contentsToGrid(QPoint pos) const;
102 [[nodiscard]] QPoint gridToContents(QPoint gpos) const;
103
104 [[nodiscard]] int timeToY(QTime time) const;
105 [[nodiscard]] QTime gyToTime(int y) const;
106
107 [[nodiscard]] QList<int> minContentsY() const;
108 [[nodiscard]] QList<int> maxContentsY() const;
109
110 [[nodiscard]] int visibleContentsYMin() const;
111 [[nodiscard]] int visibleContentsYMax() const;
112
113 void setStartTime(QTime startHour);
114
115 AgendaItem::QPtr insertItem(const KCalendarCore::Incidence::Ptr &incidence,
116 const QDateTime &recurrenceId,
117 int X,
118 int YTop,
119 int YBottom,
120 int itemPos,
121 int itemCount,
122 bool isSelected);
123
124 AgendaItem::QPtr insertAllDayItem(const KCalendarCore::Incidence::Ptr &event, const QDateTime &recurrenceId, int XBegin, int XEnd, bool isSelected);
125
126 void
127 insertMultiItem(const KCalendarCore::Incidence::Ptr &event, const QDateTime &recurrenceId, int XBegin, int XEnd, int YTop, int YBottom, bool isSelected);
128
129 /**
130 Removes an event and all its multi-items from the agenda. This function
131 removes the items from the view, but doesn't delete them immediately.
132 Instead, they are queued in mItemsToDelete and later deleted by the
133 slot deleteItemsToDelete() (called by QTimer::singleShot ).
134 @param incidence The pointer to the incidence that should be removed.
135 */
136 void removeIncidence(const KCalendarCore::Incidence::Ptr &incidence);
137
138 void changeColumns(int columns);
139
140 [[nodiscard]] int columns() const;
141 [[nodiscard]] int rows() const;
142
143 [[nodiscard]] double gridSpacingX() const;
144 [[nodiscard]] double gridSpacingY() const;
145
146 void clear();
147
148 /** Update configuration from preference settings */
149 void updateConfig();
150
151 void checkScrollBoundaries();
152
153 void setHolidayMask(QList<bool> *);
154
155 void setDateList(const KCalendarCore::DateList &selectedDates);
156 [[nodiscard]] KCalendarCore::DateList dateList() const;
157
158 void setCalendar(const EventViews::MultiViewCalendar::Ptr &cal);
159
160 void setIncidenceChanger(Akonadi::IncidenceChanger *changer);
161
162public Q_SLOTS:
163 void scrollUp();
164 void scrollDown();
165
166 void checkScrollBoundaries(int);
167
168 /** Deselect selected items. This function does not Q_EMIT any signals. */
169 void deselectItem();
170
171 void clearSelection();
172
173 /**
174 Select item. If the argument is 0, the currently selected item gets
175 deselected. This function emits the itemSelected(bool) signal to inform
176 about selection/deselection of events.
177 */
178 void selectItem(const AgendaItem::QPtr &);
179
180 /**
181 Selects the item associated with a given Akonadi Item id.
182 Linear search, use carefully.
183 @param id the item id of the item that should be selected. If no such
184 item exists, the selection is not changed.
185 */
186 void selectIncidenceByUid(const QString &id);
187 void selectItem(const Akonadi::Item &item);
188
189 bool removeAgendaItem(const AgendaItem::QPtr &item);
190 void showAgendaItem(const AgendaItem::QPtr &item);
191
192Q_SIGNALS:
193 void newEventSignal();
194 void newTimeSpanSignal(const QPoint &, const QPoint &);
195 void newStartSelectSignal();
196
197 void showIncidenceSignal(const KCalendarCore::Incidence::Ptr &);
198 void editIncidenceSignal(const KCalendarCore::Incidence::Ptr &);
199 void deleteIncidenceSignal(const KCalendarCore::Incidence::Ptr &);
200 void showIncidencePopupSignal(const KCalendarCore::Incidence::Ptr &, const QDate &);
201
202 void showNewEventPopupSignal();
203
204 void incidenceSelected(const KCalendarCore::Incidence::Ptr &, const QDate &);
205
206 void lowerYChanged(int);
207 void upperYChanged(int);
208
209 void startDragSignal(const KCalendarCore::Incidence::Ptr &);
210 void droppedIncidences(const KCalendarCore::Incidence::List &, const QPoint &gpos, bool allDay);
211 void droppedIncidences(const QList<QUrl> &, const QPoint &gpos, bool allDay);
212
213 void enableAgendaUpdate(bool enable);
214 void zoomView(const int delta, const QPoint &pos, const Qt::Orientation);
215
216 void mousePosSignal(const QPoint &pos);
217 void enterAgenda();
218 void leaveAgenda();
219
220 void gridSpacingYChanged(double);
221
222private:
223 enum MouseActionType { NOP, MOVE, SELECT, RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT };
224
226 createAgendaItem(const KCalendarCore::Incidence::Ptr &incidence, int itemPos, int itemCount, const QDateTime &recurrentId, bool isSelected);
227
228protected:
229 /**
230 Draw the background grid of the agenda.
231 @p cw grid width
232 @p ch grid height
233 */
234 void drawContents(QPainter *p, int cx, int cy, int cw, int ch);
235
236 int columnWidth(int column) const;
237 void resizeEvent(QResizeEvent *) override;
238
239 /** Handles mouse events. Called from eventFilter */
240 virtual bool eventFilter_mouse(QObject *, QMouseEvent *);
241#ifndef QT_NO_WHEELEVENT
242 /** Handles mousewheel events. Called from eventFilter */
243 virtual bool eventFilter_wheel(QObject *, QWheelEvent *);
244#endif
245 /** Handles key events. Called from eventFilter */
246 virtual bool eventFilter_key(QObject *, QKeyEvent *);
247
248 /** Handles drag and drop events. Called from eventFilter */
249 virtual bool eventFilter_drag(QObject *, QDropEvent *);
250
251 /** returns RESIZELEFT if pos is near the lower edge of the action item,
252 RESIZERIGHT if pos is near the higher edge, and MOVE otherwise.
253 If --reverse is used, RESIZELEFT still means resizing the beginning of
254 the event, although that means moving to the right!
255 horizontal is the same as mAllDayAgenda.
256 @param horizontal Whether horizontal resizing is possible
257 @param pos The current mouse position
258 @param item The affected item
259 */
260 MouseActionType isInResizeArea(bool horizontal, QPoint pos, const AgendaItem::QPtr &item);
261 /** Return whether the cell specified by the grid point belongs to the current select
262 */
263 [[nodiscard]] bool ptInSelection(QPoint gpos) const;
264
265 /** Start selecting time span. */
266 void startSelectAction(QPoint viewportPos);
267
268 /** Select time span. */
269 void performSelectAction(QPoint viewportPos);
270
271 /** Emd selecting time span. */
272 void endSelectAction(const QPoint &viewportPos);
273
274 /** Start moving/resizing agenda item */
275 void startItemAction(const QPoint &viewportPos);
276
277 /** Move/resize agenda item */
278 void performItemAction(QPoint viewportPos);
279
280 /** End moving/resizing agenda item */
281 void endItemAction();
282
283 /** Set cursor, when no item action is in progress */
284 void setNoActionCursor(const AgendaItem::QPtr &moveItem, QPoint viewportPos);
285 /** Sets the cursor according to the given action type.
286 @param actionType The type of action for which the cursor should be set.
287 @param acting If true, the corresponding action is running (e.g. the
288 item is currently being moved by the user). If false the
289 cursor should just indicate that the corresponding
290 action is possible */
291 void setActionCursor(int actionType, bool acting = false);
292
293 /** calculate the width of the column subcells of the given item */
294 double calcSubCellWidth(const AgendaItem::QPtr &item);
295 /** Move and resize the given item to the correct position */
296 void placeAgendaItem(const AgendaItem::QPtr &item, double subCellWidth);
297 /** Place agenda item in agenda and adjust other cells if necessary */
298 void placeSubCells(const AgendaItem::QPtr &placeItem);
299 /** Place the agenda item at the correct position (ignoring conflicting items) */
300 void adjustItemPosition(const AgendaItem::QPtr &item);
301
302 /** Process the keyevent, including the ignored keyevents of eventwidgets.
303 * Implements pgup/pgdn and cursor key navigation in the view.
304 */
305 void keyPressEvent(QKeyEvent *) override;
306
307 void calculateWorkingHours();
308
309 virtual void contentsMousePressEvent(QMouseEvent *);
310
311protected Q_SLOTS:
312 /** delete the items that are queued for deletion */
313 void deleteItemsToDelete();
314 /** Resizes all the child elements after the size of the agenda
315 changed. This is needed because Qt seems to have a bug when
316 the resizeEvent of one of the widgets in a splitter takes a
317 lot of time / does a lot of resizes.... see bug 80114 */
318 void resizeAllContents();
319
320private:
321 EVENTVIEWS_NO_EXPORT void init();
322 EVENTVIEWS_NO_EXPORT void marcus_bains();
323
324private:
325 friend class AgendaPrivate;
326 std::unique_ptr<AgendaPrivate> const d;
327};
328
329class AgendaScrollArea : public QScrollArea
330{
332public:
333 AgendaScrollArea(bool allDay, AgendaView *agendaView, bool isInteractive, QWidget *parent);
334 ~AgendaScrollArea() override;
335
336 Agenda *agenda() const;
337
338private:
339 Agenda *mAgenda = nullptr;
340};
341}
This class describes the widgets that represent the various calendar items in the agenda view.
Definition agendaitem.h:61
AgendaView is the agenda-like view that displays events in a single or multi-day view.
Definition agendaview.h:67
EventView is the abstract base class from which all other calendar views for event data are derived.
Definition eventview.h:67
Namespace EventViews provides facilities for displaying incidences, including events,...
Definition agenda.h:33
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
QObject * parent() const const
Orientation
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.