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