From 34991bac7d96b1c17601be6a5607819342571e0c Mon Sep 17 00:00:00 2001 From: eilers Date: Fri, 01 Aug 2003 14:19:44 +0000 Subject: Merging changes from BRANCH_1_0 to HEAD.. --- (limited to 'core/pim/datebook/datebookday.cpp') 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 @@ -21,6 +21,7 @@ #include "datebookday.h" #include "datebookdayheaderimpl.h" +#include "datebookdayallday.h" #include #include @@ -211,7 +212,11 @@ void DateBookDayViewQuickLineEdit::slotReturnPressed() emit(insertEvent(quickEvent)); active=0; } - this->close(true); // Close and also delete this widget + /* we need to return to this object.. */ + QTimer::singleShot(500, this, SLOT(finallyCallClose()) ); // Close and also delete this widget +} +void DateBookDayViewQuickLineEdit::finallyCallClose() { + close(true); // also deletes this widget... } void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent * e ) @@ -227,6 +232,10 @@ DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWid widgetList.setAutoDelete( true ); header = new DateBookDayHeader( startOnMonday, this, "day header" ); header->setDate( currDate.year(), currDate.month(), currDate.day() ); + + m_allDays = new DatebookdayAllday(newDb, this, "all day event list" ); + m_allDays->hide(); + view = new DateBookDayView( ampm, this, "day view" ); connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( int, int, int ) ) ); @@ -245,6 +254,7 @@ DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWid timeMarker = new DateBookDayTimeMarker( this ); timeMarker->setTime( QTime::currentTime() ); rowStyle = -1; // initialize with bogus values + jumpToCurTime = false; } void DateBookDay::setJumpToCurTime( bool bJump ) @@ -343,17 +353,31 @@ void DateBookDay::getEvents() { widgetList.clear(); + /* clear the AllDay List */ + m_allDays->hide(); // just in case + m_allDays->removeAllEvents(); + QValueList eventList = db->getEffectiveEvents( currDate, currDate ); QValueListIterator it; + QObject* object = 0; for ( it = eventList.begin(); it != eventList.end(); ++it ) { EffectiveEvent ev=*it; if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) { // Skip events ending at 00:00 starting at another day. + if (ev.event().type() == Event::AllDay ) { + object = m_allDays->addEvent( ev ); + if (!object) + continue; + }else { DateBookDayWidget* w = new DateBookDayWidget( *it, this ); - connect( w, SIGNAL( deleteMe( const Event & ) ), this, SIGNAL( removeEvent( const Event & ) ) ); - connect( w, SIGNAL( duplicateMe( const Event & ) ), this, SIGNAL( duplicateEvent( const Event & ) ) ); - connect( w, SIGNAL( editMe( const Event & ) ), this, SIGNAL( editEvent( const Event & ) ) ); - connect( w, SIGNAL( beamMe( const Event & ) ), this, SIGNAL( beamEvent( const Event & ) ) ); - widgetList.append( w ); + widgetList.append( w ); + object = w; + } + + connect( object, SIGNAL( deleteMe( const Event & ) ), this, SIGNAL( removeEvent( const Event & ) ) ); + connect( object, SIGNAL( duplicateMe( const Event & ) ), this, SIGNAL( duplicateEvent( const Event & ) ) ); + connect( object, SIGNAL( editMe( const Event & ) ), this, SIGNAL( editEvent( const Event & ) ) ); + connect( object, SIGNAL( beamMe( const Event & ) ), this, SIGNAL( beamEvent( const Event & ) ) ); + } } } @@ -396,9 +420,16 @@ static int place( const DateBookDayWidget *item, bool *used, int maxn ) void DateBookDay::relayoutPage( bool fromResize ) { setUpdatesEnabled( FALSE ); - if ( !fromResize ) + if ( !fromResize ) { getEvents(); // no need we already have them! + if (m_allDays->items() > 0 ) + m_allDays->show(); + /* + * else if ( m_allDays->items() == 0 ) already hide in getEvents + */ + } + widgetList.sort(); //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view @@ -730,6 +761,28 @@ void DateBookDayWidget::paintEvent( QPaintEvent *e ) rt.draw( &p, 7, 0, e->region(), colorGroup() ); } +/* + * we need to find the real start date for a uid + * we need to check from one day to another... + */ +QDate DateBookDay::findRealStart( int uid, const QDate& isIncluded , DateBookDB* db) { + QDate dt( isIncluded ); + QDate fnd = dt; + + bool doAgain = true; + do{ + dt = dt.addDays( -1 ); + QValueList events = db->getEffectiveEvents( dt, dt ); + for (QValueList::Iterator it = events.begin(); it != events.end(); ++it ) { + EffectiveEvent ev = (*it); + if ( uid == ev.event().uid() && ev.start() != QTime(0, 0, 0 ) ) + return ev.date(); + } + }while (doAgain ); + + return fnd; +} + void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) { DateBookDayWidget *item; @@ -747,6 +800,7 @@ void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) m.insertItem( tr( "Duplicate" ), 4 ); m.insertItem( tr( "Delete" ), 2 ); if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); + if(Ir::supported() && ev.event().doRepeat() ) m.insertItem( tr( "Beam this occurence"), 5 ); int r = m.exec( e->globalPos() ); if ( r == 1 ) { emit editMe( ev.event() ); @@ -756,7 +810,64 @@ void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) emit beamMe( ev.event() ); } else if ( r == 4 ) { emit duplicateMe( ev.event() ); - } + } else if ( r == 5 ) { + // create an Event and beam it... + /* + * Start with the easy stuff. If start and end date is the same we can just use + * the values of effective events + * If it is a multi day event we need to find the real start and end date... + */ + if ( ev.event().start().date() == ev.event().end().date() ) { + Event event( ev.event() ); + + QDateTime dt( ev.date(), ev.start() ); + event.setStart( dt ); + + dt.setTime( ev.end() ); + event.setEnd( dt ); + emit beamMe( event ); + }else { + /* + * at least the the Times are right now + */ + QDateTime start( ev.event().start() ); + QDateTime end ( ev.event().end () ); + + + /* + * ok we know the start date or we need to find it + */ + if ( ev.start() != QTime( 0, 0, 0 ) ) { + start.setDate( ev.date() ); + }else { + QDate dt = DateBookDay::findRealStart( ev.event().uid(), ev.date(), dateBook->db ); + start.setDate( dt ); + } + + + /* + * ok we know now the end date... + * else + * get to know the offset btw the real start and real end + * and then add it to the new start date... + */ + if ( ev.end() != QTime(23, 59, 59 ) ) { + end.setDate( ev.date() ); + }else{ + int days = ev.event().start().date().daysTo( ev.event().end().date() ); + end.setDate( start.date().addDays( days ) ); + } + + + + Event event( ev.event() ); + event.setStart( start ); + event.setEnd ( end ); + + + emit beamMe( event ); + } + } } void DateBookDayWidget::setGeometry( const QRect &r ) -- cgit v0.9.0.2