author | zecke <zecke> | 2004-02-16 21:32:58 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-16 21:32:58 (UTC) |
commit | e228f4aa24ce73a49dde349544e55689cb0eccba (patch) (unidiff) | |
tree | 5b9be29793b2a72f9260cb1325751d31e40c18f0 | |
parent | 38d601a7d2a975bc0cbcc4cc933844f5572ec4fa (diff) | |
download | opie-e228f4aa24ce73a49dde349544e55689cb0eccba.zip opie-e228f4aa24ce73a49dde349544e55689cb0eccba.tar.gz opie-e228f4aa24ce73a49dde349544e55689cb0eccba.tar.bz2 |
Take care of the lifetime of the EffectiveEvent/Occurence
Make sure not to keep reference on non existing objects
-rw-r--r-- | core/pim/datebook/datebookday.cpp | 10 | ||||
-rw-r--r-- | core/pim/datebook/datebookday.h | 2 | ||||
-rw-r--r-- | core/pim/datebook/datebookdayallday.cpp | 11 | ||||
-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 4 |
4 files changed, 13 insertions, 14 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index 4d64099..751a1da 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp | |||
@@ -670,264 +670,266 @@ DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db ) | |||
670 | 670 | ||
671 | setBackgroundMode( PaletteBase ); | 671 | setBackgroundMode( PaletteBase ); |
672 | 672 | ||
673 | QTime start = ev.start(); | 673 | QTime start = ev.start(); |
674 | QTime end = ev.end(); | 674 | QTime end = ev.end(); |
675 | int y = start.hour()*60+start.minute(); | 675 | int y = start.hour()*60+start.minute(); |
676 | int h = end.hour()*60+end.minute()-y; | 676 | int h = end.hour()*60+end.minute()-y; |
677 | int rh = dateBook->dayView()->rowHeight(0); | 677 | int rh = dateBook->dayView()->rowHeight(0); |
678 | y = y*rh/60; | 678 | y = y*rh/60; |
679 | h = h*rh/60; | 679 | h = h*rh/60; |
680 | 680 | ||
681 | if ( h < 12 ) h = 12;// Make sure the widget is no smaller than 12 pixels high, so that it's possible to read atleast the first line. | 681 | if ( h < 12 ) h = 12;// Make sure the widget is no smaller than 12 pixels high, so that it's possible to read atleast the first line. |
682 | if ( y > ((24*rh)-12) ) y=(24*rh)-12;// Make sure the widget fits inside the dayview. | 682 | if ( y > ((24*rh)-12) ) y=(24*rh)-12;// Make sure the widget fits inside the dayview. |
683 | geom.setY( y ); | 683 | geom.setY( y ); |
684 | geom.setHeight( h ); | 684 | geom.setHeight( h ); |
685 | geom.setX( 0 ); | 685 | geom.setX( 0 ); |
686 | geom.setWidth(dateBook->dayView()->columnWidth(0)-1); | 686 | geom.setWidth(dateBook->dayView()->columnWidth(0)-1); |
687 | 687 | ||
688 | } | 688 | } |
689 | 689 | ||
690 | void DateBookDayWidget::setAllDayText( QString &text ) { | 690 | void DateBookDayWidget::setAllDayText( QString &text ) { |
691 | text += "<b>" + tr("This is an all day event.") + "</b>"; | 691 | text += "<b>" + tr("This is an all day event.") + "</b>"; |
692 | } | 692 | } |
693 | 693 | ||
694 | void DateBookDayWidget::setEventText( QString& text ) { | 694 | void DateBookDayWidget::setEventText( QString& text ) { |
695 | bool whichClock = dateBook->dayView()->whichClock(); | 695 | bool whichClock = dateBook->dayView()->whichClock(); |
696 | if ( ev.startDate() != ev.endDate() ) { | 696 | if ( ev.startDate() != ev.endDate() ) { |
697 | text += "<b>" + tr("Start") + "</b>: "; | 697 | text += "<b>" + tr("Start") + "</b>: "; |
698 | text += TimeString::timeString( ev.event().start().time(), whichClock, FALSE ); | 698 | text += TimeString::timeString( ev.event().start().time(), whichClock, FALSE ); |
699 | text += " - " + TimeString::longDateString( ev.startDate() ) + "<br>"; | 699 | text += " - " + TimeString::longDateString( ev.startDate() ) + "<br>"; |
700 | text += "<b>" + tr("End") + "</b>: "; | 700 | text += "<b>" + tr("End") + "</b>: "; |
701 | text += TimeString::timeString( ev.event().end().time(), whichClock, FALSE ); | 701 | text += TimeString::timeString( ev.event().end().time(), whichClock, FALSE ); |
702 | text += " - " + TimeString::longDateString( ev.endDate() ); | 702 | text += " - " + TimeString::longDateString( ev.endDate() ); |
703 | } else { | 703 | } else { |
704 | text += "<b>" + tr("Time") + "</b>: "; | 704 | text += "<b>" + tr("Time") + "</b>: "; |
705 | text += TimeString::timeString( ev.start(), whichClock, FALSE ); | 705 | text += TimeString::timeString( ev.start(), whichClock, FALSE ); |
706 | text += "<b>" + tr(" - ") + "</b>"; | 706 | text += "<b>" + tr(" - ") + "</b>"; |
707 | text += TimeString::timeString( ev.end(), whichClock, FALSE ); | 707 | text += TimeString::timeString( ev.end(), whichClock, FALSE ); |
708 | } | 708 | } |
709 | } | 709 | } |
710 | 710 | ||
711 | DateBookDayWidget::~DateBookDayWidget() | 711 | DateBookDayWidget::~DateBookDayWidget() |
712 | { | 712 | { |
713 | } | 713 | } |
714 | 714 | ||
715 | void DateBookDayWidget::paintEvent( QPaintEvent *e ) | 715 | void DateBookDayWidget::paintEvent( QPaintEvent *e ) |
716 | { | 716 | { |
717 | QPainter p( this ); | 717 | QPainter p( this ); |
718 | 718 | ||
719 | if (dateBook->getSelectedWidget() == this) { | 719 | if (dateBook->getSelectedWidget() == this) { |
720 | p.setBrush( QColor( 155, 240, 230 ) ); // selected item | 720 | p.setBrush( QColor( 155, 240, 230 ) ); // selected item |
721 | } else { | 721 | } else { |
722 | if (dateBook->date() == QDate::currentDate()) { | 722 | if (dateBook->date() == QDate::currentDate()) { |
723 | QTime curTime = QTime::currentTime(); | 723 | QTime curTime = QTime::currentTime(); |
724 | if (ev.end() < curTime) { | 724 | if (ev.end() < curTime) { |
725 | p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive | 725 | p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive |
726 | } else { | 726 | } else { |
727 | //change color in dependence of the time till the event starts | 727 | //change color in dependence of the time till the event starts |
728 | int duration = curTime.secsTo(ev.start()); | 728 | int duration = curTime.secsTo(ev.start()); |
729 | if (duration < 0) duration = 0; | 729 | if (duration < 0) duration = 0; |
730 | int colChange = duration*160/86400; //86400: secs per day, 160: max color shift | 730 | int colChange = duration*160/86400; //86400: secs per day, 160: max color shift |
731 | p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue | 731 | p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue |
732 | } | 732 | } |
733 | } else { | 733 | } else { |
734 | p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date) | 734 | p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date) |
735 | //perhaps make a distinction between future/past dates | 735 | //perhaps make a distinction between future/past dates |
736 | } | 736 | } |
737 | } | 737 | } |
738 | 738 | ||
739 | p.setPen( QColor(100, 100, 100) ); | 739 | p.setPen( QColor(100, 100, 100) ); |
740 | p.drawRect(rect()); | 740 | p.drawRect(rect()); |
741 | 741 | ||
742 | // p.drawRect(0,0, 5, height()); | 742 | // p.drawRect(0,0, 5, height()); |
743 | 743 | ||
744 | int y = 0; | 744 | int y = 0; |
745 | int d = 0; | 745 | int d = 0; |
746 | 746 | ||
747 | if ( ev.event().hasAlarm() ) { | 747 | if ( ev.event().hasAlarm() ) { |
748 | p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); | 748 | p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); |
749 | y = 20; | 749 | y = 20; |
750 | d = 20; | 750 | d = 20; |
751 | } | 751 | } |
752 | 752 | ||
753 | if ( ev.event().hasRepeat() ) { | 753 | if ( ev.event().hasRepeat() ) { |
754 | p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); | 754 | p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); |
755 | d = 20; | 755 | d = 20; |
756 | y += 20; | 756 | y += 20; |
757 | } | 757 | } |
758 | 758 | ||
759 | QSimpleRichText rt( text, font() ); | 759 | QSimpleRichText rt( text, font() ); |
760 | rt.setWidth( geom.width() - d - 6 ); | 760 | rt.setWidth( geom.width() - d - 6 ); |
761 | rt.draw( &p, 7, 0, e->region(), colorGroup() ); | 761 | rt.draw( &p, 7, 0, e->region(), colorGroup() ); |
762 | } | 762 | } |
763 | 763 | ||
764 | /* | 764 | /* |
765 | * we need to find the real start date for a uid | 765 | * we need to find the real start date for a uid |
766 | * we need to check from one day to another... | 766 | * we need to check from one day to another... |
767 | */ | 767 | */ |
768 | QDate DateBookDay::findRealStart( int uid, const QDate& isIncluded , DateBookDB* db) { | 768 | QDate DateBookDay::findRealStart( int uid, const QDate& isIncluded , DateBookDB* db) { |
769 | QDate dt( isIncluded ); | 769 | QDate dt( isIncluded ); |
770 | QDate fnd = dt; | 770 | QDate fnd = dt; |
771 | 771 | ||
772 | bool doAgain = true; | 772 | bool doAgain = true; |
773 | do{ | 773 | do{ |
774 | dt = dt.addDays( -1 ); | 774 | dt = dt.addDays( -1 ); |
775 | QValueList<EffectiveEvent> events = db->getEffectiveEvents( dt, dt ); | 775 | QValueList<EffectiveEvent> events = db->getEffectiveEvents( dt, dt ); |
776 | for (QValueList<EffectiveEvent>::Iterator it = events.begin(); it != events.end(); ++it ) { | 776 | for (QValueList<EffectiveEvent>::Iterator it = events.begin(); it != events.end(); ++it ) { |
777 | EffectiveEvent ev = (*it); | 777 | EffectiveEvent ev = (*it); |
778 | if ( uid == ev.event().uid() && ev.start() != QTime(0, 0, 0 ) ) | 778 | if ( uid == ev.event().uid() && ev.start() != QTime(0, 0, 0 ) ) |
779 | return ev.date(); | 779 | return ev.date(); |
780 | } | 780 | } |
781 | }while (doAgain ); | 781 | }while (doAgain ); |
782 | 782 | ||
783 | return fnd; | 783 | return fnd; |
784 | } | 784 | } |
785 | 785 | ||
786 | void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) | 786 | void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) |
787 | { | 787 | { |
788 | DateBookDayWidget *item; | 788 | DateBookDayWidget *item; |
789 | 789 | ||
790 | item = dateBook->getSelectedWidget(); | 790 | item = dateBook->getSelectedWidget(); |
791 | if (item) | 791 | if (item) |
792 | item->update(); | 792 | item->update(); |
793 | 793 | ||
794 | dateBook->setSelectedWidget(this); | 794 | dateBook->setSelectedWidget(this); |
795 | update(); | 795 | update(); |
796 | dateBook->repaint(); | 796 | dateBook->repaint(); |
797 | 797 | ||
798 | Event eve = ev.event(); | ||
799 | |||
798 | QPopupMenu m; | 800 | QPopupMenu m; |
799 | m.insertItem( tr( "Edit" ), 1 ); | 801 | m.insertItem( tr( "Edit" ), 1 ); |
800 | m.insertItem( tr( "Duplicate" ), 4 ); | 802 | m.insertItem( tr( "Duplicate" ), 4 ); |
801 | m.insertItem( tr( "Delete" ), 2 ); | 803 | m.insertItem( tr( "Delete" ), 2 ); |
802 | if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); | 804 | if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); |
803 | if(Ir::supported() && ev.event().doRepeat() ) m.insertItem( tr( "Beam this occurence"), 5 ); | 805 | if(Ir::supported() && ev.event().doRepeat() ) m.insertItem( tr( "Beam this occurence"), 5 ); |
804 | int r = m.exec( e->globalPos() ); | 806 | int r = m.exec( e->globalPos() ); |
805 | if ( r == 1 ) { | 807 | if ( r == 1 ) { |
806 | emit editMe( ev.event() ); | 808 | emit editMe( eve ); |
807 | } else if ( r == 2 ) { | 809 | } else if ( r == 2 ) { |
808 | emit deleteMe( ev.event() ); | 810 | emit deleteMe( eve ); |
809 | } else if ( r == 3 ) { | 811 | } else if ( r == 3 ) { |
810 | emit beamMe( ev.event() ); | 812 | emit beamMe( eve ); |
811 | } else if ( r == 4 ) { | 813 | } else if ( r == 4 ) { |
812 | emit duplicateMe( ev.event() ); | 814 | emit duplicateMe( eve ); |
813 | } else if ( r == 5 ) { | 815 | } else if ( r == 5 ) { |
814 | // create an Event and beam it... | 816 | // create an Event and beam it... |
815 | /* | 817 | /* |
816 | * Start with the easy stuff. If start and end date is the same we can just use | 818 | * Start with the easy stuff. If start and end date is the same we can just use |
817 | * the values of effective events | 819 | * the values of effective events |
818 | * If it is a multi day event we need to find the real start and end date... | 820 | * If it is a multi day event we need to find the real start and end date... |
819 | */ | 821 | */ |
820 | if ( ev.event().start().date() == ev.event().end().date() ) { | 822 | if ( ev.event().start().date() == ev.event().end().date() ) { |
821 | Event event( ev.event() ); | 823 | Event event( ev.event() ); |
822 | 824 | ||
823 | QDateTime dt( ev.date(), ev.start() ); | 825 | QDateTime dt( ev.date(), ev.start() ); |
824 | event.setStart( dt ); | 826 | event.setStart( dt ); |
825 | 827 | ||
826 | dt.setTime( ev.end() ); | 828 | dt.setTime( ev.end() ); |
827 | event.setEnd( dt ); | 829 | event.setEnd( dt ); |
828 | emit beamMe( event ); | 830 | emit beamMe( event ); |
829 | }else { | 831 | }else { |
830 | /* | 832 | /* |
831 | * at least the the Times are right now | 833 | * at least the the Times are right now |
832 | */ | 834 | */ |
833 | QDateTime start( ev.event().start() ); | 835 | QDateTime start( ev.event().start() ); |
834 | QDateTime end ( ev.event().end () ); | 836 | QDateTime end ( ev.event().end () ); |
835 | 837 | ||
836 | 838 | ||
837 | /* | 839 | /* |
838 | * ok we know the start date or we need to find it | 840 | * ok we know the start date or we need to find it |
839 | */ | 841 | */ |
840 | if ( ev.start() != QTime( 0, 0, 0 ) ) { | 842 | if ( ev.start() != QTime( 0, 0, 0 ) ) { |
841 | start.setDate( ev.date() ); | 843 | start.setDate( ev.date() ); |
842 | }else { | 844 | }else { |
843 | QDate dt = DateBookDay::findRealStart( ev.event().uid(), ev.date(), dateBook->db ); | 845 | QDate dt = DateBookDay::findRealStart( ev.event().uid(), ev.date(), dateBook->db ); |
844 | start.setDate( dt ); | 846 | start.setDate( dt ); |
845 | } | 847 | } |
846 | 848 | ||
847 | 849 | ||
848 | /* | 850 | /* |
849 | * ok we know now the end date... | 851 | * ok we know now the end date... |
850 | * else | 852 | * else |
851 | * get to know the offset btw the real start and real end | 853 | * get to know the offset btw the real start and real end |
852 | * and then add it to the new start date... | 854 | * and then add it to the new start date... |
853 | */ | 855 | */ |
854 | if ( ev.end() != QTime(23, 59, 59 ) ) { | 856 | if ( ev.end() != QTime(23, 59, 59 ) ) { |
855 | end.setDate( ev.date() ); | 857 | end.setDate( ev.date() ); |
856 | }else{ | 858 | }else{ |
857 | int days = ev.event().start().date().daysTo( ev.event().end().date() ); | 859 | int days = ev.event().start().date().daysTo( ev.event().end().date() ); |
858 | end.setDate( start.date().addDays( days ) ); | 860 | end.setDate( start.date().addDays( days ) ); |
859 | } | 861 | } |
860 | 862 | ||
861 | 863 | ||
862 | 864 | ||
863 | Event event( ev.event() ); | 865 | Event event( ev.event() ); |
864 | event.setStart( start ); | 866 | event.setStart( start ); |
865 | event.setEnd ( end ); | 867 | event.setEnd ( end ); |
866 | 868 | ||
867 | 869 | ||
868 | emit beamMe( event ); | 870 | emit beamMe( event ); |
869 | } | 871 | } |
870 | } | 872 | } |
871 | } | 873 | } |
872 | 874 | ||
873 | void DateBookDayWidget::setGeometry( const QRect &r ) | 875 | void DateBookDayWidget::setGeometry( const QRect &r ) |
874 | { | 876 | { |
875 | geom = r; | 877 | geom = r; |
876 | setFixedSize( r.width()+1, r.height()+1 ); | 878 | setFixedSize( r.width()+1, r.height()+1 ); |
877 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); | 879 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); |
878 | show(); | 880 | show(); |
879 | } | 881 | } |
880 | 882 | ||
881 | 883 | ||
882 | //--------------------------------------------------------------------------------------------- | 884 | //--------------------------------------------------------------------------------------------- |
883 | //--------------------------------------------------------------------------------------------- | 885 | //--------------------------------------------------------------------------------------------- |
884 | 886 | ||
885 | 887 | ||
886 | DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) | 888 | DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) |
887 | : QWidget( db->dayView()->viewport() ), dateBook( db ) | 889 | : QWidget( db->dayView()->viewport() ), dateBook( db ) |
888 | { | 890 | { |
889 | setBackgroundMode( PaletteBase ); | 891 | setBackgroundMode( PaletteBase ); |
890 | } | 892 | } |
891 | 893 | ||
892 | DateBookDayTimeMarker::~DateBookDayTimeMarker() | 894 | DateBookDayTimeMarker::~DateBookDayTimeMarker() |
893 | { | 895 | { |
894 | } | 896 | } |
895 | 897 | ||
896 | void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ ) | 898 | void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ ) |
897 | { | 899 | { |
898 | QPainter p( this ); | 900 | QPainter p( this ); |
899 | p.setBrush( QColor( 255, 0, 0 ) ); | 901 | p.setBrush( QColor( 255, 0, 0 ) ); |
900 | 902 | ||
901 | QPen pen; | 903 | QPen pen; |
902 | pen.setStyle(NoPen); | 904 | pen.setStyle(NoPen); |
903 | 905 | ||
904 | p.setPen( pen ); | 906 | p.setPen( pen ); |
905 | p.drawRect(rect()); | 907 | p.drawRect(rect()); |
906 | } | 908 | } |
907 | 909 | ||
908 | void DateBookDayTimeMarker::setTime( const QTime &t ) | 910 | void DateBookDayTimeMarker::setTime( const QTime &t ) |
909 | { | 911 | { |
910 | int y = t.hour()*60+t.minute(); | 912 | int y = t.hour()*60+t.minute(); |
911 | int rh = dateBook->dayView()->rowHeight(0); | 913 | int rh = dateBook->dayView()->rowHeight(0); |
912 | y = y*rh/60; | 914 | y = y*rh/60; |
913 | 915 | ||
914 | geom.setX( 0 ); | 916 | geom.setX( 0 ); |
915 | 917 | ||
916 | int x = dateBook->dayView()->columnWidth(0)-1; | 918 | int x = dateBook->dayView()->columnWidth(0)-1; |
917 | geom.setWidth( x ); | 919 | geom.setWidth( x ); |
918 | 920 | ||
919 | geom.setY( y ); | 921 | geom.setY( y ); |
920 | geom.setHeight( 1 ); | 922 | geom.setHeight( 1 ); |
921 | 923 | ||
922 | setGeometry( geom ); | 924 | setGeometry( geom ); |
923 | 925 | ||
924 | time = t; | 926 | time = t; |
925 | } | 927 | } |
926 | 928 | ||
927 | void DateBookDayTimeMarker::setGeometry( const QRect &r ) | 929 | void DateBookDayTimeMarker::setGeometry( const QRect &r ) |
928 | { | 930 | { |
929 | geom = r; | 931 | geom = r; |
930 | setFixedSize( r.width()+1, r.height()+1 ); | 932 | setFixedSize( r.width()+1, r.height()+1 ); |
931 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); | 933 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); |
932 | show(); | 934 | show(); |
933 | } | 935 | } |
diff --git a/core/pim/datebook/datebookday.h b/core/pim/datebook/datebookday.h index 3898cbc..c8cb26b 100644 --- a/core/pim/datebook/datebookday.h +++ b/core/pim/datebook/datebookday.h | |||
@@ -1,236 +1,236 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef DATEBOOKDAY_H | 20 | #ifndef DATEBOOKDAY_H |
21 | #define DATEBOOKDAY_H | 21 | #define DATEBOOKDAY_H |
22 | 22 | ||
23 | #include <qpe/event.h> | 23 | #include <qpe/event.h> |
24 | 24 | ||
25 | #include <qdatetime.h> | 25 | #include <qdatetime.h> |
26 | #include <qtable.h> | 26 | #include <qtable.h> |
27 | #include <qvbox.h> | 27 | #include <qvbox.h> |
28 | #include <qlist.h> | 28 | #include <qlist.h> |
29 | 29 | ||
30 | #include "datebook.h" | 30 | #include "datebook.h" |
31 | #include <qlineedit.h> | 31 | #include <qlineedit.h> |
32 | 32 | ||
33 | class DateBookDayHeader; | 33 | class DateBookDayHeader; |
34 | class DateBookDB; | 34 | class DateBookDB; |
35 | class DatebookdayAllday; | 35 | class DatebookdayAllday; |
36 | class QDateTime; | 36 | class QDateTime; |
37 | class QMouseEvent; | 37 | class QMouseEvent; |
38 | class QPaintEvent; | 38 | class QPaintEvent; |
39 | class QResizeEvent; | 39 | class QResizeEvent; |
40 | 40 | ||
41 | class DateBookDayViewQuickLineEdit : public QLineEdit | 41 | class DateBookDayViewQuickLineEdit : public QLineEdit |
42 | { | 42 | { |
43 | Q_OBJECT | 43 | Q_OBJECT |
44 | public: | 44 | public: |
45 | DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name=0); | 45 | DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name=0); |
46 | protected: | 46 | protected: |
47 | Event quickEvent; | 47 | Event quickEvent; |
48 | int active; | 48 | int active; |
49 | void focusOutEvent( QFocusEvent *e ); | 49 | void focusOutEvent( QFocusEvent *e ); |
50 | protected slots: | 50 | protected slots: |
51 | void slotReturnPressed(void); | 51 | void slotReturnPressed(void); |
52 | void finallyCallClose(); | 52 | void finallyCallClose(); |
53 | signals: | 53 | signals: |
54 | void insertEvent(const Event &e); | 54 | void insertEvent(const Event &e); |
55 | }; | 55 | }; |
56 | 56 | ||
57 | 57 | ||
58 | class DateBookDayView : public QTable | 58 | class DateBookDayView : public QTable |
59 | { | 59 | { |
60 | Q_OBJECT | 60 | Q_OBJECT |
61 | public: | 61 | public: |
62 | DateBookDayView( bool hourClock, QWidget *parent, const char *name ); | 62 | DateBookDayView( bool hourClock, QWidget *parent, const char *name ); |
63 | bool whichClock() const; | 63 | bool whichClock() const; |
64 | 64 | ||
65 | void setRowStyle( int style ); | 65 | void setRowStyle( int style ); |
66 | 66 | ||
67 | public slots: | 67 | public slots: |
68 | void moveUp(); | 68 | void moveUp(); |
69 | void moveDown(); | 69 | void moveDown(); |
70 | void slotDateChanged( int year, int month, int day ); | 70 | void slotDateChanged( int year, int month, int day ); |
71 | 71 | ||
72 | signals: | 72 | signals: |
73 | void sigColWidthChanged(); | 73 | void sigColWidthChanged(); |
74 | void sigCapturedKey( const QString &txt ); | 74 | void sigCapturedKey( const QString &txt ); |
75 | protected slots: | 75 | protected slots: |
76 | void slotChangeClock( bool ); | 76 | void slotChangeClock( bool ); |
77 | protected: | 77 | protected: |
78 | virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected ); | 78 | virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected ); |
79 | virtual void paintFocus( QPainter *p, const QRect &cr ); | 79 | virtual void paintFocus( QPainter *p, const QRect &cr ); |
80 | 80 | ||
81 | virtual void resizeEvent( QResizeEvent *e ); | 81 | virtual void resizeEvent( QResizeEvent *e ); |
82 | void keyPressEvent( QKeyEvent *e ); | 82 | void keyPressEvent( QKeyEvent *e ); |
83 | void contentsMouseReleaseEvent( QMouseEvent *e ); | 83 | void contentsMouseReleaseEvent( QMouseEvent *e ); |
84 | void initHeader(); | 84 | void initHeader(); |
85 | private: | 85 | private: |
86 | bool ampm; | 86 | bool ampm; |
87 | QDate currDate; | 87 | QDate currDate; |
88 | DateBookDayViewQuickLineEdit *quickLineEdit; | 88 | DateBookDayViewQuickLineEdit *quickLineEdit; |
89 | }; | 89 | }; |
90 | 90 | ||
91 | class DateBookDay; | 91 | class DateBookDay; |
92 | class DateBookDayWidget : public QWidget | 92 | class DateBookDayWidget : public QWidget |
93 | { | 93 | { |
94 | Q_OBJECT | 94 | Q_OBJECT |
95 | 95 | ||
96 | public: | 96 | public: |
97 | DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db ); | 97 | DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db ); |
98 | ~DateBookDayWidget(); | 98 | ~DateBookDayWidget(); |
99 | 99 | ||
100 | const QRect &geometry() { return geom; } | 100 | const QRect &geometry() { return geom; } |
101 | void setGeometry( const QRect &r ); | 101 | void setGeometry( const QRect &r ); |
102 | 102 | ||
103 | const EffectiveEvent &event() const { return ev; } | 103 | const EffectiveEvent &event() const { return ev; } |
104 | 104 | ||
105 | signals: | 105 | signals: |
106 | void deleteMe( const Event &e ); | 106 | void deleteMe( const Event &e ); |
107 | void duplicateMe( const Event &e ); | 107 | void duplicateMe( const Event &e ); |
108 | void editMe( const Event &e ); | 108 | void editMe( const Event &e ); |
109 | void beamMe( const Event &e ); | 109 | void beamMe( const Event &e ); |
110 | 110 | ||
111 | protected: | 111 | protected: |
112 | void paintEvent( QPaintEvent *e ); | 112 | void paintEvent( QPaintEvent *e ); |
113 | void mousePressEvent( QMouseEvent *e ); | 113 | void mousePressEvent( QMouseEvent *e ); |
114 | 114 | ||
115 | private: | 115 | private: |
116 | /** | 116 | /** |
117 | * Sets the text for an all day Event | 117 | * Sets the text for an all day Event |
118 | * All day events have no time associated | 118 | * All day events have no time associated |
119 | */ | 119 | */ |
120 | void setAllDayText( QString& text ); | 120 | void setAllDayText( QString& text ); |
121 | 121 | ||
122 | /** | 122 | /** |
123 | * Sets the EventText | 123 | * Sets the EventText |
124 | * it got a start and an end Time | 124 | * it got a start and an end Time |
125 | */ | 125 | */ |
126 | void setEventText( QString& text ); | 126 | void setEventText( QString& text ); |
127 | const EffectiveEvent ev; | 127 | EffectiveEvent ev; |
128 | DateBookDay *dateBook; | 128 | DateBookDay *dateBook; |
129 | QString text; | 129 | QString text; |
130 | QRect geom; | 130 | QRect geom; |
131 | }; | 131 | }; |
132 | 132 | ||
133 | //Marker for current time in the dayview | 133 | //Marker for current time in the dayview |
134 | class DateBookDayTimeMarker : public QWidget | 134 | class DateBookDayTimeMarker : public QWidget |
135 | { | 135 | { |
136 | Q_OBJECT | 136 | Q_OBJECT |
137 | 137 | ||
138 | public: | 138 | public: |
139 | DateBookDayTimeMarker( DateBookDay *db ); | 139 | DateBookDayTimeMarker( DateBookDay *db ); |
140 | ~DateBookDayTimeMarker(); | 140 | ~DateBookDayTimeMarker(); |
141 | 141 | ||
142 | const QRect &geometry() { return geom; } | 142 | const QRect &geometry() { return geom; } |
143 | void setGeometry( const QRect &r ); | 143 | void setGeometry( const QRect &r ); |
144 | void setTime( const QTime &t ); | 144 | void setTime( const QTime &t ); |
145 | 145 | ||
146 | signals: | 146 | signals: |
147 | 147 | ||
148 | protected: | 148 | protected: |
149 | void paintEvent( QPaintEvent *e ); | 149 | void paintEvent( QPaintEvent *e ); |
150 | 150 | ||
151 | private: | 151 | private: |
152 | QRect geom; | 152 | QRect geom; |
153 | QTime time; | 153 | QTime time; |
154 | DateBookDay *dateBook; | 154 | DateBookDay *dateBook; |
155 | }; | 155 | }; |
156 | 156 | ||
157 | //reimplemented the compareItems function so that it sorts DayWidgets by geometry heights | 157 | //reimplemented the compareItems function so that it sorts DayWidgets by geometry heights |
158 | class WidgetListClass : public QList<DateBookDayWidget> | 158 | class WidgetListClass : public QList<DateBookDayWidget> |
159 | { | 159 | { |
160 | private: | 160 | private: |
161 | 161 | ||
162 | int compareItems( QCollection::Item s1, QCollection::Item s2 ) | 162 | int compareItems( QCollection::Item s1, QCollection::Item s2 ) |
163 | { | 163 | { |
164 | //hmm, don't punish me for that ;) | 164 | //hmm, don't punish me for that ;) |
165 | if (reinterpret_cast<DateBookDayWidget*>(s1)->geometry().height() > reinterpret_cast<DateBookDayWidget*>(s2)->geometry().height()) | 165 | if (reinterpret_cast<DateBookDayWidget*>(s1)->geometry().height() > reinterpret_cast<DateBookDayWidget*>(s2)->geometry().height()) |
166 | { | 166 | { |
167 | return -1; | 167 | return -1; |
168 | } else | 168 | } else |
169 | { | 169 | { |
170 | return 1; | 170 | return 1; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | }; | 175 | }; |
176 | 176 | ||
177 | class DateBookDay : public QVBox | 177 | class DateBookDay : public QVBox |
178 | { | 178 | { |
179 | Q_OBJECT | 179 | Q_OBJECT |
180 | 180 | ||
181 | friend class DateBookDayWidget; // for beam this occurence and access to DateBookDB | 181 | friend class DateBookDayWidget; // for beam this occurence and access to DateBookDB |
182 | public: | 182 | public: |
183 | DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, | 183 | DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, |
184 | QWidget *parent, const char *name ); | 184 | QWidget *parent, const char *name ); |
185 | void selectedDates( QDateTime &start, QDateTime &end ); | 185 | void selectedDates( QDateTime &start, QDateTime &end ); |
186 | QDate date() const; | 186 | QDate date() const; |
187 | DateBookDayView *dayView() const { return view; } | 187 | DateBookDayView *dayView() const { return view; } |
188 | void setStartViewTime( int startHere ); | 188 | void setStartViewTime( int startHere ); |
189 | int startViewTime() const; | 189 | int startViewTime() const; |
190 | void setSelectedWidget( DateBookDayWidget * ); | 190 | void setSelectedWidget( DateBookDayWidget * ); |
191 | DateBookDayWidget * getSelectedWidget( void ); | 191 | DateBookDayWidget * getSelectedWidget( void ); |
192 | void setJumpToCurTime( bool bJump ); | 192 | void setJumpToCurTime( bool bJump ); |
193 | void setRowStyle( int style ); | 193 | void setRowStyle( int style ); |
194 | static QDate findRealStart( int uid, const QDate& isIncluded, | 194 | static QDate findRealStart( int uid, const QDate& isIncluded, |
195 | DateBookDB* ); | 195 | DateBookDB* ); |
196 | 196 | ||
197 | public slots: | 197 | public slots: |
198 | void setDate( int y, int m, int d ); | 198 | void setDate( int y, int m, int d ); |
199 | void setDate( QDate ); | 199 | void setDate( QDate ); |
200 | void redraw(); | 200 | void redraw(); |
201 | void slotWeekChanged( bool bStartOnMonday ); | 201 | void slotWeekChanged( bool bStartOnMonday ); |
202 | void updateView();//updates TimeMarker and DayWidget-colors | 202 | void updateView();//updates TimeMarker and DayWidget-colors |
203 | 203 | ||
204 | signals: | 204 | signals: |
205 | void removeEvent( const Event& ); | 205 | void removeEvent( const Event& ); |
206 | void editEvent( const Event& ); | 206 | void editEvent( const Event& ); |
207 | void duplicateEvent( const Event& ); | 207 | void duplicateEvent( const Event& ); |
208 | void beamEvent( const Event& ); | 208 | void beamEvent( const Event& ); |
209 | void newEvent(); | 209 | void newEvent(); |
210 | void sigNewEvent( const QString & ); | 210 | void sigNewEvent( const QString & ); |
211 | 211 | ||
212 | protected slots: | 212 | protected slots: |
213 | void keyPressEvent(QKeyEvent *); | 213 | void keyPressEvent(QKeyEvent *); |
214 | 214 | ||
215 | private slots: | 215 | private slots: |
216 | void dateChanged( int y, int m, int d ); | 216 | void dateChanged( int y, int m, int d ); |
217 | void slotColWidthChanged() { relayoutPage(); }; | 217 | void slotColWidthChanged() { relayoutPage(); }; |
218 | 218 | ||
219 | private: | 219 | private: |
220 | void getEvents(); | 220 | void getEvents(); |
221 | void relayoutPage( bool fromResize = false ); | 221 | void relayoutPage( bool fromResize = false ); |
222 | DateBookDayWidget *intersects( const DateBookDayWidget *item, const QRect &geom ); | 222 | DateBookDayWidget *intersects( const DateBookDayWidget *item, const QRect &geom ); |
223 | QDate currDate; | 223 | QDate currDate; |
224 | DateBookDayView *view; | 224 | DateBookDayView *view; |
225 | DateBookDayHeader *header; | 225 | DateBookDayHeader *header; |
226 | DatebookdayAllday *m_allDays; | 226 | DatebookdayAllday *m_allDays; |
227 | DateBookDB *db; | 227 | DateBookDB *db; |
228 | WidgetListClass widgetList;//reimplemented QList for sorting widgets by height | 228 | WidgetListClass widgetList;//reimplemented QList for sorting widgets by height |
229 | int startTime; | 229 | int startTime; |
230 | bool jumpToCurTime;//should we jump to current time in dayview? | 230 | bool jumpToCurTime;//should we jump to current time in dayview? |
231 | int rowStyle; | 231 | int rowStyle; |
232 | DateBookDayWidget *selectedWidget; //actual selected widget (obviously) | 232 | DateBookDayWidget *selectedWidget; //actual selected widget (obviously) |
233 | DateBookDayTimeMarker *timeMarker;//marker for current time | 233 | DateBookDayTimeMarker *timeMarker;//marker for current time |
234 | }; | 234 | }; |
235 | 235 | ||
236 | #endif | 236 | #endif |
diff --git a/core/pim/datebook/datebookdayallday.cpp b/core/pim/datebook/datebookdayallday.cpp index 2294f3c..1244fd3 100644 --- a/core/pim/datebook/datebookdayallday.cpp +++ b/core/pim/datebook/datebookdayallday.cpp | |||
@@ -31,205 +31,206 @@ | |||
31 | */ | 31 | */ |
32 | DatebookdayAllday::DatebookdayAllday(DateBookDB* db, QWidget* parent, const char* name, WFlags ) | 32 | DatebookdayAllday::DatebookdayAllday(DateBookDB* db, QWidget* parent, const char* name, WFlags ) |
33 | : QScrollView( parent, name ),item_count(0),dateBook(db) | 33 | : QScrollView( parent, name ),item_count(0),dateBook(db) |
34 | { | 34 | { |
35 | if ( !name ) | 35 | if ( !name ) |
36 | setName( "DatebookdayAllday" ); | 36 | setName( "DatebookdayAllday" ); |
37 | setMinimumSize( QSize( 0, 0 ) ); | 37 | setMinimumSize( QSize( 0, 0 ) ); |
38 | setMaximumHeight(3* (QFontMetrics(font()).height()+4) ); | 38 | setMaximumHeight(3* (QFontMetrics(font()).height()+4) ); |
39 | 39 | ||
40 | m_MainFrame = new QFrame(viewport()); | 40 | m_MainFrame = new QFrame(viewport()); |
41 | m_MainFrame->setFrameStyle(QFrame::NoFrame|QFrame::Plain); | 41 | m_MainFrame->setFrameStyle(QFrame::NoFrame|QFrame::Plain); |
42 | setFrameStyle(QFrame::NoFrame|QFrame::Plain); | 42 | setFrameStyle(QFrame::NoFrame|QFrame::Plain); |
43 | setResizePolicy( QScrollView::Default ); | 43 | setResizePolicy( QScrollView::Default ); |
44 | setHScrollBarMode( AlwaysOff ); | 44 | setHScrollBarMode( AlwaysOff ); |
45 | addChild(m_MainFrame); | 45 | addChild(m_MainFrame); |
46 | 46 | ||
47 | datebookdayalldayLayout = new QVBoxLayout( m_MainFrame ); | 47 | datebookdayalldayLayout = new QVBoxLayout( m_MainFrame ); |
48 | datebookdayalldayLayout->setSpacing( 0 ); | 48 | datebookdayalldayLayout->setSpacing( 0 ); |
49 | datebookdayalldayLayout->setMargin( 0 ); | 49 | datebookdayalldayLayout->setMargin( 0 ); |
50 | 50 | ||
51 | lblDesc = new DatebookEventDesc(parent->parentWidget(),""); | 51 | lblDesc = new DatebookEventDesc(parent->parentWidget(),""); |
52 | lblDesc->setBackgroundColor(Qt::yellow); | 52 | lblDesc->setBackgroundColor(Qt::yellow); |
53 | lblDesc->hide(); | 53 | lblDesc->hide(); |
54 | subWidgets.setAutoDelete(true); | 54 | subWidgets.setAutoDelete(true); |
55 | } | 55 | } |
56 | 56 | ||
57 | /* | 57 | /* |
58 | * Destroys the object and frees any allocated resources | 58 | * Destroys the object and frees any allocated resources |
59 | */ | 59 | */ |
60 | DatebookdayAllday::~DatebookdayAllday() | 60 | DatebookdayAllday::~DatebookdayAllday() |
61 | { | 61 | { |
62 | // no need to delete child widgets, Qt does it all for us | 62 | // no need to delete child widgets, Qt does it all for us |
63 | } | 63 | } |
64 | 64 | ||
65 | DatebookAlldayDisp* DatebookdayAllday::addEvent(const EffectiveEvent&ev) | 65 | DatebookAlldayDisp* DatebookdayAllday::addEvent(const EffectiveEvent&ev) |
66 | { | 66 | { |
67 | DatebookAlldayDisp * lb; | 67 | DatebookAlldayDisp * lb; |
68 | lb = new DatebookAlldayDisp(dateBook,ev,m_MainFrame,NULL); | 68 | lb = new DatebookAlldayDisp(dateBook,ev,m_MainFrame,NULL); |
69 | lb->show(); | 69 | lb->show(); |
70 | datebookdayalldayLayout->addWidget(lb); | 70 | datebookdayalldayLayout->addWidget(lb); |
71 | subWidgets.append(lb); | 71 | subWidgets.append(lb); |
72 | 72 | ||
73 | connect(lb,SIGNAL(displayMe(const Event &)),lblDesc,SLOT(disp_event(const Event&))); | 73 | connect(lb,SIGNAL(displayMe(const Event &)),lblDesc,SLOT(disp_event(const Event&))); |
74 | ++item_count; | 74 | ++item_count; |
75 | 75 | ||
76 | return lb; | 76 | return lb; |
77 | } | 77 | } |
78 | 78 | ||
79 | void DatebookdayAllday::removeAllEvents() | 79 | void DatebookdayAllday::removeAllEvents() |
80 | { | 80 | { |
81 | subWidgets.clear(); | 81 | subWidgets.clear(); |
82 | item_count = 0; | 82 | item_count = 0; |
83 | } | 83 | } |
84 | 84 | ||
85 | DatebookAlldayDisp::DatebookAlldayDisp(DateBookDB *db,const EffectiveEvent& ev, | 85 | DatebookAlldayDisp::DatebookAlldayDisp(DateBookDB *db,const EffectiveEvent& ev, |
86 | QWidget* parent,const char* name,WFlags f) | 86 | QWidget* parent,const char* name,WFlags f) |
87 | : QLabel(parent,name,f),m_Ev(ev),dateBook(db) | 87 | : QLabel(parent,name,f),m_Ev(ev),dateBook(db) |
88 | { | 88 | { |
89 | QString strDesc = m_Ev.description(); | 89 | QString strDesc = m_Ev.description(); |
90 | strDesc = strDesc.replace(QRegExp("<"),"<"); | 90 | strDesc = strDesc.replace(QRegExp("<"),"<"); |
91 | setBackgroundColor(yellow); | 91 | setBackgroundColor(yellow); |
92 | setText(strDesc); | 92 | setText(strDesc); |
93 | setFrameStyle(QFrame::Raised|QFrame::Panel); | 93 | setFrameStyle(QFrame::Raised|QFrame::Panel); |
94 | 94 | ||
95 | int s = QFontMetrics(font()).height()+4; | 95 | int s = QFontMetrics(font()).height()+4; |
96 | setMaximumHeight( s ); | 96 | setMaximumHeight( s ); |
97 | setMinimumSize( QSize( 0, s ) ); | 97 | setMinimumSize( QSize( 0, s ) ); |
98 | } | 98 | } |
99 | 99 | ||
100 | DatebookAlldayDisp::~DatebookAlldayDisp() | 100 | DatebookAlldayDisp::~DatebookAlldayDisp() |
101 | { | 101 | { |
102 | } | 102 | } |
103 | 103 | ||
104 | void DatebookAlldayDisp::beam_single_event() | 104 | void DatebookAlldayDisp::beam_single_event() |
105 | { | 105 | { |
106 | // create an Event and beam it... | 106 | // create an Event and beam it... |
107 | /* | 107 | /* |
108 | * Start with the easy stuff. If start and end date is the same we can just use | 108 | * Start with the easy stuff. If start and end date is the same we can just use |
109 | * the values of effective m_Events | 109 | * the values of effective m_Events |
110 | * If it is a multi day m_Event we need to find the real start and end date... | 110 | * If it is a multi day m_Event we need to find the real start and end date... |
111 | */ | 111 | */ |
112 | if ( m_Ev.event().start().date() == m_Ev.event().end().date() ) { | 112 | if ( m_Ev.event().start().date() == m_Ev.event().end().date() ) { |
113 | Event m_Event( m_Ev.event() ); | 113 | Event m_Event( m_Ev.event() ); |
114 | 114 | ||
115 | QDateTime dt( m_Ev.date(), m_Ev.start() ); | 115 | QDateTime dt( m_Ev.date(), m_Ev.start() ); |
116 | m_Event.setStart( dt ); | 116 | m_Event.setStart( dt ); |
117 | 117 | ||
118 | dt.setTime( m_Ev.end() ); | 118 | dt.setTime( m_Ev.end() ); |
119 | m_Event.setEnd( dt ); | 119 | m_Event.setEnd( dt ); |
120 | emit beamMe( m_Event ); | 120 | emit beamMe( m_Event ); |
121 | }else { | 121 | }else { |
122 | /* | 122 | /* |
123 | * at least the the Times are right now | 123 | * at least the the Times are right now |
124 | */ | 124 | */ |
125 | QDateTime start( m_Ev.event().start() ); | 125 | QDateTime start( m_Ev.event().start() ); |
126 | QDateTime end ( m_Ev.event().end () ); | 126 | QDateTime end ( m_Ev.event().end () ); |
127 | 127 | ||
128 | /* | 128 | /* |
129 | * ok we know the start date or we need to find it | 129 | * ok we know the start date or we need to find it |
130 | */ | 130 | */ |
131 | if ( m_Ev.start() != QTime( 0, 0, 0 ) ) { | 131 | if ( m_Ev.start() != QTime( 0, 0, 0 ) ) { |
132 | start.setDate( m_Ev.date() ); | 132 | start.setDate( m_Ev.date() ); |
133 | }else { | 133 | }else { |
134 | QDate dt = DateBookDay::findRealStart( m_Ev.event().uid(), m_Ev.date(), dateBook ); | 134 | QDate dt = DateBookDay::findRealStart( m_Ev.event().uid(), m_Ev.date(), dateBook ); |
135 | start.setDate( dt ); | 135 | start.setDate( dt ); |
136 | } | 136 | } |
137 | 137 | ||
138 | /* | 138 | /* |
139 | * ok we know now the end date... | 139 | * ok we know now the end date... |
140 | * else | 140 | * else |
141 | * get to know the offset btw the real start and real end | 141 | * get to know the offset btw the real start and real end |
142 | * and then add it to the new start date... | 142 | * and then add it to the new start date... |
143 | */ | 143 | */ |
144 | if ( m_Ev.end() != QTime(23, 59, 59 ) ) { | 144 | if ( m_Ev.end() != QTime(23, 59, 59 ) ) { |
145 | end.setDate( m_Ev.date() ); | 145 | end.setDate( m_Ev.date() ); |
146 | }else{ | 146 | }else{ |
147 | int days = m_Ev.event().start().date().daysTo( m_Ev.event().end().date() ); | 147 | int days = m_Ev.event().start().date().daysTo( m_Ev.event().end().date() ); |
148 | end.setDate( start.date().addDays( days ) ); | 148 | end.setDate( start.date().addDays( days ) ); |
149 | } | 149 | } |
150 | Event m_Event( m_Ev.event() ); | 150 | Event m_Event( m_Ev.event() ); |
151 | m_Event.setStart( start ); | 151 | m_Event.setStart( start ); |
152 | m_Event.setEnd ( end ); | 152 | m_Event.setEnd ( end ); |
153 | emit beamMe( m_Event ); | 153 | emit beamMe( m_Event ); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | 156 | ||
157 | void DatebookAlldayDisp::mousePressEvent(QMouseEvent*e) | 157 | void DatebookAlldayDisp::mousePressEvent(QMouseEvent*e) |
158 | { | 158 | { |
159 | Event ev = m_Ev.event(); | ||
159 | QColor b = backgroundColor(); | 160 | QColor b = backgroundColor(); |
160 | setBackgroundColor(green); | 161 | setBackgroundColor(green); |
161 | update(); | 162 | update(); |
162 | QPopupMenu m; | 163 | QPopupMenu m; |
163 | m.insertItem( DateBookDayWidget::tr( "Edit" ), 1 ); | 164 | m.insertItem( DateBookDayWidget::tr( "Edit" ), 1 ); |
164 | m.insertItem( DateBookDayWidget::tr( "Duplicate" ), 4 ); | 165 | m.insertItem( DateBookDayWidget::tr( "Duplicate" ), 4 ); |
165 | m.insertItem( DateBookDayWidget::tr( "Delete" ), 2 ); | 166 | m.insertItem( DateBookDayWidget::tr( "Delete" ), 2 ); |
166 | if(Ir::supported()) m.insertItem( DateBookDayWidget::tr( "Beam" ), 3 ); | 167 | if(Ir::supported()) m.insertItem( DateBookDayWidget::tr( "Beam" ), 3 ); |
167 | if(Ir::supported() && m_Ev.event().doRepeat() ) m.insertItem( DateBookDayWidget::tr( "Beam this occurence"), 5 ); | 168 | if(Ir::supported() && m_Ev.event().doRepeat() ) m.insertItem( DateBookDayWidget::tr( "Beam this occurence"), 5 ); |
168 | m.insertItem( tr( "Info"),6); | 169 | m.insertItem( tr( "Info"),6); |
169 | int r = m.exec( e->globalPos() ); | 170 | int r = m.exec( e->globalPos() ); |
170 | setBackgroundColor(b); | 171 | setBackgroundColor(b); |
171 | update(); | 172 | update(); |
172 | switch (r) { | 173 | switch (r) { |
173 | case 1: | 174 | case 1: |
174 | emit editMe( m_Ev.event() ); | 175 | emit editMe( ev ); |
175 | break; | 176 | break; |
176 | case 2: | 177 | case 2: |
177 | emit deleteMe( m_Ev.event() ); | 178 | emit deleteMe( ev ); |
178 | break; | 179 | break; |
179 | case 3: | 180 | case 3: |
180 | emit beamMe( m_Ev.event() ); | 181 | emit beamMe( ev ); |
181 | break; | 182 | break; |
182 | case 4: | 183 | case 4: |
183 | emit duplicateMe( m_Ev.event() ); | 184 | emit duplicateMe( ev ); |
184 | break; | 185 | break; |
185 | case 5: | 186 | case 5: |
186 | beam_single_event(); | 187 | beam_single_event(); |
187 | break; | 188 | break; |
188 | case 6: | 189 | case 6: |
189 | emit displayMe( m_Ev.event() ); | 190 | emit displayMe( ev ); |
190 | break; | 191 | break; |
191 | default: | 192 | default: |
192 | break; | 193 | break; |
193 | } | 194 | } |
194 | } | 195 | } |
195 | 196 | ||
196 | DatebookEventDesc::DatebookEventDesc(QWidget*parent,const char*name) | 197 | DatebookEventDesc::DatebookEventDesc(QWidget*parent,const char*name) |
197 | :QLabel(parent,name) | 198 | :QLabel(parent,name) |
198 | { | 199 | { |
199 | m_Timer=new QTimer(this); | 200 | m_Timer=new QTimer(this); |
200 | connect(m_Timer,SIGNAL(timeout()),this,SLOT(hide())); | 201 | connect(m_Timer,SIGNAL(timeout()),this,SLOT(hide())); |
201 | setFrameStyle(QFrame::Sunken|QFrame::Panel); | 202 | setFrameStyle(QFrame::Sunken|QFrame::Panel); |
202 | setTextFormat(RichText); | 203 | setTextFormat(RichText); |
203 | } | 204 | } |
204 | 205 | ||
205 | DatebookEventDesc::~DatebookEventDesc() | 206 | DatebookEventDesc::~DatebookEventDesc() |
206 | { | 207 | { |
207 | } | 208 | } |
208 | 209 | ||
209 | void DatebookEventDesc::mousePressEvent(QMouseEvent*) | 210 | void DatebookEventDesc::mousePressEvent(QMouseEvent*) |
210 | { | 211 | { |
211 | hide(); | 212 | hide(); |
212 | if (m_Timer->isActive()) m_Timer->stop(); | 213 | if (m_Timer->isActive()) m_Timer->stop(); |
213 | } | 214 | } |
214 | 215 | ||
215 | void DatebookEventDesc::disp_event(const Event&e) | 216 | void DatebookEventDesc::disp_event(const Event&e) |
216 | { | 217 | { |
217 | if (m_Timer->isActive()) m_Timer->stop(); | 218 | if (m_Timer->isActive()) m_Timer->stop(); |
218 | QString text; | 219 | QString text; |
219 | text = "<b><i>"+e.description()+"</i></b><br>"; | 220 | text = "<b><i>"+e.description()+"</i></b><br>"; |
220 | if (e.notes().length()>0) { | 221 | if (e.notes().length()>0) { |
221 | text+="<b>"+e.notes()+"</b><br>"; | 222 | text+="<b>"+e.notes()+"</b><br>"; |
222 | } | 223 | } |
223 | if (e.location().length()>0) { | 224 | if (e.location().length()>0) { |
224 | text+="<i>"+e.location()+"</i><br>"; | 225 | text+="<i>"+e.location()+"</i><br>"; |
225 | } | 226 | } |
226 | text = text.replace(QRegExp("\n"),"<br>"); | 227 | text = text.replace(QRegExp("\n"),"<br>"); |
227 | setText(text); | 228 | setText(text); |
228 | QSize s = sizeHint(); | 229 | QSize s = sizeHint(); |
229 | s+=QSize(10,10); | 230 | s+=QSize(10,10); |
230 | resize(s); | 231 | resize(s); |
231 | move( QMAX(0,(parentWidget()->width()-width()) / 2), | 232 | move( QMAX(0,(parentWidget()->width()-width()) / 2), |
232 | (parentWidget()->height()-height())/2 ); | 233 | (parentWidget()->height()-height())/2 ); |
233 | show(); | 234 | show(); |
234 | m_Timer->start(2000,true); | 235 | m_Timer->start(2000,true); |
235 | } | 236 | } |
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index 8435132..933e191 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp | |||
@@ -1,445 +1,441 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "datebookweek.h" | 20 | #include "datebookweek.h" |
21 | #include "datebookweekheaderimpl.h" | 21 | #include "datebookweekheaderimpl.h" |
22 | 22 | ||
23 | #include <qpe/datebookdb.h> | 23 | #include <qpe/datebookdb.h> |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | #include <qpe/calendar.h> | 25 | #include <qpe/calendar.h> |
26 | 26 | ||
27 | #include <qheader.h> | 27 | #include <qheader.h> |
28 | #include <qlabel.h> | 28 | #include <qlabel.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | 31 | ||
32 | //----------------------------------------------------------------- | 32 | //----------------------------------------------------------------- |
33 | 33 | ||
34 | 34 | ||
35 | DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) | 35 | DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) |
36 | : ev( e ) | 36 | : ev( e ) |
37 | { | 37 | { |
38 | // with the current implementation change the color for all day events | 38 | // with the current implementation change the color for all day events |
39 | if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { | 39 | if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { |
40 | c = Qt::green; | 40 | c = Qt::green; |
41 | } else { | 41 | } else { |
42 | c = ev.event().hasAlarm() ? Qt::red : Qt::blue; | 42 | c = ev.event().hasAlarm() ? Qt::red : Qt::blue; |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
46 | void DateBookWeekItem::setGeometry( int x, int y, int w, int h ) | 46 | void DateBookWeekItem::setGeometry( int x, int y, int w, int h ) |
47 | { | 47 | { |
48 | r.setRect( x, y, w, h ); | 48 | r.setRect( x, y, w, h ); |
49 | } | 49 | } |
50 | 50 | ||
51 | 51 | ||
52 | //------------------=--------------------------------------------- | 52 | //------------------=--------------------------------------------- |
53 | 53 | ||
54 | DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, | 54 | DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, |
55 | QWidget *parent, const char *name ) | 55 | QWidget *parent, const char *name ) |
56 | : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), | 56 | : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), |
57 | showingEvent( false ) | 57 | showingEvent( false ) |
58 | { | 58 | { |
59 | items.setAutoDelete( true ); | 59 | items.setAutoDelete( true ); |
60 | 60 | ||
61 | viewport()->setBackgroundMode( PaletteBase ); | 61 | viewport()->setBackgroundMode( PaletteBase ); |
62 | 62 | ||
63 | header = new QHeader( this ); | 63 | header = new QHeader( this ); |
64 | header->addLabel( "" ); | 64 | header->addLabel( "" ); |
65 | 65 | ||
66 | header->setMovingEnabled( false ); | 66 | header->setMovingEnabled( false ); |
67 | header->setResizeEnabled( false ); | 67 | header->setResizeEnabled( false ); |
68 | header->setClickEnabled( false, 0 ); | 68 | header->setClickEnabled( false, 0 ); |
69 | initNames(); | 69 | initNames(); |
70 | 70 | ||
71 | 71 | ||
72 | connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); | 72 | connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); |
73 | 73 | ||
74 | QObject::connect(qApp, SIGNAL(clockChanged(bool)), | 74 | QObject::connect(qApp, SIGNAL(clockChanged(bool)), |
75 | this, SLOT(slotChangeClock(bool))); | 75 | this, SLOT(slotChangeClock(bool))); |
76 | 76 | ||
77 | QFontMetrics fm( font() ); | 77 | QFontMetrics fm( font() ); |
78 | rowHeight = fm.height()+2; | 78 | rowHeight = fm.height()+2; |
79 | 79 | ||
80 | resizeContents( width(), 24*rowHeight ); | 80 | resizeContents( width(), 24*rowHeight ); |
81 | } | 81 | } |
82 | 82 | ||
83 | void DateBookWeekView::initNames() | 83 | void DateBookWeekView::initNames() |
84 | { | 84 | { |
85 | #warning Please review this ! (eilers) | ||
86 | |||
87 | // Ok, I am Mr. Pedantic, but shouldn't we count until 6 instead of 7, if bOnMonday is false ? (eilers) | ||
88 | 85 | ||
89 | static bool bFirst = true; | 86 | static bool bFirst = true; |
90 | if ( bFirst ) { | 87 | if ( bFirst ) { |
91 | if ( bOnMonday ) { | 88 | if ( bOnMonday ) { |
92 | for ( int i = 1; i<=7; i++ ) { | 89 | for ( int i = 1; i<=7; i++ ) { |
93 | header->addLabel( Calendar::nameOfDay( i ) ); | 90 | header->addLabel( Calendar::nameOfDay( i ) ); |
94 | } | 91 | } |
95 | 92 | ||
96 | } else { | 93 | } else { |
97 | header->addLabel( Calendar::nameOfDay( 7 ) ); | 94 | header->addLabel( Calendar::nameOfDay( 7 ) ); |
98 | for ( int i = 1; i<7; i++ ) { | 95 | for ( int i = 1; i<7; i++ ) { |
99 | header->addLabel( Calendar::nameOfDay( i ) ); | 96 | header->addLabel( Calendar::nameOfDay( i ) ); |
100 | } | 97 | } |
101 | } | 98 | } |
102 | bFirst = false; | 99 | bFirst = false; |
103 | } else { | 100 | } else { |
104 | // we are change things... | 101 | // we are change things... |
105 | if ( bOnMonday ) { | 102 | if ( bOnMonday ) { |
106 | for ( int i = 1; i<=7; i++ ) { | 103 | for ( int i = 1; i<=7; i++ ) { |
107 | header->setLabel( i, Calendar::nameOfDay( i ) ); | 104 | header->setLabel( i, Calendar::nameOfDay( i ) ); |
108 | } | 105 | } |
109 | 106 | ||
110 | } else { | 107 | } else { |
111 | header->setLabel( 1, Calendar::nameOfDay( 7 ) ); | 108 | header->setLabel( 1, Calendar::nameOfDay( 7 ) ); |
112 | for ( int i = 1; i<7; i++ ) { | 109 | for ( int i = 1; i<7; i++ ) { |
113 | header->setLabel( i+1, Calendar::nameOfDay( i ) ); | 110 | header->setLabel( i+1, Calendar::nameOfDay( i ) ); |
114 | } | 111 | } |
115 | 112 | ||
116 | } | 113 | } |
117 | } | 114 | } |
118 | } | 115 | } |
119 | 116 | ||
120 | 117 | ||
121 | 118 | ||
122 | void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) | 119 | void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) |
123 | { | 120 | { |
124 | items.clear(); | 121 | items.clear(); |
125 | QValueListIterator<EffectiveEvent> it; | 122 | QValueListIterator<EffectiveEvent> it; |
126 | for ( it = ev.begin(); it != ev.end(); ++it ) { | 123 | for ( it = ev.begin(); it != ev.end(); ++it ) { |
127 | DateBookWeekItem *i = new DateBookWeekItem( *it ); | 124 | DateBookWeekItem *i = new DateBookWeekItem( *it ); |
128 | 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. | 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. |
129 | positionItem( i ); | 126 | positionItem( i ); |
130 | items.append( i ); | 127 | items.append( i ); |
131 | } | 128 | } |
132 | } | 129 | } |
133 | viewport()->update(); | 130 | viewport()->update(); |
134 | } | 131 | } |
135 | 132 | ||
136 | void DateBookWeekView::moveToHour( int h ) | 133 | void DateBookWeekView::moveToHour( int h ) |
137 | { | 134 | { |
138 | int offset = h*rowHeight; | 135 | int offset = h*rowHeight; |
139 | setContentsPos( 0, offset ); | 136 | setContentsPos( 0, offset ); |
140 | } | 137 | } |
141 | 138 | ||
142 | void DateBookWeekView::keyPressEvent( QKeyEvent *e ) | 139 | void DateBookWeekView::keyPressEvent( QKeyEvent *e ) |
143 | { | 140 | { |
144 | e->ignore(); | 141 | e->ignore(); |
145 | } | 142 | } |
146 | 143 | ||
147 | void DateBookWeekView::slotChangeClock( bool c ) | 144 | void DateBookWeekView::slotChangeClock( bool c ) |
148 | { | 145 | { |
149 | ampm = c; | 146 | ampm = c; |
150 | viewport()->update(); | 147 | viewport()->update(); |
151 | } | 148 | } |
152 | 149 | ||
153 | static inline int db_round30min( int m ) | 150 | static inline int db_round30min( int m ) |
154 | { | 151 | { |
155 | if ( m < 15 ) | 152 | if ( m < 15 ) |
156 | m = 0; | 153 | m = 0; |
157 | else if ( m < 45 ) | 154 | else if ( m < 45 ) |
158 | m = 1; | 155 | m = 1; |
159 | else | 156 | else |
160 | m = 2; | 157 | m = 2; |
161 | 158 | ||
162 | return m; | 159 | return m; |
163 | } | 160 | } |
164 | 161 | ||
165 | void DateBookWeekView::alterDay( int day ) | 162 | void DateBookWeekView::alterDay( int day ) |
166 | { | 163 | { |
167 | if ( !bOnMonday ) { | 164 | if ( !bOnMonday ) { |
168 | day--; | 165 | day--; |
169 | } | 166 | } |
170 | emit showDay( day ); | 167 | emit showDay( day ); |
171 | } | 168 | } |
172 | 169 | ||
173 | void DateBookWeekView::positionItem( DateBookWeekItem *i ) | 170 | void DateBookWeekView::positionItem( DateBookWeekItem *i ) |
174 | { | 171 | { |
175 | const int Width = 8; | 172 | const int Width = 8; |
176 | const EffectiveEvent ev = i->event(); | 173 | const EffectiveEvent ev = i->event(); |
177 | 174 | ||
178 | // 30 minute intervals | 175 | // 30 minute intervals |
179 | int y = ev.start().hour() * 2; | 176 | int y = ev.start().hour() * 2; |
180 | y += db_round30min( ev.start().minute() ); | 177 | y += db_round30min( ev.start().minute() ); |
181 | int y2 = ev.end().hour() * 2; | 178 | int y2 = ev.end().hour() * 2; |
182 | y2 += db_round30min( ev.end().minute() ); | 179 | y2 += db_round30min( ev.end().minute() ); |
183 | if ( y > 47 ) y = 47; | 180 | if ( y > 47 ) y = 47; |
184 | if ( y2 > 48 ) y2 = 48; | 181 | if ( y2 > 48 ) y2 = 48; |
185 | y = (y * rowHeight) / 2; | 182 | y = (y * rowHeight) / 2; |
186 | y2 = (y2 * rowHeight) / 2; | 183 | y2 = (y2 * rowHeight) / 2; |
187 | 184 | ||
188 | int h; | 185 | int h; |
189 | if ( ev.event().type() == Event::AllDay ) { | 186 | if ( ev.event().type() == Event::AllDay ) { |
190 | h = (48 * rowHeight) / 2; | 187 | h = (48 * rowHeight) / 2; |
191 | y = 0; | 188 | y = 0; |
192 | } else { | 189 | } else { |
193 | h=y2-y; | 190 | h=y2-y; |
194 | if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2; | 191 | if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2; |
195 | } | 192 | } |
196 | 193 | ||
197 | int dow = ev.date().dayOfWeek(); | 194 | int dow = ev.date().dayOfWeek(); |
198 | if ( !bOnMonday ) { | 195 | if ( !bOnMonday ) { |
199 | if ( dow == 7 ) | 196 | if ( dow == 7 ) |
200 | dow = 1; | 197 | dow = 1; |
201 | else | 198 | else |
202 | dow++; | 199 | dow++; |
203 | } | 200 | } |
204 | int x = header->sectionPos( dow ) - 1; | 201 | int x = header->sectionPos( dow ) - 1; |
205 | int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); | 202 | int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); |
206 | DateBookWeekItem *isect = 0; | 203 | DateBookWeekItem *isect = 0; |
207 | do { | 204 | do { |
208 | i->setGeometry( x, y, Width, h ); | 205 | i->setGeometry( x, y, Width, h ); |
209 | isect = intersects( i ); | 206 | isect = intersects( i ); |
210 | x += Width - 1; | 207 | x += Width - 1; |
211 | } while ( isect && x < xlim ); | 208 | } while ( isect && x < xlim ); |
212 | } | 209 | } |
213 | 210 | ||
214 | DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) | 211 | DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) |
215 | { | 212 | { |
216 | QRect geom = item->geometry(); | 213 | QRect geom = item->geometry(); |
217 | 214 | ||
218 | // We allow the edges to overlap | 215 | // We allow the edges to overlap |
219 | geom.moveBy( 1, 1 ); | 216 | geom.moveBy( 1, 1 ); |
220 | geom.setSize( geom.size()-QSize(2,2) ); | 217 | geom.setSize( geom.size()-QSize(2,2) ); |
221 | 218 | ||
222 | QListIterator<DateBookWeekItem> it(items); | 219 | QListIterator<DateBookWeekItem> it(items); |
223 | for ( ; it.current(); ++it ) { | 220 | for ( ; it.current(); ++it ) { |
224 | DateBookWeekItem *i = it.current(); | 221 | DateBookWeekItem *i = it.current(); |
225 | if ( i != item ) { | 222 | if ( i != item ) { |
226 | if ( i->geometry().intersects( geom ) ) { | 223 | if ( i->geometry().intersects( geom ) ) { |
227 | return i; | 224 | return i; |
228 | } | 225 | } |
229 | } | 226 | } |
230 | } | 227 | } |
231 | 228 | ||
232 | return 0; | 229 | return 0; |
233 | } | 230 | } |
234 | 231 | ||
235 | void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) | 232 | void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) |
236 | { | 233 | { |
237 | QListIterator<DateBookWeekItem> it(items); | 234 | QListIterator<DateBookWeekItem> it(items); |
238 | for ( ; it.current(); ++it ) { | 235 | for ( ; it.current(); ++it ) { |
239 | DateBookWeekItem *i = it.current(); | 236 | DateBookWeekItem *i = it.current(); |
240 | if ( i->geometry().contains( e->pos() ) ) { | 237 | if ( i->geometry().contains( e->pos() ) ) { |
241 | showingEvent = true; | 238 | showingEvent = true; |
242 | emit signalShowEvent( i->event() ); | 239 | emit signalShowEvent( i->event() ); |
243 | break; | 240 | break; |
244 | } | 241 | } |
245 | } | 242 | } |
246 | } | 243 | } |
247 | 244 | ||
248 | void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) | 245 | void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) |
249 | { | 246 | { |
250 | if ( showingEvent ) { | 247 | if ( showingEvent ) { |
251 | showingEvent = false; | 248 | showingEvent = false; |
252 | emit signalHideEvent(); | 249 | emit signalHideEvent(); |
253 | } else { | 250 | } else { |
254 | int d = header->sectionAt( e->pos().x() ); | 251 | int d = header->sectionAt( e->pos().x() ); |
255 | if ( d > 0 ) { | 252 | if ( d > 0 ) { |
256 | // if ( !bOnMonday ) | 253 | // if ( !bOnMonday ) |
257 | // d--; | 254 | // d--; |
258 | emit showDay( d ); | 255 | emit showDay( d ); |
259 | } | 256 | } |
260 | } | 257 | } |
261 | } | 258 | } |
262 | 259 | ||
263 | void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) | 260 | void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) |
264 | { | 261 | { |
265 | QRect ur( cx, cy, cw, ch ); | 262 | QRect ur( cx, cy, cw, ch ); |
266 | p->setPen( lightGray ); | 263 | p->setPen( lightGray ); |
267 | for ( int i = 1; i <= 7; i++ ) | 264 | for ( int i = 1; i <= 7; i++ ) |
268 | p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); | 265 | p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); |
269 | 266 | ||
270 | p->setPen( black ); | 267 | p->setPen( black ); |
271 | for ( int t = 0; t < 24; t++ ) { | 268 | for ( int t = 0; t < 24; t++ ) { |
272 | int y = t*rowHeight; | 269 | int y = t*rowHeight; |
273 | if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { | 270 | if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { |
274 | QString s; | 271 | QString s; |
275 | if ( ampm ) { | 272 | if ( ampm ) { |
276 | if ( t == 0 ) | 273 | if ( t == 0 ) |
277 | s = QString::number( 12 ); | 274 | s = QString::number( 12 ); |
278 | else if ( t == 12 ) | 275 | else if ( t == 12 ) |
279 | s = QString::number(12) + tr( "p" ); | 276 | s = QString::number(12) + tr( "p" ); |
280 | else if ( t > 12 ) { | 277 | else if ( t > 12 ) { |
281 | if ( t - 12 < 10 ) | 278 | if ( t - 12 < 10 ) |
282 | s = " "; | 279 | s = " "; |
283 | else | 280 | else |
284 | s = ""; | 281 | s = ""; |
285 | s += QString::number( t - 12 ) + tr("p"); | 282 | s += QString::number( t - 12 ) + tr("p"); |
286 | } else { | 283 | } else { |
287 | if ( 12 - t < 3 ) | 284 | if ( 12 - t < 3 ) |
288 | s = ""; | 285 | s = ""; |
289 | else | 286 | else |
290 | s = " "; | 287 | s = " "; |
291 | s += QString::number( t ); | 288 | s += QString::number( t ); |
292 | } | 289 | } |
293 | } else { | 290 | } else { |
294 | s = QString::number( t ); | 291 | s = QString::number( t ); |
295 | if ( s.length() == 1 ) | 292 | if ( s.length() == 1 ) |
296 | s.prepend( "0" ); | 293 | s.prepend( "0" ); |
297 | } | 294 | } |
298 | p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); | 295 | p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); |
299 | } | 296 | } |
300 | } | 297 | } |
301 | 298 | ||
302 | QListIterator<DateBookWeekItem> it(items); | 299 | QListIterator<DateBookWeekItem> it(items); |
303 | for ( ; it.current(); ++it ) { | 300 | for ( ; it.current(); ++it ) { |
304 | DateBookWeekItem *i = it.current(); | 301 | DateBookWeekItem *i = it.current(); |
305 | if ( i->geometry().intersects( ur ) ) { | 302 | if ( i->geometry().intersects( ur ) ) { |
306 | p->setBrush( i->color() ); | 303 | p->setBrush( i->color() ); |
307 | p->drawRect( i->geometry() ); | 304 | p->drawRect( i->geometry() ); |
308 | } | 305 | } |
309 | } | 306 | } |
310 | } | 307 | } |
311 | 308 | ||
312 | void DateBookWeekView::resizeEvent( QResizeEvent *e ) | 309 | void DateBookWeekView::resizeEvent( QResizeEvent *e ) |
313 | { | 310 | { |
314 | const int hourWidth = 20; | 311 | const int hourWidth = 20; |
315 | QScrollView::resizeEvent( e ); | 312 | QScrollView::resizeEvent( e ); |
316 | 313 | ||
317 | #warning check the geometry i have choosen BRANCH_1_0 (waspe) | ||
318 | 314 | ||
319 | //HEAD | 315 | //HEAD |
320 | /* | 316 | /* |
321 | int avail = visibleWidth(); | 317 | int avail = visibleWidth(); |
322 | header->setGeometry( leftMargin()+frameWidth()+frameRect().left() , frameWidth(), | 318 | header->setGeometry( leftMargin()+frameWidth()+frameRect().left() , frameWidth(), |
323 | visibleWidth(), header->sizeHint().height() ); | 319 | visibleWidth(), header->sizeHint().height() ); |
324 | setMargins( 0, header->sizeHint().height(), 0, 0 ); | 320 | setMargins( 0, header->sizeHint().height(), 0, 0 ); |
325 | */ | 321 | */ |
326 | //BRANCH_1_0 | 322 | //BRANCH_1_0 |
327 | int avail = width()-qApp->style().scrollBarExtent().width()-1; | 323 | int avail = width()-qApp->style().scrollBarExtent().width()-1; |
328 | header->setGeometry( 0, 0, avail, header->sizeHint().height() ); | 324 | header->setGeometry( 0, 0, avail, header->sizeHint().height() ); |
329 | setMargins( 0, header->height(), 0, 0 ); | 325 | setMargins( 0, header->height(), 0, 0 ); |
330 | 326 | ||
331 | 327 | ||
332 | header->resizeSection( 0, hourWidth ); | 328 | header->resizeSection( 0, hourWidth ); |
333 | int sw = (avail - hourWidth) / 7; | 329 | int sw = (avail - hourWidth) / 7; |
334 | for ( int i = 1; i < 7; i++ ) | 330 | for ( int i = 1; i < 7; i++ ) |
335 | header->resizeSection( i, sw ); | 331 | header->resizeSection( i, sw ); |
336 | header->resizeSection( 7, avail - hourWidth - sw*6 ); | 332 | header->resizeSection( 7, avail - hourWidth - sw*6 ); |
337 | } | 333 | } |
338 | 334 | ||
339 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) | 335 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) |
340 | { | 336 | { |
341 | bOnMonday = bStartOnMonday; | 337 | bOnMonday = bStartOnMonday; |
342 | initNames(); | 338 | initNames(); |
343 | } | 339 | } |
344 | 340 | ||
345 | //------------------------------------------------------------------- | 341 | //------------------------------------------------------------------- |
346 | 342 | ||
347 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, | 343 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, |
348 | QWidget *parent, const char *name ) | 344 | QWidget *parent, const char *name ) |
349 | : QWidget( parent, name ), | 345 | : QWidget( parent, name ), |
350 | db( newDB ), | 346 | db( newDB ), |
351 | startTime( 0 ), | 347 | startTime( 0 ), |
352 | ampm( ap ), | 348 | ampm( ap ), |
353 | bStartOnMonday( startOnMonday ) | 349 | bStartOnMonday( startOnMonday ) |
354 | { | 350 | { |
355 | setFocusPolicy(StrongFocus); | 351 | setFocusPolicy(StrongFocus); |
356 | QVBoxLayout *vb = new QVBoxLayout( this ); | 352 | QVBoxLayout *vb = new QVBoxLayout( this ); |
357 | header = new DateBookWeekHeader( bStartOnMonday, this ); | 353 | header = new DateBookWeekHeader( bStartOnMonday, this ); |
358 | view = new DateBookWeekView( ampm, startOnMonday, this ); | 354 | view = new DateBookWeekView( ampm, startOnMonday, this ); |
359 | vb->addWidget( header ); | 355 | vb->addWidget( header ); |
360 | vb->addWidget( view ); | 356 | vb->addWidget( view ); |
361 | 357 | ||
362 | lblDesc = new QLabel( this, "event label" ); | 358 | lblDesc = new QLabel( this, "event label" ); |
363 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); | 359 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); |
364 | lblDesc->setBackgroundColor( yellow ); | 360 | lblDesc->setBackgroundColor( yellow ); |
365 | lblDesc->hide(); | 361 | lblDesc->hide(); |
366 | 362 | ||
367 | tHide = new QTimer( this ); | 363 | tHide = new QTimer( this ); |
368 | 364 | ||
369 | connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); | 365 | connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); |
370 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); | 366 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); |
371 | connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); | 367 | connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); |
372 | connect( header, SIGNAL( dateChanged( QDate &) ), this, SLOT( dateChanged( QDate &) ) ); | 368 | connect( header, SIGNAL( dateChanged( QDate &) ), this, SLOT( dateChanged( QDate &) ) ); |
373 | connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); | 369 | connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); |
374 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); | 370 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); |
375 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); | 371 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); |
376 | setDate(QDate::currentDate()); | 372 | setDate(QDate::currentDate()); |
377 | } | 373 | } |
378 | 374 | ||
379 | void DateBookWeek::keyPressEvent(QKeyEvent *e) | 375 | void DateBookWeek::keyPressEvent(QKeyEvent *e) |
380 | { | 376 | { |
381 | switch(e->key()) { | 377 | switch(e->key()) { |
382 | case Key_Up: | 378 | case Key_Up: |
383 | view->scrollBy(0, -20); | 379 | view->scrollBy(0, -20); |
384 | break; | 380 | break; |
385 | case Key_Down: | 381 | case Key_Down: |
386 | view->scrollBy(0, 20); | 382 | view->scrollBy(0, 20); |
387 | break; | 383 | break; |
388 | case Key_Left: | 384 | case Key_Left: |
389 | setDate(date().addDays(-7)); | 385 | setDate(date().addDays(-7)); |
390 | break; | 386 | break; |
391 | case Key_Right: | 387 | case Key_Right: |
392 | setDate(date().addDays(7)); | 388 | setDate(date().addDays(7)); |
393 | break; | 389 | break; |
394 | default: | 390 | default: |
395 | e->ignore(); | 391 | e->ignore(); |
396 | } | 392 | } |
397 | } | 393 | } |
398 | 394 | ||
399 | void DateBookWeek::showDay( int day ) | 395 | void DateBookWeek::showDay( int day ) |
400 | { | 396 | { |
401 | QDate d=bdate; | 397 | QDate d=bdate; |
402 | 398 | ||
403 | // Calculate offset to first day of week. | 399 | // Calculate offset to first day of week. |
404 | int dayoffset=d.dayOfWeek() % 7; | 400 | int dayoffset=d.dayOfWeek() % 7; |
405 | 401 | ||
406 | if(bStartOnMonday) dayoffset--; | 402 | if(bStartOnMonday) dayoffset--; |
407 | 403 | ||
408 | day--; | 404 | day--; |
409 | d=d.addDays(day-dayoffset); | 405 | d=d.addDays(day-dayoffset); |
410 | emit showDate( d.year(), d.month(), d.day() ); | 406 | emit showDate( d.year(), d.month(), d.day() ); |
411 | } | 407 | } |
412 | 408 | ||
413 | void DateBookWeek::setDate( int y, int m, int d ) | 409 | void DateBookWeek::setDate( int y, int m, int d ) |
414 | { | 410 | { |
415 | setDate(QDate(y, m, d)); | 411 | setDate(QDate(y, m, d)); |
416 | } | 412 | } |
417 | 413 | ||
418 | void DateBookWeek::setDate(QDate newdate) | 414 | void DateBookWeek::setDate(QDate newdate) |
419 | { | 415 | { |
420 | bdate=newdate; | 416 | bdate=newdate; |
421 | dow = newdate.dayOfWeek(); | 417 | dow = newdate.dayOfWeek(); |
422 | header->setDate( newdate ); | 418 | header->setDate( newdate ); |
423 | } | 419 | } |
424 | 420 | ||
425 | void DateBookWeek::dateChanged( QDate &newdate ) | 421 | void DateBookWeek::dateChanged( QDate &newdate ) |
426 | { | 422 | { |
427 | bdate=newdate; | 423 | bdate=newdate; |
428 | getEvents(); | 424 | getEvents(); |
429 | } | 425 | } |
430 | 426 | ||
431 | QDate DateBookWeek::date() const | 427 | QDate DateBookWeek::date() const |
432 | { | 428 | { |
433 | return bdate; | 429 | return bdate; |
434 | } | 430 | } |
435 | 431 | ||
436 | void DateBookWeek::getEvents() | 432 | void DateBookWeek::getEvents() |
437 | { | 433 | { |
438 | QDate startWeek = weekDate(); | 434 | QDate startWeek = weekDate(); |
439 | 435 | ||
440 | QDate endWeek = startWeek.addDays( 6 ); | 436 | QDate endWeek = startWeek.addDays( 6 ); |
441 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); | 437 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); |
442 | view->showEvents( eventList ); | 438 | view->showEvents( eventList ); |
443 | view->moveToHour( startTime ); | 439 | view->moveToHour( startTime ); |
444 | } | 440 | } |
445 | 441 | ||