author | umopapisdn <umopapisdn> | 2003-03-28 11:58:29 (UTC) |
---|---|---|
committer | umopapisdn <umopapisdn> | 2003-03-28 11:58:29 (UTC) |
commit | 6cee1b34ffc7b3b8a0c8e1831fff0cc1af0e708a (patch) (side-by-side diff) | |
tree | 4b25e548986b560f2fbe5f91ce61491046dcc361 | |
parent | 469731b3a6cb94037330d1f40398bede57a7c0f2 (diff) | |
download | opie-6cee1b34ffc7b3b8a0c8e1831fff0cc1af0e708a.zip opie-6cee1b34ffc7b3b8a0c8e1831fff0cc1af0e708a.tar.gz opie-6cee1b34ffc7b3b8a0c8e1831fff0cc1af0e708a.tar.bz2 |
Bugfix: (Bug #000782) Display events with no duration, unless it's an "effective event" ending at 00:00 starting at a previous day. (i.e ending at midnight)
-rw-r--r-- | core/pim/datebook/datebookday.cpp | 2 | ||||
-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 2 | ||||
-rw-r--r-- | core/pim/datebook/datebookweeklst.cpp | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index 5d472a6..af98e06 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp @@ -1,696 +1,696 @@ /********************************************************************** ** 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 <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 <qtimer.h> DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, const char *name ) : QTable( 24, 1, parent, name ), ampm( whichClock ) { enableClipper(TRUE); setTopMargin( 0 ); horizontalHeader()->hide(); setLeftMargin(38); setColumnStretchable( 0, TRUE ); setHScrollBarMode( QScrollView::AlwaysOff ); verticalHeader()->setPalette(white); verticalHeader()->setResizeEnabled(FALSE); setSelectionMode( Single ); // get rid of being able to edit things... QTableItem *tmp; int row; for ( row = 0; row < numRows(); row++ ) { tmp = new QTableItem( this, QTableItem::Never, QString::null); setItem( row, 0, tmp ); //setRowHeight( row, 40); } initHeader(); QObject::connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotChangeClock(bool)) ); } void DateBookDayView::initHeader() { QString strTmp; for ( int i = 0; i < 24; ++i ) { if ( ampm ) { if ( i == 0 ) strTmp = QString::number(12) + ":00"; else if ( i == 12 ) strTmp = QString::number(12) + tr(":00p"); else if ( i > 12 ) strTmp = QString::number( i - 12 ) + tr(":00p"); else strTmp = QString::number(i) + ":00"; } else { if ( i < 10 ) strTmp = "0" + QString::number(i) + ":00"; else strTmp = QString::number(i) + ":00"; } strTmp = strTmp.rightJustify( 6, ' ' ); verticalHeader()->setLabel( i, strTmp ); setRowStretchable( i, FALSE ); } } void DateBookDayView::slotChangeClock( bool newClock ) { ampm = newClock; initHeader(); } bool DateBookDayView::whichClock() const { return ampm; } void DateBookDayView::moveUp() { scrollBy(0, -20); } void DateBookDayView::moveDown() { scrollBy(0, 20); } void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) { int w = cr.width(); int h = cr.height(); p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); if ( showGrid() ) { // Draw our lines int x2 = w - 1; int y2 = h - 1; QPen pen( p->pen() ); p->setPen( colorGroup().dark() ); p->drawLine( x2, 0, x2, y2 ); p->drawLine( 0, y2, x2, y2 ); p->setPen( colorGroup().midlight() ); p->drawLine( 0, y2 - h/2, x2, y2 - h/2); p->setPen( pen ); } } void DateBookDayView::paintFocus( QPainter *, const QRect & ) { } void DateBookDayView::resizeEvent( QResizeEvent *e ) { QTable::resizeEvent( e ); columnWidthChanged( 0 ); emit sigColWidthChanged(); } void DateBookDayView::keyPressEvent( QKeyEvent *e ) { QString txt = e->text(); if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { // we this is some sort of thing we know about... e->accept(); emit sigCapturedKey( txt ); } else { // I don't know what this key is, do you? e->ignore(); } } void DateBookDayView::setRowStyle( int style ) { if (style<0) style = 0; for (int i=0; i<numRows(); i++) setRowHeight(i, style*10+20); } //=========================================================================== 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() ); view = new DateBookDayView( ampm, this, "day view" ); connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( 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 } 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; } DateBookDayWidget * DateBookDay::getSelectedWidget( void ) { return selectedWidget; } void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) { start.setDate( currDate ); end.setDate( currDate ); int sh=99,eh=-1; int n = dayView()->numSelections(); for (int i=0; i<n; i++) { QTableSelection sel = dayView()->selection( i ); sh = QMIN(sh,sel.topRow()); eh = QMAX(sh,sel.bottomRow()+1); } if (sh > 23 || eh < 1) { sh=8; eh=9; } start.setTime( QTime( sh, 0, 0 ) ); end.setTime( QTime( eh, 0, 0 ) ); } void DateBookDay::setDate( int y, int m, int d ) { header->setDate( y, m, d ); selectedWidget = 0; } void DateBookDay::setDate( QDate d) { header->setDate( d.year(), d.month(), d.day() ); selectedWidget = 0; } void DateBookDay::dateChanged( int y, int m, int d ) { QDate date( y, m, d ); if ( currDate == date ) return; currDate.setYMD( y, m, d ); relayoutPage(); dayView()->clearSelection(); QTableSelection ts; 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(); QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); QValueListIterator<EffectiveEvent> it; for ( it = eventList.begin(); it != eventList.end(); ++it ) { EffectiveEvent ev=*it; - if(!(ev.end().hour()==ev.start().hour() && ev.end().minute()==ev.start().minute())) { // Skip effective events with no duration. (i.e ending at 00:00) + if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) { // Skip events ending at 00:00 starting at another day. 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 ); } } } 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 ) getEvents(); // no need we already have them! 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) if (geometries[j].intersects(geometries[i])) intersectedWidgets.append(j); //for each of these intersecting widgets find out how many widgets are they intersecting with for ( uint j = 0; j < intersectedWidgets.count(); j++) { QArray<int> inter(wCount); inter[j]=1; if (intersectedWidgets[j] != -1) for ( uint k = j; k < intersectedWidgets.count(); k++) if (j != k && intersectedWidgets[k] != -1) if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) { inter[j]++; intersectedWidgets[k] = -1; } if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; } if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; } for ( int i = 0; i < wCount; i++) { DateBookDayWidget *w = widgetList.at(i); QRect geom = w->geometry(); geom.setX( 0 ); wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); geom.setWidth( wd ); while ( intersects( w, geom ) ) { geom.moveBy( wd + 2 + 1, 0 ); } w->setGeometry( geom ); } if (jumpToCurTime && this->date() == QDate::currentDate()) view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour else view->setContentsPos( 0, startTime * view->rowHeight(0) ); } else { int hours[24]; memset( hours, 0, 24*sizeof( int ) ); bool overFlow = FALSE; for ( int i = 0; i < wCount; i++ ) { DateBookDayWidget *w = widgetList.at(i); int start = w->event().start().hour(); QTime e = w->event().end(); int end = e.hour(); if ( e.minute() < 5 ) end--; if ( end < start ) end = start; while( start <= end ) { hours[start]++; if ( hours[start] >= 10 ) overFlow = TRUE; ++start; } if ( overFlow ) break; } for ( int i = 0; i < 24; i++ ) { n = QMAX( n, hours[i] ); } wid = ( view->columnWidth(0)-1 ) / n; bool used[24*10]; memset( used, FALSE, 24*10*sizeof( bool ) ); for ( int i = 0; i < wCount; i++ ) { DateBookDayWidget *w = widgetList.at(i); int xp = place( w, used, n ); if ( xp != -1 ) { QRect geom = w->geometry(); geom.setX( xp*(wid+2) ); geom.setWidth( wid ); w->setGeometry( geom ); } } if (jumpToCurTime && this->date() == QDate::currentDate()) view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour else view->setContentsPos( 0, startTime * view->rowHeight(0) ); } timeMarker->setTime( QTime::currentTime() ); //display timeMarker timeMarker->raise(); //on top of all widgets if (this->date() == QDate::currentDate()) //only show timeMarker on current day timeMarker->show(); else timeMarker->hide(); setUpdatesEnabled( TRUE ); return; } DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) { int i = 0; DateBookDayWidget *w = widgetList.at(i); int wCount = widgetList.count(); while ( i < wCount && w != item ) { if ( w->geometry().intersects( geom ) ) { return w; } w = widgetList.at(++i); } return 0; } QDate DateBookDay::date() const { return currDate; } void DateBookDay::setStartViewTime( int startHere ) { startTime = startHere; dayView()->clearSelection(); QTableSelection ts; if (jumpToCurTime && this->date() == QDate::currentDate()) //this should probably be in datebook.cpp where it's called? { ts.init( QTime::currentTime().hour(), 0); ts.expandTo( QTime::currentTime().hour(), 0); } else { ts.init( startTime, 0 ); ts.expandTo( startTime, 0 ); } dayView()->addSelection( ts ); } int DateBookDay::startViewTime() const { return startTime; } void DateBookDay::slotWeekChanged( bool bStartOnMonday ) { header->setStartOfWeek( bStartOnMonday ); // redraw(); } void DateBookDay::keyPressEvent(QKeyEvent *e) { switch(e->key()) { case Key_Up: view->moveUp(); break; case Key_Down: view->moveDown(); break; case Key_Left: setDate(QDate(currDate).addDays(-1)); break; case Key_Right: setDate(QDate(currDate).addDays(1)); break; default: e->ignore(); } } //=========================================================================== DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db ) : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db ) { // why would someone use "<"? Oh well, fix it up... // I wonder what other things may be messed up... QString strDesc = ev.description(); int where = strDesc.find( "<" ); while ( where != -1 ) { strDesc.remove( where, 1 ); strDesc.insert( where, "<" ); where = strDesc.find( "<", where ); } QString strCat; // ### Fix later... // QString strCat = ev.category(); // where = strCat.find( "<" ); // while ( where != -1 ) { // strCat.remove( where, 1 ); // strCat.insert( where, "<" ); // where = strCat.find( "<", where ); // } QString strNote = ev.notes(); where = strNote.find( "<" ); while ( where != -1 ) { strNote.remove( where, 1 ); strNote.insert( where, "<" ); where = strNote.find( "<", where ); } text = "<b>" + strDesc + "</b><br>" + "<i>"; if ( !strCat.isEmpty() ) { text += strCat + "</i><br>"; } if (ev.event().type() == Event::Normal ) setEventText( text ); else setAllDayText( text ); text += "<br><br>" + strNote; setBackgroundMode( PaletteBase ); QTime start = ev.start(); QTime end = ev.end(); int y = start.hour()*60+start.minute(); int h = end.hour()*60+end.minute()-y; int rh = dateBook->dayView()->rowHeight(0); y = y*rh/60; h = h*rh/60; if ( h < 3 ) { h = 3; } geom.setY( y ); geom.setHeight( h ); geom.setX( 0 ); geom.setWidth(dateBook->dayView()->columnWidth(0)-1); } void DateBookDayWidget::setAllDayText( QString &text ) { text += "<b>" + tr("This is an all day event.") + "</b><br>"; } void DateBookDayWidget::setEventText( QString& text ) { bool whichClock = dateBook->dayView()->whichClock(); if ( ev.startDate() != ev.endDate() ) { text += "<b>" + tr("Start") + "</b>: "; text += TimeString::timeString( ev.event().start().time(), whichClock, FALSE ); text += " - " + TimeString::longDateString( ev.startDate() ) + "<br>"; text += "<b>" + tr("End") + "</b>: "; text += TimeString::timeString( ev.event().end().time(), whichClock, FALSE ); text += " - " + TimeString::longDateString( ev.endDate() ) + "<br>"; } else { text += "<b>" + tr("Time") + "</b>: "; text += TimeString::timeString( ev.start(), whichClock, FALSE ); text += "<b>" + tr(" - ") + "</b>"; text += TimeString::timeString( ev.end(), whichClock, FALSE ); } } DateBookDayWidget::~DateBookDayWidget() { } void DateBookDayWidget::paintEvent( QPaintEvent *e ) { QPainter p( this ); if (dateBook->getSelectedWidget() == this) { p.setBrush( QColor( 155, 240, 230 ) ); // selected item } else { if (dateBook->date() == QDate::currentDate()) { QTime curTime = QTime::currentTime(); if (ev.end() < curTime) { p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive } else { //change color in dependence of the time till the event starts int duration = curTime.secsTo(ev.start()); if (duration < 0) duration = 0; int colChange = duration*160/86400; //86400: secs per day, 160: max color shift p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue } } else { p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date) //perhaps make a distinction between future/past dates } } p.setPen( QColor(100, 100, 100) ); p.drawRect(rect()); // p.drawRect(0,0, 5, height()); int y = 0; int d = 0; diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index 5bbf86a..874cf24 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp @@ -1,526 +1,526 @@ /********************************************************************** ** 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 "datebookweek.h" #include "datebookweekheaderimpl.h" #include <qpe/calendar.h> #include <qpe/datebookdb.h> #include <qpe/event.h> #include <qpe/qpeapplication.h> #include <qpe/timestring.h> #include <qdatetime.h> #include <qheader.h> #include <qlabel.h> #include <qlayout.h> #include <qpainter.h> #include <qpopupmenu.h> #include <qtimer.h> #include <qspinbox.h> #include <qstyle.h> //----------------------------------------------------------------- DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) : ev( e ) { // with the current implementation change the color for all day events if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { c = Qt::green; } else { c = ev.event().hasAlarm() ? Qt::red : Qt::blue; } } void DateBookWeekItem::setGeometry( int x, int y, int w, int h ) { r.setRect( x, y, w, h ); } //------------------=--------------------------------------------- DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, QWidget *parent, const char *name ) : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), showingEvent( false ) { items.setAutoDelete( true ); viewport()->setBackgroundMode( PaletteBase ); header = new QHeader( this ); header->addLabel( "" ); header->setMovingEnabled( false ); header->setResizeEnabled( false ); header->setClickEnabled( false, 0 ); initNames(); connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); QObject::connect(qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotChangeClock(bool))); QFontMetrics fm( font() ); rowHeight = fm.height()+2; resizeContents( width(), 24*rowHeight ); } void DateBookWeekView::initNames() { static bool bFirst = true; if ( bFirst ) { if ( bOnMonday ) { header->addLabel( tr("M", "Monday" ) ); header->addLabel( tr("T", "Tuesday") ); header->addLabel( tr("W", "Wednesday" ) ); header->addLabel( tr("T", "Thursday" ) ); header->addLabel( tr("F", "Friday" ) ); header->addLabel( tr("S", "Saturday" ) ); header->addLabel( tr("S", "Sunday" ) ); } else { header->addLabel( tr("S", "Sunday" ) ); header->addLabel( tr("M", "Monday") ); header->addLabel( tr("T", "Tuesday") ); header->addLabel( tr("W", "Wednesday" ) ); header->addLabel( tr("T", "Thursday" ) ); header->addLabel( tr("F", "Friday" ) ); header->addLabel( tr("S", "Saturday" ) ); } bFirst = false; } else { // we are change things... if ( bOnMonday ) { header->setLabel( 1, tr("M", "Monday") ); header->setLabel( 2, tr("T", "Tuesday") ); header->setLabel( 3, tr("W", "Wednesday" ) ); header->setLabel( 4, tr("T", "Thursday" ) ); header->setLabel( 5, tr("F", "Friday" ) ); header->setLabel( 6, tr("S", "Saturday" ) ); header->setLabel( 7, tr("S", "Sunday" ) ); } else { header->setLabel( 1, tr("S", "Sunday" ) ); header->setLabel( 2, tr("M", "Monday") ); header->setLabel( 3, tr("T", "Tuesday") ); header->setLabel( 4, tr("W", "Wednesday" ) ); header->setLabel( 5, tr("T", "Thursday" ) ); header->setLabel( 6, tr("F", "Friday" ) ); header->setLabel( 7, tr("S", "Saturday" ) ); } } } void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) { items.clear(); QValueListIterator<EffectiveEvent> it; for ( it = ev.begin(); it != ev.end(); ++it ) { DateBookWeekItem *i = new DateBookWeekItem( *it ); - if(!(i->event().end().hour()==i->event().start().hour() && i->event().end().minute()==i->event().start().minute())) { // Skip effective events with no duration. (i.e ending at 00:00) + if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) { // Skip events ending at 00:00 starting at another day. positionItem( i ); items.append( i ); } } viewport()->update(); } void DateBookWeekView::moveToHour( int h ) { int offset = h*rowHeight; setContentsPos( 0, offset ); } void DateBookWeekView::keyPressEvent( QKeyEvent *e ) { e->ignore(); } void DateBookWeekView::slotChangeClock( bool c ) { ampm = c; viewport()->update(); } static inline int db_round30min( int m ) { if ( m < 15 ) m = 0; else if ( m < 45 ) m = 1; else m = 2; return m; } void DateBookWeekView::alterDay( int day ) { if ( !bOnMonday ) { day--; } emit showDay( day ); } void DateBookWeekView::positionItem( DateBookWeekItem *i ) { const int Width = 8; const EffectiveEvent ev = i->event(); // 30 minute intervals int y = ev.start().hour() * 2; y += db_round30min( ev.start().minute() ); int y2 = ev.end().hour() * 2; y2 += db_round30min( ev.end().minute() ); if ( y > 47 ) y = 47; if ( y2 > 48 ) y2 = 48; y = y * rowHeight / 2; y2 = y2 * rowHeight / 2; int h; if ( ev.event().type() == Event::AllDay ) { h = 48 * rowHeight / 2; y = 0; } else { h=y2-y; if ( h < 1 ) h = 1; } int dow = ev.date().dayOfWeek(); if ( !bOnMonday ) { if ( dow == 7 ) dow = 1; else dow++; } int x = header->sectionPos( dow ) - 1; int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); DateBookWeekItem *isect = 0; do { i->setGeometry( x, y, Width, h ); isect = intersects( i ); x += Width - 1; } while ( isect && x < xlim ); } DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) { QRect geom = item->geometry(); // We allow the edges to overlap geom.moveBy( 1, 1 ); geom.setSize( geom.size()-QSize(2,2) ); QListIterator<DateBookWeekItem> it(items); for ( ; it.current(); ++it ) { DateBookWeekItem *i = it.current(); if ( i != item ) { if ( i->geometry().intersects( geom ) ) { return i; } } } return 0; } void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) { QListIterator<DateBookWeekItem> it(items); for ( ; it.current(); ++it ) { DateBookWeekItem *i = it.current(); if ( i->geometry().contains( e->pos() ) ) { showingEvent = true; emit signalShowEvent( i->event() ); break; } } } void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) { if ( showingEvent ) { showingEvent = false; emit signalHideEvent(); } else { int d = header->sectionAt( e->pos().x() ); if ( d > 0 ) { // if ( !bOnMonday ) // d--; emit showDay( d ); } } } void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) { QRect ur( cx, cy, cw, ch ); p->setPen( lightGray ); for ( int i = 1; i <= 7; i++ ) p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); p->setPen( black ); for ( int t = 0; t < 24; t++ ) { int y = t*rowHeight; if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { QString s; if ( ampm ) { if ( t == 0 ) s = QString::number( 12 ); else if ( t == 12 ) s = QString::number(12) + tr( "p" ); else if ( t > 12 ) { if ( t - 12 < 10 ) s = " "; else s = ""; s += QString::number( t - 12 ) + tr("p"); } else { if ( 12 - t < 3 ) s = ""; else s = " "; s += QString::number( t ); } } else { s = QString::number( t ); if ( s.length() == 1 ) s.prepend( "0" ); } p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); } } QListIterator<DateBookWeekItem> it(items); for ( ; it.current(); ++it ) { DateBookWeekItem *i = it.current(); if ( i->geometry().intersects( ur ) ) { p->setBrush( i->color() ); p->drawRect( i->geometry() ); } } } void DateBookWeekView::resizeEvent( QResizeEvent *e ) { const int hourWidth = 20; QScrollView::resizeEvent( e ); int avail = width()-qApp->style().scrollBarExtent().width()-1; header->setGeometry( 0, 0, avail, header->sizeHint().height() ); setMargins( 0, header->height(), 0, 0 ); header->resizeSection( 0, hourWidth ); int sw = (avail - hourWidth) / 7; for ( int i = 1; i < 7; i++ ) header->resizeSection( i, sw ); header->resizeSection( 7, avail - hourWidth - sw*6 ); } void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) { bOnMonday = bStartOnMonday; initNames(); } //------------------------------------------------------------------- DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, QWidget *parent, const char *name ) : QWidget( parent, name ), db( newDB ), startTime( 0 ), ampm( ap ), bStartOnMonday( startOnMonday ) { setFocusPolicy(StrongFocus); QVBoxLayout *vb = new QVBoxLayout( this ); header = new DateBookWeekHeader( bStartOnMonday, this ); view = new DateBookWeekView( ampm, startOnMonday, this ); vb->addWidget( header ); vb->addWidget( view ); lblDesc = new QLabel( this, "event label" ); lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); lblDesc->setBackgroundColor( yellow ); lblDesc->hide(); tHide = new QTimer( this ); connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); connect( header, SIGNAL( dateChanged( int, int ) ), this, SLOT( dateChanged( int, int ) ) ); connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); connect( header->spinYear, SIGNAL(valueChanged(int)), this, SLOT(slotYearChanged(int)) ); connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); setDate(QDate::currentDate()); } void DateBookWeek::keyPressEvent(QKeyEvent *e) { switch(e->key()) { case Key_Up: view->scrollBy(0, -20); break; case Key_Down: view->scrollBy(0, 20); break; case Key_Left: setDate(date().addDays(-7)); break; case Key_Right: setDate(date().addDays(7)); break; default: e->ignore(); } } void DateBookWeek::showDay( int day ) { QDate d; d = dateFromWeek( _week, year, bStartOnMonday ); day--; d = d.addDays( day ); emit showDate( d.year(), d.month(), d.day() ); } void DateBookWeek::setDate( int y, int m, int d ) { QDate date; date.setYMD( y, m, d ); setDate(QDate(y, m, d)); } void DateBookWeek::setDate(QDate date) { dow = date.dayOfWeek(); int w, y; calcWeek( date, w, y, bStartOnMonday ); header->setDate( y, w ); } void DateBookWeek::dateChanged( int y, int w ) { year = y; _week = w; getEvents(); } QDate DateBookWeek::date() const { QDate d; d = dateFromWeek( _week - 1, year, bStartOnMonday ); if ( bStartOnMonday ) d = d.addDays( 7 + dow - 1 ); else { if ( dow == 7 ) d = d.addDays( dow ); else d = d.addDays( 7 + dow ); } return d; } void DateBookWeek::getEvents() { QDate startWeek = weekDate(); QDate endWeek = startWeek.addDays( 6 ); QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); view->showEvents( eventList ); view->moveToHour( startTime ); } void DateBookWeek::generateAllDayTooltext( QString& text ) { text += "<b>" + tr("This is an all day event.") + "</b><br>"; } void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { str += "<b>" + QObject::tr("Start") + "</b>: "; str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); if( ev.startDate()!=ev.endDate() ) { str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; } str += "<br>"; str += "<b>" + QObject::tr("End") + "</b>: "; str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); if( ev.startDate()!=ev.endDate() ) { str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; } } void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) { if ( tHide->isActive() ) tHide->stop(); // why would someone use "<"? Oh well, fix it up... // I wonder what other things may be messed up... QString strDesc = ev.description(); int where = strDesc.find( "<" ); while ( where != -1 ) { strDesc.remove( where, 1 ); strDesc.insert( where, "<" ); where = strDesc.find( "<", where ); } QString strCat; // ### FIX later... // QString strCat = ev.category(); // where = strCat.find( "<" ); // while ( where != -1 ) { // strCat.remove( where, 1 ); // strCat.insert( where, "<" ); // where = strCat.find( "<", where ); // } QString strLocation = ev.location(); while ( where != -1 ) { strLocation.remove( where, 1 ); strLocation.insert( where, "<" ); where = strLocation.find( "<", where ); } QString strNote = ev.notes(); where = strNote.find( "<" ); while ( where != -1 ) { strNote.remove( where, 1 ); strNote.insert( where, "<" ); where = strNote.find( "<", where ); } diff --git a/core/pim/datebook/datebookweeklst.cpp b/core/pim/datebook/datebookweeklst.cpp index 4ceb360..3d6a029 100644 --- a/core/pim/datebook/datebookweeklst.cpp +++ b/core/pim/datebook/datebookweeklst.cpp @@ -1,381 +1,381 @@ #include "datebookweeklst.h" #include "datebookweekheaderimpl.h" #include <qpe/calendar.h> #include <qpe/datebookdb.h> #include <qpe/event.h> #include <qpe/qpeapplication.h> #include <qpe/timestring.h> #include <qpe/datebookmonth.h> #include <qpe/config.h> #include <qpe/resource.h> #include <qdatetime.h> #include <qheader.h> #include <qlabel.h> #include <qlayout.h> #include <qpainter.h> #include <qpopupmenu.h> #include <qtimer.h> #include <qstyle.h> #include <qtoolbutton.h> #include <qvbox.h> #include <qsizepolicy.h> #include <qabstractlayout.h> #include <qtl.h> bool calcWeek(const QDate &d, int &week, int &year, bool startOnMonday = false); DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, const char* name, WFlags fl) : DateBookWeekLstHeaderBase(parent, name, fl) { setBackgroundMode( PaletteButton ); labelDate->setBackgroundMode( PaletteButton ); labelWeek->setBackgroundMode( PaletteButton ); forward->setBackgroundMode( PaletteButton ); forward->setPixmap( Resource::loadPixmap("forward") ); back->setBackgroundMode( PaletteButton ); back->setPixmap( Resource::loadPixmap("back") ); DateBookWeekLstHeaderBaseLayout->setSpacing(0); DateBookWeekLstHeaderBaseLayout->setMargin(0); //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); connect(back, SIGNAL(clicked()), this, SLOT(prevWeek())); connect(forward, SIGNAL(clicked()), this, SLOT(nextWeek())); connect(labelWeek, SIGNAL(clicked()), this, SLOT(pickDate())); connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); onMonday=onM; } DateBookWeekLstHeader::~DateBookWeekLstHeader(){} void DateBookWeekLstHeader::setDate(const QDate &d) { date=d; int year,week; calcWeek(d,week,year,onMonday); labelWeek->setText(tr( "W: %1" ).arg( ( QString::number(week)) ) ); QDate start=date; QDate stop=start.addDays(6); labelDate->setText( QString::number(start.day()) + " " + start.monthName(start.month()) + " - " + QString::number(stop.day()) + " " + start.monthName(stop.month()) ); emit dateChanged(year,week); } void DateBookWeekLstHeader::pickDate() { static QPopupMenu *m1 = 0; static DateBookMonth *picker = 0; if ( !m1 ) { m1 = new QPopupMenu( this ); picker = new DateBookMonth( m1, 0, TRUE ); m1->insertItem( picker ); connect( picker, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( setDate( int, int, int ) ) ); //connect( m1, SIGNAL( aboutToHide() ), //this, SLOT( gotHide() ) ); } picker->setDate( date.year(), date.month(), date.day() ); m1->popup(mapToGlobal(labelWeek->pos()+QPoint(0,labelWeek->height()))); picker->setFocus(); } void DateBookWeekLstHeader::setDate(int y, int m, int d) { QDate new_date(y,m,d); setDate(new_date); } void DateBookWeekLstHeader::nextWeek() { setDate(date.addDays(7)); } void DateBookWeekLstHeader::prevWeek() { setDate(date.addDays(-7)); } DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/, QWidget* parent, const char* name, WFlags fl ) : DateBookWeekLstDayHdrBase(parent, name, fl) { date=d; static const char *wdays={"MTWTFSS"}; char day=wdays[d.dayOfWeek()-1]; label->setText( QString(QObject::tr(QString(QChar(day)))) + " " + QString::number(d.day()) ); add->setText("+"); if (d == QDate::currentDate()) { QPalette pal=label->palette(); pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); label->setPalette(pal); /* QFont f=label->font(); f.setItalic(true); label->setFont(f); label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); */ } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday QPalette pal=label->palette(); pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); label->setPalette(pal); } connect (label, SIGNAL(clicked()), this, SLOT(showDay())); connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); } void DateBookWeekLstDayHdr::showDay() { emit showDate(date.year(), date.month(), date.day()); } void DateBookWeekLstDayHdr::newEvent() { QDateTime start, stop; start=stop=date; start.setTime(QTime(10,0)); stop.setTime(QTime(12,0)); emit addEvent(start,stop,"",0); } DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev, QWidget* parent, const char* name, WFlags fl) : OClickableLabel(parent,name,fl), event(ev) { char s[10]; if ( ev.startDate() != ev.date() ) { // multiday event (not first day) if ( ev.endDate() == ev.date() ) { // last day strcpy(s, "__|__"); } else { strcpy(s, " |---"); } } else { if(ev.event().type() == Event::Normal ) sprintf(s,"%.2d:%.2d",ev.start().hour(),ev.start().minute()); else sprintf(s," "); } setText(QString(s) + " " + ev.description()); connect(this, SIGNAL(clicked()), this, SLOT(editMe())); setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); } void DateBookWeekLstEvent::editMe() { emit editEvent(event.event()); } DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, const QDate &d, bool onM, QWidget* parent, const char* name, WFlags fl) : QWidget( parent, name, fl ) { onMonday=onM; setPalette(white); setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); QVBoxLayout *layout = new QVBoxLayout( this ); qBubbleSort(ev); QValueListIterator<EffectiveEvent> it; it=ev.begin(); int dayOrder[7]; if (onMonday) for (int d=0; d<7; d++) dayOrder[d]=d+1; else { for (int d=0; d<7; d++) dayOrder[d]=d; dayOrder[0]=7; } for (int i=0; i<7; i++) { // Header DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i), onMonday,this); connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); connect(hdr, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); layout->addWidget(hdr); // Events while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { - if(!((*it).end().hour()==(*it).start().hour() && (*it).end().minute()==(*it).start().minute())) { // Skip effective events with no duration. (i.e ending at 00:00) + if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) { // Skip events ending at 00:00 starting at another day. DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,this); layout->addWidget(l); connect (l, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); } it++; } layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); } } DateBookWeekLstView::~DateBookWeekLstView(){} void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, QValueList<EffectiveEvent> &ev2, QDate &d, bool onM, QWidget* parent, const char* name, WFlags fl) : QWidget( parent, name, fl ) { QHBoxLayout *layout = new QHBoxLayout( this ); DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this); layout->addWidget(w); connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &,const QString &)), this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); layout->addWidget(w); connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); } DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, QWidget *parent, const char *name ) : QWidget( parent, name ), db( newDB ), startTime( 0 ), ampm( ap ), onMonday(onM) { setFocusPolicy(StrongFocus); layout = new QVBoxLayout( this ); layout->setMargin(0); header=new DateBookWeekLstHeader(onM, this); layout->addWidget( header ); connect(header, SIGNAL(dateChanged(int,int)), this, SLOT(dateChanged(int,int))); connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); scroll=new QScrollView(this); //scroll->setVScrollBarMode(QScrollView::AlwaysOn); //scroll->setHScrollBarMode(QScrollView::AlwaysOff); scroll->setResizePolicy(QScrollView::AutoOneFit); layout->addWidget(scroll); view=NULL; Config config("DateBook"); config.setGroup("Main"); dbl=config.readBoolEntry("weeklst_dbl", false); header->dbl->setOn(dbl); } DateBookWeekLst::~DateBookWeekLst(){ Config config("DateBook"); config.setGroup("Main"); config.writeEntry("weeklst_dbl", dbl); } void DateBookWeekLst::setDate(const QDate &d) { int w,y; calcWeek(d,w,y,onMonday); year=y; _week=w; header->setDate(date()); } void DateBookWeekLst::setDbl(bool on) { dbl=on; redraw(); } void DateBookWeekLst::redraw() {getEvents();} QDate DateBookWeekLst::date() const { QDate d; d.setYMD(year,1,1); int dow= d.dayOfWeek(); if (!onMonday) if (dow==7) dow=1; else dow++; d=d.addDays( (_week-1)*7 - dow + 1 ); return d; } void DateBookWeekLst::getEvents() { QDate start = date(); QDate stop = start.addDays(6); QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); if (view) delete view; if (dbl) { QDate start2=start.addDays(7); stop=start2.addDays(6); QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); view=new DateBookWeekLstDblView(el,el2,start,onMonday,scroll); } else { view=new DateBookWeekLstView(el,start,onMonday,scroll); } connect (view, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); scroll->addChild(view); view->show(); scroll->updateScrollBars(); } void DateBookWeekLst::dateChanged(int y, int w) { year=y; _week=w; getEvents(); } void DateBookWeekLst::keyPressEvent(QKeyEvent *e) { switch(e->key()) { case Key_Up: scroll->scrollBy(0, -20); break; case Key_Down: scroll->scrollBy(0, 20); break; case Key_Left: header->prevWeek(); break; case Key_Right: header->nextWeek(); break; default: e->ignore(); } } |