summaryrefslogtreecommitdiffabout
path: root/korganizer/datenavigatorcontainer.cpp
Unidiff
Diffstat (limited to 'korganizer/datenavigatorcontainer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/datenavigatorcontainer.cpp114
1 files changed, 91 insertions, 23 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp
index bb27bce..6de7c45 100644
--- a/korganizer/datenavigatorcontainer.cpp
+++ b/korganizer/datenavigatorcontainer.cpp
@@ -1,242 +1,310 @@
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
38DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, 38DateNavigatorContainer::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
53DateNavigatorContainer::~DateNavigatorContainer() 52DateNavigatorContainer::~DateNavigatorContainer()
54{ 53{
55} 54}
56 55
57void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) 56void 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
80void 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}
81void DateNavigatorContainer::setCalendar( Calendar *cal ) 129void 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}
138void 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
91void DateNavigatorContainer::updateDayMatrix() 153void 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
100void DateNavigatorContainer::updateToday() 162void 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
112void DateNavigatorContainer::updateView() 174void 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
121void DateNavigatorContainer::updateConfig() 183void 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 191QDate 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}
207QDate DateNavigatorContainer::firstAvailableDate() const
208{
209 return QDate ( mNavigatorView->baseDate().year(), mNavigatorView->baseDate().month(), 1 );
210}
130void DateNavigatorContainer::selectDates( const DateList &dateList ) 211void 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
182void DateNavigatorContainer::setBaseDates() 255void 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
198void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) 266void 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;