summaryrefslogtreecommitdiff
path: root/core/pim/datebook/datebookweek.cpp
authoralwin <alwin>2005-03-17 14:01:23 (UTC)
committer alwin <alwin>2005-03-17 14:01:23 (UTC)
commit8752141a5341877369f89a42fa1f0b5d08f56dbd (patch) (unidiff)
tree63dc48ee207a4e9fbb6b9e8abddb239ec724c155 /core/pim/datebook/datebookweek.cpp
parentafee05f4b4c1e8dab8463e3423fcfc8f9d45aa8b (diff)
downloadopie-8752141a5341877369f89a42fa1f0b5d08f56dbd.zip
opie-8752141a5341877369f89a42fa1f0b5d08f56dbd.tar.gz
opie-8752141a5341877369f89a42fa1f0b5d08f56dbd.tar.bz2
1. datebookweeklist - a week has SEVEN days, not SIX. I'm wondering why
events on sunday never showed there ;) 2. extra file datebooktypes contains some special classes used by datebook so other classes must not include the big mainheader file. 3. added support for holiday-plugins to week-views. Month view is a little bit more tricky 'cause TT has never heard about virtual methods and so I have the choice between complete copy the monthview and make the modifications or changing the interface of datebookdb-class to virtual. both isn't nice.
Diffstat (limited to 'core/pim/datebook/datebookweek.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebookweek.cpp489
1 files changed, 245 insertions, 244 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp
index 7503751..a509d89 100644
--- a/core/pim/datebook/datebookweek.cpp
+++ b/core/pim/datebook/datebookweek.cpp
@@ -21,2 +21,3 @@
21#include "datebookweekheaderimpl.h" 21#include "datebookweekheaderimpl.h"
22#include "datebooktypes.h"
22 23
@@ -54,3 +55,3 @@ void DateBookWeekItem::setGeometry( int x, int y, int w, int h )
54DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, 55DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday,
55 QWidget *parent, const char *name ) 56 QWidget *parent, const char *name )
56 : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), 57 : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ),
@@ -74,3 +75,3 @@ DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday,
74 QObject::connect(qApp, SIGNAL(clockChanged(bool)), 75 QObject::connect(qApp, SIGNAL(clockChanged(bool)),
75 this, SLOT(slotChangeClock(bool))); 76 this, SLOT(slotChangeClock(bool)));
76 77
@@ -87,3 +88,3 @@ void DateBookWeekView::initNames()
87 if ( bFirst ) { 88 if ( bFirst ) {
88 if ( bOnMonday ) { 89 if ( bOnMonday ) {
89 for ( int i = 1; i<=7; i++ ) { 90 for ( int i = 1; i<=7; i++ ) {
@@ -92,3 +93,3 @@ void DateBookWeekView::initNames()
92 93
93 } else { 94 } else {
94 header->addLabel( Calendar::nameOfDay( 7 ) ); 95 header->addLabel( Calendar::nameOfDay( 7 ) );
@@ -98,6 +99,6 @@ void DateBookWeekView::initNames()
98 } 99 }
99 bFirst = false; 100 bFirst = false;
100 } else { 101 } else {
101 // we are change things... 102 // we are change things...
102 if ( bOnMonday ) { 103 if ( bOnMonday ) {
103 for ( int i = 1; i<=7; i++ ) { 104 for ( int i = 1; i<=7; i++ ) {
@@ -106,3 +107,3 @@ void DateBookWeekView::initNames()
106 107
107 } else { 108 } else {
108 header->setLabel( 1, Calendar::nameOfDay( 7 ) ); 109 header->setLabel( 1, Calendar::nameOfDay( 7 ) );
@@ -112,3 +113,3 @@ void DateBookWeekView::initNames()
112 113
113 } 114 }
114 } 115 }
@@ -120,12 +121,12 @@ void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev )
120{ 121{
121 items.clear(); 122 items.clear();
122 QValueListIterator<EffectiveEvent> it; 123 QValueListIterator<EffectiveEvent> it;
123 for ( it = ev.begin(); it != ev.end(); ++it ) { 124 for ( it = ev.begin(); it != ev.end(); ++it ) {
124 DateBookWeekItem *i = new DateBookWeekItem( *it ); 125 DateBookWeekItem *i = new DateBookWeekItem( *it );
125 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. 126 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.
126 positionItem( i ); 127 positionItem( i );
127 items.append( i ); 128 items.append( i );
128 } 129 }
129 } 130 }
130 viewport()->update(); 131 viewport()->update();
131} 132}
@@ -152,7 +153,7 @@ static inline int db_round30min( int m )
152 if ( m < 15 ) 153 if ( m < 15 )
153 m = 0; 154 m = 0;
154 else if ( m < 45 ) 155 else if ( m < 45 )
155 m = 1; 156 m = 1;
156 else 157 else
157 m = 2; 158 m = 2;
158 159
@@ -164,3 +165,3 @@ void DateBookWeekView::alterDay( int day )
164 if ( !bOnMonday ) { 165 if ( !bOnMonday ) {
165 day--; 166 day--;
166 } 167 }
@@ -186,7 +187,7 @@ void DateBookWeekView::positionItem( DateBookWeekItem *i )
186 if ( ev.event().type() == Event::AllDay ) { 187 if ( ev.event().type() == Event::AllDay ) {
187 h = (48 * rowHeight) / 2; 188 h = (48 * rowHeight) / 2;
188 y = 0; 189 y = 0;
189 } else { 190 } else {
190 h=y2-y; 191 h=y2-y;
191 if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2; 192 if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2;
192 } 193 }
@@ -195,6 +196,6 @@ void DateBookWeekView::positionItem( DateBookWeekItem *i )
195 if ( !bOnMonday ) { 196 if ( !bOnMonday ) {
196 if ( dow == 7 ) 197 if ( dow == 7 )
197 dow = 1; 198 dow = 1;
198 else 199 else
199 dow++; 200 dow++;
200 } 201 }
@@ -204,5 +205,5 @@ void DateBookWeekView::positionItem( DateBookWeekItem *i )
204 do { 205 do {
205 i->setGeometry( x, y, Width, h ); 206 i->setGeometry( x, y, Width, h );
206 isect = intersects( i ); 207 isect = intersects( i );
207 x += Width - 1; 208 x += Width - 1;
208 } while ( isect && x < xlim ); 209 } while ( isect && x < xlim );
@@ -220,8 +221,8 @@ DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item )
220 for ( ; it.current(); ++it ) { 221 for ( ; it.current(); ++it ) {
221 DateBookWeekItem *i = it.current(); 222 DateBookWeekItem *i = it.current();
222 if ( i != item ) { 223 if ( i != item ) {
223 if ( i->geometry().intersects( geom ) ) { 224 if ( i->geometry().intersects( geom ) ) {
224 return i; 225 return i;
225 } 226 }
226 } 227 }
227 } 228 }
@@ -235,8 +236,8 @@ void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e )
235 for ( ; it.current(); ++it ) { 236 for ( ; it.current(); ++it ) {
236 DateBookWeekItem *i = it.current(); 237 DateBookWeekItem *i = it.current();
237 if ( i->geometry().contains( e->pos() ) ) { 238 if ( i->geometry().contains( e->pos() ) ) {
238 showingEvent = true; 239 showingEvent = true;
239 emit signalShowEvent( i->event() ); 240 emit signalShowEvent( i->event() );
240 break; 241 break;
241 } 242 }
242 } 243 }
@@ -247,11 +248,11 @@ void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e )
247 if ( showingEvent ) { 248 if ( showingEvent ) {
248 showingEvent = false; 249 showingEvent = false;
249 emit signalHideEvent(); 250 emit signalHideEvent();
250 } else { 251 } else {
251 int d = header->sectionAt( e->pos().x() ); 252 int d = header->sectionAt( e->pos().x() );
252 if ( d > 0 ) { 253 if ( d > 0 ) {
253 // if ( !bOnMonday ) 254// if ( !bOnMonday )
254 // d--; 255// d--;
255 emit showDay( d ); 256 emit showDay( d );
256 } 257 }
257 } 258 }
@@ -264,3 +265,3 @@ void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch
264 for ( int i = 1; i <= 7; i++ ) 265 for ( int i = 1; i <= 7; i++ )
265 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); 266 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch );
266 267
@@ -268,30 +269,30 @@ void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch
268 for ( int t = 0; t < 24; t++ ) { 269 for ( int t = 0; t < 24; t++ ) {
269 int y = t*rowHeight; 270 int y = t*rowHeight;
270 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { 271 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) {
271 QString s; 272 QString s;
272 if ( ampm ) { 273 if ( ampm ) {
273 if ( t == 0 ) 274 if ( t == 0 )
274 s = QString::number( 12 ); 275 s = QString::number( 12 );
275 else if ( t == 12 ) 276 else if ( t == 12 )
276 s = QString::number(12) + tr( "p" ); 277 s = QString::number(12) + tr( "p" );
277 else if ( t > 12 ) { 278 else if ( t > 12 ) {
278 if ( t - 12 < 10 ) 279 if ( t - 12 < 10 )
279 s = " "; 280 s = " ";
280 else 281 else
281 s = ""; 282 s = "";
282 s += QString::number( t - 12 ) + tr("p"); 283 s += QString::number( t - 12 ) + tr("p");
283 } else { 284 } else {
284 if ( 12 - t < 3 ) 285 if ( 12 - t < 3 )
285 s = ""; 286 s = "";
286 else 287 else
287 s = " "; 288 s = " ";
288 s += QString::number( t ); 289 s += QString::number( t );
289 } 290 }
290 } else { 291 } else {
291 s = QString::number( t ); 292 s = QString::number( t );
292 if ( s.length() == 1 ) 293 if ( s.length() == 1 )
293 s.prepend( "0" ); 294 s.prepend( "0" );
294 } 295 }
295 p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); 296 p->drawText( 1, y+p->fontMetrics().ascent()+1, s );
296 } 297 }
297 } 298 }
@@ -300,7 +301,7 @@ void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch
300 for ( ; it.current(); ++it ) { 301 for ( ; it.current(); ++it ) {
301 DateBookWeekItem *i = it.current(); 302 DateBookWeekItem *i = it.current();
302 if ( i->geometry().intersects( ur ) ) { 303 if ( i->geometry().intersects( ur ) ) {
303 p->setBrush( i->color() ); 304 p->setBrush( i->color() );
304 p->drawRect( i->geometry() ); 305 p->drawRect( i->geometry() );
305 } 306 }
306 } 307 }
@@ -318,3 +319,3 @@ void DateBookWeekView::resizeEvent( QResizeEvent *e )
318 header->setGeometry( leftMargin()+frameWidth()+frameRect().left() , frameWidth(), 319 header->setGeometry( leftMargin()+frameWidth()+frameRect().left() , frameWidth(),
319 visibleWidth(), header->sizeHint().height() ); 320 visibleWidth(), header->sizeHint().height() );
320 setMargins( 0, header->sizeHint().height(), 0, 0 ); 321 setMargins( 0, header->sizeHint().height(), 0, 0 );
@@ -330,3 +331,3 @@ void DateBookWeekView::resizeEvent( QResizeEvent *e )
330 for ( int i = 1; i < 7; i++ ) 331 for ( int i = 1; i < 7; i++ )
331 header->resizeSection( i, sw ); 332 header->resizeSection( i, sw );
332 header->resizeSection( 7, avail - hourWidth - sw*6 ); 333 header->resizeSection( 7, avail - hourWidth - sw*6 );
@@ -342,4 +343,4 @@ void DateBookWeekView::setStartOfWeek( bool bStartOnMonday )
342 343
343DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, 344DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDBHoliday *newDB,
344 QWidget *parent, const char *name ) 345 QWidget *parent, const char *name )
345 : QWidget( parent, name ), 346 : QWidget( parent, name ),
@@ -350,24 +351,24 @@ DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB,
350{ 351{
351 setFocusPolicy(StrongFocus); 352 setFocusPolicy(StrongFocus);
352 QVBoxLayout *vb = new QVBoxLayout( this ); 353 QVBoxLayout *vb = new QVBoxLayout( this );
353 header = new DateBookWeekHeader( bStartOnMonday, this ); 354 header = new DateBookWeekHeader( bStartOnMonday, this );
354 view = new DateBookWeekView( ampm, startOnMonday, this ); 355 view = new DateBookWeekView( ampm, startOnMonday, this );
355 vb->addWidget( header ); 356 vb->addWidget( header );
356 vb->addWidget( view ); 357 vb->addWidget( view );
357 358
358 lblDesc = new QLabel( this, "event label" ); 359 lblDesc = new QLabel( this, "event label" );
359 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); 360 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box );
360 lblDesc->setBackgroundColor( yellow ); 361 lblDesc->setBackgroundColor( yellow );
361 lblDesc->hide(); 362 lblDesc->hide();
362 363
363 tHide = new QTimer( this ); 364 tHide = new QTimer( this );
364 365
365 connect( view, SIGNAL( showDay(int) ), this, SLOT( showDay(int) ) ); 366 connect( view, SIGNAL( showDay(int) ), this, SLOT( showDay(int) ) );
366 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); 367 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) );
367 connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); 368 connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) );
368 connect( header, SIGNAL( dateChanged(QDate&) ), this, SLOT( dateChanged(QDate&) ) ); 369 connect( header, SIGNAL( dateChanged(QDate&) ), this, SLOT( dateChanged(QDate&) ) );
369 connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); 370 connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) );
370 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); 371 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) );
371 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); 372 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool)));
372 setDate(QDate::currentDate()); 373 setDate(QDate::currentDate());
373} 374}
@@ -377,16 +378,16 @@ void DateBookWeek::keyPressEvent(QKeyEvent *e)
377 switch(e->key()) { 378 switch(e->key()) {
378 case Key_Up: 379 case Key_Up:
379 view->scrollBy(0, -20); 380 view->scrollBy(0, -20);
380 break; 381 break;
381 case Key_Down: 382 case Key_Down:
382 view->scrollBy(0, 20); 383 view->scrollBy(0, 20);
383 break; 384 break;
384 case Key_Left: 385 case Key_Left:
385 setDate(date().addDays(-7)); 386 setDate(date().addDays(-7));
386 break; 387 break;
387 case Key_Right: 388 case Key_Right:
388 setDate(date().addDays(7)); 389 setDate(date().addDays(7));
389 break; 390 break;
390 default: 391 default:
391 e->ignore(); 392 e->ignore();
392 } 393 }
@@ -396,12 +397,12 @@ void DateBookWeek::showDay( int day )
396{ 397{
397 QDate d=bdate; 398 QDate d=bdate;
398 399
399 // Calculate offset to first day of week. 400 // Calculate offset to first day of week.
400 int dayoffset=d.dayOfWeek() % 7; 401 int dayoffset=d.dayOfWeek() % 7;
401 402
402 if(bStartOnMonday) dayoffset--; 403 if(bStartOnMonday) dayoffset--;
403 404
404 day--; 405 day--;
405 d=d.addDays(day-dayoffset); 406 d=d.addDays(day-dayoffset);
406 emit showDate( d.year(), d.month(), d.day() ); 407 emit showDate( d.year(), d.month(), d.day() );
407} 408}
@@ -410,3 +411,3 @@ void DateBookWeek::setDate( int y, int m, int d )
410{ 411{
411 setDate(QDate(y, m, d)); 412 setDate(QDate(y, m, d));
412} 413}
@@ -415,5 +416,5 @@ void DateBookWeek::setDate(QDate newdate)
415{ 416{
416 bdate=newdate; 417 bdate=newdate;
417 dow = newdate.dayOfWeek(); 418 dow = newdate.dayOfWeek();
418 header->setDate( newdate ); 419 header->setDate( newdate );
419} 420}
@@ -422,4 +423,4 @@ void DateBookWeek::dateChanged( QDate &newdate )
422{ 423{
423 bdate=newdate; 424 bdate=newdate;
424 getEvents(); 425 getEvents();
425} 426}
@@ -428,3 +429,3 @@ QDate DateBookWeek::date() const
428{ 429{
429 return bdate; 430 return bdate;
430} 431}
@@ -433,8 +434,8 @@ void DateBookWeek::getEvents()
433{ 434{
434 QDate startWeek = weekDate(); 435 QDate startWeek = weekDate();
435 436
436 QDate endWeek = startWeek.addDays( 6 ); 437 QDate endWeek = startWeek.addDays( 6 );
437 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); 438 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek);
438 view->showEvents( eventList ); 439 view->showEvents( eventList );
439 view->moveToHour( startTime ); 440 view->moveToHour( startTime );
440} 441}
@@ -442,3 +443,3 @@ void DateBookWeek::getEvents()
442void DateBookWeek::generateAllDayTooltext( QString& text ) { 443void DateBookWeek::generateAllDayTooltext( QString& text ) {
443 text += "<b>" + tr("This is an all day event.") + "</b><br>"; 444 text += "<b>" + tr("This is an all day event.") + "</b><br>";
444} 445}
@@ -446,13 +447,13 @@ void DateBookWeek::generateAllDayTooltext( QString& text ) {
446void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { 447void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) {
447 str += "<b>" + QObject::tr("Start") + "</b>: "; 448 str += "<b>" + QObject::tr("Start") + "</b>: ";
448 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); 449 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE );
449 if( ev.startDate()!=ev.endDate() ) { 450 if( ev.startDate()!=ev.endDate() ) {
450 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; 451 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>";
451 } 452 }
452 str += "<br>"; 453 str += "<br>";
453 str += "<b>" + QObject::tr("End") + "</b>: "; 454 str += "<b>" + QObject::tr("End") + "</b>: ";
454 str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); 455 str += TimeString::timeString( ev.event().end().time(), ampm, FALSE );
455 if( ev.startDate()!=ev.endDate() ) { 456 if( ev.startDate()!=ev.endDate() ) {
456 str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; 457 str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>";
457 } 458 }
458} 459}
@@ -469,5 +470,5 @@ void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
469 while ( where != -1 ) { 470 while ( where != -1 ) {
470 strDesc.remove( where, 1 ); 471 strDesc.remove( where, 1 );
471 strDesc.insert( where, "&#60;" ); 472 strDesc.insert( where, "&#60;" );
472 where = strDesc.find( "<", where ); 473 where = strDesc.find( "<", where );
473 } 474 }
@@ -479,5 +480,5 @@ void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
479// while ( where != -1 ) { 480// while ( where != -1 ) {
480 // strCat.remove( where, 1 ); 481// strCat.remove( where, 1 );
481 // strCat.insert( where, "&#60;" ); 482// strCat.insert( where, "&#60;" );
482 // where = strCat.find( "<", where ); 483// where = strCat.find( "<", where );
483// } 484// }
@@ -486,5 +487,5 @@ void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
486 while ( where != -1 ) { 487 while ( where != -1 ) {
487 strLocation.remove( where, 1 ); 488 strLocation.remove( where, 1 );
488 strLocation.insert( where, "&#60;" ); 489 strLocation.insert( where, "&#60;" );
489 where = strLocation.find( "<", where ); 490 where = strLocation.find( "<", where );
490 } 491 }
@@ -494,5 +495,5 @@ void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
494 while ( where != -1 ) { 495 while ( where != -1 ) {
495 strNote.remove( where, 1 ); 496 strNote.remove( where, 1 );
496 strNote.insert( where, "&#60;" ); 497 strNote.insert( where, "&#60;" );
497 where = strNote.find( "<", where ); 498 where = strNote.find( "<", where );
498 } 499 }
@@ -503,3 +504,3 @@ void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
503 + "<br>" + TimeString::longDateString( ev.date() ) 504 + "<br>" + TimeString::longDateString( ev.date() )
504 + "<br>"; 505 + "<br>";
505 506
@@ -542,10 +543,10 @@ void DateBookWeek::slotYearChanged( int y )
542{ 543{
543 int totWeek; 544 int totWeek;
544 QDate d( y, 12, 31 ); 545 QDate d( y, 12, 31 );
545 int throwAway; 546 int throwAway;
546 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 547 calcWeek( d, totWeek, throwAway, bStartOnMonday );
547 while ( totWeek == 1 ) { 548 while ( totWeek == 1 ) {
548 d = d.addDays( -1 ); 549 d = d.addDays( -1 );
549 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 550 calcWeek( d, totWeek, throwAway, bStartOnMonday );
550 } 551 }
551} 552}
@@ -554,6 +555,6 @@ void DateBookWeek::slotWeekChanged( bool onMonday )
554{ 555{
555 bStartOnMonday = onMonday; 556 bStartOnMonday = onMonday;
556 view->setStartOfWeek( bStartOnMonday ); 557 view->setStartOfWeek( bStartOnMonday );
557 header->setStartOfWeek( bStartOnMonday ); 558 header->setStartOfWeek( bStartOnMonday );
558 redraw(); 559 redraw();
559} 560}
@@ -562,3 +563,3 @@ void DateBookWeek::slotClockChanged( bool ap )
562{ 563{
563 ampm = ap; 564 ampm = ap;
564} 565}
@@ -568,11 +569,11 @@ QDate DateBookWeek::weekDate() const
568{ 569{
569 QDate d=bdate; 570 QDate d=bdate;
570 571
571 // Calculate offset to first day of week. 572 // Calculate offset to first day of week.
572 int dayoffset=d.dayOfWeek(); 573 int dayoffset=d.dayOfWeek();
573 if(bStartOnMonday) dayoffset--; 574 if(bStartOnMonday) dayoffset--;
574 else if( dayoffset == 7 ) 575 else if( dayoffset == 7 )
575 dayoffset = 0; 576 dayoffset = 0;
576 577
577 return d.addDays(-dayoffset); 578 return d.addDays(-dayoffset);
578} 579}
@@ -602,3 +603,3 @@ QDate DateBookWeek::weekDate() const
602bool calcWeek( const QDate &d, int &week, int &year, 603bool calcWeek( const QDate &d, int &week, int &year,
603 bool startOnMonday ) 604 bool startOnMonday )
604{ 605{
@@ -613,58 +614,58 @@ bool calcWeek( const QDate &d, int &week, int &year,
613 if ( !d.isValid() ) 614 if ( !d.isValid() )
614 return false; 615 return false;
615 616
616 if ( startOnMonday ) { 617 if ( startOnMonday ) {
617 // find the Jan1Weekday; 618 // find the Jan1Weekday;
618 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { 619 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) {
619 yearNumber = d.year() - 1; 620 yearNumber = d.year() - 1;
620 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) 621 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) )
621 weekNumber = 53; 622 weekNumber = 53;
622 else 623 else
623 weekNumber = 52; 624 weekNumber = 52;
624 } else 625 } else
625 yearNumber = d.year(); 626 yearNumber = d.year();
626 if ( yearNumber == d.year() ) { 627 if ( yearNumber == d.year() ) {
627 int totalDays = 365; 628 int totalDays = 365;
628 if ( QDate::leapYear(yearNumber) ) 629 if ( QDate::leapYear(yearNumber) )
629 totalDays++; 630 totalDays++;
630 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) 631 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) )
631 || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { 632 || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) {
632 yearNumber++; 633 yearNumber++;
633 weekNumber = 1; 634 weekNumber = 1;
634 } 635 }
635 } 636 }
636 if ( yearNumber == d.year() ) { 637 if ( yearNumber == d.year() ) {
637 int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); 638 int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 );
638 weekNumber = j / 7; 639 weekNumber = j / 7;
639 if ( jan1WeekDay > 4 ) 640 if ( jan1WeekDay > 4 )
640 weekNumber--; 641 weekNumber--;
641 } 642 }
642 } else { 643 } else {
643 // it's better to keep these cases separate... 644 // it's better to keep these cases separate...
644 if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 645 if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4
645 && jan1WeekDay != 7 ) { 646 && jan1WeekDay != 7 ) {
646 yearNumber = d.year() - 1; 647 yearNumber = d.year() - 1;
647 if ( jan1WeekDay == 6 648 if ( jan1WeekDay == 6
648 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { 649 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) {
649 weekNumber = 53; 650 weekNumber = 53;
650 }else 651 }else
651 weekNumber = 52; 652 weekNumber = 52;
652 } else 653 } else
653 yearNumber = d.year(); 654 yearNumber = d.year();
654 if ( yearNumber == d.year() ) { 655 if ( yearNumber == d.year() ) {
655 int totalDays = 365; 656 int totalDays = 365;
656 if ( QDate::leapYear( yearNumber ) ) 657 if ( QDate::leapYear( yearNumber ) )
657 totalDays++; 658 totalDays++;
658 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { 659 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) {
659 yearNumber++; 660 yearNumber++;
660 weekNumber = 1; 661 weekNumber = 1;
661 } 662 }
662 } 663 }
663 if ( yearNumber == d.year() ) { 664 if ( yearNumber == d.year() ) {
664 int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); 665 int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 );
665 weekNumber = j / 7; 666 weekNumber = j / 7;
666 if ( jan1WeekDay > 4 ) { 667 if ( jan1WeekDay > 4 ) {
667 weekNumber--; 668 weekNumber--;
668 } 669 }
669 } 670 }
670 } 671 }