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