author | zautrix <zautrix> | 2005-03-20 00:09:33 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-20 00:09:33 (UTC) |
commit | 0ef9fe870982bd005806d7f51898a740cd52fec8 (patch) (unidiff) | |
tree | 891d95449e3f23159c50d7a38f03006bedfb41be | |
parent | 84c18843bbd1203878367572d3a6800a0586c7f1 (diff) | |
download | kdepimpi-0ef9fe870982bd005806d7f51898a740cd52fec8.zip kdepimpi-0ef9fe870982bd005806d7f51898a740cd52fec8.tar.gz kdepimpi-0ef9fe870982bd005806d7f51898a740cd52fec8.tar.bz2 |
cooooooool
-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 | |||
@@ -5,145 +5,219 @@ | |||
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 ode 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 | #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> |
35 | #include <libkcal/icaldrag.h> | 36 | #include <libkcal/icaldrag.h> |
36 | #include <libkcal/dndfactory.h> | 37 | #include <libkcal/dndfactory.h> |
37 | #include <libkcal/calendarresources.h> | 38 | #include <libkcal/calendarresources.h> |
38 | #include <libkcal/resourcecalendar.h> | 39 | #include <libkcal/resourcecalendar.h> |
39 | #include <kresources/resourceselectdialog.h> | 40 | #include <kresources/resourceselectdialog.h> |
40 | 41 | ||
41 | #include <kcalendarsystem.h> | 42 | #include <kcalendarsystem.h> |
42 | 43 | ||
43 | #ifndef KORG_NOPLUGINS | 44 | #ifndef KORG_NOPLUGINS |
44 | #include "kocore.h" | 45 | #include "kocore.h" |
45 | #endif | 46 | #endif |
46 | #include "koprefs.h" | 47 | #include "koprefs.h" |
47 | #include "koglobals.h" | 48 | #include "koglobals.h" |
48 | 49 | ||
49 | #include "kodaymatrix.h" | 50 | #include "kodaymatrix.h" |
50 | 51 | ||
51 | // ============================================================================ | 52 | // ============================================================================ |
52 | // D Y N A M I C T I P | 53 | // D Y N A M I C T I P |
53 | // ============================================================================ | 54 | // ============================================================================ |
54 | 55 | ||
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; |
67 | int dwidth = sz.width() / 7; | 81 | int dwidth = sz.width() / 7; |
68 | int row = pos.y()/dheight; | 82 | int row = pos.y()/dheight; |
69 | int col = pos.x()/dwidth; | 83 | int col = pos.x()/dwidth; |
70 | 84 | ||
71 | QRect rct(col*dwidth, row*dheight, dwidth, dheight); | 85 | QRect rct(col*dwidth, row*dheight, dwidth, dheight); |
72 | 86 | ||
73 | // kdDebug() << "DynamicTip::maybeTip matrix cell index [" << | 87 | // kdDebug() << "DynamicTip::maybeTip matrix cell index [" << |
74 | // col << "][" << row << "] => " <<(col+row*7) << endl; | 88 | // col << "][" << row << "] => " <<(col+row*7) << endl; |
75 | 89 | ||
76 | //show holiday names only | 90 | //show holiday names only |
77 | QString str = matrix->getHolidayLabel(col+row*7); | 91 | QString str = matrix->getHolidayLabel(col+row*7); |
78 | if (str.isEmpty()) return; | 92 | if (str.isEmpty()) return; |
79 | tip(rct, str); | 93 | tip(rct, str); |
80 | } | 94 | } |
81 | 95 | ||
82 | 96 | ||
83 | // ============================================================================ | 97 | // ============================================================================ |
84 | // K O D A Y M A T R I X | 98 | // K O D A Y M A T R I X |
85 | // ============================================================================ | 99 | // ============================================================================ |
86 | 100 | ||
87 | const int KODayMatrix::NOSELECTION = -1000; | 101 | const int KODayMatrix::NOSELECTION = -1000; |
88 | const int KODayMatrix::NUMDAYS = 42; | 102 | const int KODayMatrix::NUMDAYS = 42; |
89 | 103 | ||
90 | KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) | 104 | KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) |
91 | : QFrame( parent, name ), mCalendar( 0 ) | 105 | : QFrame( parent, name ), mCalendar( 0 ) |
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 |
108 | mDefaultBackColor = palette().active().base(); | 123 | mDefaultBackColor = palette().active().base(); |
109 | mDefaultTextColor = palette().active().foreground(); | 124 | mDefaultTextColor = palette().active().foreground(); |
110 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); | 125 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); |
111 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); | 126 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); |
112 | mSelectedDaysColor = QColor("white"); | 127 | mSelectedDaysColor = QColor("white"); |
113 | mTodayMarginWidth = 2; | 128 | mTodayMarginWidth = 2; |
114 | mSelEnd = mSelStart = NOSELECTION; | 129 | mSelEnd = mSelStart = NOSELECTION; |
115 | 130 | ||
116 | setAcceptDrops(true); | 131 | setAcceptDrops(true); |
117 | //setFont( QFont("Arial", 10) ); | 132 | //setFont( QFont("Arial", 10) ); |
118 | 133 | ||
119 | mUpdateTimer = new QTimer( this ); | 134 | mUpdateTimer = new QTimer( this ); |
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 | ||
132 | updateEvents(); | 206 | updateEvents(); |
133 | } | 207 | } |
134 | 208 | ||
135 | QColor KODayMatrix::getShadedColor(QColor color) | 209 | QColor KODayMatrix::getShadedColor(QColor color) |
136 | { | 210 | { |
137 | QColor shaded; | 211 | QColor shaded; |
138 | int h=0; | 212 | int h=0; |
139 | int s=0; | 213 | int s=0; |
140 | int v=0; | 214 | int v=0; |
141 | color.hsv(&h,&s,&v); | 215 | color.hsv(&h,&s,&v); |
142 | s = s/4; | 216 | s = s/4; |
143 | v = 192+v/4; | 217 | v = 192+v/4; |
144 | shaded.setHsv(h,s,v); | 218 | shaded.setHsv(h,s,v); |
145 | 219 | ||
146 | return shaded; | 220 | return shaded; |
147 | } | 221 | } |
148 | 222 | ||
149 | KODayMatrix::~KODayMatrix() | 223 | KODayMatrix::~KODayMatrix() |
@@ -225,59 +299,66 @@ void KODayMatrix::recalculateToday() | |||
225 | 299 | ||
226 | void KODayMatrix::updateView() | 300 | void KODayMatrix::updateView() |
227 | { | 301 | { |
228 | updateView(startdate); | 302 | updateView(startdate); |
229 | } | 303 | } |
230 | void KODayMatrix::repaintViewTimed() | 304 | void KODayMatrix::repaintViewTimed() |
231 | { | 305 | { |
232 | mRepaintTimer->stop(); | 306 | mRepaintTimer->stop(); |
233 | repaint(false); | 307 | repaint(false); |
234 | } | 308 | } |
235 | void KODayMatrix::updateViewTimed() | 309 | void KODayMatrix::updateViewTimed() |
236 | { | 310 | { |
237 | mUpdateTimer->stop(); | 311 | mUpdateTimer->stop(); |
238 | if ( !mCalendar ) { | 312 | if ( !mCalendar ) { |
239 | qDebug("NOT CAL "); | 313 | qDebug("NOT CAL "); |
240 | return; | 314 | return; |
241 | } | 315 | } |
242 | //qDebug("KODayMatrix::updateViewTimed "); | 316 | //qDebug("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; |
266 | } else { | 347 | } else { |
267 | mHolidays[i] = QString::null; | 348 | mHolidays[i] = QString::null; |
268 | } | 349 | } |
269 | } | 350 | } |
270 | if ( ! mPendingUpdateBeforeRepaint ) | 351 | if ( ! mPendingUpdateBeforeRepaint ) |
271 | repaint(false); | 352 | repaint(false); |
272 | } | 353 | } |
273 | void KODayMatrix::updateView(QDate actdate) | 354 | void KODayMatrix::updateView(QDate actdate) |
274 | { | 355 | { |
275 | 356 | ||
276 | if ( ! actdate.isValid() ) { | 357 | if ( ! actdate.isValid() ) { |
277 | //qDebug("date not valid "); | 358 | //qDebug("date not valid "); |
278 | return; | 359 | return; |
279 | } | 360 | } |
280 | mDayChanged = false; | 361 | mDayChanged = false; |
281 | //flag to indicate if the starting day of the matrix has changed by this call | 362 | //flag to indicate if the starting day of the matrix has changed by this call |
282 | //mDayChanged = false; | 363 | //mDayChanged = false; |
283 | // if a new startdate is to be set then apply Cornelius's calculation | 364 | // if a new startdate is to be set then apply Cornelius's calculation |
@@ -286,53 +367,53 @@ void KODayMatrix::updateView(QDate actdate) | |||
286 | // reset index of selection according to shift of starting date from startdate to actdate | 367 | // reset index of selection according to shift of starting date from startdate to actdate |
287 | if (mSelStart != NOSELECTION) { | 368 | if (mSelStart != NOSELECTION) { |
288 | int tmp = actdate.daysTo(startdate); | 369 | int tmp = actdate.daysTo(startdate); |
289 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; | 370 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; |
290 | // shift selection if new one would be visible at least partly ! | 371 | // shift selection if new one would be visible at least partly ! |
291 | 372 | ||
292 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { | 373 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { |
293 | // nested if is required for next X display pushed from a different month - correction required | 374 | // nested if is required for next X display pushed from a different month - correction required |
294 | // otherwise, for month forward and backward, it must be avoided | 375 | // otherwise, for month forward and backward, it must be avoided |
295 | if( mSelStart > NUMDAYS || mSelStart < 0 ) | 376 | if( mSelStart > NUMDAYS || mSelStart < 0 ) |
296 | mSelStart = mSelStart + tmp; | 377 | mSelStart = mSelStart + tmp; |
297 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) | 378 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) |
298 | mSelEnd = mSelEnd + tmp; | 379 | mSelEnd = mSelEnd + tmp; |
299 | } | 380 | } |
300 | } | 381 | } |
301 | startdate = actdate; | 382 | startdate = actdate; |
302 | mDayChanged = true; | 383 | mDayChanged = true; |
303 | recalculateToday(); | 384 | recalculateToday(); |
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; |
321 | 402 | ||
322 | for( int i = 0; i < NUMDAYS; i++ ) { | 403 | for( int i = 0; i < NUMDAYS; i++ ) { |
323 | // if events are set for the day then remember to draw it bold | 404 | // if events are set for the day then remember to draw it bold |
324 | QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); | 405 | QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); |
325 | int numEvents = eventlist.count(); | 406 | int numEvents = eventlist.count(); |
326 | Event *event; | 407 | Event *event; |
327 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { | 408 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { |
328 | ushort recurType = event->doesRecur(); | 409 | ushort recurType = event->doesRecur(); |
329 | 410 | ||
330 | if ( ( recurType == Recurrence::rDaily && | 411 | if ( ( recurType == Recurrence::rDaily && |
331 | !KOPrefs::instance()->mDailyRecur ) || | 412 | !KOPrefs::instance()->mDailyRecur ) || |
332 | ( recurType == Recurrence::rWeekly && | 413 | ( recurType == Recurrence::rWeekly && |
333 | !KOPrefs::instance()->mWeeklyRecur ) ) { | 414 | !KOPrefs::instance()->mWeeklyRecur ) ) { |
334 | numEvents--; | 415 | numEvents--; |
335 | } | 416 | } |
336 | } | 417 | } |
337 | events[ i ] = numEvents; | 418 | events[ i ] = numEvents; |
338 | } | 419 | } |
@@ -347,87 +428,98 @@ const QDate& KODayMatrix::getDate(int offset) | |||
347 | return days[offset]; | 428 | return days[offset]; |
348 | } | 429 | } |
349 | 430 | ||
350 | QString KODayMatrix::getHolidayLabel(int offset) | 431 | QString KODayMatrix::getHolidayLabel(int offset) |
351 | { | 432 | { |
352 | if (offset < 0 || offset > NUMDAYS-1) { | 433 | if (offset < 0 || offset > NUMDAYS-1) { |
353 | qDebug("Wrong offset1 "); | 434 | qDebug("Wrong offset1 "); |
354 | return 0; | 435 | return 0; |
355 | } | 436 | } |
356 | return mHolidays[offset]; | 437 | return mHolidays[offset]; |
357 | } | 438 | } |
358 | 439 | ||
359 | int KODayMatrix::getDayIndexFrom(int x, int y) | 440 | int KODayMatrix::getDayIndexFrom(int x, int y) |
360 | { | 441 | { |
361 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? | 442 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? |
362 | 6 - x/daysize.width() : x/daysize.width()); | 443 | 6 - x/daysize.width() : x/daysize.width()); |
363 | } | 444 | } |
364 | 445 | ||
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) { |
385 | mSelStart = tmp; | 474 | mSelStart = tmp; |
386 | repaint(false); | 475 | repaint(false); |
387 | } | 476 | } |
388 | } else { | 477 | } else { |
389 | mSelStart = mSelInit; | 478 | mSelStart = mSelInit; |
390 | 479 | ||
391 | //repaint only if selection has changed | 480 | //repaint only if selection has changed |
392 | if (tmp != mSelEnd) { | 481 | if (tmp != mSelEnd) { |
393 | mSelEnd = tmp; | 482 | mSelEnd = tmp; |
394 | repaint(false); | 483 | repaint(false); |
395 | } | 484 | } |
396 | } | 485 | } |
397 | 486 | ||
398 | DateList daylist; | 487 | DateList daylist; |
399 | if ( mSelStart < 0 ) | 488 | if ( mSelStart < 0 ) |
400 | mSelStart = 0; | 489 | mSelStart = 0; |
401 | for (int i = mSelStart; i <= mSelEnd; i++) { | 490 | for (int i = mSelStart; i <= mSelEnd; i++) { |
402 | daylist.append(days[i]); | 491 | daylist.append(days[i]); |
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) { |
416 | mSelStart = tmp; | 508 | mSelStart = tmp; |
417 | repaint(false); | 509 | repaint(false); |
418 | } | 510 | } |
419 | } else { | 511 | } else { |
420 | mSelStart = mSelInit; | 512 | mSelStart = mSelInit; |
421 | 513 | ||
422 | //repaint only if selection has changed | 514 | //repaint only if selection has changed |
423 | if (tmp != mSelEnd) { | 515 | if (tmp != mSelEnd) { |
424 | mSelEnd = tmp; | 516 | mSelEnd = tmp; |
425 | repaint(false); | 517 | repaint(false); |
426 | } | 518 | } |
427 | } | 519 | } |
428 | } | 520 | } |
429 | 521 | ||
430 | // ---------------------------------------------------------------------------- | 522 | // ---------------------------------------------------------------------------- |
431 | // D R A G ' N D R O P H A N D L I N G | 523 | // D R A G ' N D R O P H A N D L I N G |
432 | // ---------------------------------------------------------------------------- | 524 | // ---------------------------------------------------------------------------- |
433 | 525 | ||
@@ -609,59 +701,63 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent) | |||
609 | mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); | 701 | mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); |
610 | } else { | 702 | } else { |
611 | mTodayPen.setColor(mHolidayColorShaded); | 703 | mTodayPen.setColor(mHolidayColorShaded); |
612 | } | 704 | } |
613 | } | 705 | } |
614 | //draw gray rectangle for today if in selection | 706 | //draw gray rectangle for today if in selection |
615 | if (i >= mSelStart && i <= mSelEnd) { | 707 | if (i >= mSelStart && i <= mSelEnd) { |
616 | QColor grey("grey"); | 708 | QColor grey("grey"); |
617 | mTodayPen.setColor(grey); | 709 | mTodayPen.setColor(grey); |
618 | } | 710 | } |
619 | p.setPen(mTodayPen); | 711 | p.setPen(mTodayPen); |
620 | p.drawRect(col*dwidth, row*dheight, dwidth, dheight); | 712 | p.drawRect(col*dwidth, row*dheight, dwidth, dheight); |
621 | p.setPen(tmppen); | 713 | p.setPen(tmppen); |
622 | } | 714 | } |
623 | 715 | ||
624 | // if any events are on that day then draw it using a bold font | 716 | // if any events are on that day then draw it using a bold font |
625 | if (events[i] > 0) { | 717 | if (events[i] > 0) { |
626 | QFont myFont = font(); | 718 | QFont myFont = font(); |
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 |
650 | if (!mHolidays[i].isNull()) { | 746 | if (!mHolidays[i].isNull()) { |
651 | p.setPen(actcol); | 747 | p.setPen(actcol); |
652 | } | 748 | } |
653 | // reset bold font to plain font | 749 | // reset bold font to plain font |
654 | if (events[i] > 0) { | 750 | if (events[i] > 0) { |
655 | QFont myFont = font(); | 751 | QFont myFont = font(); |
656 | myFont.setBold(false); | 752 | myFont.setBold(false); |
657 | p.setFont(myFont); | 753 | p.setFont(myFont); |
658 | } | 754 | } |
659 | } | 755 | } |
660 | bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); | 756 | bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); |
661 | } | 757 | } |
662 | 758 | ||
663 | // ---------------------------------------------------------------------------- | 759 | // ---------------------------------------------------------------------------- |
664 | // R E SI Z E E V E N T H A N D L I N G | 760 | // R E SI Z E E V E N T H A N D L I N G |
665 | // ---------------------------------------------------------------------------- | 761 | // ---------------------------------------------------------------------------- |
666 | 762 | ||
667 | void KODayMatrix::resizeEvent(QResizeEvent *) | 763 | void KODayMatrix::resizeEvent(QResizeEvent *) |
diff --git a/korganizer/kodaymatrix.h b/korganizer/kodaymatrix.h index ba4853f..c049942 100644 --- a/korganizer/kodaymatrix.h +++ b/korganizer/kodaymatrix.h | |||
@@ -11,49 +11,49 @@ | |||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 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 | 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. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | #ifndef _KODAYMAT_H | 23 | #ifndef _KODAYMAT_H |
24 | #define _KODAYMAT_H | 24 | #define _KODAYMAT_H |
25 | 25 | ||
26 | #include <libkcal/calendar.h> | 26 | #include <libkcal/calendar.h> |
27 | 27 | ||
28 | #include <qstring.h> | 28 | #include <qstring.h> |
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; |
42 | 42 | ||
43 | class KODayMatrix; | 43 | class KODayMatrix; |
44 | 44 | ||
45 | using namespace KCal; | 45 | using namespace KCal; |
46 | 46 | ||
47 | 47 | ||
48 | /** | 48 | /** |
49 | * small helper class to dynamically show tooltips inside the day matrix. | 49 | * small helper class to dynamically show tooltips inside the day matrix. |
50 | * This class asks the day matrix object for a appropriate label which | 50 | * This class asks the day matrix object for a appropriate label which |
51 | * is in our special case the name of the holiday or null if this day is no holiday. | 51 | * is in our special case the name of the holiday or null if this day is no holiday. |
52 | */ | 52 | */ |
53 | class DynamicTip : public QToolTip | 53 | class DynamicTip : public QToolTip |
54 | { | 54 | { |
55 | public: | 55 | public: |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Constructor that expects a KODayMatrix object as parent. | 58 | * Constructor that expects a KODayMatrix object as parent. |
59 | * | 59 | * |
@@ -148,48 +148,49 @@ public: | |||
148 | * DateList. | 148 | * DateList. |
149 | */ | 149 | */ |
150 | void addSelectedDaysTo(DateList&); | 150 | void addSelectedDaysTo(DateList&); |
151 | 151 | ||
152 | /** sets the actual to be displayed selection in the day matrix starting from | 152 | /** sets the actual to be displayed selection in the day matrix starting from |
153 | * start and ending with end. Theview must be manually updated by calling | 153 | * start and ending with end. Theview must be manually updated by calling |
154 | * repaint. (?) | 154 | * repaint. (?) |
155 | */ | 155 | */ |
156 | void setSelectedDaysFrom(const QDate& start, const QDate& end); | 156 | void setSelectedDaysFrom(const QDate& start, const QDate& end); |
157 | void clearSelection(); | 157 | void clearSelection(); |
158 | 158 | ||
159 | /** Is today visible in the view? Keep this in sync with | 159 | /** Is today visible in the view? Keep this in sync with |
160 | * the values today (below) can take. | 160 | * the values today (below) can take. |
161 | */ | 161 | */ |
162 | bool isTodayVisible() const { return today>=0; } ; | 162 | bool isTodayVisible() const { return today>=0; } ; |
163 | 163 | ||
164 | /** If today is visible, then we can find out if today is | 164 | /** If today is visible, then we can find out if today is |
165 | * near the beginning or the end of the month. | 165 | * near the beginning or the end of the month. |
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(); |
178 | void updateViewTimed(); | 179 | void updateViewTimed(); |
179 | void repaintViewTimed(); | 180 | void repaintViewTimed(); |
180 | 181 | ||
181 | /** | 182 | /** |
182 | * Calculate which square in the matrix should be | 183 | * Calculate which square in the matrix should be |
183 | * hilighted to indicate it's today. | 184 | * hilighted to indicate it's today. |
184 | */ | 185 | */ |
185 | void recalculateToday(); | 186 | void recalculateToday(); |
186 | 187 | ||
187 | /* | 188 | /* |
188 | void setStartDate(QDate); | 189 | void setStartDate(QDate); |
189 | */ | 190 | */ |
190 | 191 | ||
191 | signals: | 192 | signals: |
192 | 193 | ||
193 | /** emitted if the user selects a block of days with the mouse by dragging a rectangle | 194 | /** emitted if the user selects a block of days with the mouse by dragging a rectangle |
194 | * inside the matrix | 195 | * inside the matrix |
195 | * | 196 | * |
@@ -203,48 +204,50 @@ signals: | |||
203 | */ | 204 | */ |
204 | void eventDropped(Event *event); | 205 | void eventDropped(Event *event); |
205 | 206 | ||
206 | protected: | 207 | protected: |
207 | 208 | ||
208 | void paintEvent(QPaintEvent *ev); | 209 | void paintEvent(QPaintEvent *ev); |
209 | 210 | ||
210 | void mousePressEvent (QMouseEvent* e); | 211 | void mousePressEvent (QMouseEvent* e); |
211 | 212 | ||
212 | void mouseReleaseEvent (QMouseEvent* e); | 213 | void mouseReleaseEvent (QMouseEvent* e); |
213 | 214 | ||
214 | void mouseMoveEvent (QMouseEvent* e); | 215 | void mouseMoveEvent (QMouseEvent* e); |
215 | 216 | ||
216 | void dragEnterEvent(QDragEnterEvent *); | 217 | void dragEnterEvent(QDragEnterEvent *); |
217 | 218 | ||
218 | void dragMoveEvent(QDragMoveEvent *); | 219 | void dragMoveEvent(QDragMoveEvent *); |
219 | 220 | ||
220 | void dragLeaveEvent(QDragLeaveEvent *); | 221 | void dragLeaveEvent(QDragLeaveEvent *); |
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 | ||
233 | /** returns the index of the day located at the matrix's widget (x,y) position. | 236 | /** returns the index of the day located at the matrix's widget (x,y) position. |
234 | * | 237 | * |
235 | * @param x horizontal coordinate | 238 | * @param x horizontal coordinate |
236 | * @param y vertical coordinate | 239 | * @param y vertical coordinate |
237 | */ | 240 | */ |
238 | int getDayIndexFrom(int x, int y); | 241 | int getDayIndexFrom(int x, int y); |
239 | 242 | ||
240 | /** calculates a "shaded" color from the supplied color object. | 243 | /** calculates a "shaded" color from the supplied color object. |
241 | * (Copied from Cornelius's kdpdatebutton.cpp) | 244 | * (Copied from Cornelius's kdpdatebutton.cpp) |
242 | * | 245 | * |
243 | * @param color source based on which a shaded color should be calculated. | 246 | * @param color source based on which a shaded color should be calculated. |
244 | */ | 247 | */ |
245 | QColor getShadedColor(QColor color); | 248 | QColor getShadedColor(QColor color); |
246 | 249 | ||
247 | /** number of days to be displayed. For now there is no support for any other number then 42. | 250 | /** number of days to be displayed. For now there is no support for any other number then 42. |
248 | so change it at your own risk :o) */ | 251 | so change it at your own risk :o) */ |
249 | static const int NUMDAYS; | 252 | static const int NUMDAYS; |
250 | 253 | ||