Documentation: Menus.docbook Composer menu Message and correcct formatting.
[kdepim.git] / korganizer / kodaymatrix.h
bloba9dbd2a6f348ee8a16cd229ac26f540737d19e22
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>
36 /**
37 * Replacement for kdpdatebuton.cpp that used 42 widgets for the day
38 * matrix to be displayed. Cornelius thought this was a waste of memory
39 * and a lot of overhead. In addition the selection was not very intuitive
40 * so I decided to rewrite it using a QFrame that draws the labels and
41 * allows for dragging selection while maintaining nearly full compatibility
42 * in behavior with its predecessor.
44 * The following functionality has been changed:
46 * o when shifting events in the agenda view from one day to another
47 * the day matrix is updated now
49 * o dragging an event to the matrix will MOVE not COPY the event to the
50 * new date.
52 * o no support for Ctrl+click to create groups of dates
53 * (This has not really been supported in the predecessor.
54 * It was not very intuitive nor was it user friendly.)
55 * This feature has been replaced with dragging a selection on the matrix.
56 * The matrix will automatically choose the appropriate selection (e.g. you
57 * are not any longer able to select two distinct groups of date selections
58 * as in the old class)
60 * o now that you can select more than a week it can happen that not all
61 * selected days are displayed in the matrix. However this is preferred
62 * to the alternative which would mean to adjust the selection and leave
63 * some days undisplayed while scrolling through the months
65 * @short day matrix widget of the KDateNavigator
67 * @author Eitzenberger Thomas
69 class KODayMatrix: public QFrame, public Akonadi::ETMCalendar::CalendarObserver
71 Q_OBJECT
72 public:
73 /** constructor to create a day matrix widget.
75 * @param parent widget that is the parent of the day matrix.
76 * Normally this should be a KDateNavigator
78 explicit KODayMatrix( QWidget *parent );
80 /** destructor that deallocates all dynamically allocated private members.
82 ~KODayMatrix();
84 /** returns the first and last date of the 6*7 matrix that displays @p month
85 * @param month The month we want to get matrix boundaries
87 static QPair<QDate,QDate> matrixLimits( const QDate &month );
89 /**
90 Associate a calendar with this day matrix. If there is a calendar, the
91 day matrix will accept drops and days with events will be highlighted.
93 void setCalendar( const Akonadi::ETMCalendar::Ptr & );
95 /** updates the day matrix to start with the given date. Does all the
96 * necessary checks for holidays or events on a day and stores them
97 * for display later on.
98 * Does NOT update the view visually. Call repaint() for this.
100 * @param actdate recalculates the day matrix to show NUMDAYS starting
101 * from this date.
103 void updateView( const QDate &actdate );
106 Update incidence states of dates. Depending of the preferences days with
107 incidences are highlighted in some way.
109 void updateIncidences();
112 * Returns the QDate object associated with day indexed by the supplied
113 * offset.
115 const QDate &getDate( int offset ) const;
118 * Returns the official name of this holy day or 0 if there is no label
119 * for this day.
121 QString getHolidayLabel( int offset ) const;
124 * Adds all actual selected days from mSelStart to mSelEnd to the supplied
125 * DateList.
127 void addSelectedDaysTo( KCalCore::DateList & );
130 * Sets the actual to be displayed selection in the day matrix starting
131 * from start and ending with end. Theview must be manually updated by
132 * calling repaint. (?)
133 * @param start start of the new selection
134 * @param end end date of the new selection
136 void setSelectedDaysFrom( const QDate &start, const QDate &end );
139 Clear all selections.
141 void clearSelection();
143 /** Is today visible in the view? Keep this in sync with
144 * the values today (below) can take.
146 bool isTodayVisible() const { return mToday >= 0; }
149 * If today is visible, then we can find out if today is
150 * near the beginning or the end of the month.
151 * This is dependent on today remaining the index
152 * in the array of visible dates and going from
153 * top left (0) to bottom right (41).
155 bool isBeginningOfMonth() const { return mToday <= 8; }
156 bool isEndOfMonth() const { return mToday >= 27; }
159 * Reimplemented from Akonadi::ETMCalendar
160 * They set mPendingChanges to true
162 void calendarIncidenceAdded( const KCalCore::Incidence::Ptr &incidence );
163 void calendarIncidenceChanged( const KCalCore::Incidence::Ptr &incidence );
164 void calendarIncidenceDeleted( const KCalCore::Incidence::Ptr &incidence );
166 /** Sets which incidences should be highlighted */
167 void setHighlightMode( bool highlightEvents,
168 bool highlightTodos,
169 bool highlightJournals );
170 void setUpdateNeeded();
171 public slots:
173 * Recalculates all the flags of the days in the matrix like holidays or
174 * events on a day (Actually calls above method with the actual startdate).
176 void updateView();
179 * Calculates which square in the matrix should be hiighted to indicate
180 * the square is on "today".
182 void recalculateToday();
185 * Handle resource changes.
187 void resourcesChanged();
189 signals:
191 * Emitted if the user selects a block of days with the mouse by dragging
192 * a rectangle inside the matrix
194 * @param daylist list of days that have been selected by the user
196 void selected( const KCalCore::DateList &daylist );
198 void newEventSignal( const QDate &date );
199 void newTodoSignal( const QDate &date );
200 void newJournalSignal( const QDate &date );
203 * Emitted if the user has dropped an incidence (event or todo) inside
204 * the matrix.
206 * @param incidence the dropped calendar incidence
207 * @param dt QDate that has been selected
209 void incidenceDropped( const Akonadi::Item &item, const QDate &dt );
212 * Emitted if the user has dropped an event inside the matrix and chose
213 * to move it instead of copy
215 * @param oldincidence the new calendar incidence
216 * @param dt QDate that has been selected
218 void incidenceDroppedMove( const Akonadi::Item &item, const QDate &dt );
220 protected:
221 bool event( QEvent *e );
223 void paintEvent( QPaintEvent *ev );
225 void mousePressEvent( QMouseEvent *e );
227 void mouseReleaseEvent( QMouseEvent *e );
229 void mouseMoveEvent( QMouseEvent *e );
231 void resizeEvent( QResizeEvent * );
233 void dragEnterEvent( QDragEnterEvent *e );
235 void dragMoveEvent( QDragMoveEvent *e );
237 void dragLeaveEvent( QDragLeaveEvent *e );
239 void dropEvent( QDropEvent *e );
241 private:
243 * Pop-up a context menu for creating a new Event, To-do, or Journal.
245 void popupMenu( const QDate &date );
247 /** returns the index of the day located at the matrix's widget (x,y) position.
249 * @param x horizontal coordinate
250 * @param y vertical coordinate
252 int getDayIndexFrom( int x, int y ) const;
254 /** calculates a "shaded" color from the supplied color object.
255 * (Copied from Cornelius's kdpdatebutton.cpp)
257 * @param color source based on which a shaded color should be calculated.
259 QColor getShadedColor( const QColor &color ) const;
261 /** updates mEvent list with all days that have events */
262 void updateEvents();
264 /** updates mEvent list with all days that have to-dos with due date */
265 void updateTodos();
267 /** updates mEvent list with all days that have journals */
268 void updateJournals();
270 /** number of days to be displayed. For now there is no support for any
271 other number than 42. so change it at your own risk :o) */
272 static const int NUMDAYS;
274 /** calendar instance to be queried for holidays, events, ... */
275 Akonadi::ETMCalendar::Ptr mCalendar;
277 /** starting date of the matrix */
278 QDate mStartDate;
280 /** array of day labels to optimeize drawing performance. */
281 QString *mDayLabels;
283 /** array of days displayed to reduce memory consumption by
284 subsequently calling QDate::addDays(). */
285 QDate *mDays;
287 /** List for storing days which should be drawn using bold font. */
288 QList<QDate> mEvents;
290 /** stores holiday names of the days shown in the matrix. */
291 QMap<int,QString> mHolidays;
293 /** index of today or -1 if today is not visible in the matrix. */
294 int mToday;
296 /** index of day where dragged selection was initiated.
297 used to detect "negative" timely selections */
298 int mSelInit;
300 /** if mSelStart has this value it indicates that there is no
301 actual selection in the matrix. */
302 static const int NOSELECTION;
304 /** index of first selected day. */
305 int mSelStart;
307 /** index of last selected day. */
308 int mSelEnd;
310 /** default width of the frame drawn around today if it is visible
311 in the matrix. */
312 int mTodayMarginWidth;
314 /** stores actual size of each day in the widget so we don't need to
315 * ask on every repaint.
317 QRect mDaySize;
320 * Indicate pending calendar changes.
322 bool mPendingChanges;
324 /** Whether days with events are highlighted */
325 bool mHighlightEvents;
327 /** Whether days with to-dos (with due date) are highlighted */
328 bool mHighlightTodos;
330 /** Whether days with journals are highlighted */
331 bool mHighlightJournals;
334 #endif