-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index e16f516..ddd41af 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp | |||
@@ -324,380 +324,388 @@ void DateBookWeekView::resizeEvent( QResizeEvent *e ) | |||
324 | { | 324 | { |
325 | const int hourWidth = 20; | 325 | const int hourWidth = 20; |
326 | QScrollView::resizeEvent( e ); | 326 | QScrollView::resizeEvent( e ); |
327 | int avail = width()-qApp->style().scrollBarExtent().width()-1; | 327 | int avail = width()-qApp->style().scrollBarExtent().width()-1; |
328 | header->setGeometry( 0, 0, avail, header->sizeHint().height() ); | 328 | header->setGeometry( 0, 0, avail, header->sizeHint().height() ); |
329 | setMargins( 0, header->height(), 0, 0 ); | 329 | setMargins( 0, header->height(), 0, 0 ); |
330 | header->resizeSection( 0, hourWidth ); | 330 | header->resizeSection( 0, hourWidth ); |
331 | int sw = (avail - hourWidth) / 7; | 331 | int sw = (avail - hourWidth) / 7; |
332 | for ( int i = 1; i < 7; i++ ) | 332 | for ( int i = 1; i < 7; i++ ) |
333 | header->resizeSection( i, sw ); | 333 | header->resizeSection( i, sw ); |
334 | header->resizeSection( 7, avail - hourWidth - sw*6 ); | 334 | header->resizeSection( 7, avail - hourWidth - sw*6 ); |
335 | } | 335 | } |
336 | 336 | ||
337 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) | 337 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) |
338 | { | 338 | { |
339 | bOnMonday = bStartOnMonday; | 339 | bOnMonday = bStartOnMonday; |
340 | initNames(); | 340 | initNames(); |
341 | } | 341 | } |
342 | 342 | ||
343 | //------------------------------------------------------------------- | 343 | //------------------------------------------------------------------- |
344 | 344 | ||
345 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, | 345 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, |
346 | QWidget *parent, const char *name ) | 346 | QWidget *parent, const char *name ) |
347 | : QWidget( parent, name ), | 347 | : QWidget( parent, name ), |
348 | db( newDB ), | 348 | db( newDB ), |
349 | startTime( 0 ), | 349 | startTime( 0 ), |
350 | ampm( ap ), | 350 | ampm( ap ), |
351 | bStartOnMonday( startOnMonday ) | 351 | bStartOnMonday( startOnMonday ) |
352 | { | 352 | { |
353 | setFocusPolicy(StrongFocus); | 353 | setFocusPolicy(StrongFocus); |
354 | QVBoxLayout *vb = new QVBoxLayout( this ); | 354 | QVBoxLayout *vb = new QVBoxLayout( this ); |
355 | header = new DateBookWeekHeader( bStartOnMonday, this ); | 355 | header = new DateBookWeekHeader( bStartOnMonday, this ); |
356 | view = new DateBookWeekView( ampm, startOnMonday, this ); | 356 | view = new DateBookWeekView( ampm, startOnMonday, this ); |
357 | vb->addWidget( header ); | 357 | vb->addWidget( header ); |
358 | vb->addWidget( view ); | 358 | vb->addWidget( view ); |
359 | 359 | ||
360 | lblDesc = new QLabel( this, "event label" ); | 360 | lblDesc = new QLabel( this, "event label" ); |
361 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); | 361 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); |
362 | lblDesc->setBackgroundColor( yellow ); | 362 | lblDesc->setBackgroundColor( yellow ); |
363 | lblDesc->hide(); | 363 | lblDesc->hide(); |
364 | 364 | ||
365 | tHide = new QTimer( this ); | 365 | tHide = new QTimer( this ); |
366 | 366 | ||
367 | connect( view, SIGNAL( showDay( int ) ), | 367 | connect( view, SIGNAL( showDay( int ) ), |
368 | this, SLOT( showDay( int ) ) ); | 368 | this, SLOT( showDay( int ) ) ); |
369 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), | 369 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), |
370 | this, SLOT(slotShowEvent(const EffectiveEvent&)) ); | 370 | this, SLOT(slotShowEvent(const EffectiveEvent&)) ); |
371 | connect( view, SIGNAL(signalHideEvent()), | 371 | connect( view, SIGNAL(signalHideEvent()), |
372 | this, SLOT(slotHideEvent()) ); | 372 | this, SLOT(slotHideEvent()) ); |
373 | connect( header, SIGNAL( dateChanged( int, int ) ), | 373 | connect( header, SIGNAL( dateChanged( int, int ) ), |
374 | this, SLOT( dateChanged( int, int ) ) ); | 374 | this, SLOT( dateChanged( int, int ) ) ); |
375 | connect( tHide, SIGNAL( timeout() ), | 375 | connect( tHide, SIGNAL( timeout() ), |
376 | lblDesc, SLOT( hide() ) ); | 376 | lblDesc, SLOT( hide() ) ); |
377 | connect( header->spinYear, SIGNAL(valueChanged(int)), | 377 | connect( header->spinYear, SIGNAL(valueChanged(int)), |
378 | this, SLOT(slotYearChanged(int)) ); | 378 | this, SLOT(slotYearChanged(int)) ); |
379 | connect( qApp, SIGNAL(weekChanged(bool)), | 379 | connect( qApp, SIGNAL(weekChanged(bool)), |
380 | this, SLOT(slotWeekChanged(bool)) ); | 380 | this, SLOT(slotWeekChanged(bool)) ); |
381 | connect( qApp, SIGNAL(clockChanged(bool)), | 381 | connect( qApp, SIGNAL(clockChanged(bool)), |
382 | this, SLOT(slotClockChanged(bool))); | 382 | this, SLOT(slotClockChanged(bool))); |
383 | setDate(QDate::currentDate()); | 383 | setDate(QDate::currentDate()); |
384 | 384 | ||
385 | } | 385 | } |
386 | 386 | ||
387 | void DateBookWeek::keyPressEvent(QKeyEvent *e) | 387 | void DateBookWeek::keyPressEvent(QKeyEvent *e) |
388 | { | 388 | { |
389 | switch(e->key()) { | 389 | switch(e->key()) { |
390 | case Key_Up: | 390 | case Key_Up: |
391 | view->scrollBy(0, -20); | 391 | view->scrollBy(0, -20); |
392 | break; | 392 | break; |
393 | case Key_Down: | 393 | case Key_Down: |
394 | view->scrollBy(0, 20); | 394 | view->scrollBy(0, 20); |
395 | break; | 395 | break; |
396 | case Key_Left: | 396 | case Key_Left: |
397 | setDate(date().addDays(-7)); | 397 | setDate(date().addDays(-7)); |
398 | break; | 398 | break; |
399 | case Key_Right: | 399 | case Key_Right: |
400 | setDate(date().addDays(7)); | 400 | setDate(date().addDays(7)); |
401 | break; | 401 | break; |
402 | default: | 402 | default: |
403 | e->ignore(); | 403 | e->ignore(); |
404 | } | 404 | } |
405 | } | 405 | } |
406 | 406 | ||
407 | void DateBookWeek::showDay( int day ) | 407 | void DateBookWeek::showDay( int day ) |
408 | { | 408 | { |
409 | QDate d; | 409 | QDate d; |
410 | d = dateFromWeek( _week, year, bStartOnMonday ); | 410 | d = dateFromWeek( _week, year, bStartOnMonday ); |
411 | day--; | 411 | day--; |
412 | d = d.addDays( day ); | 412 | d = d.addDays( day ); |
413 | emit showDate( d.year(), d.month(), d.day() ); | 413 | emit showDate( d.year(), d.month(), d.day() ); |
414 | } | 414 | } |
415 | 415 | ||
416 | void DateBookWeek::setDate( int y, int m, int d ) | 416 | void DateBookWeek::setDate( int y, int m, int d ) |
417 | { | 417 | { |
418 | QDate date; | 418 | QDate date; |
419 | date.setYMD( y, m, d ); | 419 | date.setYMD( y, m, d ); |
420 | setDate(QDate(y, m, d)); | 420 | setDate(QDate(y, m, d)); |
421 | } | 421 | } |
422 | 422 | ||
423 | void DateBookWeek::setDate(QDate date) | 423 | void DateBookWeek::setDate(QDate date) |
424 | { | 424 | { |
425 | dow = date.dayOfWeek(); | 425 | dow = date.dayOfWeek(); |
426 | int w, y; | 426 | int w, y; |
427 | calcWeek( date, w, y, bStartOnMonday ); | 427 | calcWeek( date, w, y, bStartOnMonday ); |
428 | header->setDate( y, w ); | 428 | header->setDate( y, w ); |
429 | } | 429 | } |
430 | 430 | ||
431 | void DateBookWeek::dateChanged( int y, int w ) | 431 | void DateBookWeek::dateChanged( int y, int w ) |
432 | { | 432 | { |
433 | year = y; | 433 | year = y; |
434 | _week = w; | 434 | _week = w; |
435 | getEvents(); | 435 | getEvents(); |
436 | } | 436 | } |
437 | 437 | ||
438 | QDate DateBookWeek::date() const | 438 | QDate DateBookWeek::date() const |
439 | { | 439 | { |
440 | QDate d; | 440 | QDate d; |
441 | d = dateFromWeek( _week - 1, year, bStartOnMonday ); | 441 | d = dateFromWeek( _week - 1, year, bStartOnMonday ); |
442 | if ( bStartOnMonday ) | 442 | if ( bStartOnMonday ) |
443 | d = d.addDays( 7 + dow - 1 ); | 443 | d = d.addDays( 7 + dow - 1 ); |
444 | else { | 444 | else { |
445 | if ( dow == 7 ) | 445 | if ( dow == 7 ) |
446 | d = d.addDays( dow ); | 446 | d = d.addDays( dow ); |
447 | else | 447 | else |
448 | d = d.addDays( 7 + dow ); | 448 | d = d.addDays( 7 + dow ); |
449 | } | 449 | } |
450 | return d; | 450 | return d; |
451 | } | 451 | } |
452 | 452 | ||
453 | void DateBookWeek::getEvents() | 453 | void DateBookWeek::getEvents() |
454 | { | 454 | { |
455 | QDate startWeek = weekDate(); | 455 | QDate startWeek = weekDate(); |
456 | 456 | ||
457 | QDate endWeek = startWeek.addDays( 6 ); | 457 | QDate endWeek = startWeek.addDays( 6 ); |
458 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, | 458 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, |
459 | endWeek); | 459 | endWeek); |
460 | view->showEvents( eventList ); | 460 | view->showEvents( eventList ); |
461 | view->moveToHour( startTime ); | 461 | view->moveToHour( startTime ); |
462 | } | 462 | } |
463 | 463 | ||
464 | void DateBookWeek::generateAllDayTooltext( QString& text ) { | 464 | void DateBookWeek::generateAllDayTooltext( QString& text ) { |
465 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; | 465 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; |
466 | } | 466 | } |
467 | 467 | ||
468 | void DateBookWeek::generateNormalTooltext( QString& str, | 468 | void DateBookWeek::generateNormalTooltext( QString& str, |
469 | const EffectiveEvent &ev ) { | 469 | const EffectiveEvent &ev ) { |
470 | str += "<b>" + QObject::tr("Start") + "</b>: "; | 470 | str += "<b>" + QObject::tr("Start") + "</b>: "; |
471 | 471 | ||
472 | if ( ev.startDate() != ev.date() ) { | 472 | if ( ev.startDate() != ev.date() ) { |
473 | // multi-day event. Show start date | 473 | // multi-day event. Show start date |
474 | str += TimeString::longDateString( ev.startDate() ); | 474 | str += TimeString::longDateString( ev.startDate() ); |
475 | } else { | 475 | } else { |
476 | // Show start time. | 476 | // Show start time. |
477 | str += TimeString::timeString(ev.start(), ampm, FALSE ); | 477 | str += TimeString::timeString(ev.start(), ampm, FALSE ); |
478 | } | 478 | } |
479 | 479 | ||
480 | 480 | ||
481 | str += "<br><b>" + QObject::tr("End") + "</b>: "; | 481 | str += "<br><b>" + QObject::tr("End") + "</b>: "; |
482 | if ( ev.endDate() != ev.date() ) { | 482 | if ( ev.endDate() != ev.date() ) { |
483 | // multi-day event. Show end date | 483 | // multi-day event. Show end date |
484 | str += TimeString::longDateString( ev.endDate() ); | 484 | str += TimeString::longDateString( ev.endDate() ); |
485 | } else { | 485 | } else { |
486 | // Show end time. | 486 | // Show end time. |
487 | str += TimeString::timeString( ev.end(), ampm, FALSE ); | 487 | str += TimeString::timeString( ev.end(), ampm, FALSE ); |
488 | } | 488 | } |
489 | } | 489 | } |
490 | 490 | ||
491 | void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) | 491 | void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) |
492 | { | 492 | { |
493 | if ( tHide->isActive() ) | 493 | if ( tHide->isActive() ) |
494 | tHide->stop(); | 494 | tHide->stop(); |
495 | 495 | ||
496 | // why would someone use "<"? Oh well, fix it up... | 496 | // why would someone use "<"? Oh well, fix it up... |
497 | // I wonder what other things may be messed up... | 497 | // I wonder what other things may be messed up... |
498 | QString strDesc = ev.description(); | 498 | QString strDesc = ev.description(); |
499 | int where = strDesc.find( "<" ); | 499 | int where = strDesc.find( "<" ); |
500 | while ( where != -1 ) { | 500 | while ( where != -1 ) { |
501 | strDesc.remove( where, 1 ); | 501 | strDesc.remove( where, 1 ); |
502 | strDesc.insert( where, "<" ); | 502 | strDesc.insert( where, "<" ); |
503 | where = strDesc.find( "<", where ); | 503 | where = strDesc.find( "<", where ); |
504 | } | 504 | } |
505 | 505 | ||
506 | QString strCat; | 506 | QString strCat; |
507 | // ### FIX later... | 507 | // ### FIX later... |
508 | // QString strCat = ev.category(); | 508 | // QString strCat = ev.category(); |
509 | // where = strCat.find( "<" ); | 509 | // where = strCat.find( "<" ); |
510 | // while ( where != -1 ) { | 510 | // while ( where != -1 ) { |
511 | // strCat.remove( where, 1 ); | 511 | // strCat.remove( where, 1 ); |
512 | // strCat.insert( where, "<" ); | 512 | // strCat.insert( where, "<" ); |
513 | // where = strCat.find( "<", where ); | 513 | // where = strCat.find( "<", where ); |
514 | // } | 514 | // } |
515 | 515 | ||
516 | QString strLocation = ev.location(); | ||
517 | while ( where != -1 ) { | ||
518 | strLocation.remove( where, 1 ); | ||
519 | strLocation.insert( where, "<" ); | ||
520 | where = strLocation.find( "<", where ); | ||
521 | } | ||
522 | |||
516 | QString strNote = ev.notes(); | 523 | QString strNote = ev.notes(); |
517 | where = strNote.find( "<" ); | 524 | where = strNote.find( "<" ); |
518 | while ( where != -1 ) { | 525 | while ( where != -1 ) { |
519 | strNote.remove( where, 1 ); | 526 | strNote.remove( where, 1 ); |
520 | strNote.insert( where, "<" ); | 527 | strNote.insert( where, "<" ); |
521 | where = strNote.find( "<", where ); | 528 | where = strNote.find( "<", where ); |
522 | } | 529 | } |
523 | 530 | ||
524 | QString str = "<b>" + strDesc + "</b><br>" + "<i>" | 531 | QString str = "<b>" + strDesc + "</b><br>" |
525 | + strCat + "</i>" | 532 | + strLocation + "<br>" |
533 | + "<i>" + strCat + "</i>" | ||
526 | + "<br>" + TimeString::longDateString( ev.date() ) | 534 | + "<br>" + TimeString::longDateString( ev.date() ) |
527 | + "<br>"; | 535 | + "<br>"; |
528 | 536 | ||
529 | if (ev.event().type() == Event::Normal ) | 537 | if (ev.event().type() == Event::Normal ) |
530 | generateNormalTooltext( str, ev ); | 538 | generateNormalTooltext( str, ev ); |
531 | else | 539 | else |
532 | generateAllDayTooltext( str ); | 540 | generateAllDayTooltext( str ); |
533 | 541 | ||
534 | str += "<br><br>" + strNote; | 542 | str += "<br><br>" + strNote; |
535 | 543 | ||
536 | lblDesc->setText( str ); | 544 | lblDesc->setText( str ); |
537 | lblDesc->resize( lblDesc->sizeHint() ); | 545 | lblDesc->resize( lblDesc->sizeHint() ); |
538 | // move the label so it is "centerd" horizontally... | 546 | // move the label so it is "centerd" horizontally... |
539 | lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 ); | 547 | lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 ); |
540 | lblDesc->show(); | 548 | lblDesc->show(); |
541 | } | 549 | } |
542 | 550 | ||
543 | void DateBookWeek::slotHideEvent() | 551 | void DateBookWeek::slotHideEvent() |
544 | { | 552 | { |
545 | tHide->start( 2000, true ); | 553 | tHide->start( 2000, true ); |
546 | } | 554 | } |
547 | 555 | ||
548 | void DateBookWeek::setStartViewTime( int startHere ) | 556 | void DateBookWeek::setStartViewTime( int startHere ) |
549 | { | 557 | { |
550 | startTime = startHere; | 558 | startTime = startHere; |
551 | view->moveToHour( startTime ); | 559 | view->moveToHour( startTime ); |
552 | } | 560 | } |
553 | 561 | ||
554 | int DateBookWeek::startViewTime() const | 562 | int DateBookWeek::startViewTime() const |
555 | { | 563 | { |
556 | return startTime; | 564 | return startTime; |
557 | } | 565 | } |
558 | 566 | ||
559 | void DateBookWeek::redraw() | 567 | void DateBookWeek::redraw() |
560 | { | 568 | { |
561 | getEvents(); | 569 | getEvents(); |
562 | } | 570 | } |
563 | 571 | ||
564 | void DateBookWeek::slotYearChanged( int y ) | 572 | void DateBookWeek::slotYearChanged( int y ) |
565 | { | 573 | { |
566 | int totWeek; | 574 | int totWeek; |
567 | QDate d( y, 12, 31 ); | 575 | QDate d( y, 12, 31 ); |
568 | int throwAway; | 576 | int throwAway; |
569 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); | 577 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); |
570 | while ( totWeek == 1 ) { | 578 | while ( totWeek == 1 ) { |
571 | d = d.addDays( -1 ); | 579 | d = d.addDays( -1 ); |
572 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); | 580 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); |
573 | } | 581 | } |
574 | if ( totWeek != totalWeeks() ) | 582 | if ( totWeek != totalWeeks() ) |
575 | setTotalWeeks( totWeek ); | 583 | setTotalWeeks( totWeek ); |
576 | } | 584 | } |
577 | 585 | ||
578 | 586 | ||
579 | void DateBookWeek::setTotalWeeks( int numWeeks ) | 587 | void DateBookWeek::setTotalWeeks( int numWeeks ) |
580 | { | 588 | { |
581 | header->spinWeek->setMaxValue( numWeeks ); | 589 | header->spinWeek->setMaxValue( numWeeks ); |
582 | } | 590 | } |
583 | 591 | ||
584 | int DateBookWeek::totalWeeks() const | 592 | int DateBookWeek::totalWeeks() const |
585 | { | 593 | { |
586 | return header->spinWeek->maxValue(); | 594 | return header->spinWeek->maxValue(); |
587 | } | 595 | } |
588 | 596 | ||
589 | void DateBookWeek::slotWeekChanged( bool onMonday ) | 597 | void DateBookWeek::slotWeekChanged( bool onMonday ) |
590 | { | 598 | { |
591 | bStartOnMonday = onMonday; | 599 | bStartOnMonday = onMonday; |
592 | view->setStartOfWeek( bStartOnMonday ); | 600 | view->setStartOfWeek( bStartOnMonday ); |
593 | header->setStartOfWeek( bStartOnMonday ); | 601 | header->setStartOfWeek( bStartOnMonday ); |
594 | redraw(); | 602 | redraw(); |
595 | } | 603 | } |
596 | 604 | ||
597 | void DateBookWeek::slotClockChanged( bool ap ) | 605 | void DateBookWeek::slotClockChanged( bool ap ) |
598 | { | 606 | { |
599 | ampm = ap; | 607 | ampm = ap; |
600 | } | 608 | } |
601 | 609 | ||
602 | // return the date at the beginning of the week... | 610 | // return the date at the beginning of the week... |
603 | QDate DateBookWeek::weekDate() const | 611 | QDate DateBookWeek::weekDate() const |
604 | { | 612 | { |
605 | return dateFromWeek( _week, year, bStartOnMonday ); | 613 | return dateFromWeek( _week, year, bStartOnMonday ); |
606 | } | 614 | } |
607 | 615 | ||
608 | // this used to only be needed by datebook.cpp, but now we need it inside | 616 | // this used to only be needed by datebook.cpp, but now we need it inside |
609 | // week view since | 617 | // week view since |
610 | // we need to be able to figure out our total number of weeks on the fly... | 618 | // we need to be able to figure out our total number of weeks on the fly... |
611 | // this is probably the best place to put it.. | 619 | // this is probably the best place to put it.. |
612 | 620 | ||
613 | // For Weeks that start on Monday... (EASY!) | 621 | // For Weeks that start on Monday... (EASY!) |
614 | // At the moment we will use ISO 8601 method for computing | 622 | // At the moment we will use ISO 8601 method for computing |
615 | // the week. Granted, other countries use other methods, | 623 | // the week. Granted, other countries use other methods, |
616 | // bet we aren't doing any Locale stuff at the moment. So, | 624 | // bet we aren't doing any Locale stuff at the moment. So, |
617 | // this should pass. This Algorithim is public domain and | 625 | // this should pass. This Algorithim is public domain and |
618 | // available at: | 626 | // available at: |
619 | // http://personal.ecu.edu/mccartyr/ISOwdALG.txt | 627 | // http://personal.ecu.edu/mccartyr/ISOwdALG.txt |
620 | // the week number is return, and the year number is returned in year | 628 | // the week number is return, and the year number is returned in year |
621 | // for Instance 2001/12/31 is actually the first week in 2002. | 629 | // for Instance 2001/12/31 is actually the first week in 2002. |
622 | // There is a more mathematical definition, but I will implement it when | 630 | // There is a more mathematical definition, but I will implement it when |
623 | // we are pass our deadline. | 631 | // we are pass our deadline. |
624 | 632 | ||
625 | // For Weeks that start on Sunday... (ahh... home rolled) | 633 | // For Weeks that start on Sunday... (ahh... home rolled) |
626 | // okay, if Jan 1 is on Friday or Saturday, | 634 | // okay, if Jan 1 is on Friday or Saturday, |
627 | // it will go to the pervious | 635 | // it will go to the pervious |
628 | // week... | 636 | // week... |
629 | 637 | ||
630 | bool calcWeek( const QDate &d, int &week, int &year, | 638 | bool calcWeek( const QDate &d, int &week, int &year, |
631 | bool startOnMonday ) | 639 | bool startOnMonday ) |
632 | { | 640 | { |
633 | int weekNumber; | 641 | int weekNumber; |
634 | int yearNumber; | 642 | int yearNumber; |
635 | 643 | ||
636 | // remove a pesky warning, (Optimizations on g++) | 644 | // remove a pesky warning, (Optimizations on g++) |
637 | weekNumber = -1; | 645 | weekNumber = -1; |
638 | int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); | 646 | int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); |
639 | int dayOfWeek = d.dayOfWeek(); | 647 | int dayOfWeek = d.dayOfWeek(); |
640 | 648 | ||
641 | if ( !d.isValid() ) | 649 | if ( !d.isValid() ) |
642 | return false; | 650 | return false; |
643 | 651 | ||
644 | if ( startOnMonday ) { | 652 | if ( startOnMonday ) { |
645 | // find the Jan1Weekday; | 653 | // find the Jan1Weekday; |
646 | if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { | 654 | if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { |
647 | yearNumber = d.year() - 1; | 655 | yearNumber = d.year() - 1; |
648 | if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) | 656 | if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) |
649 | weekNumber = 53; | 657 | weekNumber = 53; |
650 | else | 658 | else |
651 | weekNumber = 52; | 659 | weekNumber = 52; |
652 | } else | 660 | } else |
653 | yearNumber = d.year(); | 661 | yearNumber = d.year(); |
654 | if ( yearNumber == d.year() ) { | 662 | if ( yearNumber == d.year() ) { |
655 | int totalDays = 365; | 663 | int totalDays = 365; |
656 | if ( QDate::leapYear(yearNumber) ) | 664 | if ( QDate::leapYear(yearNumber) ) |
657 | totalDays++; | 665 | totalDays++; |
658 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) | 666 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) |
659 | || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { | 667 | || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { |
660 | yearNumber++; | 668 | yearNumber++; |
661 | weekNumber = 1; | 669 | weekNumber = 1; |
662 | } | 670 | } |
663 | } | 671 | } |
664 | if ( yearNumber == d.year() ) { | 672 | if ( yearNumber == d.year() ) { |
665 | int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); | 673 | int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); |
666 | weekNumber = j / 7; | 674 | weekNumber = j / 7; |
667 | if ( jan1WeekDay > 4 ) | 675 | if ( jan1WeekDay > 4 ) |
668 | weekNumber--; | 676 | weekNumber--; |
669 | } | 677 | } |
670 | } else { | 678 | } else { |
671 | // it's better to keep these cases separate... | 679 | // it's better to keep these cases separate... |
672 | if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 | 680 | if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 |
673 | && jan1WeekDay != 7 ) { | 681 | && jan1WeekDay != 7 ) { |
674 | yearNumber = d.year() - 1; | 682 | yearNumber = d.year() - 1; |
675 | if ( jan1WeekDay == 6 | 683 | if ( jan1WeekDay == 6 |
676 | || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { | 684 | || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { |
677 | weekNumber = 53; | 685 | weekNumber = 53; |
678 | }else | 686 | }else |
679 | weekNumber = 52; | 687 | weekNumber = 52; |
680 | } else | 688 | } else |
681 | yearNumber = d.year(); | 689 | yearNumber = d.year(); |
682 | if ( yearNumber == d.year() ) { | 690 | if ( yearNumber == d.year() ) { |
683 | int totalDays = 365; | 691 | int totalDays = 365; |
684 | if ( QDate::leapYear( yearNumber ) ) | 692 | if ( QDate::leapYear( yearNumber ) ) |
685 | totalDays++; | 693 | totalDays++; |
686 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { | 694 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { |
687 | yearNumber++; | 695 | yearNumber++; |
688 | weekNumber = 1; | 696 | weekNumber = 1; |
689 | } | 697 | } |
690 | } | 698 | } |
691 | if ( yearNumber == d.year() ) { | 699 | if ( yearNumber == d.year() ) { |
692 | int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); | 700 | int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); |
693 | weekNumber = j / 7; | 701 | weekNumber = j / 7; |
694 | if ( jan1WeekDay > 4 ) { | 702 | if ( jan1WeekDay > 4 ) { |
695 | weekNumber--; | 703 | weekNumber--; |
696 | } | 704 | } |
697 | } | 705 | } |
698 | } | 706 | } |
699 | year = yearNumber; | 707 | year = yearNumber; |
700 | week = weekNumber; | 708 | week = weekNumber; |
701 | return true; | 709 | return true; |
702 | } | 710 | } |
703 | 711 | ||