Eventviews

eventview.h
1/*
2 SPDX-FileCopyrightText: 1999 Preston Brown <pbrown@kde.org>
3 SPDX-FileCopyrightText: 2000, 2001 Cornelius Schumacher <schumacher@kde.org>
4 SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
5 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
6 SPDX-FileContributor: Kevin Krammer <krake@kdab.com>
7
8 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
9*/
10#pragma once
11
12#include "eventviews_export.h"
13
14#include <Akonadi/Collection>
15#include <Akonadi/CollectionCalendar>
16#include <Akonadi/Item>
17
18#include <KCalendarCore/Incidence>
19#include <KCalendarCore/Todo>
20
21#include <QByteArray>
22#include <QDate>
23#include <QSet>
24#include <QWidget>
25
26#include <memory>
27
29
30namespace CalendarSupport
31{
32class CollectionSelection;
33class KCalPrefs;
34}
35
36namespace Akonadi
37{
38class IncidenceChanger;
39}
40
42class KConfigGroup;
43
44namespace EventViews
45{
46enum {
47 BUSY_BACKGROUND_ALPHA = 70
48};
49
50class EventViewPrivate;
51class Prefs;
52using PrefsPtr = QSharedPointer<Prefs>;
54
55/**
56 EventView is the abstract base class from which all other calendar views
57 for event data are derived. It provides methods for displaying
58 appointments and events on one or more days. The actual number of
59 days that a view actually supports is not defined by this abstract class;
60 that is up to the classes that inherit from it. It also provides
61 methods for updating the display, retrieving the currently selected
62 event (or events), and the like.
63
64 @short Abstract class from which all event views are derived.
65 @author Preston Brown <pbrown@kde.org>
66 @see KOListView, AgendaView, KOMonthView
67*/
68class EVENTVIEWS_EXPORT EventView : public QWidget
69{
70 Q_OBJECT
71public:
72 enum {
73 // This value is passed to QColor's lighter(int factor) for selected events
74 BRIGHTNESS_FACTOR = 110
75 };
76
77 enum ItemIcon {
78 CalendarCustomIcon = 0,
79 TaskIcon,
80 JournalIcon,
81 RecurringIcon,
82 ReminderIcon,
83 ReadOnlyIcon,
84 ReplyIcon,
85 AttendingIcon,
86 TentativeIcon,
87 OrganizerIcon,
88 IconCount = 10 // Always keep at the end
89 };
90
91 enum Change {
92 NothingChanged = 0,
93 IncidencesAdded = 1,
94 IncidencesEdited = 2,
95 IncidencesDeleted = 4,
96 DatesChanged = 8,
97 FilterChanged = 16,
98 ResourcesChanged = 32,
99 ZoomChanged = 64,
100 ConfigChanged = 128
101 };
102 Q_DECLARE_FLAGS(Changes, Change)
103
104 /**
105 * Constructs a view.
106 * @param cal is a pointer to the calendar object from which events
107 * will be retrieved for display.
108 * @param parent is the parent QWidget.
109 */
110 explicit EventView(QWidget *parent = nullptr);
111
112 /**
113 * Destructor. Views will do view-specific cleanups here.
114 */
115 ~EventView() override;
116
117 virtual void addCalendar(const Akonadi::CollectionCalendar::Ptr &calendar);
118 virtual void removeCalendar(const Akonadi::CollectionCalendar::Ptr &calendar);
119
120 virtual void setModel(QAbstractItemModel *model);
121 QAbstractItemModel *model() const;
122 Akonadi::EntityTreeModel *entityTreeModel() const;
123
124 /*
125 update config is called after prefs are set.
126 */
127 virtual void setPreferences(const PrefsPtr &preferences);
128 [[nodiscard]] PrefsPtr preferences() const;
129
130 virtual void setKCalPreferences(const KCalPrefsPtr &preferences);
131 [[nodiscard]] KCalPrefsPtr kcalPreferences() const;
132
133 /**
134 @return a list of selected events. Most views can probably only
135 select a single event at a time, but some may be able to select
136 more than one.
137 */
139
140 /**
141 Returns a list of the dates of selected events. Most views can
142 probably only select a single event at a time, but some may be able
143 to select more than one.
144 */
146
147 /**
148 Returns the start of the selection, or an invalid QDateTime if there is no selection
149 or the view doesn't support selecting cells.
150 */
151 virtual QDateTime selectionStart() const;
152
153 /**
154 Returns the end of the selection, or an invalid QDateTime if there is no selection
155 or the view doesn't support selecting cells.
156 */
157 virtual QDateTime selectionEnd() const;
158
159 /**
160 Sets the default start/end date/time for new events.
161 Return true if anything was changed
162 */
163 virtual bool eventDurationHint(QDateTime &startDt, QDateTime &endDt, bool &allDay) const;
164
165 /**
166 Returns whether or not date range selection is enabled. This setting only
167 applies to views that actually supports selecting cells.
168 @see selectionStart()
169 @see selectionEnd()
170 */
171 [[nodiscard]] bool dateRangeSelectionEnabled() const;
172
173 /**
174 Enable or disable date range selection.
175 @see dateRangeSelectionEnabled()
176 */
177 void setDateRangeSelectionEnabled(bool enable);
178
179 /**
180 Returns the number of currently shown dates.
181 A return value of 0 means no idea.
182 */
183 virtual int currentDateCount() const = 0;
184
185 /**
186 * returns whether this view supports zoom.
187 * Base implementation returns false.
188 */
189 virtual bool supportsZoom() const;
190
191 virtual bool hasConfigurationDialog() const;
192
193 virtual void showConfigurationDialog(QWidget *parent);
194
195 [[nodiscard]] QByteArray identifier() const;
196 void setIdentifier(const QByteArray &identifier);
197
198 /**
199 * reads the view configuration. View-specific configuration can be
200 * restored via doRestoreConfig()
201 *
202 * @param configGroup the group to read settings from
203 * @see doRestoreConfig()
204 */
205 void restoreConfig(const KConfigGroup &configGroup);
206
207 /**
208 * writes out the view configuration. View-specific configuration can be
209 * saved via doSaveConfig()
210 *
211 * @param configGroup the group to store settings in
212 * @see doSaveConfig()
213 */
214 void saveConfig(KConfigGroup &configGroup);
215
216 //----------------------------------------------------------------------------
217 KCheckableProxyModel *takeCustomCollectionSelectionProxyModel();
218 KCheckableProxyModel *customCollectionSelectionProxyModel() const;
219 void setCustomCollectionSelectionProxyModel(KCheckableProxyModel *model);
220
221 CalendarSupport::CollectionSelection *customCollectionSelection() const;
222
223 static CalendarSupport::CollectionSelection *globalCollectionSelection();
224 static void setGlobalCollectionSelection(CalendarSupport::CollectionSelection *selection);
225 //----------------------------------------------------------------------------
226
227 /**
228 * returns the view at the given widget coordinate. This is usually the view
229 * itself, except for composite views, where a subview will be returned.
230 * The default implementation returns @p this .
231 */
232 virtual EventView *viewAt(const QPoint &p);
233
234 /**
235 * @param preferredMonth Used by month orientated views. Contains the
236 * month to show when the week crosses months. It's a QDate instead
237 * of uint so it can be easily fed to KCalendarSystem's functions.
238 */
239 virtual void setDateRange(const QDateTime &start, const QDateTime &end, const QDate &preferredMonth = QDate());
240
241 [[nodiscard]] QDateTime startDateTime() const;
242 [[nodiscard]] QDateTime endDateTime() const;
243
244 [[nodiscard]] QDateTime actualStartDateTime() const;
245 [[nodiscard]] QDateTime actualEndDateTime() const;
246
247 [[nodiscard]] int showMoveRecurDialog(const KCalendarCore::Incidence::Ptr &incidence, QDate date);
248
249 /**
250 Handles key events, opens the new event dialog when enter is pressed, activates type ahead.
251 */
252 [[nodiscard]] bool processKeyEvent(QKeyEvent *);
253
254 /*
255 * Sets the QObject that will receive key events that were made
256 * while the new event dialog was still being created.
257 */
258 void setTypeAheadReceiver(QObject *o);
259
260 /**
261 Returns the selection of collection to be used by this view
262 (custom if set, or global otherwise).
263 */
264 CalendarSupport::CollectionSelection *collectionSelection() const;
265
266 /**
267 Notifies the view that there are pending changes so a redraw is needed.
268 @param needed if the update is needed or not.
269 */
270 virtual void setChanges(Changes changes);
271
272 /**
273 Returns if there are pending changes and a redraw is needed.
274 */
275 [[nodiscard]] Changes changes() const;
276
277 /**
278 * Returns a variation of @p color that will be used for the border
279 * of an agenda or month item.
280 */
281 [[nodiscard]] static QColor itemFrameColor(const QColor &color, bool selected);
282
283 [[nodiscard]] QString iconForItem(const Akonadi::Item &);
284
285 [[nodiscard]] Akonadi::CollectionCalendar::Ptr calendarForCollection(const Akonadi::Collection &collection) const;
286 [[nodiscard]] Akonadi::CollectionCalendar::Ptr calendarForCollection(Akonadi::Collection::Id collectionId) const;
287
288public Q_SLOTS:
289 /**
290 Shows given incidences. Depending on the actual view it might not
291 be possible to show all given events.
292
293 @param incidenceList a list of incidences to show.
294 @param date is the QDate on which the incidences are being shown.
295 */
296 virtual void showIncidences(const Akonadi::Item::List &incidenceList, const QDate &date) = 0;
297
298 /**
299 Updates the current display to reflect changes that may have happened
300 in the calendar since the last display refresh.
301 */
302 virtual void updateView() = 0;
303 virtual void dayPassed(const QDate &);
304
305 /**
306 Assign a new incidence change helper object.
307 */
308 virtual void setIncidenceChanger(Akonadi::IncidenceChanger *changer);
309
310 /**
311 Write all unsaved data back to calendar store.
312 */
313 virtual void flushView();
314
315 /**
316 Re-reads the configuration and picks up relevant
317 changes which are applicable to the view.
318 */
319 virtual void updateConfig();
320
321 /**
322 Clear selection. The incidenceSelected signal is not emitted.
323 */
324 virtual void clearSelection();
325
326 void focusChanged(QWidget *, QWidget *);
327
328 /**
329 Perform the default action for an incidence, e.g. open the event editor,
330 when double-clicking an event in the agenda view.
331 */
332 void defaultAction(const Akonadi::Item &incidence);
333
334 /**
335 Set which holiday regions the user wants to use.
336 @param regions a list of Holiday Regions strings.
337 */
338 void setHolidayRegions(const QStringList &regions);
339
340Q_SIGNALS:
341 /**
342 * when the view changes the dates that are selected in one way or
343 * another, this signal is emitted. It should be connected back to
344 * the KDateNavigator object so that it changes appropriately,
345 * and any other objects that need to be aware that the list of
346 * selected dates has changed.
347 * @param datelist the new list of selected dates
348 */
350
351 /**
352 * Emitted when an event is moved using the mouse in an agenda
353 * view (week / month).
354 */
355 void shiftedEvent(const QDate &olddate, const QDate &newdate);
356
357 void incidenceSelected(const Akonadi::Item &, const QDate);
358
359 /**
360 * instructs the receiver to show the incidence in read-only mode.
361 */
363
364 /**
365 * instructs the receiver to begin editing the incidence specified in
366 * some manner. Doesn't make sense to connect to more than one
367 * receiver.
368 */
370
371 /**
372 * instructs the receiver to delete the Incidence in some manner; some
373 * possibilities include automatically, with a confirmation dialog
374 * box, etc. Doesn't make sense to connect to more than one receiver.
375 */
377
378 /**
379 * instructs the receiver to cut the Incidence
380 */
382
383 /**
384 * instructs the receiver to copy the incidence
385 */
387
388 /**
389 * instructs the receiver to paste the incidence
390 */
392
393 /**
394 * instructs the receiver to toggle the alarms of the Incidence.
395 */
397
398 /**
399 * instructs the receiver to toggle the completion state of the Incidence
400 * (which must be a Todo type).
401 */
403
404 /**
405 * Copy the incidence to the specified resource.
406 */
408
409 /**
410 * Move the incidence to the specified resource.
411 */
413
414 /** Dissociate from a recurring incidence the occurrence on the given
415 * date to a new incidence or dissociate all occurrences from the
416 * given date onwards.
417 */
419
420 /**
421 * instructs the receiver to create a new event in given collection. Doesn't make
422 * sense to connect to more than one receiver.
423 */
425 /**
426 * instructs the receiver to create a new event with the specified beginning
427 * time. Doesn't make sense to connect to more than one receiver.
428 */
429 void newEventSignal(const QDate &);
430 /**
431 * instructs the receiver to create a new event with the specified beginning
432 * time. Doesn't make sense to connect to more than one receiver.
433 */
435 /**
436 * instructs the receiver to create a new event, with the specified
437 * beginning end ending times. Doesn't make sense to connect to more
438 * than one receiver.
439 */
440 void newEventSignal(const QDateTime &, const QDateTime &);
441
442 void newTodoSignal(const QDate &);
443 void newSubTodoSignal(const Akonadi::Item &);
444
445 void newJournalSignal(const QDate &);
446
447protected Q_SLOTS:
448 virtual void calendarReset();
449
450private:
451 EVENTVIEWS_NO_EXPORT void onCollectionChanged(const Akonadi::Collection &, const QSet<QByteArray> &);
452
453protected:
455 Akonadi::CollectionCalendar::Ptr calendar3(const Akonadi::Item &item) const;
456 Akonadi::CollectionCalendar::Ptr calendar3(const KCalendarCore::Incidence::Ptr &incidence) const;
457
458 bool makesWholeDayBusy(const KCalendarCore::Incidence::Ptr &incidence) const;
459 Akonadi::IncidenceChanger *changer() const;
460
461 /**
462 * reimplement to read view-specific settings.
463 */
464 virtual void doRestoreConfig(const KConfigGroup &configGroup);
465
466 /**
467 * reimplement to write view-specific settings.
468 */
469 virtual void doSaveConfig(KConfigGroup &configGroup);
470
471 /**
472 @deprecated
473 */
474 virtual void showDates(const QDate &start, const QDate &end, const QDate &preferredMonth = QDate()) = 0;
475
476 /**
477 * from the requested date range (passed via setDateRange()), calculates the
478 * adjusted date range actually displayed by the view, depending on the
479 * view's supported range (e.g., a month view always displays one month)
480 * The default implementation returns the range unmodified
481 *
482 * @param preferredMonth Used by month orientated views. Contains the
483 * month to show when the week crosses months. It's a QDate instead of
484 * uint so it can be easily fed to KCalendarSystem's functions.
485 */
486 virtual QPair<QDateTime, QDateTime> actualDateRange(const QDateTime &start, const QDateTime &end, const QDate &preferredMonth = QDate()) const;
487 virtual void handleBackendError(const QString &error);
488
489private:
490 std::unique_ptr<EventViewPrivate> const d_ptr;
491 Q_DECLARE_PRIVATE(EventView)
492};
493}
EventView is the abstract base class from which all other calendar views for event data are derived.
Definition eventview.h:69
void toggleTodoCompletedSignal(const Akonadi::Item &)
instructs the receiver to toggle the completion state of the Incidence (which must be a Todo type).
void newEventSignal(const QDate &)
instructs the receiver to create a new event with the specified beginning time.
virtual void updateView()=0
Updates the current display to reflect changes that may have happened in the calendar since the last ...
void dissociateOccurrencesSignal(const Akonadi::Item &, const QDate &)
Dissociate from a recurring incidence the occurrence on the given date to a new incidence or dissocia...
void showIncidenceSignal(const Akonadi::Item &)
instructs the receiver to show the incidence in read-only mode.
void toggleAlarmSignal(const Akonadi::Item &)
instructs the receiver to toggle the alarms of the Incidence.
void moveIncidenceToResourceSignal(const Akonadi::Item &, const Akonadi::Collection &)
Move the incidence to the specified resource.
~EventView() override
Destructor.
virtual Akonadi::Item::List selectedIncidences() const =0
void newEventSignal()
instructs the receiver to create a new event in given collection.
void deleteIncidenceSignal(const Akonadi::Item &)
instructs the receiver to delete the Incidence in some manner; some possibilities include automatical...
void copyIncidenceToResourceSignal(const Akonadi::Item &, const Akonadi::Collection &)
Copy the incidence to the specified resource.
void shiftedEvent(const QDate &olddate, const QDate &newdate)
Emitted when an event is moved using the mouse in an agenda view (week / month).
void datesSelected(const KCalendarCore::DateList &datelist)
when the view changes the dates that are selected in one way or another, this signal is emitted.
virtual void showIncidences(const Akonadi::Item::List &incidenceList, const QDate &date)=0
Shows given incidences.
virtual KCalendarCore::DateList selectedIncidenceDates() const =0
Returns a list of the dates of selected events.
void pasteIncidenceSignal()
instructs the receiver to paste the incidence
void cutIncidenceSignal(const Akonadi::Item &)
instructs the receiver to cut the Incidence
void editIncidenceSignal(const Akonadi::Item &)
instructs the receiver to begin editing the incidence specified in some manner.
virtual void showDates(const QDate &start, const QDate &end, const QDate &preferredMonth=QDate())=0
void copyIncidenceSignal(const Akonadi::Item &)
instructs the receiver to copy the incidence
virtual int currentDateCount() const =0
Returns the number of currently shown dates.
void newEventSignal(const QDateTime &, const QDateTime &)
instructs the receiver to create a new event, with the specified beginning end ending times.
void newEventSignal(const QDateTime &)
instructs the receiver to create a new event with the specified beginning time.
Q_SCRIPTABLE Q_NOREPLY void start()
Namespace EventViews provides facilities for displaying incidences, including events,...
Definition agenda.h:33
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.