SVN_SILENT made messages (.desktop file) - always resolve ours
[kdepim.git] / korganizer / kodaymatrix.h
blob0c7132323d8ae9e22f40630b7187ac75ddc5f3ac
1 /*
2 This file is part of KOrganizer.
4 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at>
5 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
6 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.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.
27 #ifndef KORG_KODAYMATRIX_H
28 #define KORG_KODAYMATRIX_H
30 #include <Akonadi/Calendar/ETMCalendar>
32 #include <KCalCore/IncidenceBase> //for KCalCore::DateList typedef
34 #include <QFrame>
35 #include <QDate>
37 /**
38 * Replacement for kdpdatebuton.cpp that used 42 widgets for the day
39 * matrix to be displayed. Cornelius thought this was a waste of memory
40 * and a lot of overhead. In addition the selection was not very intuitive
41 * so I decided to rewrite it using a QFrame that draws the labels and
42 * allows for dragging selection while maintaining nearly full compatibility
43 * in behavior with its predecessor.
45 * The following functionality has been changed:
47 * o when shifting events in the agenda view from one day to another
48 * the day matrix is updated now
50 * o dragging an event to the matrix will MOVE not COPY the event to the
51 * new date.
53 * o no support for Ctrl+click to create groups of dates
54 * (This has not really been supported in the predecessor.
55 * It was not very intuitive nor was it user friendly.)
56 * This feature has been replaced with dragging a selection on the matrix.
57 * The matrix will automatically choose the appropriate selection (e.g. you
58 * are not any longer able to select two distinct groups of date selections
59 * as in the old class)
61 * o now that you can select more than a week it can happen that not all
62 * selected days are displayed in the matrix. However this is preferred
63 * to the alternative which would mean to adjust the selection and leave
64 * some days undisplayed while scrolling through the months
66 * @short day matrix widget of the KDateNavigator
68 * @author Eitzenberger Thomas
70 class KODayMatrix: public QFrame, public Akonadi::ETMCalendar::CalendarObserver
72 Q_OBJECT
73 public:
74 /** constructor to create a day matrix widget.
76 * @param parent widget that is the parent of the day matrix.
77 * Normally this should be a KDateNavigator
79 explicit KODayMatrix(QWidget *parent);
81 /** destructor that deallocates all dynamically allocated private members.
83 ~KODayMatrix();
85 /** returns the first and last date of the 6*7 matrix that displays @p month
86 * @param month The month we want to get matrix boundaries
88 static QPair<QDate, QDate> matrixLimits(const QDate &month);
90 /**
91 Associate a calendar with this day matrix. If there is a calendar, the
92 day matrix will accept drops and days with events will be highlighted.
94 void setCalendar(const Akonadi::ETMCalendar::Ptr &);
96 /** updates the day matrix to start with the given date. Does all the
97 * necessary checks for holidays or events on a day and stores them
98 * for display later on.
99 * Does NOT update the view visually. Call repaint() for this.
101 * @param actdate recalculates the day matrix to show NUMDAYS starting
102 * from this date.
104 void updateView(const QDate &actdate);
107 Update incidence states of dates. Depending of the preferences days with
108 incidences are highlighted in some way.
110 void updateIncidences();
113 * Returns the QDate object associated with day indexed by the supplied
114 * offset.
116 const QDate &getDate(int offset) const;
119 * Returns the official name of this holy day or 0 if there is no label
120 * for this day.
122 QString getHolidayLabel(int offset) const;
125 * Adds all actual selected days from mSelStart to mSelEnd to the supplied
126 * DateList.
128 void addSelectedDaysTo(KCalCore::DateList &);
131 * Sets the actual to be displayed selection in the day matrix starting
132 * from start and ending with end. Theview must be manually updated by
133 * calling repaint. (?)
134 * @param start start of the new selection
135 * @param end end date of the new selection
137 void setSelectedDaysFrom(const QDate &start, const QDate &end);
140 Clear all selections.
142 void clearSelection();
144 /** Is today visible in the view? Keep this in sync with
145 * the values today (below) can take.
147 bool isTodayVisible() const
149 return mToday >= 0;
153 * If today is visible, then we can find out if today is
154 * near the beginning or the end of the month.
155 * This is dependent on today remaining the index
156 * in the array of visible dates and going from
157 * top left (0) to bottom right (41).
159 bool isBeginningOfMonth() const
161 return mToday <= 8;
163 bool isEndOfMonth() const
165 return mToday >= 27;
169 * Reimplemented from Akonadi::ETMCalendar
170 * They set mPendingChanges to true
172 void calendarIncidenceAdded(const KCalCore::Incidence::Ptr &incidence) Q_DECL_OVERRIDE;
173 void calendarIncidenceChanged(const KCalCore::Incidence::Ptr &incidence) Q_DECL_OVERRIDE;
174 void calendarIncidenceDeleted(const KCalCore::Incidence::Ptr &incidence) Q_DECL_OVERRIDE;
176 /** Sets which incidences should be highlighted */
177 void setHighlightMode(bool highlightEvents,
178 bool highlightTodos,
179 bool highlightJournals);
180 void setUpdateNeeded();
181 public Q_SLOTS:
183 * Recalculates all the flags of the days in the matrix like holidays or
184 * events on a day (Actually calls above method with the actual startdate).
186 void updateView();
189 * Calculates which square in the matrix should be hiighted to indicate
190 * the square is on "today".
192 void recalculateToday();
195 * Handle resource changes.
197 void resourcesChanged();
199 Q_SIGNALS:
201 * Emitted if the user selects a block of days with the mouse by dragging
202 * a rectangle inside the matrix
204 * @param daylist list of days that have been selected by the user
206 void selected(const KCalCore::DateList &daylist);
208 void newEventSignal(const QDate &date);
209 void newTodoSignal(const QDate &date);
210 void newJournalSignal(const QDate &date);
213 * Emitted if the user has dropped an incidence (event or todo) inside
214 * the matrix.
216 * @param incidence the dropped calendar incidence
217 * @param dt QDate that has been selected
219 void incidenceDropped(const Akonadi::Item &item, const QDate &dt);
222 * Emitted if the user has dropped an event inside the matrix and chose
223 * to move it instead of copy
225 * @param oldincidence the new calendar incidence
226 * @param dt QDate that has been selected
228 void incidenceDroppedMove(const Akonadi::Item &item, const QDate &dt);
230 protected:
231 bool event(QEvent *e) Q_DECL_OVERRIDE;
233 void paintEvent(QPaintEvent *ev) Q_DECL_OVERRIDE;
235 void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
237 void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
239 void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
241 void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
243 void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
245 void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE;
247 void dragLeaveEvent(QDragLeaveEvent *e) Q_DECL_OVERRIDE;
249 void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE;
251 private:
253 * Pop-up a context menu for creating a new Event, To-do, or Journal.
255 void popupMenu(const QDate &date);
257 /** returns the index of the day located at the matrix's widget (x,y) position.
259 * @param x horizontal coordinate
260 * @param y vertical coordinate
262 int getDayIndexFrom(int x, int y) const;
264 /** calculates a "shaded" color from the supplied color object.
265 * (Copied from Cornelius's kdpdatebutton.cpp)
267 * @param color source based on which a shaded color should be calculated.
269 QColor getShadedColor(const QColor &color) const;
271 /** updates mEvent list with all days that have events */
272 void updateEvents();
274 /** updates mEvent list with all days that have to-dos with due date */
275 void updateTodos();
277 /** updates mEvent list with all days that have journals */
278 void updateJournals();
280 /** number of days to be displayed. For now there is no support for any
281 other number than 42. so change it at your own risk :o) */
282 static const int NUMDAYS;
284 /** calendar instance to be queried for holidays, events, ... */
285 Akonadi::ETMCalendar::Ptr mCalendar;
287 /** starting date of the matrix */
288 QDate mStartDate;
290 /** array of day labels to optimeize drawing performance. */
291 QString *mDayLabels;
293 /** array of days displayed to reduce memory consumption by
294 subsequently calling QDate::addDays(). */
295 QDate *mDays;
297 /** List for storing days which should be drawn using bold font. */
298 QList<QDate> mEvents;
300 /** stores holiday names of the days shown in the matrix. */
301 QMap<int, QString> mHolidays;
303 /** index of today or -1 if today is not visible in the matrix. */
304 int mToday;
306 /** index of day where dragged selection was initiated.
307 used to detect "negative" timely selections */
308 int mSelInit;
310 /** if mSelStart has this value it indicates that there is no
311 actual selection in the matrix. */
312 static const int NOSELECTION;
314 /** index of first selected day. */
315 int mSelStart;
317 /** index of last selected day. */
318 int mSelEnd;
320 /** default width of the frame drawn around today if it is visible
321 in the matrix. */
322 int mTodayMarginWidth;
324 /** stores actual size of each day in the widget so we don't need to
325 * ask on every repaint.
327 QRect mDaySize;
330 * Indicate pending calendar changes.
332 bool mPendingChanges;
334 /** Whether days with events are highlighted */
335 bool mHighlightEvents;
337 /** Whether days with to-dos (with due date) are highlighted */
338 bool mHighlightTodos;
340 /** Whether days with journals are highlighted */
341 bool mHighlightJournals;
344 #endif