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