-rw-r--r-- | korganizer/datenavigatorcontainer.cpp | 114 | ||||
-rw-r--r-- | korganizer/datenavigatorcontainer.h | 7 | ||||
-rw-r--r-- | korganizer/kdatenavigator.cpp | 1 |
3 files changed, 98 insertions, 24 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp index bb27bce..6de7c45 100644 --- a/korganizer/datenavigatorcontainer.cpp +++ b/korganizer/datenavigatorcontainer.cpp | |||
@@ -43,13 +43,12 @@ DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, | |||
43 | mExtraViews.setAutoDelete( true ); | 43 | mExtraViews.setAutoDelete( true ); |
44 | 44 | ||
45 | mNavigatorView = new KDateNavigator( this, name ); | 45 | mNavigatorView = new KDateNavigator( this, name ); |
46 | 46 | ||
47 | connectNavigatorView( mNavigatorView ); | 47 | connectNavigatorView( mNavigatorView ); |
48 | //setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); | 48 | //setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); |
49 | mDisplayedEndDate = QDate::currentDate(); | ||
50 | mLastDisplayedDN = 0; | 49 | mLastDisplayedDN = 0; |
51 | } | 50 | } |
52 | 51 | ||
53 | DateNavigatorContainer::~DateNavigatorContainer() | 52 | DateNavigatorContainer::~DateNavigatorContainer() |
54 | { | 53 | { |
55 | } | 54 | } |
@@ -72,24 +71,87 @@ void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) | |||
72 | 71 | ||
73 | connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); | 72 | connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); |
74 | connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); | 73 | connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); |
75 | connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); | 74 | connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); |
76 | connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); | 75 | connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); |
77 | 76 | ||
78 | connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) ); | 77 | connect( v, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); |
79 | } | 78 | } |
80 | 79 | ||
80 | void DateNavigatorContainer::slotMonthSelected( int month ) | ||
81 | { | ||
82 | //qDebug("slotMonthSelected %d ", month); | ||
83 | QDate baseDate = mNavigatorView->baseDate(); | ||
84 | if ( baseDate.month() == month ) | ||
85 | return; | ||
86 | //qDebug("month %d %d ",baseDate.month(),month); | ||
87 | QDate date = QDate ( baseDate.year(), baseDate.month() , 15 ); | ||
88 | date = date.addDays( -(baseDate.month()-month ) *30 ); | ||
89 | QDate newBase = QDate ( date.year(), date.month() , baseDate.day() ); | ||
90 | |||
91 | #if 0 | ||
92 | mFirstSelectedDate = dateList.first() ; | ||
93 | mSelectedDateCount = dateList.count() ; | ||
94 | |||
95 | KDateNavigator *view = mExtraViews.at( 0 ); | ||
96 | QDate date = view->baseDate(); | ||
97 | |||
98 | QDate curEnd = date.addDays( (mLastDisplayedDN)*30 +7); | ||
99 | //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() ); | ||
100 | if ( lDate < curEnd && date.addDays( -30 ) < fDate) { | ||
101 | mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate ); | ||
102 | mNavigatorView->dayMatrix()->repaint( false ); | ||
103 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | ||
104 | KDateNavigator *n = mExtraViews.at( i ); | ||
105 | if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) { | ||
106 | n->dayMatrix()->repaint( false ); | ||
107 | } | ||
108 | } | ||
109 | return; | ||
110 | } | ||
111 | #endif | ||
112 | //qDebug("NEW BASE %s", newBase.toString().latin1()); | ||
113 | mNavigatorView->setBaseDate( newBase ); | ||
114 | QDate last = lastAvailableDate(); | ||
115 | QDate first = firstAvailableDate(); | ||
116 | |||
117 | QDate selFirst = mFirstSelectedDate; | ||
118 | QDate selLast = selFirst.addDays( mSelectedDateCount-1 ); | ||
119 | if ( selFirst >= first && selLast <= last ) { | ||
120 | setBaseDates(); | ||
121 | updateDayMatrixDates(); | ||
122 | } | ||
123 | else { | ||
124 | setBaseDates(); | ||
125 | updateDayMatrixDates(); | ||
126 | emit monthSelected( month ); | ||
127 | } | ||
128 | } | ||
81 | void DateNavigatorContainer::setCalendar( Calendar *cal ) | 129 | void DateNavigatorContainer::setCalendar( Calendar *cal ) |
82 | { | 130 | { |
83 | mCalendar = cal; | 131 | mCalendar = cal; |
84 | mNavigatorView->setCalendar( cal ); | 132 | mNavigatorView->setCalendar( cal ); |
85 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | 133 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
86 | KDateNavigator *n = mExtraViews.at( i ); | 134 | KDateNavigator *n = mExtraViews.at( i ); |
87 | n->setCalendar( cal ); | 135 | n->setCalendar( cal ); |
88 | } | 136 | } |
89 | } | 137 | } |
138 | void DateNavigatorContainer::updateDayMatrixDates() | ||
139 | { | ||
140 | |||
141 | QDate fDate = mFirstSelectedDate; | ||
142 | QDate lDate = fDate.addDays( mSelectedDateCount - 1 ); | ||
143 | mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate ); | ||
144 | mNavigatorView->dayMatrix()->repaint( false ); | ||
145 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | ||
146 | KDateNavigator *n = mExtraViews.at( i ); | ||
147 | if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) { | ||
148 | n->dayMatrix()->repaint( false ); | ||
149 | } | ||
150 | } | ||
151 | } | ||
90 | 152 | ||
91 | void DateNavigatorContainer::updateDayMatrix() | 153 | void DateNavigatorContainer::updateDayMatrix() |
92 | { | 154 | { |
93 | mNavigatorView->updateDayMatrix(); | 155 | mNavigatorView->updateDayMatrix(); |
94 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | 156 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
95 | KDateNavigator *n = mExtraViews.at( i ); | 157 | KDateNavigator *n = mExtraViews.at( i ); |
@@ -123,15 +185,36 @@ void DateNavigatorContainer::updateConfig() | |||
123 | mNavigatorView->updateConfig(); | 185 | mNavigatorView->updateConfig(); |
124 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | 186 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
125 | KDateNavigator *n = mExtraViews.at( i ); | 187 | KDateNavigator *n = mExtraViews.at( i ); |
126 | n->updateConfig(); | 188 | n->updateConfig(); |
127 | } | 189 | } |
128 | } | 190 | } |
129 | 191 | QDate DateNavigatorContainer::lastAvailableDate() const | |
192 | { | ||
193 | QDate date = mNavigatorView->baseDate(); | ||
194 | QDate last = QDate ( date.year(), date.month(), date.daysInMonth() ); | ||
195 | int iii = mLastDisplayedDN; | ||
196 | if ( mLastDisplayedDN ) | ||
197 | last = last.addDays( 1); | ||
198 | while ( iii ) { | ||
199 | last = last.addDays( last.daysInMonth ()); | ||
200 | //qDebug("DATE %s ", last.toString().latin1() ); | ||
201 | --iii; | ||
202 | } | ||
203 | if ( mLastDisplayedDN ) | ||
204 | last = last.addDays( -1); | ||
205 | return last; | ||
206 | } | ||
207 | QDate DateNavigatorContainer::firstAvailableDate() const | ||
208 | { | ||
209 | return QDate ( mNavigatorView->baseDate().year(), mNavigatorView->baseDate().month(), 1 ); | ||
210 | } | ||
130 | void DateNavigatorContainer::selectDates( const DateList &dateList ) | 211 | void DateNavigatorContainer::selectDates( const DateList &dateList ) |
131 | { | 212 | { |
213 | mFirstSelectedDate = dateList.first() ; | ||
214 | mSelectedDateCount = dateList.count() ; | ||
132 | if ( !mLastDisplayedDN ) { | 215 | if ( !mLastDisplayedDN ) { |
133 | mNavigatorView->selectDates( dateList ); | 216 | mNavigatorView->selectDates( dateList ); |
134 | return; | 217 | return; |
135 | } | 218 | } |
136 | QDate fDate = dateList.first(); | 219 | QDate fDate = dateList.first(); |
137 | QDate lDate = dateList.last(); | 220 | QDate lDate = dateList.last(); |
@@ -146,26 +229,16 @@ void DateNavigatorContainer::selectDates( const DateList &dateList ) | |||
146 | bDate = bDate.addDays( bDate.daysInMonth () - bDate.day() +1 ); | 229 | bDate = bDate.addDays( bDate.daysInMonth () - bDate.day() +1 ); |
147 | view->setBaseDate( bDate, false ); | 230 | view->setBaseDate( bDate, false ); |
148 | view->dayMatrix()->setSelectedDaysFrom(fDate , lDate); | 231 | view->dayMatrix()->setSelectedDaysFrom(fDate , lDate); |
149 | } | 232 | } |
150 | return; | 233 | return; |
151 | } | 234 | } |
152 | KDateNavigator *view = mExtraViews.at( 0 ); | 235 | //qDebug("%s %s ", lastAvailableDate().toString().latin1(), firstAvailableDate().toString().latin1() ); |
153 | QDate date = view->baseDate(); | ||
154 | |||
155 | QDate curEnd = date.addDays( (mLastDisplayedDN)*30 +7); | ||
156 | //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() ); | 236 | //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() ); |
157 | if ( lDate < curEnd && date.addDays( -30 ) < fDate) { | 237 | if ( lDate <= lastAvailableDate() && firstAvailableDate() <= fDate) { |
158 | mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate ); | 238 | updateDayMatrixDates(); |
159 | mNavigatorView->dayMatrix()->repaint( false ); | ||
160 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | ||
161 | KDateNavigator *n = mExtraViews.at( i ); | ||
162 | if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) { | ||
163 | n->dayMatrix()->repaint( false ); | ||
164 | } | ||
165 | } | ||
166 | return; | 239 | return; |
167 | } | 240 | } |
168 | mNavigatorView->selectDates( dateList ); | 241 | mNavigatorView->selectDates( dateList ); |
169 | setBaseDates(); | 242 | setBaseDates(); |
170 | if ( mLastDisplayedDN ) { | 243 | if ( mLastDisplayedDN ) { |
171 | KDateNavigator *view = mExtraViews.at( 0 ); | 244 | KDateNavigator *view = mExtraViews.at( 0 ); |
@@ -178,23 +251,18 @@ void DateNavigatorContainer::selectDates( const DateList &dateList ) | |||
178 | } | 251 | } |
179 | } | 252 | } |
180 | } | 253 | } |
181 | 254 | ||
182 | void DateNavigatorContainer::setBaseDates() | 255 | void DateNavigatorContainer::setBaseDates() |
183 | { | 256 | { |
184 | KCal::DateList dateList = mNavigatorView->selectedDates(); | 257 | QDate baseDate = mNavigatorView->baseDate(); |
185 | if ( dateList.isEmpty() ) { | 258 | bool doRepaint = true; |
186 | kdError() << "DateNavigatorContainer::selectDates() empty list." << endl; | ||
187 | } | ||
188 | QDate baseDate = dateList.first(); | ||
189 | bool doRepaint = false; // skip first repaint | ||
190 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | 259 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
191 | KDateNavigator *n = mExtraViews.at( i ); | 260 | KDateNavigator *n = mExtraViews.at( i ); |
192 | baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 ); | 261 | baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 ); |
193 | n->setBaseDate( baseDate, doRepaint ); | 262 | n->setBaseDate( baseDate, doRepaint ); |
194 | doRepaint = true; | ||
195 | } | 263 | } |
196 | } | 264 | } |
197 | 265 | ||
198 | void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) | 266 | void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) |
199 | { | 267 | { |
200 | #if 0 | 268 | #if 0 |
diff --git a/korganizer/datenavigatorcontainer.h b/korganizer/datenavigatorcontainer.h index f45af20..d5e5adf 100644 --- a/korganizer/datenavigatorcontainer.h +++ b/korganizer/datenavigatorcontainer.h | |||
@@ -43,19 +43,23 @@ class DateNavigatorContainer: public QWidget | |||
43 | */ | 43 | */ |
44 | void setCalendar( Calendar * ); | 44 | void setCalendar( Calendar * ); |
45 | 45 | ||
46 | QSize minimumSizeHint() const; | 46 | QSize minimumSizeHint() const; |
47 | QSize sizeHint() const; | 47 | QSize sizeHint() const; |
48 | KDateNavigator * navigatorView() { return mNavigatorView;} | 48 | KDateNavigator * navigatorView() { return mNavigatorView;} |
49 | QDate lastAvailableDate() const ; | ||
50 | QDate firstAvailableDate() const ; | ||
49 | 51 | ||
50 | public slots: | 52 | public slots: |
51 | void selectDates( const KCal::DateList & ); | 53 | void selectDates( const KCal::DateList & ); |
52 | void updateView(); | 54 | void updateView(); |
53 | void updateConfig(); | 55 | void updateConfig(); |
54 | void updateDayMatrix(); | 56 | void updateDayMatrix(); |
57 | void updateDayMatrixDates(); | ||
55 | void updateToday(); | 58 | void updateToday(); |
59 | void slotMonthSelected( int month ); | ||
56 | 60 | ||
57 | signals: | 61 | signals: |
58 | void datesSelected( const KCal::DateList & ); | 62 | void datesSelected( const KCal::DateList & ); |
59 | void incidenceDropped( Incidence *, const QDate & ); | 63 | void incidenceDropped( Incidence *, const QDate & ); |
60 | void incidenceDroppedMove( Incidence *, const QDate & ); | 64 | void incidenceDroppedMove( Incidence *, const QDate & ); |
61 | void weekClicked( const QDate &); | 65 | void weekClicked( const QDate &); |
@@ -75,13 +79,14 @@ class DateNavigatorContainer: public QWidget | |||
75 | 79 | ||
76 | void setBaseDates(); | 80 | void setBaseDates(); |
77 | void connectNavigatorView( KDateNavigator *v ); | 81 | void connectNavigatorView( KDateNavigator *v ); |
78 | 82 | ||
79 | private: | 83 | private: |
80 | int mLastDisplayedDN; | 84 | int mLastDisplayedDN; |
81 | QDate mDisplayedEndDate; | 85 | QDate mFirstSelectedDate; |
86 | int mSelectedDateCount; | ||
82 | KDateNavigator *mNavigatorView; | 87 | KDateNavigator *mNavigatorView; |
83 | 88 | ||
84 | KCal::Calendar *mCalendar; | 89 | KCal::Calendar *mCalendar; |
85 | 90 | ||
86 | QPtrList<KDateNavigator> mExtraViews; | 91 | QPtrList<KDateNavigator> mExtraViews; |
87 | 92 | ||
diff --git a/korganizer/kdatenavigator.cpp b/korganizer/kdatenavigator.cpp index 231095f..83a57ca 100644 --- a/korganizer/kdatenavigator.cpp +++ b/korganizer/kdatenavigator.cpp | |||
@@ -187,12 +187,13 @@ void KDateNavigator::setCalendar( Calendar *cal ) | |||
187 | daymatrix->setCalendar( cal ); | 187 | daymatrix->setCalendar( cal ); |
188 | } | 188 | } |
189 | 189 | ||
190 | void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true | 190 | void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true |
191 | { | 191 | { |
192 | m_MthYr = date; | 192 | m_MthYr = date; |
193 | //qDebug("KDateNavigator::setBaseDate %s ", date.toString().latin1()); | ||
193 | 194 | ||
194 | updateDates(); | 195 | updateDates(); |
195 | updateView(); | 196 | updateView(); |
196 | 197 | ||
197 | KCal::DateList dates; | 198 | KCal::DateList dates; |
198 | dates.append( date ); | 199 | dates.append( date ); |