-rw-r--r-- | korganizer/kodaymatrix.cpp | 118 | ||||
-rw-r--r-- | korganizer/kodaymatrix.h | 5 |
2 files changed, 111 insertions, 12 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index 17a8546..1cde616 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -23,12 +23,13 @@ | |||
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 | #include <qwhatsthis.h> | ||
29 | 30 | ||
30 | #include <kglobal.h> | 31 | #include <kglobal.h> |
31 | #include <kdebug.h> | 32 | #include <kdebug.h> |
32 | #include <klocale.h> | 33 | #include <klocale.h> |
33 | 34 | ||
34 | #include <libkcal/vcaldrag.h> | 35 | #include <libkcal/vcaldrag.h> |
@@ -55,12 +56,25 @@ | |||
55 | DynamicTip::DynamicTip( QWidget * parent ) | 56 | DynamicTip::DynamicTip( QWidget * parent ) |
56 | : QToolTip( parent ) | 57 | : QToolTip( parent ) |
57 | { | 58 | { |
58 | matrix = (KODayMatrix*)parent; | 59 | matrix = (KODayMatrix*)parent; |
59 | } | 60 | } |
60 | 61 | ||
62 | class KODaymatrixWhatsThis :public QWhatsThis | ||
63 | { | ||
64 | public: | ||
65 | KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { }; | ||
66 | |||
67 | protected: | ||
68 | virtual QString text( const QPoint& p ) | ||
69 | { | ||
70 | return _view->getWhatsThisText( p ) ; | ||
71 | } | ||
72 | private: | ||
73 | KODayMatrix * _view; | ||
74 | }; | ||
61 | 75 | ||
62 | void DynamicTip::maybeTip( const QPoint &pos ) | 76 | void DynamicTip::maybeTip( const QPoint &pos ) |
63 | { | 77 | { |
64 | //calculate which cell of the matrix the mouse is in | 78 | //calculate which cell of the matrix the mouse is in |
65 | QRect sz = matrix->frameRect(); | 79 | QRect sz = matrix->frameRect(); |
66 | int dheight = sz.height()*7 / 42; | 80 | int dheight = sz.height()*7 / 42; |
@@ -92,16 +106,17 @@ KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) | |||
92 | 106 | ||
93 | #if 0 | 107 | #if 0 |
94 | KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : | 108 | KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : |
95 | QFrame(parent, name) | 109 | QFrame(parent, name) |
96 | #endif | 110 | #endif |
97 | { | 111 | { |
98 | 112 | new KODaymatrixWhatsThis(this); | |
99 | mPendingUpdateBeforeRepaint = false; | 113 | mPendingUpdateBeforeRepaint = false; |
100 | 114 | mouseDown = false; | |
101 | // initialize dynamic arrays | 115 | // initialize dynamic arrays |
116 | bDays.resize ( NUMDAYS ); | ||
102 | days = new QDate[NUMDAYS]; | 117 | days = new QDate[NUMDAYS]; |
103 | daylbls = new QString[NUMDAYS]; | 118 | daylbls = new QString[NUMDAYS]; |
104 | events = new int[NUMDAYS]; | 119 | events = new int[NUMDAYS]; |
105 | mToolTip = new DynamicTip(this); | 120 | mToolTip = new DynamicTip(this); |
106 | 121 | ||
107 | // set default values used for drawing the matrix | 122 | // set default values used for drawing the matrix |
@@ -120,12 +135,71 @@ KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const | |||
120 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); | 135 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); |
121 | mRepaintTimer = new QTimer( this ); | 136 | mRepaintTimer = new QTimer( this ); |
122 | connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); | 137 | connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); |
123 | mDayChanged = false; | 138 | mDayChanged = false; |
124 | updateView(); | 139 | updateView(); |
125 | } | 140 | } |
141 | QString KODayMatrix::getWhatsThisText( QPoint p ) | ||
142 | { | ||
143 | |||
144 | int tmp = getDayIndexFrom(p.x(), p.y()); | ||
145 | if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) | ||
146 | return QString(); | ||
147 | QDate mDate = days[tmp]; | ||
148 | QPtrList<Event> eventlist = mCalendar->events(mDate); | ||
149 | Event *event; | ||
150 | QStringList mToolTip; | ||
151 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | ||
152 | QString mToolTipText; | ||
153 | QString text; | ||
154 | int multiday = 0;// 1 = start, 2 = midddle, 3 = end day | ||
155 | if (event->isMultiDay()) { | ||
156 | QString prefix = "<->";multiday = 2; | ||
157 | QString time; | ||
158 | if ( event->doesRecur() ) { | ||
159 | if ( event->recursOn( mDate) ) { | ||
160 | prefix ="->" ;multiday = 1; | ||
161 | } | ||
162 | else { | ||
163 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); | ||
164 | if ( event->recursOn( mDate.addDays( -days)) ) { | ||
165 | prefix ="<-" ;multiday = 3; | ||
166 | } | ||
167 | } | ||
168 | } else { | ||
169 | if (mDate == event->dtStart().date()) { | ||
170 | prefix ="->" ;multiday = 1; | ||
171 | } else if (mDate == event->dtEnd().date()) { | ||
172 | prefix ="<-" ;multiday = 3; | ||
173 | } | ||
174 | } | ||
175 | if ( !event->doesFloat() ) { | ||
176 | if ( mDate == event->dtStart().date () ) | ||
177 | time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; | ||
178 | else if ( mDate == event->dtEnd().date () ) | ||
179 | time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; | ||
180 | |||
181 | } | ||
182 | text = time + event->summary(); | ||
183 | mToolTipText += prefix + text; | ||
184 | } else { | ||
185 | if (event->doesFloat()) { | ||
186 | text = event->summary(); | ||
187 | mToolTipText += text; | ||
188 | } | ||
189 | else { | ||
190 | text = KGlobal::locale()->formatTime(event->dtStart().time()); | ||
191 | text += " " + event->summary(); | ||
192 | mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); | ||
193 | } | ||
194 | } | ||
195 | mToolTip.append( mToolTipText ); | ||
196 | } | ||
197 | mToolTip.sort(); | ||
198 | return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); | ||
199 | } | ||
126 | void KODayMatrix::setCalendar( Calendar *cal ) | 200 | void KODayMatrix::setCalendar( Calendar *cal ) |
127 | { | 201 | { |
128 | mCalendar = cal; | 202 | mCalendar = cal; |
129 | 203 | ||
130 | setAcceptDrops( mCalendar ); | 204 | setAcceptDrops( mCalendar ); |
131 | 205 | ||
@@ -243,23 +317,30 @@ void KODayMatrix::updateViewTimed() | |||
243 | for(int i = 0; i < NUMDAYS; i++) { | 317 | for(int i = 0; i < NUMDAYS; i++) { |
244 | // if events are set for the day then remember to draw it bold | 318 | // if events are set for the day then remember to draw it bold |
245 | QPtrList<Event> eventlist = mCalendar->events(days[i]); | 319 | QPtrList<Event> eventlist = mCalendar->events(days[i]); |
246 | Event *event; | 320 | Event *event; |
247 | int numEvents = eventlist.count(); | 321 | int numEvents = eventlist.count(); |
248 | QString holiStr = ""; | 322 | QString holiStr = ""; |
323 | bDays.clearBit(i); | ||
249 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 324 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
250 | ushort recurType = event->recurrence()->doesRecur(); | 325 | ushort recurType = event->recurrence()->doesRecur(); |
251 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 326 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
252 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 327 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
253 | numEvents--; | 328 | numEvents--; |
254 | } | 329 | } |
255 | if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) { | 330 | if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) { |
256 | if ( !holiStr.isEmpty() ) | 331 | if ( !holiStr.isEmpty() ) |
257 | holiStr += "\n"; | 332 | holiStr += "\n"; |
258 | holiStr += event->summary(); | 333 | holiStr += event->summary(); |
259 | } | 334 | } |
335 | if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) { | ||
336 | if ( !holiStr.isEmpty() ) | ||
337 | holiStr += "\n"; | ||
338 | holiStr += event->summary(); | ||
339 | bDays.setBit(i); | ||
340 | } | ||
260 | } | 341 | } |
261 | events[i] = numEvents; | 342 | events[i] = numEvents; |
262 | //if it is a holy day then draw it red. Sundays are consider holidays, too | 343 | //if it is a holy day then draw it red. Sundays are consider holidays, too |
263 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || | 344 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || |
264 | !holiStr.isEmpty()) { | 345 | !holiStr.isEmpty()) { |
265 | mHolidays[i] = holiStr; | 346 | mHolidays[i] = holiStr; |
@@ -304,17 +385,17 @@ void KODayMatrix::updateView(QDate actdate) | |||
304 | } | 385 | } |
305 | //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); | 386 | //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); |
306 | if ( !isVisible() ) { | 387 | if ( !isVisible() ) { |
307 | mPendingUpdateBeforeRepaint = true; | 388 | mPendingUpdateBeforeRepaint = true; |
308 | } else { | 389 | } else { |
309 | #ifdef DESKTOP_VERSION | 390 | #ifdef DESKTOP_VERSION |
310 | //mRepaintTimer->start( 250 ); | 391 | //mRepaintTimer->start( 150 ); |
311 | mUpdateTimer->start( 250 ); | 392 | mUpdateTimer->start( 150 ); |
312 | #else | 393 | #else |
313 | mRepaintTimer->start( 350 ); | 394 | mRepaintTimer->start( 350 ); |
314 | mUpdateTimer->start( 2000 ); | 395 | mUpdateTimer->start( 1200 ); |
315 | #endif | 396 | #endif |
316 | } | 397 | } |
317 | } | 398 | } |
318 | void KODayMatrix::updateEvents() | 399 | void KODayMatrix::updateEvents() |
319 | { | 400 | { |
320 | if ( !mCalendar ) return; | 401 | if ( !mCalendar ) return; |
@@ -365,20 +446,28 @@ int KODayMatrix::getDayIndexFrom(int x, int y) | |||
365 | // ---------------------------------------------------------------------------- | 446 | // ---------------------------------------------------------------------------- |
366 | // M O U S E E V E N T H A N D L I N G | 447 | // M O U S E E V E N T H A N D L I N G |
367 | // ---------------------------------------------------------------------------- | 448 | // ---------------------------------------------------------------------------- |
368 | 449 | ||
369 | void KODayMatrix::mousePressEvent (QMouseEvent* e) | 450 | void KODayMatrix::mousePressEvent (QMouseEvent* e) |
370 | { | 451 | { |
452 | |||
453 | if ( e->button() == LeftButton ) | ||
454 | mouseDown = true; | ||
371 | mSelStart = getDayIndexFrom(e->x(), e->y()); | 455 | mSelStart = getDayIndexFrom(e->x(), e->y()); |
372 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; | 456 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; |
373 | mSelInit = mSelStart; | 457 | mSelInit = mSelStart; |
374 | } | 458 | } |
375 | 459 | ||
376 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) | 460 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) |
377 | { | 461 | { |
378 | 462 | if ( e->button() == LeftButton ) | |
463 | if ( ! mouseDown ) { | ||
464 | return; | ||
465 | } | ||
466 | else | ||
467 | mouseDown = false; | ||
379 | int tmp = getDayIndexFrom(e->x(), e->y()); | 468 | int tmp = getDayIndexFrom(e->x(), e->y()); |
380 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 469 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
381 | 470 | ||
382 | if (mSelInit > tmp) { | 471 | if (mSelInit > tmp) { |
383 | mSelEnd = mSelInit; | 472 | mSelEnd = mSelInit; |
384 | if (tmp != mSelStart) { | 473 | if (tmp != mSelStart) { |
@@ -403,13 +492,16 @@ void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) | |||
403 | } | 492 | } |
404 | emit selected((const DateList)daylist); | 493 | emit selected((const DateList)daylist); |
405 | 494 | ||
406 | } | 495 | } |
407 | 496 | ||
408 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) | 497 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) |
409 | { | 498 | { |
499 | if ( ! mouseDown ) { | ||
500 | return; | ||
501 | } | ||
410 | int tmp = getDayIndexFrom(e->x(), e->y()); | 502 | int tmp = getDayIndexFrom(e->x(), e->y()); |
411 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 503 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
412 | 504 | ||
413 | if (mSelInit > tmp) { | 505 | if (mSelInit > tmp) { |
414 | mSelEnd = mSelInit; | 506 | mSelEnd = mSelInit; |
415 | if (tmp != mSelStart) { | 507 | if (tmp != mSelStart) { |
@@ -627,23 +719,27 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent) | |||
627 | myFont.setBold(true); | 719 | myFont.setBold(true); |
628 | p.setFont(myFont); | 720 | p.setFont(myFont); |
629 | } | 721 | } |
630 | 722 | ||
631 | // if it is a holiday then use the default holiday color | 723 | // if it is a holiday then use the default holiday color |
632 | if (!mHolidays[i].isNull()) { | 724 | if (!mHolidays[i].isNull()) { |
633 | if (actcol == mDefaultTextColor) { | 725 | if ( bDays.testBit(i) ) { |
634 | p.setPen(KOPrefs::instance()->mHolidayColor); | 726 | p.setPen(Qt::green); |
635 | } else { | 727 | } else { |
636 | p.setPen(mHolidayColorShaded); | 728 | if (actcol == mDefaultTextColor) { |
729 | p.setPen(KOPrefs::instance()->mHolidayColor); | ||
730 | } else { | ||
731 | p.setPen(mHolidayColorShaded); | ||
732 | } | ||
637 | } | 733 | } |
638 | } | 734 | } |
639 | 735 | ||
640 | // draw selected days with special color | 736 | // draw selected days with special color |
641 | // DO NOT specially highlight holidays in selection ! | 737 | // DO NOT specially highlight holidays in selection ! |
642 | if (i >= mSelStart && i <= mSelEnd) { | 738 | if (i >= mSelStart && i <= mSelEnd) { |
643 | p.setPen(mSelectedDaysColor); | 739 | ;//p.setPen(mSelectedDaysColor); |
644 | } | 740 | } |
645 | 741 | ||
646 | p.drawText(col*dwidth, row*dheight, dwidth, dheight, | 742 | p.drawText(col*dwidth, row*dheight, dwidth, dheight, |
647 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); | 743 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); |
648 | 744 | ||
649 | // reset color to actual color | 745 | // reset color to actual color |
diff --git a/korganizer/kodaymatrix.h b/korganizer/kodaymatrix.h index ba4853f..c049942 100644 --- a/korganizer/kodaymatrix.h +++ b/korganizer/kodaymatrix.h | |||
@@ -29,13 +29,13 @@ | |||
29 | #include <qframe.h> | 29 | #include <qframe.h> |
30 | #include <qcolor.h> | 30 | #include <qcolor.h> |
31 | #include <qpen.h> | 31 | #include <qpen.h> |
32 | #include <qdatetime.h> | 32 | #include <qdatetime.h> |
33 | #include <qtooltip.h> | 33 | #include <qtooltip.h> |
34 | #include <qpixmap.h> | 34 | #include <qpixmap.h> |
35 | 35 | #include <qbitarray.h> | |
36 | #include <qmap.h> | 36 | #include <qmap.h> |
37 | 37 | ||
38 | class QDragEnterEvent; | 38 | class QDragEnterEvent; |
39 | class QDragMoveEvent; | 39 | class QDragMoveEvent; |
40 | class QDragLeaveEvent; | 40 | class QDragLeaveEvent; |
41 | class QDropEvent; | 41 | class QDropEvent; |
@@ -166,12 +166,13 @@ public: | |||
166 | * This is dependent on today remaining the index | 166 | * This is dependent on today remaining the index |
167 | * in the array of visible dates and going from | 167 | * in the array of visible dates and going from |
168 | * top left (0) to bottom right (41). | 168 | * top left (0) to bottom right (41). |
169 | */ | 169 | */ |
170 | bool isBeginningOfMonth() const { return today<=8; } ; | 170 | bool isBeginningOfMonth() const { return today<=8; } ; |
171 | bool isEndOfMonth() const { return today>=27; } ; | 171 | bool isEndOfMonth() const { return today>=27; } ; |
172 | QString getWhatsThisText( QPoint ) ; | ||
172 | 173 | ||
173 | public slots: | 174 | public slots: |
174 | /** Recalculates all the flags of the days in the matrix like holidays or events | 175 | /** Recalculates all the flags of the days in the matrix like holidays or events |
175 | * on a day (Actually calls above method with the actual startdate). | 176 | * on a day (Actually calls above method with the actual startdate). |
176 | */ | 177 | */ |
177 | void updateView(); | 178 | void updateView(); |
@@ -221,12 +222,14 @@ protected: | |||
221 | 222 | ||
222 | void dropEvent(QDropEvent *); | 223 | void dropEvent(QDropEvent *); |
223 | 224 | ||
224 | void resizeEvent(QResizeEvent *); | 225 | void resizeEvent(QResizeEvent *); |
225 | 226 | ||
226 | private: | 227 | private: |
228 | bool mouseDown; | ||
229 | QBitArray bDays; | ||
227 | QPixmap myPix; | 230 | QPixmap myPix; |
228 | QTimer* mUpdateTimer; | 231 | QTimer* mUpdateTimer; |
229 | QTimer* mRepaintTimer; | 232 | QTimer* mRepaintTimer; |
230 | bool mDayChanged; | 233 | bool mDayChanged; |
231 | bool mPendingUpdateBeforeRepaint; | 234 | bool mPendingUpdateBeforeRepaint; |
232 | 235 | ||