author | eilers <eilers> | 2003-08-01 14:19:44 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-08-01 14:19:44 (UTC) |
commit | 34991bac7d96b1c17601be6a5607819342571e0c (patch) (unidiff) | |
tree | 65d0bc2db22bcc1dc1b5eafdafd53b9cb08a6395 /core/pim/datebook/datebookday.cpp | |
parent | 5346424fc26bde232a15aa34fbb720f86218b26f (diff) | |
download | opie-34991bac7d96b1c17601be6a5607819342571e0c.zip opie-34991bac7d96b1c17601be6a5607819342571e0c.tar.gz opie-34991bac7d96b1c17601be6a5607819342571e0c.tar.bz2 |
Merging changes from BRANCH_1_0 to HEAD..
Diffstat (limited to 'core/pim/datebook/datebookday.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/pim/datebook/datebookday.cpp | 123 |
1 files changed, 117 insertions, 6 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index 0b213e9..f4008e9 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp | |||
@@ -12,24 +12,25 @@ | |||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qmessagebox.h> | 20 | #include <qmessagebox.h> |
21 | 21 | ||
22 | #include "datebookday.h" | 22 | #include "datebookday.h" |
23 | #include "datebookdayheaderimpl.h" | 23 | #include "datebookdayheaderimpl.h" |
24 | #include "datebookdayallday.h" | ||
24 | 25 | ||
25 | #include <qpe/datebookdb.h> | 26 | #include <qpe/datebookdb.h> |
26 | #include <qpe/resource.h> | 27 | #include <qpe/resource.h> |
27 | #include <qpe/event.h> | 28 | #include <qpe/event.h> |
28 | #include <qpe/qpeapplication.h> | 29 | #include <qpe/qpeapplication.h> |
29 | #include <qpe/timestring.h> | 30 | #include <qpe/timestring.h> |
30 | #include <qpe/qpedebug.h> | 31 | #include <qpe/qpedebug.h> |
31 | #include <qpe/ir.h> | 32 | #include <qpe/ir.h> |
32 | 33 | ||
33 | #include <qheader.h> | 34 | #include <qheader.h> |
34 | #include <qdatetime.h> | 35 | #include <qdatetime.h> |
35 | #include <qpainter.h> | 36 | #include <qpainter.h> |
@@ -202,58 +203,67 @@ DateBookDayViewQuickLineEdit::DateBookDayViewQuickLineEdit(const QDateTime &star | |||
202 | quickEvent.setEnd(end); | 203 | quickEvent.setEnd(end); |
203 | connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed())); | 204 | connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed())); |
204 | } | 205 | } |
205 | 206 | ||
206 | void DateBookDayViewQuickLineEdit::slotReturnPressed() | 207 | void DateBookDayViewQuickLineEdit::slotReturnPressed() |
207 | { | 208 | { |
208 | if(active && (!this->text().isEmpty())) {// Fix to avoid having this event beeing added multiple times. | 209 | if(active && (!this->text().isEmpty())) {// Fix to avoid having this event beeing added multiple times. |
209 | quickEvent.setDescription(this->text()); | 210 | quickEvent.setDescription(this->text()); |
210 | connect(this,SIGNAL(insertEvent(const Event &)),this->topLevelWidget(),SLOT(insertEvent(const Event &))); | 211 | connect(this,SIGNAL(insertEvent(const Event &)),this->topLevelWidget(),SLOT(insertEvent(const Event &))); |
211 | emit(insertEvent(quickEvent)); | 212 | emit(insertEvent(quickEvent)); |
212 | active=0; | 213 | active=0; |
213 | } | 214 | } |
214 | this->close(true);// Close and also delete this widget | 215 | /* we need to return to this object.. */ |
216 | QTimer::singleShot(500, this, SLOT(finallyCallClose()) );// Close and also delete this widget | ||
217 | } | ||
218 | void DateBookDayViewQuickLineEdit::finallyCallClose() { | ||
219 | close(true); // also deletes this widget... | ||
215 | } | 220 | } |
216 | 221 | ||
217 | void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent * e ) | 222 | void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent * e ) |
218 | { | 223 | { |
219 | slotReturnPressed(); // Reuse code to add event and close this widget. | 224 | slotReturnPressed(); // Reuse code to add event and close this widget. |
220 | } | 225 | } |
221 | 226 | ||
222 | //=========================================================================== | 227 | //=========================================================================== |
223 | 228 | ||
224 | DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name ) | 229 | DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name ) |
225 | : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 ) | 230 | : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 ) |
226 | { | 231 | { |
227 | widgetList.setAutoDelete( true ); | 232 | widgetList.setAutoDelete( true ); |
228 | header = new DateBookDayHeader( startOnMonday, this, "day header" ); | 233 | header = new DateBookDayHeader( startOnMonday, this, "day header" ); |
229 | header->setDate( currDate.year(), currDate.month(), currDate.day() ); | 234 | header->setDate( currDate.year(), currDate.month(), currDate.day() ); |
235 | |||
236 | m_allDays = new DatebookdayAllday(newDb, this, "all day event list" ); | ||
237 | m_allDays->hide(); | ||
238 | |||
230 | view = new DateBookDayView( ampm, this, "day view" ); | 239 | view = new DateBookDayView( ampm, this, "day view" ); |
231 | 240 | ||
232 | connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( int, int, int ) ) ); | 241 | connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( int, int, int ) ) ); |
233 | connect( header, SIGNAL( dateChanged( int, int, int ) ), view, SLOT( slotDateChanged( int, int, int ) ) ); | 242 | connect( header, SIGNAL( dateChanged( int, int, int ) ), view, SLOT( slotDateChanged( int, int, int ) ) ); |
234 | connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) ); | 243 | connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) ); |
235 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); | 244 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); |
236 | connect( view, SIGNAL(sigCapturedKey(const QString &)), this, SIGNAL(sigNewEvent(const QString&)) ); | 245 | connect( view, SIGNAL(sigCapturedKey(const QString &)), this, SIGNAL(sigNewEvent(const QString&)) ); |
237 | 246 | ||
238 | QTimer *timer = new QTimer( this ); | 247 | QTimer *timer = new QTimer( this ); |
239 | 248 | ||
240 | connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors | 249 | connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors |
241 | timer->start( 1000*60*5, FALSE ); //update every 5min | 250 | timer->start( 1000*60*5, FALSE ); //update every 5min |
242 | 251 | ||
243 | selectedWidget = 0; | 252 | selectedWidget = 0; |
244 | 253 | ||
245 | timeMarker = new DateBookDayTimeMarker( this ); | 254 | timeMarker = new DateBookDayTimeMarker( this ); |
246 | timeMarker->setTime( QTime::currentTime() ); | 255 | timeMarker->setTime( QTime::currentTime() ); |
247 | rowStyle = -1; // initialize with bogus values | 256 | rowStyle = -1; // initialize with bogus values |
257 | jumpToCurTime = false; | ||
248 | } | 258 | } |
249 | 259 | ||
250 | void DateBookDay::setJumpToCurTime( bool bJump ) | 260 | void DateBookDay::setJumpToCurTime( bool bJump ) |
251 | { | 261 | { |
252 | jumpToCurTime = bJump; | 262 | jumpToCurTime = bJump; |
253 | } | 263 | } |
254 | 264 | ||
255 | void DateBookDay::setRowStyle( int style ) | 265 | void DateBookDay::setRowStyle( int style ) |
256 | { | 266 | { |
257 | if (rowStyle != style) view->setRowStyle( style ); | 267 | if (rowStyle != style) view->setRowStyle( style ); |
258 | rowStyle = style; | 268 | rowStyle = style; |
259 | } | 269 | } |
@@ -334,35 +344,49 @@ void DateBookDay::dateChanged( int y, int m, int d ) | |||
334 | } | 344 | } |
335 | 345 | ||
336 | void DateBookDay::redraw() | 346 | void DateBookDay::redraw() |
337 | { | 347 | { |
338 | if ( isUpdatesEnabled() ) | 348 | if ( isUpdatesEnabled() ) |
339 | relayoutPage(); | 349 | relayoutPage(); |
340 | } | 350 | } |
341 | 351 | ||
342 | void DateBookDay::getEvents() | 352 | void DateBookDay::getEvents() |
343 | { | 353 | { |
344 | widgetList.clear(); | 354 | widgetList.clear(); |
345 | 355 | ||
356 | /* clear the AllDay List */ | ||
357 | m_allDays->hide(); // just in case | ||
358 | m_allDays->removeAllEvents(); | ||
359 | |||
346 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); | 360 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); |
347 | QValueListIterator<EffectiveEvent> it; | 361 | QValueListIterator<EffectiveEvent> it; |
362 | QObject* object = 0; | ||
348 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { | 363 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { |
349 | EffectiveEvent ev=*it; | 364 | EffectiveEvent ev=*it; |
350 | if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) {// Skip events ending at 00:00 starting at another day. | 365 | if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) {// Skip events ending at 00:00 starting at another day. |
366 | if (ev.event().type() == Event::AllDay ) { | ||
367 | object = m_allDays->addEvent( ev ); | ||
368 | if (!object) | ||
369 | continue; | ||
370 | }else { | ||
351 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); | 371 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); |
352 | connect( w, SIGNAL( deleteMe( const Event & ) ), this, SIGNAL( removeEvent( const Event & ) ) ); | ||
353 | connect( w, SIGNAL( duplicateMe( const Event & ) ), this, SIGNAL( duplicateEvent( const Event & ) ) ); | ||
354 | connect( w, SIGNAL( editMe( const Event & ) ), this, SIGNAL( editEvent( const Event & ) ) ); | ||
355 | connect( w, SIGNAL( beamMe( const Event & ) ), this, SIGNAL( beamEvent( const Event & ) ) ); | ||
356 | widgetList.append( w ); | 372 | widgetList.append( w ); |
373 | object = w; | ||
374 | } | ||
375 | |||
376 | connect( object, SIGNAL( deleteMe( const Event & ) ), this, SIGNAL( removeEvent( const Event & ) ) ); | ||
377 | connect( object, SIGNAL( duplicateMe( const Event & ) ), this, SIGNAL( duplicateEvent( const Event & ) ) ); | ||
378 | connect( object, SIGNAL( editMe( const Event & ) ), this, SIGNAL( editEvent( const Event & ) ) ); | ||
379 | connect( object, SIGNAL( beamMe( const Event & ) ), this, SIGNAL( beamEvent( const Event & ) ) ); | ||
380 | |||
357 | } | 381 | } |
358 | } | 382 | } |
359 | } | 383 | } |
360 | 384 | ||
361 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) | 385 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) |
362 | { | 386 | { |
363 | int place = 0; | 387 | int place = 0; |
364 | int start = item->event().start().hour(); | 388 | int start = item->event().start().hour(); |
365 | QTime e = item->event().end(); | 389 | QTime e = item->event().end(); |
366 | int end = e.hour(); | 390 | int end = e.hour(); |
367 | if ( e.minute() < 5 ) | 391 | if ( e.minute() < 5 ) |
368 | end--; | 392 | end--; |
@@ -387,27 +411,34 @@ static int place( const DateBookDayWidget *item, bool *used, int maxn ) | |||
387 | } | 411 | } |
388 | while( start <= end ) { | 412 | while( start <= end ) { |
389 | used[10*start+place] = TRUE; | 413 | used[10*start+place] = TRUE; |
390 | start++; | 414 | start++; |
391 | } | 415 | } |
392 | return place; | 416 | return place; |
393 | } | 417 | } |
394 | 418 | ||
395 | 419 | ||
396 | void DateBookDay::relayoutPage( bool fromResize ) | 420 | void DateBookDay::relayoutPage( bool fromResize ) |
397 | { | 421 | { |
398 | setUpdatesEnabled( FALSE ); | 422 | setUpdatesEnabled( FALSE ); |
399 | if ( !fromResize ) | 423 | if ( !fromResize ) { |
400 | getEvents(); // no need we already have them! | 424 | getEvents(); // no need we already have them! |
401 | 425 | ||
426 | if (m_allDays->items() > 0 ) | ||
427 | m_allDays->show(); | ||
428 | /* | ||
429 | * else if ( m_allDays->items() == 0 ) already hide in getEvents | ||
430 | */ | ||
431 | } | ||
432 | |||
402 | widgetList.sort(); | 433 | widgetList.sort(); |
403 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning | 434 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning |
404 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view | 435 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view |
405 | 436 | ||
406 | int wCount = widgetList.count(); | 437 | int wCount = widgetList.count(); |
407 | int wid = view->columnWidth(0)-1; | 438 | int wid = view->columnWidth(0)-1; |
408 | int wd; | 439 | int wd; |
409 | int n = 1; | 440 | int n = 1; |
410 | 441 | ||
411 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget | 442 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget |
412 | 443 | ||
413 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); | 444 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); |
@@ -721,50 +752,130 @@ void DateBookDayWidget::paintEvent( QPaintEvent *e ) | |||
721 | 752 | ||
722 | if ( ev.event().hasRepeat() ) { | 753 | if ( ev.event().hasRepeat() ) { |
723 | p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); | 754 | p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); |
724 | d = 20; | 755 | d = 20; |
725 | y += 20; | 756 | y += 20; |
726 | } | 757 | } |
727 | 758 | ||
728 | QSimpleRichText rt( text, font() ); | 759 | QSimpleRichText rt( text, font() ); |
729 | rt.setWidth( geom.width() - d - 6 ); | 760 | rt.setWidth( geom.width() - d - 6 ); |
730 | rt.draw( &p, 7, 0, e->region(), colorGroup() ); | 761 | rt.draw( &p, 7, 0, e->region(), colorGroup() ); |
731 | } | 762 | } |
732 | 763 | ||
764 | /* | ||
765 | * we need to find the real start date for a uid | ||
766 | * we need to check from one day to another... | ||
767 | */ | ||
768 | QDate DateBookDay::findRealStart( int uid, const QDate& isIncluded , DateBookDB* db) { | ||
769 | QDate dt( isIncluded ); | ||
770 | QDate fnd = dt; | ||
771 | |||
772 | bool doAgain = true; | ||
773 | do{ | ||
774 | dt = dt.addDays( -1 ); | ||
775 | QValueList<EffectiveEvent> events = db->getEffectiveEvents( dt, dt ); | ||
776 | for (QValueList<EffectiveEvent>::Iterator it = events.begin(); it != events.end(); ++it ) { | ||
777 | EffectiveEvent ev = (*it); | ||
778 | if ( uid == ev.event().uid() && ev.start() != QTime(0, 0, 0 ) ) | ||
779 | return ev.date(); | ||
780 | } | ||
781 | }while (doAgain ); | ||
782 | |||
783 | return fnd; | ||
784 | } | ||
785 | |||
733 | void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) | 786 | void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) |
734 | { | 787 | { |
735 | DateBookDayWidget *item; | 788 | DateBookDayWidget *item; |
736 | 789 | ||
737 | item = dateBook->getSelectedWidget(); | 790 | item = dateBook->getSelectedWidget(); |
738 | if (item) | 791 | if (item) |
739 | item->update(); | 792 | item->update(); |
740 | 793 | ||
741 | dateBook->setSelectedWidget(this); | 794 | dateBook->setSelectedWidget(this); |
742 | update(); | 795 | update(); |
743 | dateBook->repaint(); | 796 | dateBook->repaint(); |
744 | 797 | ||
745 | QPopupMenu m; | 798 | QPopupMenu m; |
746 | m.insertItem( tr( "Edit" ), 1 ); | 799 | m.insertItem( tr( "Edit" ), 1 ); |
747 | m.insertItem( tr( "Duplicate" ), 4 ); | 800 | m.insertItem( tr( "Duplicate" ), 4 ); |
748 | m.insertItem( tr( "Delete" ), 2 ); | 801 | m.insertItem( tr( "Delete" ), 2 ); |
749 | if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); | 802 | if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); |
803 | if(Ir::supported() && ev.event().doRepeat() ) m.insertItem( tr( "Beam this occurence"), 5 ); | ||
750 | int r = m.exec( e->globalPos() ); | 804 | int r = m.exec( e->globalPos() ); |
751 | if ( r == 1 ) { | 805 | if ( r == 1 ) { |
752 | emit editMe( ev.event() ); | 806 | emit editMe( ev.event() ); |
753 | } else if ( r == 2 ) { | 807 | } else if ( r == 2 ) { |
754 | emit deleteMe( ev.event() ); | 808 | emit deleteMe( ev.event() ); |
755 | } else if ( r == 3 ) { | 809 | } else if ( r == 3 ) { |
756 | emit beamMe( ev.event() ); | 810 | emit beamMe( ev.event() ); |
757 | } else if ( r == 4 ) { | 811 | } else if ( r == 4 ) { |
758 | emit duplicateMe( ev.event() ); | 812 | emit duplicateMe( ev.event() ); |
813 | } else if ( r == 5 ) { | ||
814 | // create an Event and beam it... | ||
815 | /* | ||
816 | * Start with the easy stuff. If start and end date is the same we can just use | ||
817 | * the values of effective events | ||
818 | * If it is a multi day event we need to find the real start and end date... | ||
819 | */ | ||
820 | if ( ev.event().start().date() == ev.event().end().date() ) { | ||
821 | Event event( ev.event() ); | ||
822 | |||
823 | QDateTime dt( ev.date(), ev.start() ); | ||
824 | event.setStart( dt ); | ||
825 | |||
826 | dt.setTime( ev.end() ); | ||
827 | event.setEnd( dt ); | ||
828 | emit beamMe( event ); | ||
829 | }else { | ||
830 | /* | ||
831 | * at least the the Times are right now | ||
832 | */ | ||
833 | QDateTime start( ev.event().start() ); | ||
834 | QDateTime end ( ev.event().end () ); | ||
835 | |||
836 | |||
837 | /* | ||
838 | * ok we know the start date or we need to find it | ||
839 | */ | ||
840 | if ( ev.start() != QTime( 0, 0, 0 ) ) { | ||
841 | start.setDate( ev.date() ); | ||
842 | }else { | ||
843 | QDate dt = DateBookDay::findRealStart( ev.event().uid(), ev.date(), dateBook->db ); | ||
844 | start.setDate( dt ); | ||
845 | } | ||
846 | |||
847 | |||
848 | /* | ||
849 | * ok we know now the end date... | ||
850 | * else | ||
851 | * get to know the offset btw the real start and real end | ||
852 | * and then add it to the new start date... | ||
853 | */ | ||
854 | if ( ev.end() != QTime(23, 59, 59 ) ) { | ||
855 | end.setDate( ev.date() ); | ||
856 | }else{ | ||
857 | int days = ev.event().start().date().daysTo( ev.event().end().date() ); | ||
858 | end.setDate( start.date().addDays( days ) ); | ||
859 | } | ||
860 | |||
861 | |||
862 | |||
863 | Event event( ev.event() ); | ||
864 | event.setStart( start ); | ||
865 | event.setEnd ( end ); | ||
866 | |||
867 | |||
868 | emit beamMe( event ); | ||
869 | } | ||
759 | } | 870 | } |
760 | } | 871 | } |
761 | 872 | ||
762 | void DateBookDayWidget::setGeometry( const QRect &r ) | 873 | void DateBookDayWidget::setGeometry( const QRect &r ) |
763 | { | 874 | { |
764 | geom = r; | 875 | geom = r; |
765 | setFixedSize( r.width()+1, r.height()+1 ); | 876 | setFixedSize( r.width()+1, r.height()+1 ); |
766 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); | 877 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); |
767 | show(); | 878 | show(); |
768 | } | 879 | } |
769 | 880 | ||
770 | 881 | ||