-rw-r--r-- | korganizer/kodaymatrix.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index faa2c21..9c3621e 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -1,633 +1,634 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> | 3 | Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> |
4 | Parts of the source code have been copied from kdpdatebutton.cpp | 4 | Parts of the source code have been copied from kdpdatebutton.cpp |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or | 8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | 9 | (at your option) any later version. |
10 | 10 | ||
11 | This program is distributed in the hope that it will be useful, | 11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. | 14 | GNU General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | 17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | 19 | ||
20 | As a special exception, permission is given to link this program | 20 | As a special exception, permission is given to link this program |
21 | with any edition of Qt, and distribute the resulting executable, | 21 | with any edition of Qt, and distribute the resulting executable, |
22 | without including the source code for Qt in the source distribution. | 22 | without including the source code for Qt in the source distribution. |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <qevent.h> | 25 | #include <qevent.h> |
26 | #include <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qptrlist.h> | 27 | #include <qptrlist.h> |
28 | #include <qtimer.h> | ||
28 | 29 | ||
29 | #include <kglobal.h> | 30 | #include <kglobal.h> |
30 | #include <kdebug.h> | 31 | #include <kdebug.h> |
31 | #include <klocale.h> | 32 | #include <klocale.h> |
32 | 33 | ||
33 | #include <libkcal/vcaldrag.h> | 34 | #include <libkcal/vcaldrag.h> |
34 | #include <libkcal/icaldrag.h> | 35 | #include <libkcal/icaldrag.h> |
35 | #include <libkcal/dndfactory.h> | 36 | #include <libkcal/dndfactory.h> |
36 | #include <libkcal/calendarresources.h> | 37 | #include <libkcal/calendarresources.h> |
37 | #include <libkcal/resourcecalendar.h> | 38 | #include <libkcal/resourcecalendar.h> |
38 | #include <kresources/resourceselectdialog.h> | 39 | #include <kresources/resourceselectdialog.h> |
39 | 40 | ||
40 | #include <kcalendarsystem.h> | 41 | #include <kcalendarsystem.h> |
41 | 42 | ||
42 | #ifndef KORG_NOPLUGINS | 43 | #ifndef KORG_NOPLUGINS |
43 | #include "kocore.h" | 44 | #include "kocore.h" |
44 | #endif | 45 | #endif |
45 | #include "koprefs.h" | 46 | #include "koprefs.h" |
46 | #include "koglobals.h" | 47 | #include "koglobals.h" |
47 | 48 | ||
48 | #include "kodaymatrix.h" | 49 | #include "kodaymatrix.h" |
49 | 50 | ||
50 | // ============================================================================ | 51 | // ============================================================================ |
51 | // D Y N A M I C T I P | 52 | // D Y N A M I C T I P |
52 | // ============================================================================ | 53 | // ============================================================================ |
53 | 54 | ||
54 | DynamicTip::DynamicTip( QWidget * parent ) | 55 | DynamicTip::DynamicTip( QWidget * parent ) |
55 | : QToolTip( parent ) | 56 | : QToolTip( parent ) |
56 | { | 57 | { |
57 | matrix = (KODayMatrix*)parent; | 58 | matrix = (KODayMatrix*)parent; |
58 | } | 59 | } |
59 | 60 | ||
60 | 61 | ||
61 | void DynamicTip::maybeTip( const QPoint &pos ) | 62 | void DynamicTip::maybeTip( const QPoint &pos ) |
62 | { | 63 | { |
63 | //calculate which cell of the matrix the mouse is in | 64 | //calculate which cell of the matrix the mouse is in |
64 | QRect sz = matrix->frameRect(); | 65 | QRect sz = matrix->frameRect(); |
65 | int dheight = sz.height()*7 / 42; | 66 | int dheight = sz.height()*7 / 42; |
66 | int dwidth = sz.width() / 7; | 67 | int dwidth = sz.width() / 7; |
67 | int row = pos.y()/dheight; | 68 | int row = pos.y()/dheight; |
68 | int col = pos.x()/dwidth; | 69 | int col = pos.x()/dwidth; |
69 | 70 | ||
70 | QRect rct(col*dwidth, row*dheight, dwidth, dheight); | 71 | QRect rct(col*dwidth, row*dheight, dwidth, dheight); |
71 | 72 | ||
72 | // kdDebug() << "DynamicTip::maybeTip matrix cell index [" << | 73 | // kdDebug() << "DynamicTip::maybeTip matrix cell index [" << |
73 | // col << "][" << row << "] => " <<(col+row*7) << endl; | 74 | // col << "][" << row << "] => " <<(col+row*7) << endl; |
74 | 75 | ||
75 | //show holiday names only | 76 | //show holiday names only |
76 | QString str = matrix->getHolidayLabel(col+row*7); | 77 | QString str = matrix->getHolidayLabel(col+row*7); |
77 | if (str.isEmpty()) return; | 78 | if (str.isEmpty()) return; |
78 | tip(rct, str); | 79 | tip(rct, str); |
79 | } | 80 | } |
80 | 81 | ||
81 | 82 | ||
82 | // ============================================================================ | 83 | // ============================================================================ |
83 | // K O D A Y M A T R I X | 84 | // K O D A Y M A T R I X |
84 | // ============================================================================ | 85 | // ============================================================================ |
85 | 86 | ||
86 | const int KODayMatrix::NOSELECTION = -1000; | 87 | const int KODayMatrix::NOSELECTION = -1000; |
87 | const int KODayMatrix::NUMDAYS = 42; | 88 | const int KODayMatrix::NUMDAYS = 42; |
88 | 89 | ||
89 | KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : | 90 | KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : |
90 | QFrame(parent, name) | 91 | QFrame(parent, name) |
91 | { | 92 | { |
92 | mCalendar = calendar; | 93 | mCalendar = calendar; |
93 | 94 | ||
94 | // initialize dynamic arrays | 95 | // initialize dynamic arrays |
95 | days = new QDate[NUMDAYS]; | 96 | days = new QDate[NUMDAYS]; |
96 | daylbls = new QString[NUMDAYS]; | 97 | daylbls = new QString[NUMDAYS]; |
97 | events = new int[NUMDAYS]; | 98 | events = new int[NUMDAYS]; |
98 | mToolTip = new DynamicTip(this); | 99 | mToolTip = new DynamicTip(this); |
99 | 100 | ||
100 | // set default values used for drawing the matrix | 101 | // set default values used for drawing the matrix |
101 | mDefaultBackColor = palette().active().base(); | 102 | mDefaultBackColor = palette().active().base(); |
102 | mDefaultTextColor = palette().active().foreground(); | 103 | mDefaultTextColor = palette().active().foreground(); |
103 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); | 104 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); |
104 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); | 105 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); |
105 | mSelectedDaysColor = QColor("white"); | 106 | mSelectedDaysColor = QColor("white"); |
106 | mTodayMarginWidth = 2; | 107 | mTodayMarginWidth = 2; |
107 | mSelEnd = mSelStart = NOSELECTION; | 108 | mSelEnd = mSelStart = NOSELECTION; |
108 | 109 | ||
109 | setAcceptDrops(true); | 110 | setAcceptDrops(true); |
110 | //setFont( QFont("Arial", 10) ); | 111 | //setFont( QFont("Arial", 10) ); |
111 | 112 | ||
112 | mUpdateTimer = new QTimer( this ); | 113 | mUpdateTimer = new QTimer( this ); |
113 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); | 114 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); |
114 | mRepaintTimer = new QTimer( this ); | 115 | mRepaintTimer = new QTimer( this ); |
115 | connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); | 116 | connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); |
116 | mDayChanged = false; | 117 | mDayChanged = false; |
117 | updateView(); | 118 | updateView(); |
118 | } | 119 | } |
119 | 120 | ||
120 | QColor KODayMatrix::getShadedColor(QColor color) | 121 | QColor KODayMatrix::getShadedColor(QColor color) |
121 | { | 122 | { |
122 | QColor shaded; | 123 | QColor shaded; |
123 | int h=0; | 124 | int h=0; |
124 | int s=0; | 125 | int s=0; |
125 | int v=0; | 126 | int v=0; |
126 | color.hsv(&h,&s,&v); | 127 | color.hsv(&h,&s,&v); |
127 | s = s/4; | 128 | s = s/4; |
128 | v = 192+v/4; | 129 | v = 192+v/4; |
129 | shaded.setHsv(h,s,v); | 130 | shaded.setHsv(h,s,v); |
130 | 131 | ||
131 | return shaded; | 132 | return shaded; |
132 | } | 133 | } |
133 | 134 | ||
134 | KODayMatrix::~KODayMatrix() | 135 | KODayMatrix::~KODayMatrix() |
135 | { | 136 | { |
136 | delete [] days; | 137 | delete [] days; |
137 | delete [] daylbls; | 138 | delete [] daylbls; |
138 | delete [] events; | 139 | delete [] events; |
139 | delete mToolTip; | 140 | delete mToolTip; |
140 | } | 141 | } |
141 | 142 | ||
142 | /* | 143 | /* |
143 | void KODayMatrix::setStartDate(QDate start) | 144 | void KODayMatrix::setStartDate(QDate start) |
144 | { | 145 | { |
145 | updateView(start); | 146 | updateView(start); |
146 | } | 147 | } |
147 | */ | 148 | */ |
148 | 149 | ||
149 | void KODayMatrix::addSelectedDaysTo(DateList& selDays) | 150 | void KODayMatrix::addSelectedDaysTo(DateList& selDays) |
150 | { | 151 | { |
151 | 152 | ||
152 | if (mSelStart == NOSELECTION) { | 153 | if (mSelStart == NOSELECTION) { |
153 | return; | 154 | return; |
154 | } | 155 | } |
155 | 156 | ||
156 | //cope with selection being out of matrix limits at top (< 0) | 157 | //cope with selection being out of matrix limits at top (< 0) |
157 | int i0 = mSelStart; | 158 | int i0 = mSelStart; |
158 | if (i0 < 0) { | 159 | if (i0 < 0) { |
159 | for (int i = i0; i < 0; i++) { | 160 | for (int i = i0; i < 0; i++) { |
160 | selDays.append(days[0].addDays(i)); | 161 | selDays.append(days[0].addDays(i)); |
161 | } | 162 | } |
162 | i0 = 0; | 163 | i0 = 0; |
163 | } | 164 | } |
164 | 165 | ||
165 | //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) | 166 | //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) |
166 | if (mSelEnd > NUMDAYS-1) { | 167 | if (mSelEnd > NUMDAYS-1) { |
167 | for (int i = i0; i <= NUMDAYS-1; i++) { | 168 | for (int i = i0; i <= NUMDAYS-1; i++) { |
168 | selDays.append(days[i]); | 169 | selDays.append(days[i]); |
169 | } | 170 | } |
170 | for (int i = NUMDAYS; i < mSelEnd; i++) { | 171 | for (int i = NUMDAYS; i < mSelEnd; i++) { |
171 | selDays.append(days[0].addDays(i)); | 172 | selDays.append(days[0].addDays(i)); |
172 | } | 173 | } |
173 | 174 | ||
174 | // apply normal routine to selection being entirely within matrix limits | 175 | // apply normal routine to selection being entirely within matrix limits |
175 | } else { | 176 | } else { |
176 | for (int i = i0; i <= mSelEnd; i++) { | 177 | for (int i = i0; i <= mSelEnd; i++) { |
177 | selDays.append(days[i]); | 178 | selDays.append(days[i]); |
178 | } | 179 | } |
179 | } | 180 | } |
180 | } | 181 | } |
181 | 182 | ||
182 | void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) | 183 | void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) |
183 | { | 184 | { |
184 | mSelStart = startdate.daysTo(start); | 185 | mSelStart = startdate.daysTo(start); |
185 | mSelEnd = startdate.daysTo(end); | 186 | mSelEnd = startdate.daysTo(end); |
186 | } | 187 | } |
187 | 188 | ||
188 | 189 | ||
189 | void KODayMatrix::recalculateToday() | 190 | void KODayMatrix::recalculateToday() |
190 | { | 191 | { |
191 | today = -1; | 192 | today = -1; |
192 | for (int i=0; i<NUMDAYS; i++) { | 193 | for (int i=0; i<NUMDAYS; i++) { |
193 | days[i] = startdate.addDays(i); | 194 | days[i] = startdate.addDays(i); |
194 | daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); | 195 | daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); |
195 | 196 | ||
196 | // if today is in the currently displayed month, hilight today | 197 | // if today is in the currently displayed month, hilight today |
197 | if (days[i].year() == QDate::currentDate().year() && | 198 | if (days[i].year() == QDate::currentDate().year() && |
198 | days[i].month() == QDate::currentDate().month() && | 199 | days[i].month() == QDate::currentDate().month() && |
199 | days[i].day() == QDate::currentDate().day()) { | 200 | days[i].day() == QDate::currentDate().day()) { |
200 | today = i; | 201 | today = i; |
201 | } | 202 | } |
202 | } | 203 | } |
203 | // qDebug(QString("Today is visible at %1.").arg(today)); | 204 | // qDebug(QString("Today is visible at %1.").arg(today)); |
204 | } | 205 | } |
205 | 206 | ||
206 | void KODayMatrix::updateView() | 207 | void KODayMatrix::updateView() |
207 | { | 208 | { |
208 | updateView(startdate); | 209 | updateView(startdate); |
209 | } | 210 | } |
210 | void KODayMatrix::repaintViewTimed() | 211 | void KODayMatrix::repaintViewTimed() |
211 | { | 212 | { |
212 | qDebug("KODayMatrix::repaintViewTimed "); | 213 | qDebug("KODayMatrix::repaintViewTimed "); |
213 | mRepaintTimer->stop(); | 214 | mRepaintTimer->stop(); |
214 | repaint(false); | 215 | repaint(false); |
215 | } | 216 | } |
216 | void KODayMatrix::updateViewTimed() | 217 | void KODayMatrix::updateViewTimed() |
217 | { | 218 | { |
218 | 219 | ||
219 | mUpdateTimer->stop(); | 220 | mUpdateTimer->stop(); |
220 | //QDate actdate = mPendingNewDate; | 221 | //QDate actdate = mPendingNewDate; |
221 | 222 | ||
222 | static int iii = 0; | 223 | static int iii = 0; |
223 | qDebug("KODayMatrix::updateView(QDate actdate) %d", ++iii ); | 224 | qDebug("KODayMatrix::updateView(QDate actdate) %d", ++iii ); |
224 | 225 | ||
225 | if (mDayChanged) { | 226 | if (mDayChanged) { |
226 | recalculateToday(); | 227 | recalculateToday(); |
227 | mDayChanged = false; | 228 | mDayChanged = false; |
228 | } | 229 | } |
229 | 230 | ||
230 | for(int i = 0; i < NUMDAYS; i++) { | 231 | for(int i = 0; i < NUMDAYS; i++) { |
231 | 232 | ||
232 | // if events are set for the day then remember to draw it bold | 233 | // if events are set for the day then remember to draw it bold |
233 | QPtrList<Event> eventlist = mCalendar->events(days[i]); | 234 | QPtrList<Event> eventlist = mCalendar->events(days[i]); |
234 | Event *event; | 235 | Event *event; |
235 | int numEvents = eventlist.count(); | 236 | int numEvents = eventlist.count(); |
236 | 237 | ||
237 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 238 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
238 | ushort recurType = event->recurrence()->doesRecur(); | 239 | ushort recurType = event->recurrence()->doesRecur(); |
239 | 240 | ||
240 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 241 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
241 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 242 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
242 | numEvents--; | 243 | numEvents--; |
243 | } | 244 | } |
244 | } | 245 | } |
245 | events[i] = numEvents; | 246 | events[i] = numEvents; |
246 | 247 | ||
247 | //if it is a holy day then draw it red. Sundays are consider holidays, too | 248 | //if it is a holy day then draw it red. Sundays are consider holidays, too |
248 | #ifndef KORG_NOPLUGINS | 249 | #ifndef KORG_NOPLUGINS |
249 | QString holiStr = KOCore::self()->holiday(days[i]); | 250 | QString holiStr = KOCore::self()->holiday(days[i]); |
250 | #else | 251 | #else |
251 | QString holiStr = QString::null; | 252 | QString holiStr = QString::null; |
252 | #endif | 253 | #endif |
253 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || | 254 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || |
254 | !holiStr.isEmpty()) { | 255 | !holiStr.isEmpty()) { |
255 | if (holiStr.isNull()) holiStr = ""; | 256 | if (holiStr.isNull()) holiStr = ""; |
256 | mHolidays[i] = holiStr; | 257 | mHolidays[i] = holiStr; |
257 | 258 | ||
258 | } else { | 259 | } else { |
259 | mHolidays[i] = QString::null; | 260 | mHolidays[i] = QString::null; |
260 | } | 261 | } |
261 | } | 262 | } |
262 | repaint(false); | 263 | repaint(false); |
263 | } | 264 | } |
264 | void KODayMatrix::updateView(QDate actdate) | 265 | void KODayMatrix::updateView(QDate actdate) |
265 | { | 266 | { |
266 | 267 | ||
267 | //flag to indicate if the starting day of the matrix has changed by this call | 268 | //flag to indicate if the starting day of the matrix has changed by this call |
268 | //mDayChanged = false; | 269 | //mDayChanged = false; |
269 | // if a new startdate is to be set then apply Cornelius's calculation | 270 | // if a new startdate is to be set then apply Cornelius's calculation |
270 | // of the first day to be shown | 271 | // of the first day to be shown |
271 | if (actdate != startdate) { | 272 | if (actdate != startdate) { |
272 | // reset index of selection according to shift of starting date from startdate to actdate | 273 | // reset index of selection according to shift of starting date from startdate to actdate |
273 | if (mSelStart != NOSELECTION) { | 274 | if (mSelStart != NOSELECTION) { |
274 | int tmp = actdate.daysTo(startdate); | 275 | int tmp = actdate.daysTo(startdate); |
275 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; | 276 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; |
276 | // shift selection if new one would be visible at least partly ! | 277 | // shift selection if new one would be visible at least partly ! |
277 | 278 | ||
278 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { | 279 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { |
279 | // nested if is required for next X display pushed from a different month - correction required | 280 | // nested if is required for next X display pushed from a different month - correction required |
280 | // otherwise, for month forward and backward, it must be avoided | 281 | // otherwise, for month forward and backward, it must be avoided |
281 | if( mSelStart > NUMDAYS || mSelStart < 0 ) | 282 | if( mSelStart > NUMDAYS || mSelStart < 0 ) |
282 | mSelStart = mSelStart + tmp; | 283 | mSelStart = mSelStart + tmp; |
283 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) | 284 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) |
284 | mSelEnd = mSelEnd + tmp; | 285 | mSelEnd = mSelEnd + tmp; |
285 | } | 286 | } |
286 | } | 287 | } |
287 | 288 | ||
288 | startdate = actdate; | 289 | startdate = actdate; |
289 | mDayChanged = true; | 290 | mDayChanged = true; |
290 | } | 291 | } |
291 | qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); | 292 | qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); |
292 | static int iii = 0; | 293 | static int iii = 0; |
293 | if ( iii < 2 ) { | 294 | if ( iii < 2 ) { |
294 | ++iii; | 295 | ++iii; |
295 | updateViewTimed(); | 296 | updateViewTimed(); |
296 | } else { | 297 | } else { |
297 | if ( !isVisible() ) { | 298 | if ( !isVisible() ) { |
298 | mUpdateTimer->start( 2000 ); | 299 | mUpdateTimer->start( 2000 ); |
299 | } else { | 300 | } else { |
300 | if ( mDayChanged ) { | 301 | if ( mDayChanged ) { |
301 | mUpdateTimer->start( 250 ); | 302 | mUpdateTimer->start( 250 ); |
302 | } else { | 303 | } else { |
303 | mRepaintTimer->start( 250 ); | 304 | mRepaintTimer->start( 250 ); |
304 | mUpdateTimer->start( 2000 ); | 305 | mUpdateTimer->start( 2000 ); |
305 | } | 306 | } |
306 | } | 307 | } |
307 | } | 308 | } |
308 | 309 | ||
309 | } | 310 | } |
310 | 311 | ||
311 | const QDate& KODayMatrix::getDate(int offset) | 312 | const QDate& KODayMatrix::getDate(int offset) |
312 | { | 313 | { |
313 | if (offset < 0 || offset > NUMDAYS-1) { | 314 | if (offset < 0 || offset > NUMDAYS-1) { |
314 | qDebug("Wrong offset2 "); | 315 | qDebug("Wrong offset2 "); |
315 | return days[0]; | 316 | return days[0]; |
316 | } | 317 | } |
317 | return days[offset]; | 318 | return days[offset]; |
318 | } | 319 | } |
319 | 320 | ||
320 | QString KODayMatrix::getHolidayLabel(int offset) | 321 | QString KODayMatrix::getHolidayLabel(int offset) |
321 | { | 322 | { |
322 | if (offset < 0 || offset > NUMDAYS-1) { | 323 | if (offset < 0 || offset > NUMDAYS-1) { |
323 | qDebug("Wrong offset1 "); | 324 | qDebug("Wrong offset1 "); |
324 | return 0; | 325 | return 0; |
325 | } | 326 | } |
326 | return mHolidays[offset]; | 327 | return mHolidays[offset]; |
327 | } | 328 | } |
328 | 329 | ||
329 | int KODayMatrix::getDayIndexFrom(int x, int y) | 330 | int KODayMatrix::getDayIndexFrom(int x, int y) |
330 | { | 331 | { |
331 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? | 332 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? |
332 | 6 - x/daysize.width() : x/daysize.width()); | 333 | 6 - x/daysize.width() : x/daysize.width()); |
333 | } | 334 | } |
334 | 335 | ||
335 | // ---------------------------------------------------------------------------- | 336 | // ---------------------------------------------------------------------------- |
336 | // M O U S E E V E N T H A N D L I N G | 337 | // M O U S E E V E N T H A N D L I N G |
337 | // ---------------------------------------------------------------------------- | 338 | // ---------------------------------------------------------------------------- |
338 | 339 | ||
339 | void KODayMatrix::mousePressEvent (QMouseEvent* e) | 340 | void KODayMatrix::mousePressEvent (QMouseEvent* e) |
340 | { | 341 | { |
341 | mSelStart = getDayIndexFrom(e->x(), e->y()); | 342 | mSelStart = getDayIndexFrom(e->x(), e->y()); |
342 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; | 343 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; |
343 | mSelInit = mSelStart; | 344 | mSelInit = mSelStart; |
344 | } | 345 | } |
345 | 346 | ||
346 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) | 347 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) |
347 | { | 348 | { |
348 | 349 | ||
349 | int tmp = getDayIndexFrom(e->x(), e->y()); | 350 | int tmp = getDayIndexFrom(e->x(), e->y()); |
350 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 351 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
351 | 352 | ||
352 | if (mSelInit > tmp) { | 353 | if (mSelInit > tmp) { |
353 | mSelEnd = mSelInit; | 354 | mSelEnd = mSelInit; |
354 | if (tmp != mSelStart) { | 355 | if (tmp != mSelStart) { |
355 | mSelStart = tmp; | 356 | mSelStart = tmp; |
356 | repaint(); | 357 | repaint(); |
357 | } | 358 | } |
358 | } else { | 359 | } else { |
359 | mSelStart = mSelInit; | 360 | mSelStart = mSelInit; |
360 | 361 | ||
361 | //repaint only if selection has changed | 362 | //repaint only if selection has changed |
362 | if (tmp != mSelEnd) { | 363 | if (tmp != mSelEnd) { |
363 | mSelEnd = tmp; | 364 | mSelEnd = tmp; |
364 | repaint(); | 365 | repaint(); |
365 | } | 366 | } |
366 | } | 367 | } |
367 | 368 | ||
368 | DateList daylist; | 369 | DateList daylist; |
369 | if ( mSelStart < 0 ) | 370 | if ( mSelStart < 0 ) |
370 | mSelStart = 0; | 371 | mSelStart = 0; |
371 | for (int i = mSelStart; i <= mSelEnd; i++) { | 372 | for (int i = mSelStart; i <= mSelEnd; i++) { |
372 | daylist.append(days[i]); | 373 | daylist.append(days[i]); |
373 | } | 374 | } |
374 | emit selected((const DateList)daylist); | 375 | emit selected((const DateList)daylist); |
375 | 376 | ||
376 | } | 377 | } |
377 | 378 | ||
378 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) | 379 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) |
379 | { | 380 | { |
380 | int tmp = getDayIndexFrom(e->x(), e->y()); | 381 | int tmp = getDayIndexFrom(e->x(), e->y()); |
381 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 382 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
382 | 383 | ||
383 | if (mSelInit > tmp) { | 384 | if (mSelInit > tmp) { |
384 | mSelEnd = mSelInit; | 385 | mSelEnd = mSelInit; |
385 | if (tmp != mSelStart) { | 386 | if (tmp != mSelStart) { |
386 | mSelStart = tmp; | 387 | mSelStart = tmp; |
387 | repaint(); | 388 | repaint(); |
388 | } | 389 | } |
389 | } else { | 390 | } else { |
390 | mSelStart = mSelInit; | 391 | mSelStart = mSelInit; |
391 | 392 | ||
392 | //repaint only if selection has changed | 393 | //repaint only if selection has changed |
393 | if (tmp != mSelEnd) { | 394 | if (tmp != mSelEnd) { |
394 | mSelEnd = tmp; | 395 | mSelEnd = tmp; |
395 | repaint(); | 396 | repaint(); |
396 | } | 397 | } |
397 | } | 398 | } |
398 | } | 399 | } |
399 | 400 | ||
400 | // ---------------------------------------------------------------------------- | 401 | // ---------------------------------------------------------------------------- |
401 | // D R A G ' N D R O P H A N D L I N G | 402 | // D R A G ' N D R O P H A N D L I N G |
402 | // ---------------------------------------------------------------------------- | 403 | // ---------------------------------------------------------------------------- |
403 | 404 | ||
404 | void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) | 405 | void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) |
405 | { | 406 | { |
406 | #ifndef KORG_NODND | 407 | #ifndef KORG_NODND |
407 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 408 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
408 | e->ignore(); | 409 | e->ignore(); |
409 | return; | 410 | return; |
410 | } | 411 | } |
411 | 412 | ||
412 | // some visual feedback | 413 | // some visual feedback |
413 | // oldPalette = palette(); | 414 | // oldPalette = palette(); |
414 | // setPalette(my_HilitePalette); | 415 | // setPalette(my_HilitePalette); |
415 | // update(); | 416 | // update(); |
416 | #endif | 417 | #endif |
417 | } | 418 | } |
418 | 419 | ||
419 | void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) | 420 | void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) |
420 | { | 421 | { |
421 | #ifndef KORG_NODND | 422 | #ifndef KORG_NODND |
422 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 423 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
423 | e->ignore(); | 424 | e->ignore(); |
424 | return; | 425 | return; |
425 | } | 426 | } |
426 | 427 | ||
427 | e->accept(); | 428 | e->accept(); |
428 | #endif | 429 | #endif |
429 | } | 430 | } |
430 | 431 | ||
431 | void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) | 432 | void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) |
432 | { | 433 | { |
433 | #ifndef KORG_NODND | 434 | #ifndef KORG_NODND |
434 | // setPalette(oldPalette); | 435 | // setPalette(oldPalette); |
435 | // update(); | 436 | // update(); |
436 | #endif | 437 | #endif |
437 | } | 438 | } |
438 | 439 | ||
439 | void KODayMatrix::dropEvent(QDropEvent *e) | 440 | void KODayMatrix::dropEvent(QDropEvent *e) |
440 | { | 441 | { |
441 | #ifndef KORG_NODND | 442 | #ifndef KORG_NODND |
442 | // kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; | 443 | // kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; |
443 | 444 | ||
444 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 445 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
445 | e->ignore(); | 446 | e->ignore(); |
446 | return; | 447 | return; |
447 | } | 448 | } |
448 | 449 | ||
449 | DndFactory factory( mCalendar ); | 450 | DndFactory factory( mCalendar ); |
450 | Event *event = factory.createDrop(e); | 451 | Event *event = factory.createDrop(e); |
451 | 452 | ||
452 | if (event) { | 453 | if (event) { |
453 | e->acceptAction(); | 454 | e->acceptAction(); |
454 | 455 | ||
455 | Event *existingEvent = mCalendar->event(event->uid()); | 456 | Event *existingEvent = mCalendar->event(event->uid()); |
456 | 457 | ||
457 | if(existingEvent) { | 458 | if(existingEvent) { |
458 | // uniquify event | 459 | // uniquify event |
459 | event->recreate(); | 460 | event->recreate(); |
460 | /* | 461 | /* |
461 | KMessageBox::sorry(this, | 462 | KMessageBox::sorry(this, |
462 | i18n("Event already exists in this calendar."), | 463 | i18n("Event already exists in this calendar."), |
463 | i18n("Drop Event")); | 464 | i18n("Drop Event")); |
464 | delete event; | 465 | delete event; |
465 | return; | 466 | return; |
466 | */ | 467 | */ |
467 | } | 468 | } |
468 | // kdDebug() << "Drop new Event" << endl; | 469 | // kdDebug() << "Drop new Event" << endl; |
469 | // Adjust date | 470 | // Adjust date |
470 | QDateTime start = event->dtStart(); | 471 | QDateTime start = event->dtStart(); |
471 | QDateTime end = event->dtEnd(); | 472 | QDateTime end = event->dtEnd(); |
472 | int duration = start.daysTo(end); | 473 | int duration = start.daysTo(end); |
473 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); | 474 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); |
474 | 475 | ||
475 | start.setDate(days[idx]); | 476 | start.setDate(days[idx]); |
476 | end.setDate(days[idx].addDays(duration)); | 477 | end.setDate(days[idx].addDays(duration)); |
477 | 478 | ||
478 | event->setDtStart(start); | 479 | event->setDtStart(start); |
479 | event->setDtEnd(end); | 480 | event->setDtEnd(end); |
480 | mCalendar->addEvent(event); | 481 | mCalendar->addEvent(event); |
481 | 482 | ||
482 | emit eventDropped(event); | 483 | emit eventDropped(event); |
483 | } else { | 484 | } else { |
484 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; | 485 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; |
485 | e->ignore(); | 486 | e->ignore(); |
486 | } | 487 | } |
487 | #endif | 488 | #endif |
488 | } | 489 | } |
489 | 490 | ||
490 | // ---------------------------------------------------------------------------- | 491 | // ---------------------------------------------------------------------------- |
491 | // P A I N T E V E N T H A N D L I N G | 492 | // P A I N T E V E N T H A N D L I N G |
492 | // ---------------------------------------------------------------------------- | 493 | // ---------------------------------------------------------------------------- |
493 | 494 | ||
494 | void KODayMatrix::paintEvent(QPaintEvent * pevent) | 495 | void KODayMatrix::paintEvent(QPaintEvent * pevent) |
495 | { | 496 | { |
496 | //kdDebug() << "KODayMatrix::paintEvent() BEGIN" << endl; | 497 | //kdDebug() << "KODayMatrix::paintEvent() BEGIN" << endl; |
497 | 498 | ||
498 | QPainter p(this); | 499 | QPainter p(this); |
499 | 500 | ||
500 | QRect sz = frameRect(); | 501 | QRect sz = frameRect(); |
501 | int dheight = daysize.height(); | 502 | int dheight = daysize.height(); |
502 | int dwidth = daysize.width(); | 503 | int dwidth = daysize.width(); |
503 | int row,col; | 504 | int row,col; |
504 | int selw, selh; | 505 | int selw, selh; |
505 | bool isRTL = KOGlobals::self()->reverseLayout(); | 506 | bool isRTL = KOGlobals::self()->reverseLayout(); |
506 | 507 | ||
507 | // draw background and topleft frame | 508 | // draw background and topleft frame |
508 | p.fillRect(pevent->rect(), mDefaultBackColor); | 509 | p.fillRect(pevent->rect(), mDefaultBackColor); |
509 | p.setPen(mDefaultTextColor); | 510 | p.setPen(mDefaultTextColor); |
510 | p.drawRect(0, 0, sz.width()+1, sz.height()+1); | 511 | p.drawRect(0, 0, sz.width()+1, sz.height()+1); |
511 | 512 | ||
512 | // draw selected days with highlighted background color | 513 | // draw selected days with highlighted background color |
513 | if (mSelStart != NOSELECTION) { | 514 | if (mSelStart != NOSELECTION) { |
514 | 515 | ||
515 | row = mSelStart/7; | 516 | row = mSelStart/7; |
516 | col = mSelStart -row*7; | 517 | col = mSelStart -row*7; |
517 | QColor selcol = KOPrefs::instance()->mHighlightColor; | 518 | QColor selcol = KOPrefs::instance()->mHighlightColor; |
518 | 519 | ||
519 | if (row == mSelEnd/7) { | 520 | if (row == mSelEnd/7) { |
520 | // Single row selection | 521 | // Single row selection |
521 | p.fillRect(isRTL ? (7 - (mSelEnd-mSelStart+1) - col)*dwidth : col*dwidth, | 522 | p.fillRect(isRTL ? (7 - (mSelEnd-mSelStart+1) - col)*dwidth : col*dwidth, |
522 | row*dheight, (mSelEnd-mSelStart+1)*dwidth, dheight, selcol); | 523 | row*dheight, (mSelEnd-mSelStart+1)*dwidth, dheight, selcol); |
523 | } else { | 524 | } else { |
524 | // draw first row to the right | 525 | // draw first row to the right |
525 | p.fillRect(isRTL ? 0 : col*dwidth, row*dheight, (7-col)*dwidth, | 526 | p.fillRect(isRTL ? 0 : col*dwidth, row*dheight, (7-col)*dwidth, |
526 | dheight, selcol); | 527 | dheight, selcol); |
527 | // draw full block till last line | 528 | // draw full block till last line |
528 | selh = mSelEnd/7-row; | 529 | selh = mSelEnd/7-row; |
529 | if (selh > 1) { | 530 | if (selh > 1) { |
530 | p.fillRect(0, (row+1)*dheight, 7*dwidth, (selh-1)*dheight,selcol); | 531 | p.fillRect(0, (row+1)*dheight, 7*dwidth, (selh-1)*dheight,selcol); |
531 | } | 532 | } |
532 | // draw last block from left to mSelEnd | 533 | // draw last block from left to mSelEnd |
533 | selw = mSelEnd-7*(mSelEnd/7)+1; | 534 | selw = mSelEnd-7*(mSelEnd/7)+1; |
534 | p.fillRect(isRTL ? (7-selw)*dwidth : 0, (row+selh)*dheight, | 535 | p.fillRect(isRTL ? (7-selw)*dwidth : 0, (row+selh)*dheight, |
535 | selw*dwidth, dheight, selcol); | 536 | selw*dwidth, dheight, selcol); |
536 | } | 537 | } |
537 | } | 538 | } |
538 | 539 | ||
539 | // iterate over all days in the matrix and draw the day label in appropriate colors | 540 | // iterate over all days in the matrix and draw the day label in appropriate colors |
540 | QColor actcol = mDefaultTextColorShaded; | 541 | QColor actcol = mDefaultTextColorShaded; |
541 | p.setPen(actcol); | 542 | p.setPen(actcol); |
542 | QPen tmppen; | 543 | QPen tmppen; |
543 | for(int i = 0; i < NUMDAYS; i++) { | 544 | for(int i = 0; i < NUMDAYS; i++) { |
544 | row = i/7; | 545 | row = i/7; |
545 | col = isRTL ? 6-(i-row*7) : i-row*7; | 546 | col = isRTL ? 6-(i-row*7) : i-row*7; |
546 | 547 | ||
547 | // if it is the first day of a month switch color from normal to shaded and vice versa | 548 | // if it is the first day of a month switch color from normal to shaded and vice versa |
548 | if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { | 549 | if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { |
549 | if (actcol == mDefaultTextColorShaded) { | 550 | if (actcol == mDefaultTextColorShaded) { |
550 | actcol = mDefaultTextColor; | 551 | actcol = mDefaultTextColor; |
551 | } else { | 552 | } else { |
552 | actcol = mDefaultTextColorShaded; | 553 | actcol = mDefaultTextColorShaded; |
553 | } | 554 | } |
554 | p.setPen(actcol); | 555 | p.setPen(actcol); |
555 | } | 556 | } |
556 | 557 | ||
557 | //Reset pen color after selected days block | 558 | //Reset pen color after selected days block |
558 | if (i == mSelEnd+1) { | 559 | if (i == mSelEnd+1) { |
559 | p.setPen(actcol); | 560 | p.setPen(actcol); |
560 | } | 561 | } |
561 | 562 | ||
562 | // if today then draw rectangle around day | 563 | // if today then draw rectangle around day |
563 | if (today == i) { | 564 | if (today == i) { |
564 | tmppen = p.pen(); | 565 | tmppen = p.pen(); |
565 | QPen mTodayPen(p.pen()); | 566 | QPen mTodayPen(p.pen()); |
566 | 567 | ||
567 | mTodayPen.setWidth(mTodayMarginWidth); | 568 | mTodayPen.setWidth(mTodayMarginWidth); |
568 | //draw red rectangle for holidays | 569 | //draw red rectangle for holidays |
569 | if (!mHolidays[i].isNull()) { | 570 | if (!mHolidays[i].isNull()) { |
570 | if (actcol == mDefaultTextColor) { | 571 | if (actcol == mDefaultTextColor) { |
571 | mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); | 572 | mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); |
572 | } else { | 573 | } else { |
573 | mTodayPen.setColor(mHolidayColorShaded); | 574 | mTodayPen.setColor(mHolidayColorShaded); |
574 | } | 575 | } |
575 | } | 576 | } |
576 | //draw gray rectangle for today if in selection | 577 | //draw gray rectangle for today if in selection |
577 | if (i >= mSelStart && i <= mSelEnd) { | 578 | if (i >= mSelStart && i <= mSelEnd) { |
578 | QColor grey("grey"); | 579 | QColor grey("grey"); |
579 | mTodayPen.setColor(grey); | 580 | mTodayPen.setColor(grey); |
580 | } | 581 | } |
581 | p.setPen(mTodayPen); | 582 | p.setPen(mTodayPen); |
582 | p.drawRect(col*dwidth, row*dheight, dwidth, dheight); | 583 | p.drawRect(col*dwidth, row*dheight, dwidth, dheight); |
583 | p.setPen(tmppen); | 584 | p.setPen(tmppen); |
584 | } | 585 | } |
585 | 586 | ||
586 | // if any events are on that day then draw it using a bold font | 587 | // if any events are on that day then draw it using a bold font |
587 | if (events[i] > 0) { | 588 | if (events[i] > 0) { |
588 | QFont myFont = font(); | 589 | QFont myFont = font(); |
589 | myFont.setBold(true); | 590 | myFont.setBold(true); |
590 | p.setFont(myFont); | 591 | p.setFont(myFont); |
591 | } | 592 | } |
592 | 593 | ||
593 | // if it is a holiday then use the default holiday color | 594 | // if it is a holiday then use the default holiday color |
594 | if (!mHolidays[i].isNull()) { | 595 | if (!mHolidays[i].isNull()) { |
595 | if (actcol == mDefaultTextColor) { | 596 | if (actcol == mDefaultTextColor) { |
596 | p.setPen(KOPrefs::instance()->mHolidayColor); | 597 | p.setPen(KOPrefs::instance()->mHolidayColor); |
597 | } else { | 598 | } else { |
598 | p.setPen(mHolidayColorShaded); | 599 | p.setPen(mHolidayColorShaded); |
599 | } | 600 | } |
600 | } | 601 | } |
601 | 602 | ||
602 | // draw selected days with special color | 603 | // draw selected days with special color |
603 | // DO NOT specially highlight holidays in selection ! | 604 | // DO NOT specially highlight holidays in selection ! |
604 | if (i >= mSelStart && i <= mSelEnd) { | 605 | if (i >= mSelStart && i <= mSelEnd) { |
605 | p.setPen(mSelectedDaysColor); | 606 | p.setPen(mSelectedDaysColor); |
606 | } | 607 | } |
607 | 608 | ||
608 | p.drawText(col*dwidth, row*dheight, dwidth, dheight, | 609 | p.drawText(col*dwidth, row*dheight, dwidth, dheight, |
609 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); | 610 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); |
610 | 611 | ||
611 | // reset color to actual color | 612 | // reset color to actual color |
612 | if (!mHolidays[i].isNull()) { | 613 | if (!mHolidays[i].isNull()) { |
613 | p.setPen(actcol); | 614 | p.setPen(actcol); |
614 | } | 615 | } |
615 | // reset bold font to plain font | 616 | // reset bold font to plain font |
616 | if (events[i] > 0) { | 617 | if (events[i] > 0) { |
617 | QFont myFont = font(); | 618 | QFont myFont = font(); |
618 | myFont.setBold(false); | 619 | myFont.setBold(false); |
619 | p.setFont(myFont); | 620 | p.setFont(myFont); |
620 | } | 621 | } |
621 | } | 622 | } |
622 | } | 623 | } |
623 | 624 | ||
624 | // ---------------------------------------------------------------------------- | 625 | // ---------------------------------------------------------------------------- |
625 | // R E SI Z E E V E N T H A N D L I N G | 626 | // R E SI Z E E V E N T H A N D L I N G |
626 | // ---------------------------------------------------------------------------- | 627 | // ---------------------------------------------------------------------------- |
627 | 628 | ||
628 | void KODayMatrix::resizeEvent(QResizeEvent *) | 629 | void KODayMatrix::resizeEvent(QResizeEvent *) |
629 | { | 630 | { |
630 | QRect sz = frameRect(); | 631 | QRect sz = frameRect(); |
631 | daysize.setHeight(sz.height()*7 / NUMDAYS); | 632 | daysize.setHeight(sz.height()*7 / NUMDAYS); |
632 | daysize.setWidth(sz.width() / 7); | 633 | daysize.setWidth(sz.width() / 7); |
633 | } | 634 | } |