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 {
224 NOP,
225 MOVE,
226 SELECT,
227 RESIZETOP,
228 RESIZEBOTTOM,
229 RESIZELEFT,
230 RESIZERIGHT
231 };
232
234 createAgendaItem(const KCalendarCore::Incidence::Ptr &incidence, int itemPos, int itemCount, const QDateTime &recurrentId, bool isSelected);
235
236protected:
237 /**
238 Draw the background grid of the agenda.
239 @p cw grid width
240 @p ch grid height
241 */
242 void drawContents(QPainter *p, int cx, int cy, int cw, int ch);
243
244 int columnWidth(int column) const;
245 void resizeEvent(QResizeEvent *) override;
246
247 /** Handles mouse events. Called from eventFilter */
248 virtual bool eventFilter_mouse(QObject *, QMouseEvent *);
249#ifndef QT_NO_WHEELEVENT
250 /** Handles mousewheel events. Called from eventFilter */
251 virtual bool eventFilter_wheel(QObject *, QWheelEvent *);
252#endif
253 /** Handles key events. Called from eventFilter */
254 virtual bool eventFilter_key(QObject *, QKeyEvent *);
255
256 /** Handles drag and drop events. Called from eventFilter */
257 virtual bool eventFilter_drag(QObject *, QDropEvent *);
258
259 /** returns RESIZELEFT if pos is near the lower edge of the action item,
260 RESIZERIGHT if pos is near the higher edge, and MOVE otherwise.
261 If --reverse is used, RESIZELEFT still means resizing the beginning of
262 the event, although that means moving to the right!
263 horizontal is the same as mAllDayAgenda.
264 @param horizontal Whether horizontal resizing is possible
265 @param pos The current mouse position
266 @param item The affected item
267 */
268 MouseActionType isInResizeArea(bool horizontal, QPoint pos, const AgendaItem::QPtr &item);
269 /** Return whether the cell specified by the grid point belongs to the current select
270 */
271 [[nodiscard]] bool ptInSelection(QPoint gpos) const;
272
273 /** Start selecting time span. */
274 void startSelectAction(QPoint viewportPos);
275
276 /** Select time span. */
277 void performSelectAction(QPoint viewportPos);
278
279 /** Emd selecting time span. */
280 void endSelectAction(const QPoint &viewportPos);
281
282 /** Start moving/resizing agenda item */
283 void startItemAction(const QPoint &viewportPos);
284
285 /** Move/resize agenda item */
286 void performItemAction(QPoint viewportPos);
287
288 /** End moving/resizing agenda item */
289 void endItemAction();
290
291 /** Set cursor, when no item action is in progress */
292 void setNoActionCursor(const AgendaItem::QPtr &moveItem, QPoint viewportPos);
293 /** Sets the cursor according to the given action type.
294 @param actionType The type of action for which the cursor should be set.
295 @param acting If true, the corresponding action is running (e.g. the
296 item is currently being moved by the user). If false the
297 cursor should just indicate that the corresponding
298 action is possible */
299 void setActionCursor(int actionType, bool acting = false);
300
301 /** calculate the width of the column subcells of the given item */
302 double calcSubCellWidth(const AgendaItem::QPtr &item);
303 /** Move and resize the given item to the correct position */
304 void placeAgendaItem(const AgendaItem::QPtr &item, double subCellWidth);
305 /** Place agenda item in agenda and adjust other cells if necessary */
306 void placeSubCells(const AgendaItem::QPtr &placeItem);
307 /** Place the agenda item at the correct position (ignoring conflicting items) */
308 void adjustItemPosition(const AgendaItem::QPtr &item);
309
310 /** Process the keyevent, including the ignored keyevents of eventwidgets.
311 * Implements pgup/pgdn and cursor key navigation in the view.
312 */
313 void keyPressEvent(QKeyEvent *) override;
314
315 void calculateWorkingHours();
316
317 virtual void contentsMousePressEvent(QMouseEvent *);
318
319protected Q_SLOTS:
320 /** delete the items that are queued for deletion */
321 void deleteItemsToDelete();
322 /** Resizes all the child elements after the size of the agenda
323 changed. This is needed because Qt seems to have a bug when
324 the resizeEvent of one of the widgets in a splitter takes a
325 lot of time / does a lot of resizes.... see bug 80114 */
326 void resizeAllContents();
327
328private:
329 EVENTVIEWS_NO_EXPORT void init();
330 EVENTVIEWS_NO_EXPORT void marcus_bains();
331
332private:
333 friend class AgendaPrivate;
334 std::unique_ptr<AgendaPrivate> const d;
335};
336
337class AgendaScrollArea : public QScrollArea
338{
340public:
341 AgendaScrollArea(bool allDay, AgendaView *agendaView, bool isInteractive, QWidget *parent);
342 ~AgendaScrollArea() override;
343
344 Agenda *agenda() const;
345
346private:
347 Agenda *mAgenda = nullptr;
348};
349}
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:70
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
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 Fri Nov 22 2024 12:05:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.