summaryrefslogtreecommitdiffabout
path: root/korganizer/kdatenavigator.cpp
Unidiff
Diffstat (limited to 'korganizer/kdatenavigator.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kdatenavigator.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/korganizer/kdatenavigator.cpp b/korganizer/kdatenavigator.cpp
index 0cb767f..5eccfd6 100644
--- a/korganizer/kdatenavigator.cpp
+++ b/korganizer/kdatenavigator.cpp
@@ -1,466 +1,467 @@
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
48KDateNavigator::KDateNavigator( QWidget *parent, const char *name ) 48KDateNavigator::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 headings[i]->installEventFilter(this); 86 headings[i]->installEventFilter(this);
87 87
88 topLayout->addWidget(headings[i],1,i+1); 88 topLayout->addWidget(headings[i],1,i+1);
89 } 89 }
90 90
91 // Create the weeknumber labels 91 // Create the weeknumber labels
92 for( i = 0; i < 6; i++ ) { 92 for( i = 0; i < 6; i++ ) {
93 weeknos[i] = new QLabel(this); 93 weeknos[i] = new QLabel(this);
94 weeknos[i]->setAlignment(AlignCenter); 94 weeknos[i]->setAlignment(AlignCenter);
95 //weeknos[i]->setFont(QFont("Arial", 10)); 95 //weeknos[i]->setFont(QFont("Arial", 10));
96 if(!m_bShowWeekNums) { 96 if(!m_bShowWeekNums) {
97 weeknos[i]->hide(); 97 weeknos[i]->hide();
98 } 98 }
99 weeknos[i]->installEventFilter(this); 99 weeknos[i]->installEventFilter(this);
100 100
101 topLayout->addWidget(weeknos[i],i+2,0); 101 topLayout->addWidget(weeknos[i],i+2,0);
102 } 102 }
103 103
104 daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix"); 104 daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix");
105 daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken); 105 daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken);
106 daymatrix->setLineWidth(1); 106 daymatrix->setLineWidth(1);
107 107
108 connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ), 108 connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ),
109 SIGNAL( datesSelected( const KCal::DateList & ) ) ); 109 SIGNAL( datesSelected( const KCal::DateList & ) ) );
110 110
111 connect( daymatrix, SIGNAL( eventDropped( Event * ) ), 111 connect( daymatrix, SIGNAL( eventDropped( Event * ) ),
112 SIGNAL( eventDropped( Event * ) ) ); 112 SIGNAL( eventDropped( Event * ) ) );
113 113
114 topLayout->addMultiCellWidget(daymatrix,2,7,1,7); 114 topLayout->addMultiCellWidget(daymatrix,2,7,1,7);
115 115
116 // read settings from configuration file. 116 // read settings from configuration file.
117 updateConfig(); 117 updateConfig();
118 enableRollover(FollowMonth); 118 enableRollover(FollowMonth);
119 mySizeHint = sizeHintTwoButtons(); 119 mySizeHint = sizeHintTwoButtons();
120 myFullSizeHint = sizeHintTwoButtons( 4 ); 120 myFullSizeHint = sizeHintTwoButtons( 4 );
121 mFontChanged = false; 121 mFontChanged = false;
122 resize ( 3,3 ); 122 //resize ( 3,3 );
123 123
124} 124}
125void KDateNavigator::changeFont ( QFont fo ) 125void KDateNavigator::changeFont ( QFont fo )
126{ 126{
127 setFont( fo ); 127 setFont( fo );
128 mNavigatorBar->resetFont( fo ); 128 mNavigatorBar->resetFont( fo );
129} 129}
130QFont KDateNavigator::yourFontHint( QSize si , bool *b) 130QFont KDateNavigator::yourFontHint( QSize si , bool *b)
131{ 131{
132 QFont fo = KOPrefs::instance()->mDateNavigatorFont; 132 QFont fo = KOPrefs::instance()->mDateNavigatorFont;
133 *b = false; 133 *b = false;
134 int fontPoint = fo.pointSize(); 134 int fontPoint = fo.pointSize();
135 while ( fontPoint > 5 ) { 135 while ( fontPoint > 5 ) {
136 --fontPoint; 136 --fontPoint;
137 fo.setPointSize( fontPoint ); 137 fo.setPointSize( fontPoint );
138 setFont( fo ); 138 setFont( fo );
139 mFontChanged = true; 139 mFontChanged = true;
140 mNavigatorBar->resetFont( fo ); 140 mNavigatorBar->resetFont( fo );
141 QSize sh = sizeHintTwoButtons( 2 ); 141 QSize sh = sizeHintTwoButtons( 2 );
142 //qDebug("fp %d %d %d %d %d", fontPoint, si.width() , sh.width() , si.height() , sh.height() ); 142 //qDebug("fp %d %d %d %d %d", fontPoint, si.width() , sh.width() , si.height() , sh.height() );
143 if ( si.width() > sh.width() && si.height() > sh.height()) { 143 if ( si.width() > sh.width() && si.height() > sh.height()) {
144 if ( si.width() / sh.width() == 1 ) { 144 if ( si.width() / sh.width() == 1 ) {
145 if ( si.width() < sizeHintTwoButtons( 4 ).width()) 145 if ( si.width() < sizeHintTwoButtons( 4 ).width())
146 continue; 146 continue;
147 } 147 }
148 *b = true; 148 *b = true;
149 //qDebug("fooooooooooooooooooooooouuuuund "); 149 //qDebug("fooooooooooooooooooooooouuuuund ");
150 break; 150 break;
151 } 151 }
152 } 152 }
153 //qDebug("returnnnnnnnnnnnnnnnnnnn %d", fo.pointSize() ); 153 //qDebug("returnnnnnnnnnnnnnnnnnnn %d", fo.pointSize() );
154 return fo; 154 return fo;
155} 155}
156QSize KDateNavigator::sizeHint() const 156QSize KDateNavigator::sizeHint() const
157{ 157{
158 QFontMetrics fm ( font() ); 158 QFontMetrics fm ( font() );
159 QSize day = daymatrix->sizeHint(); 159 QSize day = daymatrix->sizeHint();
160 QSize nav = mNavigatorBar->sizeHint(); 160 QSize nav = mNavigatorBar->sizeHint();
161 int wid = fm.width( "30") + day.width()+3; 161 int wid = fm.width( "30") + day.width()+3;
162 int hei = fm.height() +day.height()+nav.height()+2; 162 int hei = fm.height() +day.height()+nav.height()+2;
163 if ( wid < nav.width() ) 163 if ( wid < nav.width() )
164 wid = nav.width() ; 164 wid = nav.width() ;
165 //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); 165 //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei);
166 return QSize ( wid, hei ); 166 return QSize ( wid, hei );
167} 167}
168QSize KDateNavigator::sizeHintTwoButtons( int butnum ) const 168QSize KDateNavigator::sizeHintTwoButtons( int butnum ) const
169{ 169{
170 QFontMetrics fm ( font() ); 170 QFontMetrics fm ( font() );
171 QSize day = daymatrix->sizeHint(); 171 QSize day = daymatrix->sizeHint();
172 QSize nav = mNavigatorBar->sizeHintTwoButtons( butnum ); 172 QSize nav = mNavigatorBar->sizeHintTwoButtons( butnum );
173 int wid = fm.width( "30") + day.width()+3; 173 int wid = fm.width( "30") + day.width()+3;
174 int hei = fm.height() +day.height()+nav.height()+2; 174 int hei = fm.height() +day.height()+nav.height()+2;
175 if ( wid < nav.width() ) 175 if ( wid < nav.width() )
176 wid = nav.width() ; 176 wid = nav.width() ;
177 //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); 177 //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei);
178 return QSize ( wid, hei ); 178 return QSize ( wid, hei );
179} 179}
180void KDateNavigator::slotMonthSelected( int m ) 180void KDateNavigator::slotMonthSelected( int m )
181{ 181{
182 if ( m_MthYr.month() <= mMonthSignalOffset) 182 if ( m_MthYr.month() <= mMonthSignalOffset)
183 m += 12; 183 m += 12;
184 //qDebug("%d mMonthSignalOffset %d emit %d", m, mMonthSignalOffset, m - mMonthSignalOffset); 184 //qDebug("%d mMonthSignalOffset %d emit %d", m, mMonthSignalOffset, m - mMonthSignalOffset);
185 emit monthSelected( m - mMonthSignalOffset ); 185 emit monthSelected( m - mMonthSignalOffset );
186 186
187} 187}
188void KDateNavigator::setCalendar( Calendar *cal ) 188void KDateNavigator::setCalendar( Calendar *cal )
189{ 189{
190 daymatrix->setCalendar( cal ); 190 daymatrix->setCalendar( cal );
191} 191}
192 192
193void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true 193void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true
194{ 194{
195 m_MthYr = date; 195 m_MthYr = date;
196 //qDebug("KDateNavigator::setBaseDate %s ", date.toString().latin1()); 196 //qDebug("KDateNavigator::setBaseDate %s ", date.toString().latin1());
197 197
198 updateDates(); 198 updateDates();
199 updateView(); 199 updateView();
200 200
201 KCal::DateList dates; 201 KCal::DateList dates;
202 dates.append( date ); 202 dates.append( date );
203 mNavigatorBar->selectDates( dates ); 203 mNavigatorBar->selectDates( dates );
204 204
205 daymatrix->clearSelection(); 205 daymatrix->clearSelection();
206 if ( doRepaint ) 206 if ( doRepaint )
207 daymatrix->repaint( false ); 207 daymatrix->repaint( false );
208} 208}
209 209
210void KDateNavigator::enableRollover(RolloverType r) 210void KDateNavigator::enableRollover(RolloverType r)
211{ 211{
212 switch(r) 212 switch(r)
213 { 213 {
214 case None : 214 case None :
215 if (updateTimer) 215 if (updateTimer)
216 { 216 {
217 updateTimer->stop(); 217 updateTimer->stop();
218 delete updateTimer; 218 delete updateTimer;
219 updateTimer=0L; 219 updateTimer=0L;
220 } 220 }
221 break; 221 break;
222 case FollowDay : 222 case FollowDay :
223 case FollowMonth : 223 case FollowMonth :
224 if (!updateTimer) 224 if (!updateTimer)
225 { 225 {
226 updateTimer = new QTimer(this); 226 updateTimer = new QTimer(this);
227 QObject::connect(updateTimer,SIGNAL(timeout()), 227 QObject::connect(updateTimer,SIGNAL(timeout()),
228 this,SLOT(possiblyPastMidnight())); 228 this,SLOT(possiblyPastMidnight()));
229 } 229 }
230 updateTimer->start(0,true); 230 updateTimer->start(0,true);
231 lastDayChecked = QDate::currentDate(); 231 lastDayChecked = QDate::currentDate();
232 } 232 }
233 updateRollover=r; 233 updateRollover=r;
234} 234}
235 235
236 236
237KDateNavigator::~KDateNavigator() 237KDateNavigator::~KDateNavigator()
238{ 238{
239} 239}
240 240
241 241
242void KDateNavigator::passedMidnight() 242void KDateNavigator::passedMidnight()
243{ 243{
244 QDate today = QDate::currentDate(); 244 QDate today = QDate::currentDate();
245 bool emitMonth = false; 245 bool emitMonth = false;
246 246
247 if (today.month() != lastDayChecked.month()) 247 if (today.month() != lastDayChecked.month())
248 { 248 {
249 if (updateRollover==FollowMonth && 249 if (updateRollover==FollowMonth &&
250 daymatrix->isEndOfMonth()) { 250 daymatrix->isEndOfMonth()) {
251 goNextMonth(); 251 goNextMonth();
252 emitMonth=true; 252 emitMonth=true;
253 } 253 }
254 } 254 }
255 daymatrix->recalculateToday(); 255 daymatrix->recalculateToday();
256 daymatrix->repaint( false ); 256 daymatrix->repaint( false );
257 emit dayPassed(today); 257 emit dayPassed(today);
258 if (emitMonth) { emit monthPassed(today); } 258 if (emitMonth) { emit monthPassed(today); }
259} 259}
260 260
261/* slot */ void KDateNavigator::possiblyPastMidnight() 261/* slot */ void KDateNavigator::possiblyPastMidnight()
262{ 262{
263 if (lastDayChecked!=QDate::currentDate()) 263 if (lastDayChecked!=QDate::currentDate())
264 { 264 {
265 passedMidnight(); 265 passedMidnight();
266 lastDayChecked=QDate::currentDate(); 266 lastDayChecked=QDate::currentDate();
267 } 267 }
268 // Set the timer to go off 1 second after midnight 268 // Set the timer to go off 1 second after midnight
269 // or after 8 minutes, whichever comes first. 269 // or after 8 minutes, whichever comes first.
270 if (updateTimer) 270 if (updateTimer)
271 { 271 {
272 QTime now = QTime::currentTime(); 272 QTime now = QTime::currentTime();
273 QTime midnight = QTime(23,59,59); 273 QTime midnight = QTime(23,59,59);
274 int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000); 274 int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000);
275 275
276 // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait)) 276 // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait))
277 //.arg(now.toString()).arg(midnight.toString())); 277 //.arg(now.toString()).arg(midnight.toString()));
278 278
279 updateTimer->stop(); 279 updateTimer->stop();
280 updateTimer->start(msecsWait,true); 280 updateTimer->start(msecsWait,true);
281 } 281 }
282} 282}
283 283
284void KDateNavigator::updateDates() 284void KDateNavigator::updateDates()
285{ 285{
286 // Find the first day of the week of the current month. 286 // Find the first day of the week of the current month.
287 //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr ); 287 //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr );
288 QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() ); 288 QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() );
289 int d2 = KOGlobals::self()->calendarSystem()->day( dayone ); 289 int d2 = KOGlobals::self()->calendarSystem()->day( dayone );
290 //int di = d1 - d2 + 1; 290 //int di = d1 - d2 + 1;
291 dayone = dayone.addDays( -d2 + 1 ); 291 dayone = dayone.addDays( -d2 + 1 );
292 292
293 int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone ); 293 int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone );
294 294
295 // If month begins on Monday and Monday is first day of week, 295 // If month begins on Monday and Monday is first day of week,
296 // month should begin on second line. Sunday doesn't have this problem. 296 // month should begin on second line. Sunday doesn't have this problem.
297 int nextLine = ( ( m_fstDayOfWkCalsys == 1) && 297 int nextLine = ( ( m_fstDayOfWkCalsys == 1) &&
298 ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0; 298 ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0;
299 299
300 // update the matrix dates 300 // update the matrix dates
301 int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine; 301 int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine;
302 302
303 303
304 daymatrix->updateView(dayone.addDays(index)); 304 daymatrix->updateView(dayone.addDays(index));
305//each updateDates is followed by an updateView -> repaint is issued there ! 305//each updateDates is followed by an updateView -> repaint is issued there !
306// daymatrix->repaint(); 306// daymatrix->repaint();
307} 307}
308 308
309void KDateNavigator::updateDayMatrix() 309void KDateNavigator::updateDayMatrix()
310{ 310{
311 daymatrix->updateView(); 311 daymatrix->updateView();
312 //daymatrix->repaint(); 312 //daymatrix->repaint();
313} 313}
314 314
315 315
316void KDateNavigator::updateView() 316void KDateNavigator::updateView()
317{ 317{
318 318
319 setUpdatesEnabled( false ); 319 setUpdatesEnabled( false );
320 320
321 int i; 321 int i;
322 322
323// kdDebug() << "updateView() -> daymatrix->updateView()" << endl; 323// kdDebug() << "updateView() -> daymatrix->updateView()" << endl;
324 daymatrix->updateView(); 324 daymatrix->updateView();
325 325
326 // set the week numbers. 326 // set the week numbers.
327 for(i = 0; i < 6; i++) { 327 for(i = 0; i < 6; i++) {
328 QString weeknum; 328 QString weeknum;
329 // remember, according to ISO 8601, the first week of the year is the 329 // remember, according to ISO 8601, the first week of the year is the
330 // first week that contains a thursday. Thus we must subtract off 4, 330 // first week that contains a thursday. Thus we must subtract off 4,
331 // not just 1. 331 // not just 1.
332 332
333 //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear(); 333 //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear();
334 int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4))); 334 int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4)));
335 335
336 int add = 0; 336 int add = 0;
337 if ( ! KGlobal::locale()->weekStartsMonday() ) 337 if ( ! KGlobal::locale()->weekStartsMonday() )
338 ++add; 338 ++add;
339 if (dayOfYear % 7 != 0) 339 if (dayOfYear % 7 != 0)
340 weeknum.setNum(dayOfYear / 7 + 1+add); 340 weeknum.setNum(dayOfYear / 7 + 1+add);
341 else 341 else
342 weeknum.setNum(dayOfYear / 7 +add); 342 weeknum.setNum(dayOfYear / 7 +add);
343 weeknos[i]->setText(weeknum); 343 weeknos[i]->setText(weeknum);
344 } 344 }
345 345
346 setUpdatesEnabled( true ); 346 setUpdatesEnabled( true );
347// kdDebug() << "updateView() -> repaint()" << endl; 347// kdDebug() << "updateView() -> repaint()" << endl;
348 repaint(); 348 repaint();
349 // daymatrix->repaint(); 349 // daymatrix->repaint();
350} 350}
351 351
352void KDateNavigator::updateConfig() 352void KDateNavigator::updateConfig()
353{ 353{
354 int day; 354 int day;
355 for(int i=0; i<7; i++) { 355 for(int i=0; i<7; i++) {
356 // take the first letter of the day name to be the abbreviation 356 // take the first letter of the day name to be the abbreviation
357 if (KGlobal::locale()->weekStartsMonday()) { 357 if (KGlobal::locale()->weekStartsMonday()) {
358 day = i+1; 358 day = i+1;
359 } else { 359 } else {
360 if (i==0) day = 7; 360 if (i==0) day = 7;
361 else day = i; 361 else day = i;
362 } 362 }
363 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day, 363 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day,
364 true ); 364 true );
365 if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 ); 365 if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 );
366 headings[i]->setText( dayName ); 366 headings[i]->setText( dayName );
367 } 367 }
368 updateDates(); 368 updateDates();
369 updateView(); 369 updateView();
370} 370}
371 371
372void KDateNavigator::setShowWeekNums(bool enabled) 372void KDateNavigator::setShowWeekNums(bool enabled)
373{ 373{
374 qDebug("KDateNavigator::setShowWeekNums***************************** ");
374 m_bShowWeekNums = enabled; 375 m_bShowWeekNums = enabled;
375 for(int i=0; i<6; i++) { 376 for(int i=0; i<6; i++) {
376 if(enabled) 377 if(enabled)
377 weeknos[i]->show(); 378 weeknos[i]->show();
378 else 379 else
379 weeknos[i]->hide(); 380 weeknos[i]->hide();
380 } 381 }
381 resize(size()); 382 resize(size());
382} 383}
383 384
384void KDateNavigator::selectDates(const DateList& dateList) 385void KDateNavigator::selectDates(const DateList& dateList)
385{ 386{
386 387
387 if (dateList.count() > 0) { 388 if (dateList.count() > 0) {
388 mNavigatorBar->selectDates( dateList ); 389 mNavigatorBar->selectDates( dateList );
389 mSelectedDates = dateList; 390 mSelectedDates = dateList;
390 391
391 // set our record of the month and year that this datetbl is 392 // set our record of the month and year that this datetbl is
392 // displaying. 393 // displaying.
393 m_MthYr = mSelectedDates.first(); 394 m_MthYr = mSelectedDates.first();
394 395
395 396
396 // set our record of the first day of the week of the current 397 // set our record of the first day of the week of the current
397 // month. This needs to be done before calling dayToIndex, since it 398 // month. This needs to be done before calling dayToIndex, since it
398 // relies on this information being up to date. 399 // relies on this information being up to date.
399 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); 400 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1);
400 m_fstDayOfWk = dayone.dayOfWeek(); 401 m_fstDayOfWk = dayone.dayOfWeek();
401 402
402 updateDates(); 403 updateDates();
403 404
404 daymatrix->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 405 daymatrix->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
405 406
406 updateView(); 407 updateView();
407 } 408 }
408} 409}
409 410
410int KDateNavigator::dayNum(int row, int col) 411int KDateNavigator::dayNum(int row, int col)
411{ 412{
412 return 7 * (row - 1) + (col + 1) - m_fstDayOfWk; 413 return 7 * (row - 1) + (col + 1) - m_fstDayOfWk;
413} 414}
414 415
415int KDateNavigator::dayToIndex(int dayNum) 416int KDateNavigator::dayToIndex(int dayNum)
416{ 417{
417 int row, col; 418 int row, col;
418 419
419 row = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) / 7; 420 row = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) / 7;
420 if (KGlobal::locale()->weekStartsMonday() && (m_fstDayOfWk == 1)) 421 if (KGlobal::locale()->weekStartsMonday() && (m_fstDayOfWk == 1))
421 row++; 422 row++;
422 col = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) % 7; 423 col = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) % 7;
423 return row * 7 + col; 424 return row * 7 + col;
424} 425}
425 426
426void KDateNavigator::wheelEvent (QWheelEvent *e) 427void KDateNavigator::wheelEvent (QWheelEvent *e)
427{ 428{
428 if(e->delta()>0) emit goPrevious(); 429 if(e->delta()>0) emit goPrevious();
429 else emit goNext(); 430 else emit goNext();
430 431
431 e->accept(); 432 e->accept();
432} 433}
433 434
434bool KDateNavigator::eventFilter (QObject *o,QEvent *e) 435bool KDateNavigator::eventFilter (QObject *o,QEvent *e)
435{ 436{
436 if (e->type() == QEvent::MouseButtonPress) { 437 if (e->type() == QEvent::MouseButtonPress) {
437 int i; 438 int i;
438 for(i=0;i<6;++i) { 439 for(i=0;i<6;++i) {
439 if (o == weeknos[i]) { 440 if (o == weeknos[i]) {
440 QDate weekstart = daymatrix->getDate(i*7); 441 QDate weekstart = daymatrix->getDate(i*7);
441 emit weekClicked(weekstart); 442 emit weekClicked(weekstart);
442 break; 443 break;
443 } 444 }
444 } 445 }
445 for(i=0;i<7;++i) { 446 for(i=0;i<7;++i) {
446 if (o == headings[i]) { 447 if (o == headings[i]) {
447 KCal::DateList selDays; 448 KCal::DateList selDays;
448 QDate date = daymatrix->getDate(14); 449 QDate date = daymatrix->getDate(14);
449 int dio = date.daysInMonth(); 450 int dio = date.daysInMonth();
450 int j; 451 int j;
451 int ye = date.year(); 452 int ye = date.year();
452 int mo = date.month(); 453 int mo = date.month();
453 for ( j = 1; j <= dio; ++j ) { 454 for ( j = 1; j <= dio; ++j ) {
454 selDays.append( QDate( ye, mo, j ) ); 455 selDays.append( QDate( ye, mo, j ) );
455 } 456 }
456 emit datesSelected( selDays ); 457 emit datesSelected( selDays );
457 break; 458 break;
458 } 459 }
459 } 460 }
460 return true; 461 return true;
461 } else { 462 } else {
462 return false; 463 return false;
463 } 464 }
464} 465}
465 466
466//#include "kdatenavigator.moc" 467//#include "kdatenavigator.moc"