-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index e30c776..5bbf86a 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp @@ -1,337 +1,339 @@ /********************************************************************** ** 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 ); - positionItem( i ); - items.append( i ); - } - viewport()->update(); + 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) + 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 ); |