author | eilers <eilers> | 2003-08-01 14:19:44 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-08-01 14:19:44 (UTC) |
commit | 34991bac7d96b1c17601be6a5607819342571e0c (patch) (side-by-side diff) | |
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 @@ -1,47 +1,48 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include <qmessagebox.h> #include "datebookday.h" #include "datebookdayheaderimpl.h" +#include "datebookdayallday.h" #include <qpe/datebookdb.h> #include <qpe/resource.h> #include <qpe/event.h> #include <qpe/qpeapplication.h> #include <qpe/timestring.h> #include <qpe/qpedebug.h> #include <qpe/ir.h> #include <qheader.h> #include <qdatetime.h> #include <qpainter.h> #include <qsimplerichtext.h> #include <qpopupmenu.h> #include <qtextcodec.h> #include <qpalette.h> #include <qlineedit.h> #include <qtimer.h> DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, const char *name ) : QTable( 24, 1, parent, name ), ampm( whichClock ), currDate( QDate::currentDate() ) { @@ -190,82 +191,91 @@ void DateBookDayView::contentsMouseReleaseEvent( QMouseEvent *e ) quickLineEdit->setGeometry(0,0,this->columnWidth(0)-1,this->rowHeight(0)); this->moveChild(quickLineEdit,0,sh*this->rowHeight(0)); quickLineEdit->setFocus(); quickLineEdit->show(); } //=========================================================================== DateBookDayViewQuickLineEdit::DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name) : QLineEdit(parent,name) { active=1; quickEvent.setStart(start); quickEvent.setEnd(end); connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed())); } void DateBookDayViewQuickLineEdit::slotReturnPressed() { if(active && (!this->text().isEmpty())) { // Fix to avoid having this event beeing added multiple times. quickEvent.setDescription(this->text()); connect(this,SIGNAL(insertEvent(const Event &)),this->topLevelWidget(),SLOT(insertEvent(const Event &))); 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 ) { slotReturnPressed(); // Reuse code to add event and close this widget. } //=========================================================================== DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name ) : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 ) { 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 ) ) ); connect( header, SIGNAL( dateChanged( int, int, int ) ), view, SLOT( slotDateChanged( int, int, int ) ) ); connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) ); connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); connect( view, SIGNAL(sigCapturedKey(const QString &)), this, SIGNAL(sigNewEvent(const QString&)) ); QTimer *timer = new QTimer( this ); connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) ); //connect timer for updating timeMarker & daywidgetcolors timer->start( 1000*60*5, FALSE ); //update every 5min selectedWidget = 0; timeMarker = new DateBookDayTimeMarker( this ); timeMarker->setTime( QTime::currentTime() ); rowStyle = -1; // initialize with bogus values + jumpToCurTime = false; } void DateBookDay::setJumpToCurTime( bool bJump ) { jumpToCurTime = bJump; } void DateBookDay::setRowStyle( int style ) { if (rowStyle != style) view->setRowStyle( style ); rowStyle = style; } void DateBookDay::updateView( void ) { timeMarker->setTime( QTime::currentTime() ); //need to find a way to update all DateBookDayWidgets } void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) { selectedWidget = w; } @@ -322,104 +332,125 @@ void DateBookDay::dateChanged( int y, int m, int d ) if (jumpToCurTime && this->date() == QDate::currentDate()) { ts.init( QTime::currentTime().hour(), 0); ts.expandTo( QTime::currentTime().hour(), 0); } else { ts.init( startTime, 0 ); ts.expandTo( startTime, 0 ); } dayView()->addSelection( ts ); selectedWidget = 0; } void DateBookDay::redraw() { if ( isUpdatesEnabled() ) relayoutPage(); } void DateBookDay::getEvents() { widgetList.clear(); + /* clear the AllDay List */ + m_allDays->hide(); // just in case + m_allDays->removeAllEvents(); + QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); QValueListIterator<EffectiveEvent> 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 ); + 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 & ) ) ); + } } } static int place( const DateBookDayWidget *item, bool *used, int maxn ) { int place = 0; int start = item->event().start().hour(); QTime e = item->event().end(); int end = e.hour(); if ( e.minute() < 5 ) end--; if ( end < start ) end = start; while ( place < maxn ) { bool free = TRUE; int s = start; while( s <= end ) { if ( used[10*s+place] ) { free = FALSE; break; } s++; } if ( free ) break; place++; } if ( place == maxn ) { return -1; } while( start <= end ) { used[10*start+place] = TRUE; start++; } return place; } 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 int wCount = widgetList.count(); int wid = view->columnWidth(0)-1; int wd; int n = 1; QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); if ( wCount < 20 ) { QArray<QRect> geometries(wCount); for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++); //stores geometry for each widget in vector for ( int i = 0; i < wCount; i++) { QValueList<int> intersectedWidgets; //find all widgets intersecting with widgetList.at(i) for ( int j = 0; j < wCount; j++) { if (i != j) @@ -709,74 +740,154 @@ void DateBookDayWidget::paintEvent( QPaintEvent *e ) p.drawRect(rect()); // p.drawRect(0,0, 5, height()); int y = 0; int d = 0; if ( ev.event().hasAlarm() ) { p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); y = 20; d = 20; } if ( ev.event().hasRepeat() ) { p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); d = 20; y += 20; } QSimpleRichText rt( text, font() ); rt.setWidth( geom.width() - d - 6 ); 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<EffectiveEvent> events = db->getEffectiveEvents( dt, dt ); + for (QValueList<EffectiveEvent>::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; item = dateBook->getSelectedWidget(); if (item) item->update(); dateBook->setSelectedWidget(this); update(); dateBook->repaint(); QPopupMenu m; m.insertItem( tr( "Edit" ), 1 ); 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() ); } else if ( r == 2 ) { emit deleteMe( ev.event() ); } else if ( r == 3 ) { 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 ) { geom = r; setFixedSize( r.width()+1, r.height()+1 ); dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); show(); } //--------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------- DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) : QWidget( db->dayView()->viewport() ), dateBook( db ) { setBackgroundMode( PaletteBase ); } DateBookDayTimeMarker::~DateBookDayTimeMarker() { |