SVN_SILENT made messages (.desktop file)
[kdepim.git] / calendarviews / eventview.h
blob583f2e572c5d15249db09b6ee0c63e3fb849b3d3
1 /*
2 Copyright (c) 1999 Preston Brown <pbrown@kde.org>
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
5 Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
6 Author: Kevin Krammer, krake@kdab.com
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 As a special exception, permission is given to link this program
23 with any edition of Qt, and distribute the resulting executable,
24 without including the source code for Qt in the source distribution.
26 #ifndef EVENTVIEWS_EVENTVIEW_H
27 #define EVENTVIEWS_EVENTVIEW_H
29 #include "eventviews_export.h"
31 #include <Akonadi/Collection>
32 #include <Akonadi/Item>
33 #include <Akonadi/Calendar/ETMCalendar>
35 #include <KCalCore/Incidence>
36 #include <KCalCore/Todo>
38 #include <QWidget>
39 #include <QSet>
40 #include <QByteArray>
42 namespace boost {
43 template <typename T> class shared_ptr;
46 namespace KCalCore {
47 template <typename T> class SortableList;
48 typedef SortableList<QDate> DateList;
51 namespace KHolidays {
52 class HolidayRegion;
53 typedef boost::shared_ptr<HolidayRegion> HolidayRegionPtr;
56 namespace CalendarSupport {
57 class CollectionSelection;
58 class KCalPrefs;
61 namespace Akonadi {
62 class IncidenceChanger;
65 class KCheckableProxyModel;
66 class KConfigGroup;
68 namespace EventViews {
70 enum {
71 BUSY_BACKGROUND_ALPHA = 70
74 class EventViewPrivate;
75 class Prefs;
76 typedef boost::shared_ptr<Prefs> PrefsPtr;
77 typedef boost::shared_ptr<CalendarSupport::KCalPrefs> KCalPrefsPtr;
79 /**
80 EventView is the abstract base class from which all other calendar views
81 for event data are derived. It provides methods for displaying
82 appointments and events on one or more days. The actual number of
83 days that a view actually supports is not defined by this abstract class;
84 that is up to the classes that inherit from it. It also provides
85 methods for updating the display, retrieving the currently selected
86 event (or events), and the like.
88 @short Abstract class from which all event views are derived.
89 @author Preston Brown <pbrown@kde.org>
90 @see KOListView, AgendaView, KOMonthView
92 class EVENTVIEWS_EXPORT EventView : public QWidget
94 Q_OBJECT
95 public:
96 enum {
97 // This value is passed to QColor's lighter(int factor) for selected events
98 BRIGHTNESS_FACTOR = 125
101 enum ItemIcon {
102 CalendarCustomIcon = 0,
103 TaskIcon,
104 JournalIcon,
105 RecurringIcon,
106 ReminderIcon,
107 ReadOnlyIcon,
108 ReplyIcon,
109 AttendingIcon,
110 TentativeIcon,
111 OrganizerIcon,
112 IconCount = 10 // Always keep at the end
115 enum Change {
116 NothingChanged = 0,
117 IncidencesAdded = 1,
118 IncidencesEdited = 2,
119 IncidencesDeleted = 4,
120 DatesChanged = 8,
121 FilterChanged = 16,
122 ResourcesChanged = 32,
123 ZoomChanged = 64,
124 ConfigChanged = 128
126 Q_DECLARE_FLAGS( Changes, Change )
129 * Constructs a view.
130 * @param cal is a pointer to the calendar object from which events
131 * will be retrieved for display.
132 * @param parent is the parent QWidget.
134 explicit EventView( QWidget *parent = 0 );
137 * Destructor. Views will do view-specific cleanups here.
139 ~EventView();
141 virtual void setCalendar( const Akonadi::ETMCalendar::Ptr &cal );
144 Return calendar object of this view.
146 virtual Akonadi::ETMCalendar::Ptr calendar() const;
149 update config is called after prefs are set.
151 virtual void setPreferences( const PrefsPtr &preferences );
152 PrefsPtr preferences() const;
154 virtual void setKCalPreferences( const KCalPrefsPtr &preferences );
155 KCalPrefsPtr kcalPreferences() const;
158 @return a list of selected events. Most views can probably only
159 select a single event at a time, but some may be able to select
160 more than one.
162 virtual Akonadi::Item::List selectedIncidences() const = 0;
165 Returns a list of the dates of selected events. Most views can
166 probably only select a single event at a time, but some may be able
167 to select more than one.
169 virtual KCalCore::DateList selectedIncidenceDates() const = 0;
172 Returns the start of the selection, or an invalid QDateTime if there is no selection
173 or the view doesn't support selecting cells.
175 virtual QDateTime selectionStart() const;
178 Returns the end of the selection, or an invalid QDateTime if there is no selection
179 or the view doesn't support selecting cells.
181 virtual QDateTime selectionEnd() const;
184 Returns whether or not date range selection is enabled. This setting only
185 applies to views that actually supports selecting cells.
186 @see selectionStart()
187 @see selectionEnd()
189 bool dateRangeSelectionEnabled() const;
192 Enable or disable date range selection.
193 @see dateRangeSelectionEnabled()
195 void setDateRangeSelectionEnabled( bool enable );
198 Returns the number of currently shown dates.
199 A return value of 0 means no idea.
201 virtual int currentDateCount() const = 0;
204 * returns whether this view supports zoom.
205 * Base implementation returns false.
207 virtual bool supportsZoom() const;
209 virtual bool hasConfigurationDialog() const;
211 virtual void showConfigurationDialog( QWidget *parent );
213 QByteArray identifier() const;
214 void setIdentifier( const QByteArray &identifier );
217 * reads the view configuration. View-specific configuration can be
218 * restored via doRestoreConfig()
220 * @param configGroup the group to read settings from
221 * @see doRestoreConfig()
223 void restoreConfig( const KConfigGroup &configGroup );
226 * writes out the view configuration. View-specific configuration can be
227 * saved via doSaveConfig()
229 * @param configGroup the group to store settings in
230 * @see doSaveConfig()
232 void saveConfig( KConfigGroup &configGroup );
235 Makes the eventview display only items of collection @p id.
236 Useful for example in multi-agendaview (side-by-side) where
237 each AgendaView displays only one collection.
239 void setCollectionId( Akonadi::Collection::Id id );
240 Akonadi::Collection::Id collectionId() const;
242 //----------------------------------------------------------------------------
243 KCheckableProxyModel *takeCustomCollectionSelectionProxyModel();
244 KCheckableProxyModel *customCollectionSelectionProxyModel() const;
245 void setCustomCollectionSelectionProxyModel( KCheckableProxyModel *model );
247 CalendarSupport::CollectionSelection *customCollectionSelection() const;
249 static CalendarSupport::CollectionSelection *globalCollectionSelection();
250 static void setGlobalCollectionSelection( CalendarSupport::CollectionSelection *selection );
251 //----------------------------------------------------------------------------
254 * returns the view at the given widget coordinate. This is usually the view
255 * itself, except for composite views, where a subview will be returned.
256 * The default implementation returns @p this .
258 virtual EventView *viewAt( const QPoint &p );
261 * @param preferredMonth Used by month orientated views. Contains the
262 * month to show when the week crosses months. It's a QDate instead
263 * of uint so it can be easily fed to KCalendarSystem's functions.
265 virtual void setDateRange( const KDateTime &start, const KDateTime &end,
266 const QDate &preferredMonth = QDate() );
268 KDateTime startDateTime() const;
269 KDateTime endDateTime() const;
271 KDateTime actualStartDateTime() const;
272 KDateTime actualEndDateTime() const;
274 int showMoveRecurDialog( const KCalCore::Incidence::Ptr &incidence, const QDate &date );
277 Handles key events, opens the new event dialog when enter is pressed, activates type ahead.
279 bool processKeyEvent( QKeyEvent * );
282 * Sets the QObject that will receive key events that were made
283 * while the new event dialog was still being created.
285 void setTypeAheadReceiver( QObject *o );
288 Returns the selection of collection to be used by this view
289 (custom if set, or global otherwise).
291 CalendarSupport::CollectionSelection *collectionSelection() const;
294 Notifies the view that there are pending changes so a redraw is needed.
295 @param needed if the update is needed or not.
297 virtual void setChanges( Changes changes );
300 Returns if there are pending changes and a redraw is needed.
302 Changes changes() const;
305 * Returns a variation of @p color that will be used for the border
306 * of an agenda or month item.
308 static QColor itemFrameColor( const QColor &color, bool selected );
310 QString iconForItem( const Akonadi::Item &);
312 public Q_SLOTS:
314 Shows given incidences. Depending on the actual view it might not
315 be possible to show all given events.
317 @param incidenceList a list of incidences to show.
318 @param date is the QDate on which the incidences are being shown.
320 virtual void showIncidences( const Akonadi::Item::List &incidenceList,
321 const QDate &date ) = 0;
324 Updates the current display to reflect changes that may have happened
325 in the calendar since the last display refresh.
327 virtual void updateView() = 0;
328 virtual void dayPassed( const QDate & );
331 Assign a new incidence change helper object.
333 virtual void setIncidenceChanger( Akonadi::IncidenceChanger *changer );
336 Write all unsaved data back to calendar store.
338 virtual void flushView();
341 Re-reads the configuration and picks up relevant
342 changes which are applicable to the view.
344 virtual void updateConfig();
347 Clear selection. The incidenceSelected signal is not emitted.
349 virtual void clearSelection();
352 Sets the default start/end date/time for new events.
353 Return true if anything was changed
355 virtual bool eventDurationHint( QDateTime &startDt, QDateTime &endDt, bool &allDay ) const;
357 void focusChanged( QWidget *, QWidget * );
360 Perform the default action for an incidence, e.g. open the event editor,
361 when double-clicking an event in the agenda view.
363 void defaultAction( const Akonadi::Item &incidence );
366 Set which holidays the user wants to use.
367 @param holidayRegion a HolidayRegion object initialized with the desired locale.
369 void setHolidayRegion( const KHolidays::HolidayRegionPtr &holidayRegion );
371 Q_SIGNALS:
373 * when the view changes the dates that are selected in one way or
374 * another, this signal is emitted. It should be connected back to
375 * the KDateNavigator object so that it changes appropriately,
376 * and any other objects that need to be aware that the list of
377 * selected dates has changed.
378 * @param datelist the new list of selected dates
380 void datesSelected( const KCalCore::DateList &datelist );
383 * Emitted when an event is moved using the mouse in an agenda
384 * view (week / month).
386 void shiftedEvent( const QDate &olddate, const QDate &newdate );
388 void incidenceSelected( const Akonadi::Item &, const QDate );
391 * instructs the receiver to show the incidence in read-only mode.
393 void showIncidenceSignal( const Akonadi::Item & );
396 * instructs the receiver to begin editing the incidence specified in
397 * some manner. Doesn't make sense to connect to more than one
398 * receiver.
400 void editIncidenceSignal( const Akonadi::Item & );
403 * instructs the receiver to delete the Incidence in some manner; some
404 * possibilities include automatically, with a confirmation dialog
405 * box, etc. Doesn't make sense to connect to more than one receiver.
407 void deleteIncidenceSignal( const Akonadi::Item & );
410 * instructs the receiver to cut the Incidence
412 void cutIncidenceSignal( const Akonadi::Item & );
415 * instructs the receiver to copy the incidence
417 void copyIncidenceSignal( const Akonadi::Item & );
420 * instructs the receiver to paste the incidence
422 void pasteIncidenceSignal();
425 * instructs the receiver to toggle the alarms of the Incidence.
427 void toggleAlarmSignal( const Akonadi::Item & );
430 * instructs the receiver to toggle the completion state of the Incidence
431 * (which must be a Todo type).
433 void toggleTodoCompletedSignal( const Akonadi::Item & );
436 * Copy the incidence to the specified resource.
438 void copyIncidenceToResourceSignal( const Akonadi::Item &, const QString & );
441 * Move the incidence to the specified resource.
443 void moveIncidenceToResourceSignal( const Akonadi::Item &, const QString & );
445 /** Dissociate from a recurring incidence the occurrence on the given
446 * date to a new incidence or dissociate all occurrences from the
447 * given date onwards.
449 void dissociateOccurrencesSignal( const Akonadi::Item &, const QDate & );
452 * instructs the receiver to create a new event in given collection. Doesn't make
453 * sense to connect to more than one receiver.
455 void newEventSignal();
457 * instructs the receiver to create a new event with the specified beginning
458 * time. Doesn't make sense to connect to more than one receiver.
460 void newEventSignal( const QDate & );
462 * instructs the receiver to create a new event with the specified beginning
463 * time. Doesn't make sense to connect to more than one receiver.
465 void newEventSignal( const QDateTime & );
467 * instructs the receiver to create a new event, with the specified
468 * beginning end ending times. Doesn't make sense to connect to more
469 * than one receiver.
471 void newEventSignal( const QDateTime &, const QDateTime & );
473 void newTodoSignal( const QDate & );
474 void newSubTodoSignal( const Akonadi::Item & );
476 void newJournalSignal( const QDate & );
478 protected Q_SLOTS:
479 virtual void calendarReset();
481 private Q_SLOTS:
482 void onCollectionChanged(const Akonadi::Collection &, const QSet<QByteArray> &);
484 protected:
485 bool makesWholeDayBusy( const KCalCore::Incidence::Ptr &incidence ) const;
486 Akonadi::IncidenceChanger *changer() const;
489 * reimplement to read view-specific settings.
491 virtual void doRestoreConfig( const KConfigGroup &configGroup );
494 * reimplement to write view-specific settings.
496 virtual void doSaveConfig( KConfigGroup &configGroup );
499 @deprecated
501 virtual void showDates( const QDate &start, const QDate &end,
502 const QDate &preferredMonth = QDate() ) = 0;
505 * from the requested date range (passed via setDateRange()), calculates the
506 * adjusted date range actually displayed by the view, depending on the
507 * view's supported range (e.g., a month view always displays one month)
508 * The default implementation returns the range unmodified
510 * @param preferredMonth Used by month orientated views. Contains the
511 * month to show when the week crosses months. It's a QDate instead of
512 * uint so it can be easily fed to KCalendarSystem's functions.
514 virtual QPair<KDateTime,KDateTime> actualDateRange(
515 const KDateTime &start, const KDateTime &end, const QDate &preferredMonth = QDate() ) const;
517 virtual void incidencesAdded( const Akonadi::Item::List &incidences );
518 virtual void incidencesAboutToBeRemoved( const Akonadi::Item::List &incidences );
519 virtual void incidencesChanged( const Akonadi::Item::List &incidences );
521 virtual void handleBackendError( const QString &error );
523 private:
524 EventViewPrivate * const d_ptr;
525 Q_DECLARE_PRIVATE( EventView )
530 #endif
531 // kate: space-indent on; indent-width 2; replace-tabs on;