Diffstat (limited to 'core/pim/datebook/datebookday.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/datebookday.cpp | 236 |
1 files changed, 211 insertions, 25 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index 67a88e9..c15ccef 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp | |||
@@ -19,2 +19,3 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qmessagebox.h> | ||
20 | 21 | ||
@@ -38,2 +39,4 @@ | |||
38 | 39 | ||
40 | #include <qtimer.h> | ||
41 | |||
39 | DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, | 42 | DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, |
@@ -59,2 +62,3 @@ DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, | |||
59 | setItem( row, 0, tmp ); | 62 | setItem( row, 0, tmp ); |
63 | setRowHeight( row, 40); | ||
60 | } | 64 | } |
@@ -121,5 +125,9 @@ void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) | |||
121 | QPen pen( p->pen() ); | 125 | QPen pen( p->pen() ); |
122 | p->setPen( colorGroup().mid() ); | 126 | p->setPen( colorGroup().dark() ); |
123 | p->drawLine( x2, 0, x2, y2 ); | 127 | p->drawLine( x2, 0, x2, y2 ); |
124 | p->drawLine( 0, y2, x2, y2 ); | 128 | p->drawLine( 0, y2, x2, y2 ); |
129 | |||
130 | p->setPen( colorGroup().midlight() ); | ||
131 | p->drawLine( 0, y2 - h/2, x2, y2 - h/2); | ||
132 | |||
125 | p->setPen( pen ); | 133 | p->setPen( pen ); |
@@ -176,2 +184,29 @@ DateBookDay::DateBookDay( bool ampm, bool startOnMonday, | |||
176 | this, SIGNAL(sigNewEvent(const QString&)) ); | 184 | this, SIGNAL(sigNewEvent(const QString&)) ); |
185 | |||
186 | QTimer *timer = new QTimer( this ); | ||
187 | |||
188 | connect( timer, SIGNAL(timeout()), | ||
189 | this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors | ||
190 | timer->start( 1000*60*5, FALSE ); //update every 5min | ||
191 | |||
192 | selectedWidget = 0; | ||
193 | |||
194 | timeMarker = new DateBookDayTimeMarker( this ); | ||
195 | timeMarker->setTime( QTime::currentTime() ); | ||
196 | } | ||
197 | |||
198 | void DateBookDay::updateView( void ) | ||
199 | { | ||
200 | timeMarker->setTime( QTime::currentTime() ); | ||
201 | //need to find a way to update all DateBookDayWidgets | ||
202 | } | ||
203 | |||
204 | void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) | ||
205 | { | ||
206 | selectedWidget = w; | ||
207 | } | ||
208 | |||
209 | DateBookDayWidget * DateBookDay::getSelectedWidget( void ) | ||
210 | { | ||
211 | return selectedWidget; | ||
177 | } | 212 | } |
@@ -204,2 +239,4 @@ void DateBookDay::setDate( int y, int m, int d ) | |||
204 | header->setDate( y, m, d ); | 239 | header->setDate( y, m, d ); |
240 | |||
241 | selectedWidget = 0; | ||
205 | } | 242 | } |
@@ -209,2 +246,4 @@ void DateBookDay::setDate( QDate d) | |||
209 | header->setDate( d.year(), d.month(), d.day() ); | 246 | header->setDate( d.year(), d.month(), d.day() ); |
247 | |||
248 | selectedWidget = 0; | ||
210 | } | 249 | } |
@@ -223,2 +262,8 @@ void DateBookDay::dateChanged( int y, int m, int d ) | |||
223 | dayView()->addSelection( ts ); | 262 | dayView()->addSelection( ts ); |
263 | |||
264 | selectedWidget = 0; | ||
265 | |||
266 | if (this->date() == QDate::currentDate()) | ||
267 | timeMarker->show(); else timeMarker->hide(); | ||
268 | |||
224 | } | 269 | } |
@@ -248,2 +293,3 @@ void DateBookDay::getEvents() | |||
248 | } | 293 | } |
294 | |||
249 | } | 295 | } |
@@ -290,32 +336,73 @@ void DateBookDay::relayoutPage( bool fromResize ) | |||
290 | 336 | ||
337 | widgetList.sort(); | ||
338 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning | ||
339 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view | ||
340 | |||
291 | int wCount = widgetList.count(); | 341 | int wCount = widgetList.count(); |
292 | int wid = view->columnWidth(0)-1; | 342 | int wid = view->columnWidth(0)-1; |
343 | int wd; | ||
293 | int n = 1; | 344 | int n = 1; |
294 | 345 | ||
346 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget | ||
347 | |||
348 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); | ||
349 | |||
295 | if ( wCount < 20 ) { | 350 | if ( wCount < 20 ) { |
296 | for ( int i = 0; i < wCount; ) { | 351 | |
352 | QArray<QRect> geometries(wCount); | ||
353 | for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector | ||
354 | |||
355 | for ( int i = 0; i < wCount; i++) | ||
356 | { | ||
357 | QValueList<int> intersectedWidgets; | ||
358 | |||
359 | //find all widgets intersecting with widgetList.at(i) | ||
360 | for ( int j = 0; j < wCount; j++) | ||
361 | if (i != j) | ||
362 | if (geometries[j].intersects(geometries[i])) | ||
363 | intersectedWidgets.append(j); | ||
364 | |||
365 | //for each of these intersecting widgets find out how many widgets are they intersecting with | ||
366 | for ( uint j = 0; j < intersectedWidgets.count(); j++) | ||
367 | { | ||
368 | QArray<int> inter(wCount); | ||
369 | inter[j]=1; | ||
370 | |||
371 | if (intersectedWidgets[j] != -1) | ||
372 | for ( uint k = j; k < intersectedWidgets.count(); k++) | ||
373 | if (j != k && intersectedWidgets[k] != -1) | ||
374 | if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) | ||
375 | { | ||
376 | inter[j]++; | ||
377 | intersectedWidgets[k] = -1; | ||
378 | } | ||
379 | if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; | ||
380 | } | ||
381 | |||
382 | if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; | ||
383 | } | ||
384 | |||
385 | |||
386 | for ( int i = 0; i < wCount; i++) { | ||
297 | DateBookDayWidget *w = widgetList.at(i); | 387 | DateBookDayWidget *w = widgetList.at(i); |
298 | int x = 0; | ||
299 | int xp = 0; | ||
300 | QRect geom = w->geometry(); | 388 | QRect geom = w->geometry(); |
301 | geom.setX( x ); | 389 | |
302 | geom.setWidth( wid ); | 390 | geom.setX( 0 ); |
303 | while ( xp < n && intersects( w, geom ) ) { | 391 | |
304 | x += wid; | 392 | wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); |
305 | xp++; | 393 | |
306 | geom.moveBy( wid, 0 ); | 394 | geom.setWidth( wd ); |
307 | } | 395 | |
308 | if ( xp >= n ) { | 396 | while ( intersects( w, geom ) ) { |
309 | n++; | 397 | geom.moveBy( wd + 2 + 1, 0 ); |
310 | wid = ( view->columnWidth(0)-1 ) / n; | ||
311 | i = 0; | ||
312 | } else { | ||
313 | w->setGeometry( geom ); | ||
314 | i++; | ||
315 | } | 398 | } |
399 | w->setGeometry( geom ); | ||
316 | } | 400 | } |
401 | |||
317 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); | 402 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); |
403 | |||
404 | |||
318 | } else { | 405 | } else { |
319 | 406 | ||
320 | 407 | ||
321 | int hours[24]; | 408 | int hours[24]; |
@@ -345,6 +432,6 @@ void DateBookDay::relayoutPage( bool fromResize ) | |||
345 | wid = ( view->columnWidth(0)-1 ) / n; | 432 | wid = ( view->columnWidth(0)-1 ) / n; |
346 | 433 | ||
347 | bool used[24*10]; | 434 | bool used[24*10]; |
348 | memset( used, FALSE, 24*10*sizeof( bool ) ); | 435 | memset( used, FALSE, 24*10*sizeof( bool ) ); |
349 | 436 | ||
350 | for ( int i = 0; i < wCount; i++ ) { | 437 | for ( int i = 0; i < wCount; i++ ) { |
@@ -354,3 +441,3 @@ void DateBookDay::relayoutPage( bool fromResize ) | |||
354 | QRect geom = w->geometry(); | 441 | QRect geom = w->geometry(); |
355 | geom.setX( xp*wid ); | 442 | geom.setX( xp*(wid+2) ); |
356 | geom.setWidth( wid ); | 443 | geom.setWidth( wid ); |
@@ -361,2 +448,5 @@ void DateBookDay::relayoutPage( bool fromResize ) | |||
361 | } | 448 | } |
449 | |||
450 | timeMarker->setTime( QTime::currentTime() );//display timeMarker | ||
451 | timeMarker->raise(); //on top of all widgets | ||
362 | setUpdatesEnabled( TRUE ); | 452 | setUpdatesEnabled( TRUE ); |
@@ -498,2 +588,5 @@ DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, | |||
498 | geom.setHeight( h ); | 588 | geom.setHeight( h ); |
589 | geom.setX( 0 ); | ||
590 | geom.setWidth(dateBook->dayView()->columnWidth(0)-1); | ||
591 | |||
499 | } | 592 | } |
@@ -507,6 +600,36 @@ void DateBookDayWidget::paintEvent( QPaintEvent *e ) | |||
507 | QPainter p( this ); | 600 | QPainter p( this ); |
601 | |||
602 | if (dateBook->getSelectedWidget() == this) | ||
603 | { | ||
604 | p.setBrush( QColor( 155, 240, 230 ) ); // selected item | ||
605 | } else | ||
606 | { | ||
607 | if (dateBook->date() == QDate::currentDate()) | ||
608 | { | ||
609 | QTime curTime = QTime::currentTime(); | ||
610 | |||
611 | if (ev.end() < curTime) | ||
612 | { | ||
613 | p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive | ||
614 | } else | ||
615 | { | ||
616 | //change color in dependence of the time till the event starts | ||
617 | int duration = curTime.secsTo(ev.start()); | ||
618 | if (duration < 0) duration = 0; | ||
619 | int colChange = duration*160/86400; //86400: secs per day, 160: max color shift | ||
620 | |||
621 | p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue | ||
622 | } | ||
623 | } else | ||
624 | { | ||
625 | p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date) | ||
626 | //perhaps make a distinction between future/past dates | ||
627 | } | ||
628 | } | ||
629 | |||
508 | p.setPen( QColor(100, 100, 100) ); | 630 | p.setPen( QColor(100, 100, 100) ); |
509 | p.setBrush( QColor( 255, 240, 230 ) ); // based on priority? | ||
510 | p.drawRect(rect()); | 631 | p.drawRect(rect()); |
511 | 632 | ||
633 | // p.drawRect(0,0, 5, height()); | ||
634 | |||
512 | int y = 0; | 635 | int y = 0; |
@@ -527,3 +650,3 @@ void DateBookDayWidget::paintEvent( QPaintEvent *e ) | |||
527 | rt.setWidth( geom.width() - d - 6 ); | 650 | rt.setWidth( geom.width() - d - 6 ); |
528 | rt.draw( &p, 3, 0, e->region(), colorGroup() ); | 651 | rt.draw( &p, 7, 0, e->region(), colorGroup() ); |
529 | } | 652 | } |
@@ -532,2 +655,11 @@ void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) | |||
532 | { | 655 | { |
656 | DateBookDayWidget *item; | ||
657 | |||
658 | item = dateBook->getSelectedWidget(); | ||
659 | if (item) item->update(); | ||
660 | |||
661 | dateBook->setSelectedWidget(this); | ||
662 | update(); | ||
663 | dateBook->repaint(); | ||
664 | |||
533 | QPopupMenu m; | 665 | QPopupMenu m; |
@@ -553 +685,55 @@ void DateBookDayWidget::setGeometry( const QRect &r ) | |||
553 | } | 685 | } |
686 | |||
687 | |||
688 | //--------------------------------------------------------------------------------------------- | ||
689 | //--------------------------------------------------------------------------------------------- | ||
690 | |||
691 | |||
692 | DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) | ||
693 | : QWidget( db->dayView()->viewport() ), dateBook( db ) | ||
694 | { | ||
695 | setBackgroundMode( PaletteBase ); | ||
696 | } | ||
697 | |||
698 | DateBookDayTimeMarker::~DateBookDayTimeMarker() | ||
699 | { | ||
700 | } | ||
701 | |||
702 | void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ ) | ||
703 | { | ||
704 | QPainter p( this ); | ||
705 | p.setBrush( QColor( 255, 0, 0 ) ); | ||
706 | |||
707 | QPen pen; | ||
708 | pen.setStyle(NoPen); | ||
709 | |||
710 | p.setPen( pen ); | ||
711 | p.drawRect(rect()); | ||
712 | } | ||
713 | |||
714 | void DateBookDayTimeMarker::setTime( const QTime &t ) | ||
715 | { | ||
716 | int y = t.hour()*60+t.minute(); | ||
717 | int rh = dateBook->dayView()->rowHeight(0); | ||
718 | y = y*rh/60; | ||
719 | |||
720 | geom.setX( 0 ); | ||
721 | |||
722 | int x = dateBook->dayView()->columnWidth(0)-1; | ||
723 | geom.setWidth( x ); | ||
724 | |||
725 | geom.setY( y ); | ||
726 | geom.setHeight( 1 ); | ||
727 | |||
728 | setGeometry( geom ); | ||
729 | |||
730 | time = t; | ||
731 | } | ||
732 | |||
733 | void DateBookDayTimeMarker::setGeometry( const QRect &r ) | ||
734 | { | ||
735 | geom = r; | ||
736 | setFixedSize( r.width()+1, r.height()+1 ); | ||
737 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); | ||
738 | show(); | ||
739 | } | ||