summaryrefslogtreecommitdiffabout
path: root/korganizer/kodaymatrix.cpp
authorzautrix <zautrix>2005-03-19 19:11:16 (UTC)
committer zautrix <zautrix>2005-03-19 19:11:16 (UTC)
commit414b033f0c39b5122fd4899408a7045a6c29d7c9 (patch) (unidiff)
tree802d40e62d1b55e9b3a2daca2ba74fc47af15137 /korganizer/kodaymatrix.cpp
parent0aa5a7dce6ac1224395f7cb3fae488ba566f0e38 (diff)
downloadkdepimpi-414b033f0c39b5122fd4899408a7045a6c29d7c9.zip
kdepimpi-414b033f0c39b5122fd4899408a7045a6c29d7c9.tar.gz
kdepimpi-414b033f0c39b5122fd4899408a7045a6c29d7c9.tar.bz2
dnc
Diffstat (limited to 'korganizer/kodaymatrix.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp49
1 files changed, 46 insertions, 3 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 989f758..a886f4a 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -78,28 +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
87const int KODayMatrix::NOSELECTION = -1000; 87const int KODayMatrix::NOSELECTION = -1000;
88const int KODayMatrix::NUMDAYS = 42; 88const int KODayMatrix::NUMDAYS = 42;
89 89
90KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
91 : QFrame( parent, name ), mCalendar( 0 )
92
93#if 0
90KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : 94KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) :
91 QFrame(parent, name) 95 QFrame(parent, name)
96#endif
92{ 97{
93 mCalendar = calendar; 98
94 mPendingUpdateBeforeRepaint = false; 99 mPendingUpdateBeforeRepaint = false;
95 100
96 // initialize dynamic arrays 101 // initialize dynamic arrays
97 days = new QDate[NUMDAYS]; 102 days = new QDate[NUMDAYS];
98 daylbls = new QString[NUMDAYS]; 103 daylbls = new QString[NUMDAYS];
99 events = new int[NUMDAYS]; 104 events = new int[NUMDAYS];
100 mToolTip = new DynamicTip(this); 105 mToolTip = new DynamicTip(this);
101 106
102 // set default values used for drawing the matrix 107 // set default values used for drawing the matrix
103 mDefaultBackColor = palette().active().base(); 108 mDefaultBackColor = palette().active().base();
104 mDefaultTextColor = palette().active().foreground(); 109 mDefaultTextColor = palette().active().foreground();
105 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 110 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
@@ -109,24 +114,32 @@ KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const
109 mSelEnd = mSelStart = NOSELECTION; 114 mSelEnd = mSelStart = NOSELECTION;
110 115
111 setAcceptDrops(true); 116 setAcceptDrops(true);
112 //setFont( QFont("Arial", 10) ); 117 //setFont( QFont("Arial", 10) );
113 118
114 mUpdateTimer = new QTimer( this ); 119 mUpdateTimer = new QTimer( this );
115 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); 120 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
116 mRepaintTimer = new QTimer( this ); 121 mRepaintTimer = new QTimer( this );
117 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); 122 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
118 mDayChanged = false; 123 mDayChanged = false;
119 updateView(); 124 updateView();
120} 125}
126void KODayMatrix::setCalendar( Calendar *cal )
127{
128 mCalendar = cal;
129
130 setAcceptDrops( mCalendar );
131
132 updateEvents();
133}
121 134
122QColor KODayMatrix::getShadedColor(QColor color) 135QColor KODayMatrix::getShadedColor(QColor color)
123{ 136{
124 QColor shaded; 137 QColor shaded;
125 int h=0; 138 int h=0;
126 int s=0; 139 int s=0;
127 int v=0; 140 int v=0;
128 color.hsv(&h,&s,&v); 141 color.hsv(&h,&s,&v);
129 s = s/4; 142 s = s/4;
130 v = 192+v/4; 143 v = 192+v/4;
131 shaded.setHsv(h,s,v); 144 shaded.setHsv(h,s,v);
132 145
@@ -177,24 +190,28 @@ void KODayMatrix::addSelectedDaysTo(DateList& selDays)
177 } else { 190 } else {
178 for (int i = i0; i <= mSelEnd; i++) { 191 for (int i = i0; i <= mSelEnd; i++) {
179 selDays.append(days[i]); 192 selDays.append(days[i]);
180 } 193 }
181 } 194 }
182} 195}
183 196
184void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 197void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
185{ 198{
186 mSelStart = startdate.daysTo(start); 199 mSelStart = startdate.daysTo(start);
187 mSelEnd = startdate.daysTo(end); 200 mSelEnd = startdate.daysTo(end);
188} 201}
202void KODayMatrix::clearSelection()
203{
204 mSelEnd = mSelStart = NOSELECTION;
205}
189 206
190 207
191void KODayMatrix::recalculateToday() 208void KODayMatrix::recalculateToday()
192{ 209{
193 today = -1; 210 today = -1;
194 for (int i=0; i<NUMDAYS; i++) { 211 for (int i=0; i<NUMDAYS; i++) {
195 events[i] = 0; 212 events[i] = 0;
196 days[i] = startdate.addDays(i); 213 days[i] = startdate.addDays(i);
197 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 214 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
198 215
199 // if today is in the currently displayed month, hilight today 216 // if today is in the currently displayed month, hilight today
200 if (days[i].year() == QDate::currentDate().year() && 217 if (days[i].year() == QDate::currentDate().year() &&
@@ -208,26 +225,30 @@ void KODayMatrix::recalculateToday()
208 225
209void KODayMatrix::updateView() 226void KODayMatrix::updateView()
210{ 227{
211 updateView(startdate); 228 updateView(startdate);
212} 229}
213void KODayMatrix::repaintViewTimed() 230void KODayMatrix::repaintViewTimed()
214{ 231{
215 mRepaintTimer->stop(); 232 mRepaintTimer->stop();
216 repaint(false); 233 repaint(false);
217} 234}
218void KODayMatrix::updateViewTimed() 235void KODayMatrix::updateViewTimed()
219{ 236{
220
221 mUpdateTimer->stop(); 237 mUpdateTimer->stop();
238 if ( !mCalendar ) {
239 qDebug("NOT CAL ");
240 return;
241 }
242 //qDebug("KODayMatrix::updateViewTimed ");
222 for(int i = 0; i < NUMDAYS; i++) { 243 for(int i = 0; i < NUMDAYS; i++) {
223 // if events are set for the day then remember to draw it bold 244 // if events are set for the day then remember to draw it bold
224 QPtrList<Event> eventlist = mCalendar->events(days[i]); 245 QPtrList<Event> eventlist = mCalendar->events(days[i]);
225 Event *event; 246 Event *event;
226 int numEvents = eventlist.count(); 247 int numEvents = eventlist.count();
227 QString holiStr = ""; 248 QString holiStr = "";
228 for(event=eventlist.first();event != 0;event=eventlist.next()) { 249 for(event=eventlist.first();event != 0;event=eventlist.next()) {
229 ushort recurType = event->recurrence()->doesRecur(); 250 ushort recurType = event->recurrence()->doesRecur();
230 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 251 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
231 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 252 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
232 numEvents--; 253 numEvents--;
233 } 254 }
@@ -285,24 +306,46 @@ void KODayMatrix::updateView(QDate actdate)
285 if ( !isVisible() ) { 306 if ( !isVisible() ) {
286 mPendingUpdateBeforeRepaint = true; 307 mPendingUpdateBeforeRepaint = true;
287 } else { 308 } else {
288#ifdef DESKTOP_VERSION 309#ifdef DESKTOP_VERSION
289 //mRepaintTimer->start( 250 ); 310 //mRepaintTimer->start( 250 );
290 mUpdateTimer->start( 250 ); 311 mUpdateTimer->start( 250 );
291#else 312#else
292 mRepaintTimer->start( 350 ); 313 mRepaintTimer->start( 350 );
293 mUpdateTimer->start( 2000 ); 314 mUpdateTimer->start( 2000 );
294#endif 315#endif
295 } 316 }
296} 317}
318void KODayMatrix::updateEvents()
319{
320 if ( !mCalendar ) return;
321
322 for( int i = 0; i < NUMDAYS; i++ ) {
323 // if events are set for the day then remember to draw it bold
324 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
325 int numEvents = eventlist.count();
326 Event *event;
327 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
328 ushort recurType = event->doesRecur();
329
330 if ( ( recurType == Recurrence::rDaily &&
331 !KOPrefs::instance()->mDailyRecur ) ||
332 ( recurType == Recurrence::rWeekly &&
333 !KOPrefs::instance()->mWeeklyRecur ) ) {
334 numEvents--;
335 }
336 }
337 events[ i ] = numEvents;
338 }
339}
297 340
298const QDate& KODayMatrix::getDate(int offset) 341const QDate& KODayMatrix::getDate(int offset)
299{ 342{
300 if (offset < 0 || offset > NUMDAYS-1) { 343 if (offset < 0 || offset > NUMDAYS-1) {
301 qDebug("Wrong offset2 "); 344 qDebug("Wrong offset2 ");
302 return days[0]; 345 return days[0];
303 } 346 }
304 return days[offset]; 347 return days[offset];
305} 348}
306 349
307QString KODayMatrix::getHolidayLabel(int offset) 350QString KODayMatrix::getHolidayLabel(int offset)
308{ 351{
@@ -419,25 +462,25 @@ void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
419{ 462{
420#ifndef KORG_NODND 463#ifndef KORG_NODND
421// setPalette(oldPalette); 464// setPalette(oldPalette);
422// update(); 465// update();
423#endif 466#endif
424} 467}
425 468
426void KODayMatrix::dropEvent(QDropEvent *e) 469void KODayMatrix::dropEvent(QDropEvent *e)
427{ 470{
428#ifndef KORG_NODND 471#ifndef KORG_NODND
429// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; 472// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
430 473
431 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 474 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
432 e->ignore(); 475 e->ignore();
433 return; 476 return;
434 } 477 }
435 478
436 DndFactory factory( mCalendar ); 479 DndFactory factory( mCalendar );
437 Event *event = factory.createDrop(e); 480 Event *event = factory.createDrop(e);
438 481
439 if (event) { 482 if (event) {
440 e->acceptAction(); 483 e->acceptAction();
441 484
442 Event *existingEvent = mCalendar->event(event->uid()); 485 Event *existingEvent = mCalendar->event(event->uid());
443 486