author | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
commit | b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff) | |
tree | 2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /korganizer/kodaymatrix.h | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
-rw-r--r-- | korganizer/kodaymatrix.h | 308 |
1 files changed, 308 insertions, 0 deletions
diff --git a/korganizer/kodaymatrix.h b/korganizer/kodaymatrix.h new file mode 100644 index 0000000..b4eb2a8 --- a/dev/null +++ b/korganizer/kodaymatrix.h | |||
@@ -0,0 +1,308 @@ | |||
1 | /* | ||
2 | This file is part of KOrganizer. | ||
3 | Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | As a special exception, permission is given to link this program | ||
20 | with any edition of Qt, and distribute the resulting executable, | ||
21 | without including the source code for Qt in the source distribution. | ||
22 | */ | ||
23 | #ifndef _KODAYMAT_H | ||
24 | #define _KODAYMAT_H | ||
25 | |||
26 | #include <libkcal/calendar.h> | ||
27 | |||
28 | #include <qstring.h> | ||
29 | #include <qframe.h> | ||
30 | #include <qcolor.h> | ||
31 | #include <qpen.h> | ||
32 | #include <qdatetime.h> | ||
33 | #include <qtooltip.h> | ||
34 | |||
35 | #include <qmap.h> | ||
36 | |||
37 | class QDragEnterEvent; | ||
38 | class QDragMoveEvent; | ||
39 | class QDragLeaveEvent; | ||
40 | class QDropEvent; | ||
41 | |||
42 | class KODayMatrix; | ||
43 | |||
44 | using namespace KCal; | ||
45 | |||
46 | |||
47 | /** | ||
48 | * small helper class to dynamically show tooltips inside the day matrix. | ||
49 | * This class asks the day matrix object for a appropriate label which | ||
50 | * is in our special case the name of the holiday or null if this day is no holiday. | ||
51 | */ | ||
52 | class DynamicTip : public QToolTip | ||
53 | { | ||
54 | public: | ||
55 | |||
56 | /** | ||
57 | * Constructor that expects a KODayMatrix object as parent. | ||
58 | * | ||
59 | * @param parent the parent KODayMatrix control. | ||
60 | */ | ||
61 | DynamicTip(QWidget* parent ); | ||
62 | |||
63 | protected: | ||
64 | |||
65 | /** | ||
66 | * Qt's callback to ask the object to provide an approrpiate text for the | ||
67 | * tooltip to be shown. | ||
68 | * | ||
69 | * @param pos coordinates of the mouse. | ||
70 | */ | ||
71 | void maybeTip( const QPoint & pos); | ||
72 | |||
73 | private: | ||
74 | |||
75 | /** the parent control this tooltip is designed for. */ | ||
76 | KODayMatrix* matrix; | ||
77 | }; | ||
78 | |||
79 | /** | ||
80 | * replacement for kdpdatebuton.cpp that used 42 widgets for the day matrix to be displayed. | ||
81 | * Cornelius thought this was a waste of memory and a lot of overhead. | ||
82 | * In addition the selection was not very intuitive so I decided to rewrite it using a QFrame | ||
83 | * that draws the labels and allows for dragging selection while maintaining nearly full | ||
84 | * compatibility in behaviour with its predecessor. | ||
85 | * | ||
86 | * The following functionality has been changed: | ||
87 | * | ||
88 | * o when shifting events in the agenda view from one day to another the day matrix is updated now | ||
89 | * o TODO ET dragging an event to the matrix will MOVE not COPY the event to the new date. | ||
90 | * o no support for Ctrl+click to create groups of dates | ||
91 | * (This has not really been supported in the predecessor. It was not very intuitive nor was it | ||
92 | * user friendly.) | ||
93 | * This feature has been replaced with dragging a selection on the matrix. The matrix will | ||
94 | * automatically choose the appropriate selection (e.g. you are not any longer able to select | ||
95 | * two distinct groups of date selections as in the old class) | ||
96 | * o now that you can select more then a week it can happen that not all selected days are | ||
97 | * displayed in the matrix. However this is preferred to the alternative which would mean to | ||
98 | * adjust the selection and leave some days undisplayed while scrolling through the months | ||
99 | * | ||
100 | * @short day matrix widget of the KDateNavigator | ||
101 | * | ||
102 | * @author Eitzenberger Thomas | ||
103 | */ | ||
104 | class KODayMatrix: public QFrame { | ||
105 | |||
106 | Q_OBJECT | ||
107 | |||
108 | public: | ||
109 | |||
110 | /** constructor to create a day matrix widget. | ||
111 | * | ||
112 | * @param parent widget that is the parent of the day matrix. Normally this should | ||
113 | * be a KDateNavigator | ||
114 | * @param calendar instance of a calendar on which all calculations are based | ||
115 | * @param date start date of the matrix (is expected to be already fixed). It is | ||
116 | * assumed that this date is the first week day to be shown in the matrix. | ||
117 | * @param name name of the widget | ||
118 | */ | ||
119 | KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name ); | ||
120 | |||
121 | /** destructor that deallocates all dynamically allocated private members. | ||
122 | */ | ||
123 | ~KODayMatrix(); | ||
124 | |||
125 | /** updates the day matrix to start with the given date. Does all the necessary | ||
126 | * checks for holidays or events on a day and stores them for display later on. | ||
127 | * Does NOT update the view visually. Call repaint() for this. | ||
128 | * | ||
129 | * @param actdate recalculates the day matrix to show NUMDAYS starting from this | ||
130 | * date. | ||
131 | */ | ||
132 | void updateView(QDate actdate); | ||
133 | |||
134 | /** returns the QDate object associated with day indexed by the | ||
135 | * supplied offset. | ||
136 | */ | ||
137 | const QDate& getDate(int offset); | ||
138 | |||
139 | /** returns the official name of this holy day or 0 if there is no label | ||
140 | * for this day. | ||
141 | */ | ||
142 | QString getHolidayLabel(int offset); | ||
143 | |||
144 | /** adds all actual selected days from mSelStart to mSelEnd to the supplied | ||
145 | * DateList. | ||
146 | */ | ||
147 | void addSelectedDaysTo(DateList&); | ||
148 | |||
149 | /** sets the actual to be displayed selection in the day matrix starting from | ||
150 | * start and ending with end. Theview must be manually updated by calling | ||
151 | * repaint. (?) | ||
152 | */ | ||
153 | void setSelectedDaysFrom(const QDate& start, const QDate& end); | ||
154 | |||
155 | |||
156 | /** Is today visible in the view? Keep this in sync with | ||
157 | * the values today (below) can take. | ||
158 | */ | ||
159 | bool isTodayVisible() const { return today>=0; } ; | ||
160 | |||
161 | /** If today is visible, then we can find out if today is | ||
162 | * near the beginning or the end of the month. | ||
163 | * This is dependent on today remaining the index | ||
164 | * in the array of visible dates and going from | ||
165 | * top left (0) to bottom right (41). | ||
166 | */ | ||
167 | bool isBeginningOfMonth() const { return today<=8; } ; | ||
168 | bool isEndOfMonth() const { return today>=27; } ; | ||
169 | |||
170 | public slots: | ||
171 | /** Recalculates all the flags of the days in the matrix like holidays or events | ||
172 | * on a day (Actually calls above method with the actual startdate). | ||
173 | */ | ||
174 | void updateView(); | ||
175 | |||
176 | /** | ||
177 | * Calculate which square in the matrix should be | ||
178 | * hilighted to indicate it's today. | ||
179 | */ | ||
180 | void recalculateToday(); | ||
181 | |||
182 | /* | ||
183 | void setStartDate(QDate); | ||
184 | */ | ||
185 | |||
186 | signals: | ||
187 | |||
188 | /** emitted if the user selects a block of days with the mouse by dragging a rectangle | ||
189 | * inside the matrix | ||
190 | * | ||
191 | * @param daylist list of days that have been selected by the user | ||
192 | */ | ||
193 | void selected( const KCal::DateList &daylist ); | ||
194 | |||
195 | /** emitted if the user has dropped an event inside the matrix | ||
196 | * | ||
197 | * @param event the dropped calendar event | ||
198 | */ | ||
199 | void eventDropped(Event *event); | ||
200 | |||
201 | protected: | ||
202 | |||
203 | void paintEvent(QPaintEvent *ev); | ||
204 | |||
205 | void mousePressEvent (QMouseEvent* e); | ||
206 | |||
207 | void mouseReleaseEvent (QMouseEvent* e); | ||
208 | |||
209 | void mouseMoveEvent (QMouseEvent* e); | ||
210 | |||
211 | void dragEnterEvent(QDragEnterEvent *); | ||
212 | |||
213 | void dragMoveEvent(QDragMoveEvent *); | ||
214 | |||
215 | void dragLeaveEvent(QDragLeaveEvent *); | ||
216 | |||
217 | void dropEvent(QDropEvent *); | ||
218 | |||
219 | void resizeEvent(QResizeEvent *); | ||
220 | |||
221 | private: | ||
222 | |||
223 | /** returns the index of the day located at the matrix's widget (x,y) position. | ||
224 | * | ||
225 | * @param x horizontal coordinate | ||
226 | * @param y vertical coordinate | ||
227 | */ | ||
228 | int getDayIndexFrom(int x, int y); | ||
229 | |||
230 | /** calculates a "shaded" color from the supplied color object. | ||
231 | * (Copied from Cornelius's kdpdatebutton.cpp) | ||
232 | * | ||
233 | * @param color source based on which a shaded color should be calculated. | ||
234 | */ | ||
235 | QColor getShadedColor(QColor color); | ||
236 | |||
237 | /** number of days to be displayed. For now there is no support for any other number then 42. | ||
238 | so change it at your own risk :o) */ | ||
239 | static const int NUMDAYS; | ||
240 | |||
241 | /** calendar instance to be queried for holidays, events, ... */ | ||
242 | Calendar *mCalendar; | ||
243 | |||
244 | /** starting date of the matrix */ | ||
245 | QDate startdate; | ||
246 | |||
247 | /** array of day labels to optimeize drawing performance. */ | ||
248 | QString *daylbls; | ||
249 | |||
250 | /** array of days displayed to reduce memory consumption by | ||
251 | subsequently calling QDate::addDays(). */ | ||
252 | QDate *days; | ||
253 | |||
254 | /** array of storing the number of events on a given day. | ||
255 | * used for drawing a bold font if there is at least one event on that day. | ||
256 | */ | ||
257 | int *events; | ||
258 | |||
259 | /** stores holiday names of the days shown in the matrix. */ | ||
260 | QMap<int,QString> mHolidays; | ||
261 | |||
262 | /** indey of today or -1 if today is not visible in the matrix. */ | ||
263 | int today; | ||
264 | |||
265 | /** index of day where dragged selection was initiated. | ||
266 | used to detect "negative" timely selections */ | ||
267 | int mSelInit; | ||
268 | |||
269 | /** if mSelStart has this value it indicates that there is no | ||
270 | actual selection in the matrix. */ | ||
271 | static const int NOSELECTION; | ||
272 | |||
273 | /** index of first selected day. */ | ||
274 | int mSelStart; | ||
275 | |||
276 | /** index of last selected day. */ | ||
277 | int mSelEnd; | ||
278 | |||
279 | /** dynamic tooltip to handle mouse dependent tips for each day in the matrix. */ | ||
280 | DynamicTip* mToolTip; | ||
281 | |||
282 | |||
283 | /** default background colour of the matrix. */ | ||
284 | QColor mDefaultBackColor; | ||
285 | |||
286 | /** default text color of the matrix. */ | ||
287 | QColor mDefaultTextColor; | ||
288 | |||
289 | /** default text color for days not in the actual month. */ | ||
290 | QColor mDefaultTextColorShaded; | ||
291 | |||
292 | /** default text color for holidays not in the actual month. */ | ||
293 | QColor mHolidayColorShaded; | ||
294 | |||
295 | /** text color for selected days. */ | ||
296 | QColor mSelectedDaysColor; | ||
297 | |||
298 | /** default width of the frame drawn around today if it is visible in the matrix. */ | ||
299 | int mTodayMarginWidth; | ||
300 | |||
301 | /** stores actual size of each day in the widget so that I dont need to ask this data | ||
302 | * on every repaint. | ||
303 | */ | ||
304 | QRect daysize; | ||
305 | |||
306 | }; | ||
307 | |||
308 | #endif | ||