-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 | |||
@@ -1,319 +1,387 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | 3 | ||
4 | Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org> |
5 | Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> | 5 | Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> |
6 | 6 | ||
7 | This program is free software; you can redistribute it and/or modify | 7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | 8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or | 9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | 10 | (at your option) any later version. |
11 | 11 | ||
12 | This program is distributed in the hope that it will be useful, | 12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | 18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
20 | 20 | ||
21 | As a special exception, permission is given to link this program | 21 | As a special exception, permission is given to link this program |
22 | with any edition of Qt, and distribute the resulting executable, | 22 | with any edition of Qt, and distribute the resulting executable, |
23 | without including the source code for Qt in the source distribution. | 23 | without including the source code for Qt in the source distribution. |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <kdebug.h> | 26 | #include <kdebug.h> |
27 | #include <klocale.h> | 27 | #include <klocale.h> |
28 | 28 | ||
29 | //#include "koglobals.h" | 29 | //#include "koglobals.h" |
30 | #include "navigatorbar.h" | 30 | #include "navigatorbar.h" |
31 | #include "kdatenavigator.h" | 31 | #include "kdatenavigator.h" |
32 | 32 | ||
33 | #include <kcalendarsystem.h> | 33 | #include <kcalendarsystem.h> |
34 | 34 | ||
35 | #include "datenavigatorcontainer.h" | 35 | #include "datenavigatorcontainer.h" |
36 | #include "koprefs.h" | 36 | #include "koprefs.h" |
37 | 37 | ||
38 | DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, | 38 | DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, |
39 | const char *name ) | 39 | const char *name ) |
40 | : QWidget( parent, name ), mCalendar( 0 ), | 40 | : QWidget( parent, name ), mCalendar( 0 ), |
41 | mHorizontalCount( 1 ), mVerticalCount( 1 ) | 41 | mHorizontalCount( 1 ), mVerticalCount( 1 ) |
42 | { | 42 | { |
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 | } |
56 | 55 | ||
57 | void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) | 56 | void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) |
58 | { | 57 | { |
59 | connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), | 58 | connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), |
60 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); | 59 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); |
61 | #if 0 | 60 | #if 0 |
62 | connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), | 61 | connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), |
63 | SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); | 62 | SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); |
64 | connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), | 63 | connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), |
65 | SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); | 64 | SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); |
66 | #endif | 65 | #endif |
67 | connect( v, SIGNAL( weekClicked( const QDate & ) ), | 66 | connect( v, SIGNAL( weekClicked( const QDate & ) ), |
68 | SIGNAL( weekClicked( const QDate & ) ) ); | 67 | SIGNAL( weekClicked( const QDate & ) ) ); |
69 | 68 | ||
70 | connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); | 69 | connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); |
71 | connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); | 70 | connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); |
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 ); |
96 | n->updateDayMatrix(); | 158 | n->updateDayMatrix(); |
97 | } | 159 | } |
98 | } | 160 | } |
99 | 161 | ||
100 | void DateNavigatorContainer::updateToday() | 162 | void DateNavigatorContainer::updateToday() |
101 | { | 163 | { |
102 | qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); | 164 | qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); |
103 | #if 0 | 165 | #if 0 |
104 | mNavigatorView->updateToday(); | 166 | mNavigatorView->updateToday(); |
105 | KDateNavigator *n; | 167 | KDateNavigator *n; |
106 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { | 168 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { |
107 | n->updateToday(); | 169 | n->updateToday(); |
108 | } | 170 | } |
109 | #endif | 171 | #endif |
110 | } | 172 | } |
111 | 173 | ||
112 | void DateNavigatorContainer::updateView() | 174 | void DateNavigatorContainer::updateView() |
113 | { | 175 | { |
114 | mNavigatorView->updateView(); | 176 | mNavigatorView->updateView(); |
115 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | 177 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
116 | KDateNavigator *n = mExtraViews.at( i ); | 178 | KDateNavigator *n = mExtraViews.at( i ); |
117 | n->updateView(); | 179 | n->updateView(); |
118 | } | 180 | } |
119 | } | 181 | } |
120 | 182 | ||
121 | void DateNavigatorContainer::updateConfig() | 183 | void DateNavigatorContainer::updateConfig() |
122 | { | 184 | { |
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(); |
138 | if ( mLastDisplayedDN <= 2 ) { | 221 | if ( mLastDisplayedDN <= 2 ) { |
139 | mNavigatorView->selectDates( dateList ); | 222 | mNavigatorView->selectDates( dateList ); |
140 | KDateNavigator *view = mExtraViews.at( 0 ); | 223 | KDateNavigator *view = mExtraViews.at( 0 ); |
141 | QDate bDate = fDate.addDays( fDate.daysInMonth () - fDate.day() +1 ); | 224 | QDate bDate = fDate.addDays( fDate.daysInMonth () - fDate.day() +1 ); |
142 | view->setBaseDate( bDate, false ); | 225 | view->setBaseDate( bDate, false ); |
143 | view->dayMatrix()->setSelectedDaysFrom(fDate , lDate); | 226 | view->dayMatrix()->setSelectedDaysFrom(fDate , lDate); |
144 | if ( mLastDisplayedDN == 2 ) { | 227 | if ( mLastDisplayedDN == 2 ) { |
145 | view = mExtraViews.at( 1 ); | 228 | view = mExtraViews.at( 1 ); |
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 ); |
172 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); | 245 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); |
173 | view->dayMatrix()->repaint( false ); | 246 | view->dayMatrix()->repaint( false ); |
174 | if ( mLastDisplayedDN > 1 ) { | 247 | if ( mLastDisplayedDN > 1 ) { |
175 | KDateNavigator *view = mExtraViews.at( 1 ); | 248 | KDateNavigator *view = mExtraViews.at( 1 ); |
176 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); | 249 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); |
177 | view->dayMatrix()->repaint( false ); | 250 | view->dayMatrix()->repaint( false ); |
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 |
201 | kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl; | 269 | kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl; |
202 | kdDebug(5850) << " CURRENT SIZE: " << size() << endl; | 270 | kdDebug(5850) << " CURRENT SIZE: " << size() << endl; |
203 | kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl; | 271 | kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl; |
204 | kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl; | 272 | kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl; |
205 | kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl; | 273 | kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl; |
206 | #endif | 274 | #endif |
207 | //QSize minSize = mNavigatorView->sizeHintTwoButtons(); | 275 | //QSize minSize = mNavigatorView->sizeHintTwoButtons(); |
208 | QSize minSize = mNavigatorView->yourSizeHint(); | 276 | QSize minSize = mNavigatorView->yourSizeHint(); |
209 | 277 | ||
210 | // kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl; | 278 | // kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl; |
211 | 279 | ||
212 | int verticalCount = size().height() / minSize.height(); | 280 | int verticalCount = size().height() / minSize.height(); |
213 | int horizontalCount = size().width() / minSize.width(); | 281 | int horizontalCount = size().width() / minSize.width(); |
214 | //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() ); | 282 | //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() ); |
215 | //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount ); | 283 | //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount ); |
216 | bool fontchange = false; | 284 | bool fontchange = false; |
217 | if ( horizontalCount == 1) | 285 | if ( horizontalCount == 1) |
218 | horizontalCount = size().width() / mNavigatorView->yourFullSizeHint().width(); | 286 | horizontalCount = size().width() / mNavigatorView->yourFullSizeHint().width(); |
219 | QFont fo; | 287 | QFont fo; |
220 | if ( horizontalCount != mHorizontalCount || | 288 | if ( horizontalCount != mHorizontalCount || |
221 | verticalCount != mVerticalCount ) { | 289 | verticalCount != mVerticalCount ) { |
222 | uint count = horizontalCount * verticalCount; | 290 | uint count = horizontalCount * verticalCount; |
223 | if ( count == 0 ) { | 291 | if ( count == 0 ) { |
224 | bool ok; | 292 | bool ok; |
225 | fo = mNavigatorView->yourFontHint( size() , &ok ); | 293 | fo = mNavigatorView->yourFontHint( size() , &ok ); |
226 | //mNavigatorView->resize( size() ); | 294 | //mNavigatorView->resize( size() ); |
227 | //if ( ! ok ) | 295 | //if ( ! ok ) |
228 | // return; | 296 | // return; |
229 | int butt = 2; | 297 | int butt = 2; |
230 | horizontalCount = size().width() / mNavigatorView->sizeHintTwoButtons( ).width(); | 298 | horizontalCount = size().width() / mNavigatorView->sizeHintTwoButtons( ).width(); |
231 | if ( horizontalCount <= 1 ) | 299 | if ( horizontalCount <= 1 ) |
232 | minSize = mNavigatorView->sizeHintTwoButtons( 4 ); | 300 | minSize = mNavigatorView->sizeHintTwoButtons( 4 ); |
233 | else | 301 | else |
234 | minSize = mNavigatorView->sizeHintTwoButtons(); | 302 | minSize = mNavigatorView->sizeHintTwoButtons(); |
235 | verticalCount = size().height() / minSize.height(); | 303 | verticalCount = size().height() / minSize.height(); |
236 | horizontalCount = size().width() / minSize.width(); | 304 | horizontalCount = size().width() / minSize.width(); |
237 | if ( horizontalCount == 0 ) | 305 | if ( horizontalCount == 0 ) |
238 | horizontalCount = 1; | 306 | horizontalCount = 1; |
239 | if ( verticalCount == 0 ) | 307 | if ( verticalCount == 0 ) |
240 | verticalCount = 1; | 308 | verticalCount = 1; |
241 | fontchange = true; | 309 | fontchange = true; |
242 | count = horizontalCount * verticalCount; | 310 | count = horizontalCount * verticalCount; |
243 | } else { | 311 | } else { |
244 | if ( mNavigatorView->fontChanged() ) { | 312 | if ( mNavigatorView->fontChanged() ) { |
245 | fontchange = true; | 313 | fontchange = true; |
246 | fo = KOPrefs::instance()->mDateNavigatorFont; | 314 | fo = KOPrefs::instance()->mDateNavigatorFont; |
247 | mNavigatorView->changeFont( fo ); | 315 | mNavigatorView->changeFont( fo ); |
248 | mNavigatorView->unsetFontChanged(); | 316 | mNavigatorView->unsetFontChanged(); |
249 | } | 317 | } |
250 | } | 318 | } |
251 | 319 | ||
252 | mLastDisplayedDN = horizontalCount*verticalCount-1; | 320 | mLastDisplayedDN = horizontalCount*verticalCount-1; |
253 | bool setBaseD = false; | 321 | bool setBaseD = false; |
254 | while ( count > ( mExtraViews.count() + 1 ) ) { | 322 | while ( count > ( mExtraViews.count() + 1 ) ) { |
255 | KDateNavigator *n = new KDateNavigator( this ); | 323 | KDateNavigator *n = new KDateNavigator( this ); |
256 | n->setMonthSignalOffset ( mExtraViews.count()+1 ); | 324 | n->setMonthSignalOffset ( mExtraViews.count()+1 ); |
257 | mExtraViews.append( n ); | 325 | mExtraViews.append( n ); |
258 | n->setCalendar( mCalendar ); | 326 | n->setCalendar( mCalendar ); |
259 | setBaseD = true; | 327 | setBaseD = true; |
260 | connectNavigatorView( n ); | 328 | connectNavigatorView( n ); |
261 | n->show(); | 329 | n->show(); |
262 | } | 330 | } |
263 | int iii = 0; | 331 | int iii = 0; |
264 | while ( iii < ( mExtraViews.count() ) ) { | 332 | while ( iii < ( mExtraViews.count() ) ) { |
265 | if ( iii < count-1 ) | 333 | if ( iii < count-1 ) |
266 | mExtraViews.at( iii )->show(); | 334 | mExtraViews.at( iii )->show(); |
267 | else | 335 | else |
268 | mExtraViews.at( iii )->hide(); | 336 | mExtraViews.at( iii )->hide(); |
269 | ++iii; | 337 | ++iii; |
270 | } | 338 | } |
271 | if ( setBaseD ) | 339 | if ( setBaseD ) |
272 | setBaseDates(); | 340 | setBaseDates(); |
273 | if ( fontchange ) { | 341 | if ( fontchange ) { |
274 | //mNavigatorView->changeFont( fo ); | 342 | //mNavigatorView->changeFont( fo ); |
275 | uint i; | 343 | uint i; |
276 | for( i = 0; i < mExtraViews.count(); ++i ) { | 344 | for( i = 0; i < mExtraViews.count(); ++i ) { |
277 | KDateNavigator *view = mExtraViews.at( i ); | 345 | KDateNavigator *view = mExtraViews.at( i ); |
278 | view->changeFont( fo ); | 346 | view->changeFont( fo ); |
279 | } | 347 | } |
280 | } | 348 | } |
281 | mHorizontalCount = horizontalCount; | 349 | mHorizontalCount = horizontalCount; |
282 | mVerticalCount = verticalCount; | 350 | mVerticalCount = verticalCount; |
283 | 351 | ||
284 | } | 352 | } |
285 | //qDebug("COUNT %d ", mExtraViews.count()); | 353 | //qDebug("COUNT %d ", mExtraViews.count()); |
286 | int height = size().height() / verticalCount; | 354 | int height = size().height() / verticalCount; |
287 | int width = size().width() / horizontalCount; | 355 | int width = size().width() / horizontalCount; |
288 | 356 | ||
289 | NavigatorBar *bar = mNavigatorView->navigatorBar(); | 357 | NavigatorBar *bar = mNavigatorView->navigatorBar(); |
290 | if ( horizontalCount > 1 ) bar->showButtons( true, false ); | 358 | if ( horizontalCount > 1 ) bar->showButtons( true, false ); |
291 | else bar->showButtons( true, true ); | 359 | else bar->showButtons( true, true ); |
292 | 360 | ||
293 | mNavigatorView->setGeometry(0, | 361 | mNavigatorView->setGeometry(0, |
294 | 0, width, height ); | 362 | 0, width, height ); |
295 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { | 363 | for( uint i = 0; i < mLastDisplayedDN; ++i ) { |
296 | int x = ( i + 1 ) % horizontalCount; | 364 | int x = ( i + 1 ) % horizontalCount; |
297 | int y = ( i + 1 ) / horizontalCount; | 365 | int y = ( i + 1 ) / horizontalCount; |
298 | 366 | ||
299 | KDateNavigator *view = mExtraViews.at( i ); | 367 | KDateNavigator *view = mExtraViews.at( i ); |
300 | bar = view->navigatorBar(); | 368 | bar = view->navigatorBar(); |
301 | if ( y > 0 ) bar->showButtons( false, false ); | 369 | if ( y > 0 ) bar->showButtons( false, false ); |
302 | else { | 370 | else { |
303 | if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); | 371 | if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); |
304 | else bar->showButtons( false, false ); | 372 | else bar->showButtons( false, false ); |
305 | } | 373 | } |
306 | view->setGeometry( x * width, | 374 | view->setGeometry( x * width, |
307 | y * height, width, height ); | 375 | y * height, width, height ); |
308 | } | 376 | } |
309 | } | 377 | } |
310 | 378 | ||
311 | QSize DateNavigatorContainer::minimumSizeHint() const | 379 | QSize DateNavigatorContainer::minimumSizeHint() const |
312 | { | 380 | { |
313 | return mNavigatorView->minimumSizeHint(); | 381 | return mNavigatorView->minimumSizeHint(); |
314 | } | 382 | } |
315 | 383 | ||
316 | QSize DateNavigatorContainer::sizeHint() const | 384 | QSize DateNavigatorContainer::sizeHint() const |
317 | { | 385 | { |
318 | return mNavigatorView->yourSizeHint(); | 386 | return mNavigatorView->yourSizeHint(); |
319 | } | 387 | } |
diff --git a/korganizer/datenavigatorcontainer.h b/korganizer/datenavigatorcontainer.h index f45af20..d5e5adf 100644 --- a/korganizer/datenavigatorcontainer.h +++ b/korganizer/datenavigatorcontainer.h | |||
@@ -1,92 +1,97 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | 3 | ||
4 | Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org> |
5 | Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com> | 5 | Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com> |
6 | 6 | ||
7 | This program is free software; you can redistribute it and/or modify | 7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | 8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or | 9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | 10 | (at your option) any later version. |
11 | 11 | ||
12 | This program is distributed in the hope that it will be useful, | 12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | 18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
20 | 20 | ||
21 | As a special exception, permission is given to link this program | 21 | As a special exception, permission is given to link this program |
22 | with any edition of Qt, and distribute the resulting executable, | 22 | with any edition of Qt, and distribute the resulting executable, |
23 | without including the source code for Qt in the source distribution. | 23 | without including the source code for Qt in the source distribution. |
24 | */ | 24 | */ |
25 | #ifndef DATENAVIGATORCONTAINER_H | 25 | #ifndef DATENAVIGATORCONTAINER_H |
26 | #define DATENAVIGATORCONTAINER_H | 26 | #define DATENAVIGATORCONTAINER_H |
27 | 27 | ||
28 | class KDateNavigator; | 28 | class KDateNavigator; |
29 | 29 | ||
30 | #include <qwidget.h> | 30 | #include <qwidget.h> |
31 | #include <libkcal/calendar.h> | 31 | #include <libkcal/calendar.h> |
32 | using namespace KCal; | 32 | using namespace KCal; |
33 | 33 | ||
34 | class DateNavigatorContainer: public QWidget | 34 | class DateNavigatorContainer: public QWidget |
35 | { | 35 | { |
36 | Q_OBJECT | 36 | Q_OBJECT |
37 | public: | 37 | public: |
38 | DateNavigatorContainer( QWidget *parent = 0, const char *name = 0 ); | 38 | DateNavigatorContainer( QWidget *parent = 0, const char *name = 0 ); |
39 | ~DateNavigatorContainer(); | 39 | ~DateNavigatorContainer(); |
40 | 40 | ||
41 | /** | 41 | /** |
42 | Associate date navigator with a calendar. It is used by KODayMatrix. | 42 | Associate date navigator with a calendar. It is used by KODayMatrix. |
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 &); |
62 | 66 | ||
63 | void goPrevious(); | 67 | void goPrevious(); |
64 | void goNext(); | 68 | void goNext(); |
65 | 69 | ||
66 | void goNextMonth(); | 70 | void goNextMonth(); |
67 | void goPrevMonth(); | 71 | void goPrevMonth(); |
68 | void goNextYear(); | 72 | void goNextYear(); |
69 | void goPrevYear(); | 73 | void goPrevYear(); |
70 | 74 | ||
71 | void monthSelected( int month ); | 75 | void monthSelected( int month ); |
72 | 76 | ||
73 | protected: | 77 | protected: |
74 | void resizeEvent( QResizeEvent * ); | 78 | void resizeEvent( QResizeEvent * ); |
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 | ||
88 | int mHorizontalCount; | 93 | int mHorizontalCount; |
89 | int mVerticalCount; | 94 | int mVerticalCount; |
90 | }; | 95 | }; |
91 | 96 | ||
92 | #endif | 97 | #endif |
diff --git a/korganizer/kdatenavigator.cpp b/korganizer/kdatenavigator.cpp index 231095f..83a57ca 100644 --- a/korganizer/kdatenavigator.cpp +++ b/korganizer/kdatenavigator.cpp | |||
@@ -1,447 +1,448 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qkeycode.h> | 25 | #include <qkeycode.h> |
26 | #include <qlayout.h> | 26 | #include <qlayout.h> |
27 | #include <qtimer.h> | 27 | #include <qtimer.h> |
28 | #include <qframe.h> | 28 | #include <qframe.h> |
29 | #include <qlabel.h> | 29 | #include <qlabel.h> |
30 | #include <qapplication.h> | 30 | #include <qapplication.h> |
31 | 31 | ||
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | #include <kglobal.h> | 34 | #include <kglobal.h> |
35 | 35 | ||
36 | #include "koglobals.h" | 36 | #include "koglobals.h" |
37 | #include "koprefs.h" | 37 | #include "koprefs.h" |
38 | #ifndef KORG_NOPLUGINS | 38 | #ifndef KORG_NOPLUGINS |
39 | #include "kocore.h" | 39 | #include "kocore.h" |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | #include <kcalendarsystem.h> | 42 | #include <kcalendarsystem.h> |
43 | 43 | ||
44 | #include "navigatorbar.h" | 44 | #include "navigatorbar.h" |
45 | 45 | ||
46 | #include "kdatenavigator.h" | 46 | #include "kdatenavigator.h" |
47 | 47 | ||
48 | KDateNavigator::KDateNavigator( QWidget *parent, const char *name ) | 48 | KDateNavigator::KDateNavigator( QWidget *parent, const char *name ) |
49 | : QFrame(parent, name), | 49 | : QFrame(parent, name), |
50 | updateTimer(0L) | 50 | updateTimer(0L) |
51 | { | 51 | { |
52 | setFrameStyle(QFrame::NoFrame); | 52 | setFrameStyle(QFrame::NoFrame); |
53 | QDate startDate = QDate::currentDate(); | 53 | QDate startDate = QDate::currentDate(); |
54 | QGridLayout *topLayout = new QGridLayout(this,8,8); | 54 | QGridLayout *topLayout = new QGridLayout(this,8,8); |
55 | 55 | ||
56 | if (! startDate.isValid()) { | 56 | if (! startDate.isValid()) { |
57 | qDebug("KDateNavigator::invalid startdate "); | 57 | qDebug("KDateNavigator::invalid startdate "); |
58 | startDate = QDate::currentDate(); | 58 | startDate = QDate::currentDate(); |
59 | } | 59 | } |
60 | mMonthSignalOffset = 0; | 60 | mMonthSignalOffset = 0; |
61 | mSelectedDates.append(startDate); | 61 | mSelectedDates.append(startDate); |
62 | m_MthYr = startDate; | 62 | m_MthYr = startDate; |
63 | m_bShowWeekNums = true; | 63 | m_bShowWeekNums = true; |
64 | 64 | ||
65 | setFont( KOPrefs::instance()->mDateNavigatorFont ); | 65 | setFont( KOPrefs::instance()->mDateNavigatorFont ); |
66 | mNavigatorBar = new NavigatorBar( startDate, this ); | 66 | mNavigatorBar = new NavigatorBar( startDate, this ); |
67 | topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 ); | 67 | topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 ); |
68 | //mNavigatorBar->resize( 1,1); | 68 | //mNavigatorBar->resize( 1,1); |
69 | connect( mNavigatorBar, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); | 69 | connect( mNavigatorBar, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); |
70 | connect( mNavigatorBar, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); | 70 | connect( mNavigatorBar, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); |
71 | connect( mNavigatorBar, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); | 71 | connect( mNavigatorBar, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); |
72 | connect( mNavigatorBar, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); | 72 | connect( mNavigatorBar, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); |
73 | connect( mNavigatorBar, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); | 73 | connect( mNavigatorBar, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); |
74 | 74 | ||
75 | // get the day of the week on the first day | 75 | // get the day of the week on the first day |
76 | QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); | 76 | QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); |
77 | m_fstDayOfWk = dayone.dayOfWeek(); | 77 | m_fstDayOfWk = dayone.dayOfWeek(); |
78 | 78 | ||
79 | int i; | 79 | int i; |
80 | 80 | ||
81 | // Set up the heading fields. | 81 | // Set up the heading fields. |
82 | for( i = 0; i < 7; i++ ) { | 82 | for( i = 0; i < 7; i++ ) { |
83 | headings[i] = new QLabel("",this); | 83 | headings[i] = new QLabel("",this); |
84 | //headings[i]->setFont(QFont("Arial", 10, QFont::Bold)); | 84 | //headings[i]->setFont(QFont("Arial", 10, QFont::Bold)); |
85 | headings[i]->setAlignment(AlignCenter); | 85 | headings[i]->setAlignment(AlignCenter); |
86 | 86 | ||
87 | topLayout->addWidget(headings[i],1,i+1); | 87 | topLayout->addWidget(headings[i],1,i+1); |
88 | } | 88 | } |
89 | 89 | ||
90 | // Create the weeknumber labels | 90 | // Create the weeknumber labels |
91 | for( i = 0; i < 6; i++ ) { | 91 | for( i = 0; i < 6; i++ ) { |
92 | weeknos[i] = new QLabel(this); | 92 | weeknos[i] = new QLabel(this); |
93 | weeknos[i]->setAlignment(AlignCenter); | 93 | weeknos[i]->setAlignment(AlignCenter); |
94 | //weeknos[i]->setFont(QFont("Arial", 10)); | 94 | //weeknos[i]->setFont(QFont("Arial", 10)); |
95 | if(!m_bShowWeekNums) { | 95 | if(!m_bShowWeekNums) { |
96 | weeknos[i]->hide(); | 96 | weeknos[i]->hide(); |
97 | } | 97 | } |
98 | weeknos[i]->installEventFilter(this); | 98 | weeknos[i]->installEventFilter(this); |
99 | 99 | ||
100 | topLayout->addWidget(weeknos[i],i+2,0); | 100 | topLayout->addWidget(weeknos[i],i+2,0); |
101 | } | 101 | } |
102 | 102 | ||
103 | daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix"); | 103 | daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix"); |
104 | daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken); | 104 | daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken); |
105 | daymatrix->setLineWidth(1); | 105 | daymatrix->setLineWidth(1); |
106 | 106 | ||
107 | connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ), | 107 | connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ), |
108 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); | 108 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); |
109 | 109 | ||
110 | connect( daymatrix, SIGNAL( eventDropped( Event * ) ), | 110 | connect( daymatrix, SIGNAL( eventDropped( Event * ) ), |
111 | SIGNAL( eventDropped( Event * ) ) ); | 111 | SIGNAL( eventDropped( Event * ) ) ); |
112 | 112 | ||
113 | topLayout->addMultiCellWidget(daymatrix,2,7,1,7); | 113 | topLayout->addMultiCellWidget(daymatrix,2,7,1,7); |
114 | 114 | ||
115 | // read settings from configuration file. | 115 | // read settings from configuration file. |
116 | updateConfig(); | 116 | updateConfig(); |
117 | enableRollover(FollowMonth); | 117 | enableRollover(FollowMonth); |
118 | mySizeHint = sizeHintTwoButtons(); | 118 | mySizeHint = sizeHintTwoButtons(); |
119 | myFullSizeHint = sizeHintTwoButtons( 4 ); | 119 | myFullSizeHint = sizeHintTwoButtons( 4 ); |
120 | mFontChanged = false; | 120 | mFontChanged = false; |
121 | } | 121 | } |
122 | void KDateNavigator::changeFont ( QFont fo ) | 122 | void KDateNavigator::changeFont ( QFont fo ) |
123 | { | 123 | { |
124 | setFont( fo ); | 124 | setFont( fo ); |
125 | mNavigatorBar->resetFont( fo ); | 125 | mNavigatorBar->resetFont( fo ); |
126 | } | 126 | } |
127 | QFont KDateNavigator::yourFontHint( QSize si , bool *b) | 127 | QFont KDateNavigator::yourFontHint( QSize si , bool *b) |
128 | { | 128 | { |
129 | QFont fo = KOPrefs::instance()->mDateNavigatorFont; | 129 | QFont fo = KOPrefs::instance()->mDateNavigatorFont; |
130 | *b = false; | 130 | *b = false; |
131 | int fontPoint = fo.pointSize(); | 131 | int fontPoint = fo.pointSize(); |
132 | while ( fontPoint > 5 ) { | 132 | while ( fontPoint > 5 ) { |
133 | --fontPoint; | 133 | --fontPoint; |
134 | fo.setPointSize( fontPoint ); | 134 | fo.setPointSize( fontPoint ); |
135 | setFont( fo ); | 135 | setFont( fo ); |
136 | mFontChanged = true; | 136 | mFontChanged = true; |
137 | mNavigatorBar->resetFont( fo ); | 137 | mNavigatorBar->resetFont( fo ); |
138 | QSize sh = sizeHintTwoButtons( 2 ); | 138 | QSize sh = sizeHintTwoButtons( 2 ); |
139 | //qDebug("fp %d %d %d %d %d", fontPoint, si.width() , sh.width() , si.height() , sh.height() ); | 139 | //qDebug("fp %d %d %d %d %d", fontPoint, si.width() , sh.width() , si.height() , sh.height() ); |
140 | if ( si.width() > sh.width() && si.height() > sh.height()) { | 140 | if ( si.width() > sh.width() && si.height() > sh.height()) { |
141 | if ( si.width() / sh.width() == 1 ) { | 141 | if ( si.width() / sh.width() == 1 ) { |
142 | if ( si.width() < sizeHintTwoButtons( 4 ).width()) | 142 | if ( si.width() < sizeHintTwoButtons( 4 ).width()) |
143 | continue; | 143 | continue; |
144 | } | 144 | } |
145 | *b = true; | 145 | *b = true; |
146 | //qDebug("fooooooooooooooooooooooouuuuund "); | 146 | //qDebug("fooooooooooooooooooooooouuuuund "); |
147 | break; | 147 | break; |
148 | } | 148 | } |
149 | } | 149 | } |
150 | //qDebug("returnnnnnnnnnnnnnnnnnnn %d", fo.pointSize() ); | 150 | //qDebug("returnnnnnnnnnnnnnnnnnnn %d", fo.pointSize() ); |
151 | return fo; | 151 | return fo; |
152 | } | 152 | } |
153 | QSize KDateNavigator::sizeHint() const | 153 | QSize KDateNavigator::sizeHint() const |
154 | { | 154 | { |
155 | QFontMetrics fm ( font() ); | 155 | QFontMetrics fm ( font() ); |
156 | QSize day = daymatrix->sizeHint(); | 156 | QSize day = daymatrix->sizeHint(); |
157 | QSize nav = mNavigatorBar->sizeHint(); | 157 | QSize nav = mNavigatorBar->sizeHint(); |
158 | int wid = fm.width( "30") + day.width()+3; | 158 | int wid = fm.width( "30") + day.width()+3; |
159 | int hei = fm.height() +day.height()+nav.height()+2; | 159 | int hei = fm.height() +day.height()+nav.height()+2; |
160 | if ( wid < nav.width() ) | 160 | if ( wid < nav.width() ) |
161 | wid = nav.width() ; | 161 | wid = nav.width() ; |
162 | //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); | 162 | //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); |
163 | return QSize ( wid, hei ); | 163 | return QSize ( wid, hei ); |
164 | } | 164 | } |
165 | QSize KDateNavigator::sizeHintTwoButtons( int butnum ) const | 165 | QSize KDateNavigator::sizeHintTwoButtons( int butnum ) const |
166 | { | 166 | { |
167 | QFontMetrics fm ( font() ); | 167 | QFontMetrics fm ( font() ); |
168 | QSize day = daymatrix->sizeHint(); | 168 | QSize day = daymatrix->sizeHint(); |
169 | QSize nav = mNavigatorBar->sizeHintTwoButtons( butnum ); | 169 | QSize nav = mNavigatorBar->sizeHintTwoButtons( butnum ); |
170 | int wid = fm.width( "30") + day.width()+3; | 170 | int wid = fm.width( "30") + day.width()+3; |
171 | int hei = fm.height() +day.height()+nav.height()+2; | 171 | int hei = fm.height() +day.height()+nav.height()+2; |
172 | if ( wid < nav.width() ) | 172 | if ( wid < nav.width() ) |
173 | wid = nav.width() ; | 173 | wid = nav.width() ; |
174 | //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); | 174 | //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); |
175 | return QSize ( wid, hei ); | 175 | return QSize ( wid, hei ); |
176 | } | 176 | } |
177 | void KDateNavigator::slotMonthSelected( int m ) | 177 | void KDateNavigator::slotMonthSelected( int m ) |
178 | { | 178 | { |
179 | if ( m_MthYr.month() <= mMonthSignalOffset) | 179 | if ( m_MthYr.month() <= mMonthSignalOffset) |
180 | m += 12; | 180 | m += 12; |
181 | //qDebug("%d mMonthSignalOffset %d emit %d", m, mMonthSignalOffset, m - mMonthSignalOffset); | 181 | //qDebug("%d mMonthSignalOffset %d emit %d", m, mMonthSignalOffset, m - mMonthSignalOffset); |
182 | emit monthSelected( m - mMonthSignalOffset ); | 182 | emit monthSelected( m - mMonthSignalOffset ); |
183 | 183 | ||
184 | } | 184 | } |
185 | void KDateNavigator::setCalendar( Calendar *cal ) | 185 | void KDateNavigator::setCalendar( Calendar *cal ) |
186 | { | 186 | { |
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 ); |
199 | mNavigatorBar->selectDates( dates ); | 200 | mNavigatorBar->selectDates( dates ); |
200 | 201 | ||
201 | daymatrix->clearSelection(); | 202 | daymatrix->clearSelection(); |
202 | if ( doRepaint ) | 203 | if ( doRepaint ) |
203 | daymatrix->repaint( false ); | 204 | daymatrix->repaint( false ); |
204 | } | 205 | } |
205 | 206 | ||
206 | void KDateNavigator::enableRollover(RolloverType r) | 207 | void KDateNavigator::enableRollover(RolloverType r) |
207 | { | 208 | { |
208 | switch(r) | 209 | switch(r) |
209 | { | 210 | { |
210 | case None : | 211 | case None : |
211 | if (updateTimer) | 212 | if (updateTimer) |
212 | { | 213 | { |
213 | updateTimer->stop(); | 214 | updateTimer->stop(); |
214 | delete updateTimer; | 215 | delete updateTimer; |
215 | updateTimer=0L; | 216 | updateTimer=0L; |
216 | } | 217 | } |
217 | break; | 218 | break; |
218 | case FollowDay : | 219 | case FollowDay : |
219 | case FollowMonth : | 220 | case FollowMonth : |
220 | if (!updateTimer) | 221 | if (!updateTimer) |
221 | { | 222 | { |
222 | updateTimer = new QTimer(this); | 223 | updateTimer = new QTimer(this); |
223 | QObject::connect(updateTimer,SIGNAL(timeout()), | 224 | QObject::connect(updateTimer,SIGNAL(timeout()), |
224 | this,SLOT(possiblyPastMidnight())); | 225 | this,SLOT(possiblyPastMidnight())); |
225 | } | 226 | } |
226 | updateTimer->start(0,true); | 227 | updateTimer->start(0,true); |
227 | lastDayChecked = QDate::currentDate(); | 228 | lastDayChecked = QDate::currentDate(); |
228 | } | 229 | } |
229 | updateRollover=r; | 230 | updateRollover=r; |
230 | } | 231 | } |
231 | 232 | ||
232 | 233 | ||
233 | KDateNavigator::~KDateNavigator() | 234 | KDateNavigator::~KDateNavigator() |
234 | { | 235 | { |
235 | } | 236 | } |
236 | 237 | ||
237 | 238 | ||
238 | void KDateNavigator::passedMidnight() | 239 | void KDateNavigator::passedMidnight() |
239 | { | 240 | { |
240 | QDate today = QDate::currentDate(); | 241 | QDate today = QDate::currentDate(); |
241 | bool emitMonth = false; | 242 | bool emitMonth = false; |
242 | 243 | ||
243 | if (today.month() != lastDayChecked.month()) | 244 | if (today.month() != lastDayChecked.month()) |
244 | { | 245 | { |
245 | if (updateRollover==FollowMonth && | 246 | if (updateRollover==FollowMonth && |
246 | daymatrix->isEndOfMonth()) { | 247 | daymatrix->isEndOfMonth()) { |
247 | goNextMonth(); | 248 | goNextMonth(); |
248 | emitMonth=true; | 249 | emitMonth=true; |
249 | } | 250 | } |
250 | } | 251 | } |
251 | daymatrix->recalculateToday(); | 252 | daymatrix->recalculateToday(); |
252 | daymatrix->repaint( false ); | 253 | daymatrix->repaint( false ); |
253 | emit dayPassed(today); | 254 | emit dayPassed(today); |
254 | if (emitMonth) { emit monthPassed(today); } | 255 | if (emitMonth) { emit monthPassed(today); } |
255 | } | 256 | } |
256 | 257 | ||
257 | /* slot */ void KDateNavigator::possiblyPastMidnight() | 258 | /* slot */ void KDateNavigator::possiblyPastMidnight() |
258 | { | 259 | { |
259 | if (lastDayChecked!=QDate::currentDate()) | 260 | if (lastDayChecked!=QDate::currentDate()) |
260 | { | 261 | { |
261 | passedMidnight(); | 262 | passedMidnight(); |
262 | lastDayChecked=QDate::currentDate(); | 263 | lastDayChecked=QDate::currentDate(); |
263 | } | 264 | } |
264 | // Set the timer to go off 1 second after midnight | 265 | // Set the timer to go off 1 second after midnight |
265 | // or after 8 minutes, whichever comes first. | 266 | // or after 8 minutes, whichever comes first. |
266 | if (updateTimer) | 267 | if (updateTimer) |
267 | { | 268 | { |
268 | QTime now = QTime::currentTime(); | 269 | QTime now = QTime::currentTime(); |
269 | QTime midnight = QTime(23,59,59); | 270 | QTime midnight = QTime(23,59,59); |
270 | int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000); | 271 | int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000); |
271 | 272 | ||
272 | // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait)) | 273 | // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait)) |
273 | //.arg(now.toString()).arg(midnight.toString())); | 274 | //.arg(now.toString()).arg(midnight.toString())); |
274 | 275 | ||
275 | updateTimer->stop(); | 276 | updateTimer->stop(); |
276 | updateTimer->start(msecsWait,true); | 277 | updateTimer->start(msecsWait,true); |
277 | } | 278 | } |
278 | } | 279 | } |
279 | 280 | ||
280 | void KDateNavigator::updateDates() | 281 | void KDateNavigator::updateDates() |
281 | { | 282 | { |
282 | // Find the first day of the week of the current month. | 283 | // Find the first day of the week of the current month. |
283 | //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr ); | 284 | //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr ); |
284 | QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() ); | 285 | QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() ); |
285 | int d2 = KOGlobals::self()->calendarSystem()->day( dayone ); | 286 | int d2 = KOGlobals::self()->calendarSystem()->day( dayone ); |
286 | //int di = d1 - d2 + 1; | 287 | //int di = d1 - d2 + 1; |
287 | dayone = dayone.addDays( -d2 + 1 ); | 288 | dayone = dayone.addDays( -d2 + 1 ); |
288 | 289 | ||
289 | int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone ); | 290 | int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone ); |
290 | 291 | ||
291 | // If month begins on Monday and Monday is first day of week, | 292 | // If month begins on Monday and Monday is first day of week, |
292 | // month should begin on second line. Sunday doesn't have this problem. | 293 | // month should begin on second line. Sunday doesn't have this problem. |
293 | int nextLine = ( ( m_fstDayOfWkCalsys == 1) && | 294 | int nextLine = ( ( m_fstDayOfWkCalsys == 1) && |
294 | ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0; | 295 | ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0; |
295 | 296 | ||
296 | // update the matrix dates | 297 | // update the matrix dates |
297 | int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine; | 298 | int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine; |
298 | 299 | ||
299 | 300 | ||
300 | daymatrix->updateView(dayone.addDays(index)); | 301 | daymatrix->updateView(dayone.addDays(index)); |
301 | //each updateDates is followed by an updateView -> repaint is issued there ! | 302 | //each updateDates is followed by an updateView -> repaint is issued there ! |
302 | // daymatrix->repaint(); | 303 | // daymatrix->repaint(); |
303 | } | 304 | } |
304 | 305 | ||
305 | void KDateNavigator::updateDayMatrix() | 306 | void KDateNavigator::updateDayMatrix() |
306 | { | 307 | { |
307 | daymatrix->updateView(); | 308 | daymatrix->updateView(); |
308 | //daymatrix->repaint(); | 309 | //daymatrix->repaint(); |
309 | } | 310 | } |
310 | 311 | ||
311 | 312 | ||
312 | void KDateNavigator::updateView() | 313 | void KDateNavigator::updateView() |
313 | { | 314 | { |
314 | 315 | ||
315 | setUpdatesEnabled( false ); | 316 | setUpdatesEnabled( false ); |
316 | 317 | ||
317 | int i; | 318 | int i; |
318 | 319 | ||
319 | // kdDebug() << "updateView() -> daymatrix->updateView()" << endl; | 320 | // kdDebug() << "updateView() -> daymatrix->updateView()" << endl; |
320 | daymatrix->updateView(); | 321 | daymatrix->updateView(); |
321 | 322 | ||
322 | // set the week numbers. | 323 | // set the week numbers. |
323 | for(i = 0; i < 6; i++) { | 324 | for(i = 0; i < 6; i++) { |
324 | QString weeknum; | 325 | QString weeknum; |
325 | // remember, according to ISO 8601, the first week of the year is the | 326 | // remember, according to ISO 8601, the first week of the year is the |
326 | // first week that contains a thursday. Thus we must subtract off 4, | 327 | // first week that contains a thursday. Thus we must subtract off 4, |
327 | // not just 1. | 328 | // not just 1. |
328 | 329 | ||
329 | //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear(); | 330 | //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear(); |
330 | int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4))); | 331 | int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4))); |
331 | 332 | ||
332 | int add = 0; | 333 | int add = 0; |
333 | if ( ! KGlobal::locale()->weekStartsMonday() ) | 334 | if ( ! KGlobal::locale()->weekStartsMonday() ) |
334 | ++add; | 335 | ++add; |
335 | if (dayOfYear % 7 != 0) | 336 | if (dayOfYear % 7 != 0) |
336 | weeknum.setNum(dayOfYear / 7 + 1+add); | 337 | weeknum.setNum(dayOfYear / 7 + 1+add); |
337 | else | 338 | else |
338 | weeknum.setNum(dayOfYear / 7 +add); | 339 | weeknum.setNum(dayOfYear / 7 +add); |
339 | weeknos[i]->setText(weeknum); | 340 | weeknos[i]->setText(weeknum); |
340 | } | 341 | } |
341 | 342 | ||
342 | setUpdatesEnabled( true ); | 343 | setUpdatesEnabled( true ); |
343 | // kdDebug() << "updateView() -> repaint()" << endl; | 344 | // kdDebug() << "updateView() -> repaint()" << endl; |
344 | repaint(); | 345 | repaint(); |
345 | // daymatrix->repaint(); | 346 | // daymatrix->repaint(); |
346 | } | 347 | } |
347 | 348 | ||
348 | void KDateNavigator::updateConfig() | 349 | void KDateNavigator::updateConfig() |
349 | { | 350 | { |
350 | int day; | 351 | int day; |
351 | for(int i=0; i<7; i++) { | 352 | for(int i=0; i<7; i++) { |
352 | // take the first letter of the day name to be the abbreviation | 353 | // take the first letter of the day name to be the abbreviation |
353 | if (KGlobal::locale()->weekStartsMonday()) { | 354 | if (KGlobal::locale()->weekStartsMonday()) { |
354 | day = i+1; | 355 | day = i+1; |
355 | } else { | 356 | } else { |
356 | if (i==0) day = 7; | 357 | if (i==0) day = 7; |
357 | else day = i; | 358 | else day = i; |
358 | } | 359 | } |
359 | QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day, | 360 | QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day, |
360 | true ); | 361 | true ); |
361 | if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 ); | 362 | if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 ); |
362 | headings[i]->setText( dayName ); | 363 | headings[i]->setText( dayName ); |
363 | } | 364 | } |
364 | updateDates(); | 365 | updateDates(); |
365 | updateView(); | 366 | updateView(); |
366 | } | 367 | } |
367 | 368 | ||
368 | void KDateNavigator::setShowWeekNums(bool enabled) | 369 | void KDateNavigator::setShowWeekNums(bool enabled) |
369 | { | 370 | { |
370 | m_bShowWeekNums = enabled; | 371 | m_bShowWeekNums = enabled; |
371 | for(int i=0; i<6; i++) { | 372 | for(int i=0; i<6; i++) { |
372 | if(enabled) | 373 | if(enabled) |
373 | weeknos[i]->show(); | 374 | weeknos[i]->show(); |
374 | else | 375 | else |
375 | weeknos[i]->hide(); | 376 | weeknos[i]->hide(); |
376 | } | 377 | } |
377 | resize(size()); | 378 | resize(size()); |
378 | } | 379 | } |
379 | 380 | ||
380 | void KDateNavigator::selectDates(const DateList& dateList) | 381 | void KDateNavigator::selectDates(const DateList& dateList) |
381 | { | 382 | { |
382 | 383 | ||
383 | if (dateList.count() > 0) { | 384 | if (dateList.count() > 0) { |
384 | mNavigatorBar->selectDates( dateList ); | 385 | mNavigatorBar->selectDates( dateList ); |
385 | mSelectedDates = dateList; | 386 | mSelectedDates = dateList; |
386 | 387 | ||
387 | // set our record of the month and year that this datetbl is | 388 | // set our record of the month and year that this datetbl is |
388 | // displaying. | 389 | // displaying. |
389 | m_MthYr = mSelectedDates.first(); | 390 | m_MthYr = mSelectedDates.first(); |
390 | 391 | ||
391 | 392 | ||
392 | // set our record of the first day of the week of the current | 393 | // set our record of the first day of the week of the current |
393 | // month. This needs to be done before calling dayToIndex, since it | 394 | // month. This needs to be done before calling dayToIndex, since it |
394 | // relies on this information being up to date. | 395 | // relies on this information being up to date. |
395 | QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); | 396 | QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); |
396 | m_fstDayOfWk = dayone.dayOfWeek(); | 397 | m_fstDayOfWk = dayone.dayOfWeek(); |
397 | 398 | ||
398 | updateDates(); | 399 | updateDates(); |
399 | 400 | ||
400 | daymatrix->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); | 401 | daymatrix->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); |
401 | 402 | ||
402 | updateView(); | 403 | updateView(); |
403 | } | 404 | } |
404 | } | 405 | } |
405 | 406 | ||
406 | int KDateNavigator::dayNum(int row, int col) | 407 | int KDateNavigator::dayNum(int row, int col) |
407 | { | 408 | { |
408 | return 7 * (row - 1) + (col + 1) - m_fstDayOfWk; | 409 | return 7 * (row - 1) + (col + 1) - m_fstDayOfWk; |
409 | } | 410 | } |
410 | 411 | ||
411 | int KDateNavigator::dayToIndex(int dayNum) | 412 | int KDateNavigator::dayToIndex(int dayNum) |
412 | { | 413 | { |
413 | int row, col; | 414 | int row, col; |
414 | 415 | ||
415 | row = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) / 7; | 416 | row = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) / 7; |
416 | if (KGlobal::locale()->weekStartsMonday() && (m_fstDayOfWk == 1)) | 417 | if (KGlobal::locale()->weekStartsMonday() && (m_fstDayOfWk == 1)) |
417 | row++; | 418 | row++; |
418 | col = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) % 7; | 419 | col = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) % 7; |
419 | return row * 7 + col; | 420 | return row * 7 + col; |
420 | } | 421 | } |
421 | 422 | ||
422 | void KDateNavigator::wheelEvent (QWheelEvent *e) | 423 | void KDateNavigator::wheelEvent (QWheelEvent *e) |
423 | { | 424 | { |
424 | if(e->delta()>0) emit goPrevious(); | 425 | if(e->delta()>0) emit goPrevious(); |
425 | else emit goNext(); | 426 | else emit goNext(); |
426 | 427 | ||
427 | e->accept(); | 428 | e->accept(); |
428 | } | 429 | } |
429 | 430 | ||
430 | bool KDateNavigator::eventFilter (QObject *o,QEvent *e) | 431 | bool KDateNavigator::eventFilter (QObject *o,QEvent *e) |
431 | { | 432 | { |
432 | if (e->type() == QEvent::MouseButtonPress) { | 433 | if (e->type() == QEvent::MouseButtonPress) { |
433 | int i; | 434 | int i; |
434 | for(i=0;i<6;++i) { | 435 | for(i=0;i<6;++i) { |
435 | if (o == weeknos[i]) { | 436 | if (o == weeknos[i]) { |
436 | QDate weekstart = daymatrix->getDate(i*7); | 437 | QDate weekstart = daymatrix->getDate(i*7); |
437 | emit weekClicked(weekstart); | 438 | emit weekClicked(weekstart); |
438 | break; | 439 | break; |
439 | } | 440 | } |
440 | } | 441 | } |
441 | return true; | 442 | return true; |
442 | } else { | 443 | } else { |
443 | return false; | 444 | return false; |
444 | } | 445 | } |
445 | } | 446 | } |
446 | 447 | ||
447 | //#include "kdatenavigator.moc" | 448 | //#include "kdatenavigator.moc" |