author | zautrix <zautrix> | 2005-01-31 08:05:32 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-01-31 08:05:32 (UTC) |
commit | f7663a4c854d217bcb4f828a3ebb69cc40d0dd7c (patch) (unidiff) | |
tree | 683febfff7427b923f23178e74b7cc0e50ef461d /korganizer/kodaymatrix.cpp | |
parent | ed5723f40a93bbedfcbd9f54e6379a23c4a76096 (diff) | |
download | kdepimpi-f7663a4c854d217bcb4f828a3ebb69cc40d0dd7c.zip kdepimpi-f7663a4c854d217bcb4f828a3ebb69cc40d0dd7c.tar.gz kdepimpi-f7663a4c854d217bcb4f828a3ebb69cc40d0dd7c.tar.bz2 |
fix
-rw-r--r-- | korganizer/kodaymatrix.cpp | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index 9c3621e..be5a775 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -6,33 +6,33 @@ | |||
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 ode 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 | #include <qtimer.h> |
29 | 29 | ||
30 | #include <kglobal.h> | 30 | #include <kglobal.h> |
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <klocale.h> | 32 | #include <klocale.h> |
33 | 33 | ||
34 | #include <libkcal/vcaldrag.h> | 34 | #include <libkcal/vcaldrag.h> |
35 | #include <libkcal/icaldrag.h> | 35 | #include <libkcal/icaldrag.h> |
36 | #include <libkcal/dndfactory.h> | 36 | #include <libkcal/dndfactory.h> |
37 | #include <libkcal/calendarresources.h> | 37 | #include <libkcal/calendarresources.h> |
38 | #include <libkcal/resourcecalendar.h> | 38 | #include <libkcal/resourcecalendar.h> |
@@ -78,32 +78,33 @@ void DynamicTip::maybeTip( const QPoint &pos ) | |||
78 | if (str.isEmpty()) return; | 78 | if (str.isEmpty()) return; |
79 | tip(rct, str); | 79 | tip(rct, str); |
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | // ============================================================================ | 83 | // ============================================================================ |
84 | // K O D A Y M A T R I X | 84 | // K O D A Y M A T R I X |
85 | // ============================================================================ | 85 | // ============================================================================ |
86 | 86 | ||
87 | const int KODayMatrix::NOSELECTION = -1000; | 87 | const int KODayMatrix::NOSELECTION = -1000; |
88 | const int KODayMatrix::NUMDAYS = 42; | 88 | const int KODayMatrix::NUMDAYS = 42; |
89 | 89 | ||
90 | KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : | 90 | KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : |
91 | QFrame(parent, name) | 91 | QFrame(parent, name) |
92 | { | 92 | { |
93 | mCalendar = calendar; | 93 | mCalendar = calendar; |
94 | mPendingUpdateBeforeRepaint = false; | ||
94 | 95 | ||
95 | // initialize dynamic arrays | 96 | // initialize dynamic arrays |
96 | days = new QDate[NUMDAYS]; | 97 | days = new QDate[NUMDAYS]; |
97 | daylbls = new QString[NUMDAYS]; | 98 | daylbls = new QString[NUMDAYS]; |
98 | events = new int[NUMDAYS]; | 99 | events = new int[NUMDAYS]; |
99 | mToolTip = new DynamicTip(this); | 100 | mToolTip = new DynamicTip(this); |
100 | 101 | ||
101 | // set default values used for drawing the matrix | 102 | // set default values used for drawing the matrix |
102 | mDefaultBackColor = palette().active().base(); | 103 | mDefaultBackColor = palette().active().base(); |
103 | mDefaultTextColor = palette().active().foreground(); | 104 | mDefaultTextColor = palette().active().foreground(); |
104 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); | 105 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); |
105 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); | 106 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); |
106 | mSelectedDaysColor = QColor("white"); | 107 | mSelectedDaysColor = QColor("white"); |
107 | mTodayMarginWidth = 2; | 108 | mTodayMarginWidth = 2; |
108 | mSelEnd = mSelStart = NOSELECTION; | 109 | mSelEnd = mSelStart = NOSELECTION; |
109 | 110 | ||
@@ -178,148 +179,139 @@ void KODayMatrix::addSelectedDaysTo(DateList& selDays) | |||
178 | selDays.append(days[i]); | 179 | selDays.append(days[i]); |
179 | } | 180 | } |
180 | } | 181 | } |
181 | } | 182 | } |
182 | 183 | ||
183 | void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) | 184 | void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) |
184 | { | 185 | { |
185 | mSelStart = startdate.daysTo(start); | 186 | mSelStart = startdate.daysTo(start); |
186 | mSelEnd = startdate.daysTo(end); | 187 | mSelEnd = startdate.daysTo(end); |
187 | } | 188 | } |
188 | 189 | ||
189 | 190 | ||
190 | void KODayMatrix::recalculateToday() | 191 | void KODayMatrix::recalculateToday() |
191 | { | 192 | { |
192 | today = -1; | 193 | today = -1; |
193 | for (int i=0; i<NUMDAYS; i++) { | 194 | for (int i=0; i<NUMDAYS; i++) { |
195 | events[i] = 0; | ||
194 | days[i] = startdate.addDays(i); | 196 | days[i] = startdate.addDays(i); |
195 | daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); | 197 | daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); |
196 | 198 | ||
197 | // if today is in the currently displayed month, hilight today | 199 | // if today is in the currently displayed month, hilight today |
198 | if (days[i].year() == QDate::currentDate().year() && | 200 | if (days[i].year() == QDate::currentDate().year() && |
199 | days[i].month() == QDate::currentDate().month() && | 201 | days[i].month() == QDate::currentDate().month() && |
200 | days[i].day() == QDate::currentDate().day()) { | 202 | days[i].day() == QDate::currentDate().day()) { |
201 | today = i; | 203 | today = i; |
202 | } | 204 | } |
203 | } | 205 | } |
204 | // qDebug(QString("Today is visible at %1.").arg(today)); | 206 | // qDebug(QString("Today is visible at %1.").arg(today)); |
205 | } | 207 | } |
206 | 208 | ||
207 | void KODayMatrix::updateView() | 209 | void KODayMatrix::updateView() |
208 | { | 210 | { |
209 | updateView(startdate); | 211 | updateView(startdate); |
210 | } | 212 | } |
211 | void KODayMatrix::repaintViewTimed() | 213 | void KODayMatrix::repaintViewTimed() |
212 | { | 214 | { |
213 | qDebug("KODayMatrix::repaintViewTimed "); | 215 | //qDebug("KODayMatrix::repaintViewTimed "); |
214 | mRepaintTimer->stop(); | 216 | mRepaintTimer->stop(); |
215 | repaint(false); | 217 | repaint(false); |
216 | } | 218 | } |
217 | void KODayMatrix::updateViewTimed() | 219 | void KODayMatrix::updateViewTimed() |
218 | { | 220 | { |
219 | 221 | ||
220 | mUpdateTimer->stop(); | 222 | mUpdateTimer->stop(); |
221 | //QDate actdate = mPendingNewDate; | 223 | //qDebug("KODayMatrix::updateView(QDate actdate) %d", ++iii ); |
222 | |||
223 | static int iii = 0; | ||
224 | qDebug("KODayMatrix::updateView(QDate actdate) %d", ++iii ); | ||
225 | |||
226 | if (mDayChanged) { | ||
227 | recalculateToday(); | ||
228 | mDayChanged = false; | ||
229 | } | ||
230 | |||
231 | for(int i = 0; i < NUMDAYS; i++) { | 224 | for(int i = 0; i < NUMDAYS; i++) { |
232 | 225 | ||
233 | // if events are set for the day then remember to draw it bold | 226 | // if events are set for the day then remember to draw it bold |
234 | QPtrList<Event> eventlist = mCalendar->events(days[i]); | 227 | QPtrList<Event> eventlist = mCalendar->events(days[i]); |
235 | Event *event; | 228 | Event *event; |
236 | int numEvents = eventlist.count(); | 229 | int numEvents = eventlist.count(); |
237 | 230 | ||
238 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 231 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
239 | ushort recurType = event->recurrence()->doesRecur(); | 232 | ushort recurType = event->recurrence()->doesRecur(); |
240 | 233 | ||
241 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 234 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
242 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 235 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
243 | numEvents--; | 236 | numEvents--; |
244 | } | 237 | } |
245 | } | 238 | } |
246 | events[i] = numEvents; | 239 | events[i] = numEvents; |
247 | 240 | ||
248 | //if it is a holy day then draw it red. Sundays are consider holidays, too | 241 | //if it is a holy day then draw it red. Sundays are consider holidays, too |
249 | #ifndef KORG_NOPLUGINS | 242 | #ifndef KORG_NOPLUGINS |
250 | QString holiStr = KOCore::self()->holiday(days[i]); | 243 | QString holiStr = KOCore::self()->holiday(days[i]); |
251 | #else | 244 | #else |
252 | QString holiStr = QString::null; | 245 | QString holiStr = QString::null; |
253 | #endif | 246 | #endif |
254 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || | 247 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || |
255 | !holiStr.isEmpty()) { | 248 | !holiStr.isEmpty()) { |
256 | if (holiStr.isNull()) holiStr = ""; | 249 | if (holiStr.isNull()) holiStr = ""; |
257 | mHolidays[i] = holiStr; | 250 | mHolidays[i] = holiStr; |
258 | 251 | ||
259 | } else { | 252 | } else { |
260 | mHolidays[i] = QString::null; | 253 | mHolidays[i] = QString::null; |
261 | } | 254 | } |
262 | } | 255 | } |
263 | repaint(false); | 256 | if ( ! mPendingUpdateBeforeRepaint ) |
257 | repaint(false); | ||
264 | } | 258 | } |
265 | void KODayMatrix::updateView(QDate actdate) | 259 | void KODayMatrix::updateView(QDate actdate) |
266 | { | 260 | { |
267 | 261 | ||
262 | if ( ! actdate.isValid() ) { | ||
263 | //qDebug("date not valid "); | ||
264 | return; | ||
265 | } | ||
266 | mDayChanged = false; | ||
268 | //flag to indicate if the starting day of the matrix has changed by this call | 267 | //flag to indicate if the starting day of the matrix has changed by this call |
269 | //mDayChanged = false; | 268 | //mDayChanged = false; |
270 | // if a new startdate is to be set then apply Cornelius's calculation | 269 | // if a new startdate is to be set then apply Cornelius's calculation |
271 | // of the first day to be shown | 270 | // of the first day to be shown |
272 | if (actdate != startdate) { | 271 | if (actdate != startdate) { |
273 | // reset index of selection according to shift of starting date from startdate to actdate | 272 | // reset index of selection according to shift of starting date from startdate to actdate |
274 | if (mSelStart != NOSELECTION) { | 273 | if (mSelStart != NOSELECTION) { |
275 | int tmp = actdate.daysTo(startdate); | 274 | int tmp = actdate.daysTo(startdate); |
276 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; | 275 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; |
277 | // shift selection if new one would be visible at least partly ! | 276 | // shift selection if new one would be visible at least partly ! |
278 | 277 | ||
279 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { | 278 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { |
280 | // nested if is required for next X display pushed from a different month - correction required | 279 | // nested if is required for next X display pushed from a different month - correction required |
281 | // otherwise, for month forward and backward, it must be avoided | 280 | // otherwise, for month forward and backward, it must be avoided |
282 | if( mSelStart > NUMDAYS || mSelStart < 0 ) | 281 | if( mSelStart > NUMDAYS || mSelStart < 0 ) |
283 | mSelStart = mSelStart + tmp; | 282 | mSelStart = mSelStart + tmp; |
284 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) | 283 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) |
285 | mSelEnd = mSelEnd + tmp; | 284 | mSelEnd = mSelEnd + tmp; |
286 | } | 285 | } |
287 | } | 286 | } |
288 | |||
289 | startdate = actdate; | 287 | startdate = actdate; |
290 | mDayChanged = true; | 288 | mDayChanged = true; |
289 | recalculateToday(); | ||
291 | } | 290 | } |
292 | qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); | 291 | //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); |
293 | static int iii = 0; | 292 | if ( !isVisible() ) { |
294 | if ( iii < 2 ) { | 293 | mPendingUpdateBeforeRepaint = true; |
295 | ++iii; | ||
296 | updateViewTimed(); | ||
297 | } else { | 294 | } else { |
298 | if ( !isVisible() ) { | 295 | mRepaintTimer->start( 250 ); |
299 | mUpdateTimer->start( 2000 ); | 296 | #ifdef DESKTOP_VERSION |
300 | } else { | 297 | mUpdateTimer->start( 2000 ); |
301 | if ( mDayChanged ) { | 298 | #else |
302 | mUpdateTimer->start( 250 ); | 299 | mUpdateTimer->start( 4000 ); |
303 | } else { | 300 | #endif |
304 | mRepaintTimer->start( 250 ); | ||
305 | mUpdateTimer->start( 2000 ); | ||
306 | } | ||
307 | } | ||
308 | } | 301 | } |
309 | |||
310 | } | 302 | } |
311 | 303 | ||
312 | const QDate& KODayMatrix::getDate(int offset) | 304 | const QDate& KODayMatrix::getDate(int offset) |
313 | { | 305 | { |
314 | if (offset < 0 || offset > NUMDAYS-1) { | 306 | if (offset < 0 || offset > NUMDAYS-1) { |
315 | qDebug("Wrong offset2 "); | 307 | qDebug("Wrong offset2 "); |
316 | return days[0]; | 308 | return days[0]; |
317 | } | 309 | } |
318 | return days[offset]; | 310 | return days[offset]; |
319 | } | 311 | } |
320 | 312 | ||
321 | QString KODayMatrix::getHolidayLabel(int offset) | 313 | QString KODayMatrix::getHolidayLabel(int offset) |
322 | { | 314 | { |
323 | if (offset < 0 || offset > NUMDAYS-1) { | 315 | if (offset < 0 || offset > NUMDAYS-1) { |
324 | qDebug("Wrong offset1 "); | 316 | qDebug("Wrong offset1 "); |
325 | return 0; | 317 | return 0; |
@@ -482,33 +474,36 @@ void KODayMatrix::dropEvent(QDropEvent *e) | |||
482 | 474 | ||
483 | emit eventDropped(event); | 475 | emit eventDropped(event); |
484 | } else { | 476 | } else { |
485 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; | 477 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; |
486 | e->ignore(); | 478 | e->ignore(); |
487 | } | 479 | } |
488 | #endif | 480 | #endif |
489 | } | 481 | } |
490 | 482 | ||
491 | // ---------------------------------------------------------------------------- | 483 | // ---------------------------------------------------------------------------- |
492 | // P A I N T E V E N T H A N D L I N G | 484 | // P A I N T E V E N T H A N D L I N G |
493 | // ---------------------------------------------------------------------------- | 485 | // ---------------------------------------------------------------------------- |
494 | 486 | ||
495 | void KODayMatrix::paintEvent(QPaintEvent * pevent) | 487 | void KODayMatrix::paintEvent(QPaintEvent * pevent) |
496 | { | 488 | { |
497 | //kdDebug() << "KODayMatrix::paintEvent() BEGIN" << endl; | 489 | //kdDebug() << "KODayMatrix::paintEvent() BEGIN" << endl; |
498 | 490 | if ( mPendingUpdateBeforeRepaint ) { | |
491 | updateViewTimed(); | ||
492 | mPendingUpdateBeforeRepaint = false; | ||
493 | } | ||
499 | QPainter p(this); | 494 | QPainter p(this); |
500 | 495 | ||
501 | QRect sz = frameRect(); | 496 | QRect sz = frameRect(); |
502 | int dheight = daysize.height(); | 497 | int dheight = daysize.height(); |
503 | int dwidth = daysize.width(); | 498 | int dwidth = daysize.width(); |
504 | int row,col; | 499 | int row,col; |
505 | int selw, selh; | 500 | int selw, selh; |
506 | bool isRTL = KOGlobals::self()->reverseLayout(); | 501 | bool isRTL = KOGlobals::self()->reverseLayout(); |
507 | 502 | ||
508 | // draw background and topleft frame | 503 | // draw background and topleft frame |
509 | p.fillRect(pevent->rect(), mDefaultBackColor); | 504 | p.fillRect(pevent->rect(), mDefaultBackColor); |
510 | p.setPen(mDefaultTextColor); | 505 | p.setPen(mDefaultTextColor); |
511 | p.drawRect(0, 0, sz.width()+1, sz.height()+1); | 506 | p.drawRect(0, 0, sz.width()+1, sz.height()+1); |
512 | 507 | ||
513 | // draw selected days with highlighted background color | 508 | // draw selected days with highlighted background color |
514 | if (mSelStart != NOSELECTION) { | 509 | if (mSelStart != NOSELECTION) { |