summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2005-03-21 13:56:46 (UTC)
committer zautrix <zautrix>2005-03-21 13:56:46 (UTC)
commit41f264fea6caaf9ca0f8b34509a07157c210f851 (patch) (unidiff)
treef49b5d10db838821f79d5ae3d28b492f76663b62 /korganizer
parent098a3c6dd844a880beb2851be53314613c3a038d (diff)
downloadkdepimpi-41f264fea6caaf9ca0f8b34509a07157c210f851.zip
kdepimpi-41f264fea6caaf9ca0f8b34509a07157c210f851.tar.gz
kdepimpi-41f264fea6caaf9ca0f8b34509a07157c210f851.tar.bz2
fixes
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kdatenavigator.cpp4
-rw-r--r--korganizer/kdatenavigator.h2
-rw-r--r--korganizer/kodaymatrix.cpp8
3 files changed, 9 insertions, 5 deletions
diff --git a/korganizer/kdatenavigator.cpp b/korganizer/kdatenavigator.cpp
index 4b50b5a..2321acb 100644
--- a/korganizer/kdatenavigator.cpp
+++ b/korganizer/kdatenavigator.cpp
@@ -1,442 +1,442 @@
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 86
87 topLayout->addWidget(headings[i],1,i+1); 87 topLayout->addWidget(headings[i],1,i+1);
88 } 88 }
89 89
90 // Create the weeknumber labels 90 // Create the weeknumber labels
91 for( i = 0; i < 6; i++ ) { 91 for( i = 0; i < 6; i++ ) {
92 weeknos[i] = new QLabel(this); 92 weeknos[i] = new QLabel(this);
93 weeknos[i]->setAlignment(AlignCenter); 93 weeknos[i]->setAlignment(AlignCenter);
94 //weeknos[i]->setFont(QFont("Arial", 10)); 94 //weeknos[i]->setFont(QFont("Arial", 10));
95 if(!m_bShowWeekNums) { 95 if(!m_bShowWeekNums) {
96 weeknos[i]->hide(); 96 weeknos[i]->hide();
97 } 97 }
98 weeknos[i]->installEventFilter(this); 98 weeknos[i]->installEventFilter(this);
99 99
100 topLayout->addWidget(weeknos[i],i+2,0); 100 topLayout->addWidget(weeknos[i],i+2,0);
101 } 101 }
102 102
103 daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix"); 103 daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix");
104 daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken); 104 daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken);
105 daymatrix->setLineWidth(1); 105 daymatrix->setLineWidth(1);
106 106
107 connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ), 107 connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ),
108 SIGNAL( datesSelected( const KCal::DateList & ) ) ); 108 SIGNAL( datesSelected( const KCal::DateList & ) ) );
109 109
110 connect( daymatrix, SIGNAL( eventDropped( Event * ) ), 110 connect( daymatrix, SIGNAL( eventDropped( Event * ) ),
111 SIGNAL( eventDropped( Event * ) ) ); 111 SIGNAL( eventDropped( Event * ) ) );
112 112
113 topLayout->addMultiCellWidget(daymatrix,2,7,1,7); 113 topLayout->addMultiCellWidget(daymatrix,2,7,1,7);
114 114
115 // read settings from configuration file. 115 // read settings from configuration file.
116 updateConfig(); 116 updateConfig();
117 enableRollover(FollowMonth); 117 enableRollover(FollowMonth);
118 mySizeHint = sizeHintTwoButtons(); 118 mySizeHint = sizeHintTwoButtons();
119 mFontChanged = false; 119 mFontChanged = false;
120} 120}
121void KDateNavigator::changeFont ( QFont fo ) 121void KDateNavigator::changeFont ( QFont fo )
122{ 122{
123 setFont( fo ); 123 setFont( fo );
124 mNavigatorBar->resetFont( fo ); 124 mNavigatorBar->resetFont( fo );
125} 125}
126QFont KDateNavigator::yourFontHint( QSize si , bool *b) 126QFont KDateNavigator::yourFontHint( QSize si , bool *b)
127{ 127{
128 QFont fo = KOPrefs::instance()->mDateNavigatorFont; 128 QFont fo = KOPrefs::instance()->mDateNavigatorFont;
129 *b = false; 129 *b = false;
130 int fontPoint = fo.pointSize(); 130 int fontPoint = fo.pointSize();
131 while ( fontPoint > 5 ) { 131 while ( fontPoint > 5 ) {
132 --fontPoint; 132 --fontPoint;
133 fo.setPointSize( fontPoint ); 133 fo.setPointSize( fontPoint );
134 setFont( fo ); 134 setFont( fo );
135 mFontChanged = true; 135 mFontChanged = true;
136 mNavigatorBar->resetFont( fo ); 136 mNavigatorBar->resetFont( fo );
137 QSize sh = sizeHintTwoButtons(); 137 QSize sh = sizeHintTwoButtons();
138 //qDebug("fp %d %d %d %d %d", fontPoint, si.width() , sh.width() , si.height() , sh.height() ); 138 //qDebug("fp %d %d %d %d %d", fontPoint, si.width() , sh.width() , si.height() , sh.height() );
139 if ( si.width() > sh.width() && si.height() > sh.height()) { 139 if ( si.width() > sh.width() && si.height() > sh.height()) {
140 *b = true; 140 *b = true;
141 //qDebug("fooooooooooooooooooooooouuuuund "); 141 //qDebug("fooooooooooooooooooooooouuuuund ");
142 break; 142 break;
143 } 143 }
144 } 144 }
145 //qDebug("returnnnnnnnnnnnnnnnnnnn %d", fo.pointSize() ); 145 //qDebug("returnnnnnnnnnnnnnnnnnnn %d", fo.pointSize() );
146 return fo; 146 return fo;
147} 147}
148QSize KDateNavigator::sizeHint() const 148QSize KDateNavigator::sizeHint() const
149{ 149{
150 QFontMetrics fm ( font() ); 150 QFontMetrics fm ( font() );
151 QSize day = daymatrix->sizeHint(); 151 QSize day = daymatrix->sizeHint();
152 QSize nav = mNavigatorBar->sizeHint(); 152 QSize nav = mNavigatorBar->sizeHint();
153 int wid = fm.width( "30") + day.width()+3; 153 int wid = fm.width( "30") + day.width()+3;
154 int hei = fm.height() +day.height()+nav.height()+2; 154 int hei = fm.height() +day.height()+nav.height()+2;
155 if ( wid < nav.width() ) 155 if ( wid < nav.width() )
156 wid = nav.width() ; 156 wid = nav.width() ;
157 //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); 157 //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei);
158 return QSize ( wid, hei ); 158 return QSize ( wid, hei );
159} 159}
160QSize KDateNavigator::sizeHintTwoButtons() const 160QSize KDateNavigator::sizeHintTwoButtons() const
161{ 161{
162 QFontMetrics fm ( font() ); 162 QFontMetrics fm ( font() );
163 QSize day = daymatrix->sizeHint(); 163 QSize day = daymatrix->sizeHint();
164 QSize nav = mNavigatorBar->sizeHintTwoButtons(); 164 QSize nav = mNavigatorBar->sizeHintTwoButtons();
165 int wid = fm.width( "30") + day.width()+3; 165 int wid = fm.width( "30") + day.width()+3;
166 int hei = fm.height() +day.height()+nav.height()+2; 166 int hei = fm.height() +day.height()+nav.height()+2;
167 if ( wid < nav.width() ) 167 if ( wid < nav.width() )
168 wid = nav.width() ; 168 wid = nav.width() ;
169 //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); 169 //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei);
170 return QSize ( wid, hei ); 170 return QSize ( wid, hei );
171} 171}
172void KDateNavigator::slotMonthSelected( int m ) 172void KDateNavigator::slotMonthSelected( int m )
173{ 173{
174 if ( m_MthYr.month() <= mMonthSignalOffset) 174 if ( m_MthYr.month() <= mMonthSignalOffset)
175 m += 12; 175 m += 12;
176 int mo = m - mMonthSignalOffset; 176 //qDebug("%d mMonthSignalOffset %d emit %d", m, mMonthSignalOffset, m - mMonthSignalOffset);
177 emit monthSelected( m - mMonthSignalOffset ); 177 emit monthSelected( m - mMonthSignalOffset );
178 178
179} 179}
180void KDateNavigator::setCalendar( Calendar *cal ) 180void KDateNavigator::setCalendar( Calendar *cal )
181{ 181{
182 daymatrix->setCalendar( cal ); 182 daymatrix->setCalendar( cal );
183} 183}
184 184
185void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true 185void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true
186{ 186{
187 m_MthYr = date; 187 m_MthYr = date;
188 188
189 updateDates(); 189 updateDates();
190 updateView(); 190 updateView();
191 191
192 KCal::DateList dates; 192 KCal::DateList dates;
193 dates.append( date ); 193 dates.append( date );
194 mNavigatorBar->selectDates( dates ); 194 mNavigatorBar->selectDates( dates );
195 195
196 daymatrix->clearSelection(); 196 daymatrix->clearSelection();
197 if ( doRepaint ) 197 if ( doRepaint )
198 daymatrix->repaint(); 198 daymatrix->repaint();
199} 199}
200 200
201void KDateNavigator::enableRollover(RolloverType r) 201void KDateNavigator::enableRollover(RolloverType r)
202{ 202{
203 switch(r) 203 switch(r)
204 { 204 {
205 case None : 205 case None :
206 if (updateTimer) 206 if (updateTimer)
207 { 207 {
208 updateTimer->stop(); 208 updateTimer->stop();
209 delete updateTimer; 209 delete updateTimer;
210 updateTimer=0L; 210 updateTimer=0L;
211 } 211 }
212 break; 212 break;
213 case FollowDay : 213 case FollowDay :
214 case FollowMonth : 214 case FollowMonth :
215 if (!updateTimer) 215 if (!updateTimer)
216 { 216 {
217 updateTimer = new QTimer(this); 217 updateTimer = new QTimer(this);
218 QObject::connect(updateTimer,SIGNAL(timeout()), 218 QObject::connect(updateTimer,SIGNAL(timeout()),
219 this,SLOT(possiblyPastMidnight())); 219 this,SLOT(possiblyPastMidnight()));
220 } 220 }
221 updateTimer->start(0,true); 221 updateTimer->start(0,true);
222 lastDayChecked = QDate::currentDate(); 222 lastDayChecked = QDate::currentDate();
223 } 223 }
224 updateRollover=r; 224 updateRollover=r;
225} 225}
226 226
227 227
228KDateNavigator::~KDateNavigator() 228KDateNavigator::~KDateNavigator()
229{ 229{
230} 230}
231 231
232 232
233void KDateNavigator::passedMidnight() 233void KDateNavigator::passedMidnight()
234{ 234{
235 QDate today = QDate::currentDate(); 235 QDate today = QDate::currentDate();
236 bool emitMonth = false; 236 bool emitMonth = false;
237 237
238 if (today.month() != lastDayChecked.month()) 238 if (today.month() != lastDayChecked.month())
239 { 239 {
240 if (updateRollover==FollowMonth && 240 if (updateRollover==FollowMonth &&
241 daymatrix->isEndOfMonth()) { 241 daymatrix->isEndOfMonth()) {
242 goNextMonth(); 242 goNextMonth();
243 emitMonth=true; 243 emitMonth=true;
244 } 244 }
245 } 245 }
246 daymatrix->recalculateToday(); 246 daymatrix->recalculateToday();
247 daymatrix->repaint(); 247 daymatrix->repaint();
248 emit dayPassed(today); 248 emit dayPassed(today);
249 if (emitMonth) { emit monthPassed(today); } 249 if (emitMonth) { emit monthPassed(today); }
250} 250}
251 251
252/* slot */ void KDateNavigator::possiblyPastMidnight() 252/* slot */ void KDateNavigator::possiblyPastMidnight()
253{ 253{
254 if (lastDayChecked!=QDate::currentDate()) 254 if (lastDayChecked!=QDate::currentDate())
255 { 255 {
256 passedMidnight(); 256 passedMidnight();
257 lastDayChecked=QDate::currentDate(); 257 lastDayChecked=QDate::currentDate();
258 } 258 }
259 // Set the timer to go off 1 second after midnight 259 // Set the timer to go off 1 second after midnight
260 // or after 8 minutes, whichever comes first. 260 // or after 8 minutes, whichever comes first.
261 if (updateTimer) 261 if (updateTimer)
262 { 262 {
263 QTime now = QTime::currentTime(); 263 QTime now = QTime::currentTime();
264 QTime midnight = QTime(23,59,59); 264 QTime midnight = QTime(23,59,59);
265 int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000); 265 int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000);
266 266
267 // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait)) 267 // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait))
268 //.arg(now.toString()).arg(midnight.toString())); 268 //.arg(now.toString()).arg(midnight.toString()));
269 269
270 updateTimer->stop(); 270 updateTimer->stop();
271 updateTimer->start(msecsWait,true); 271 updateTimer->start(msecsWait,true);
272 } 272 }
273} 273}
274 274
275void KDateNavigator::updateDates() 275void KDateNavigator::updateDates()
276{ 276{
277 // Find the first day of the week of the current month. 277 // Find the first day of the week of the current month.
278 //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr ); 278 //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr );
279 QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() ); 279 QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() );
280 int d2 = KOGlobals::self()->calendarSystem()->day( dayone ); 280 int d2 = KOGlobals::self()->calendarSystem()->day( dayone );
281 //int di = d1 - d2 + 1; 281 //int di = d1 - d2 + 1;
282 dayone = dayone.addDays( -d2 + 1 ); 282 dayone = dayone.addDays( -d2 + 1 );
283 283
284 int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone ); 284 int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone );
285 285
286 // If month begins on Monday and Monday is first day of week, 286 // If month begins on Monday and Monday is first day of week,
287 // month should begin on second line. Sunday doesn't have this problem. 287 // month should begin on second line. Sunday doesn't have this problem.
288 int nextLine = ( ( m_fstDayOfWkCalsys == 1) && 288 int nextLine = ( ( m_fstDayOfWkCalsys == 1) &&
289 ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0; 289 ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0;
290 290
291 // update the matrix dates 291 // update the matrix dates
292 int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine; 292 int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine;
293 293
294 294
295 daymatrix->updateView(dayone.addDays(index)); 295 daymatrix->updateView(dayone.addDays(index));
296//each updateDates is followed by an updateView -> repaint is issued there ! 296//each updateDates is followed by an updateView -> repaint is issued there !
297// daymatrix->repaint(); 297// daymatrix->repaint();
298} 298}
299 299
300void KDateNavigator::updateDayMatrix() 300void KDateNavigator::updateDayMatrix()
301{ 301{
302 daymatrix->updateView(); 302 daymatrix->updateView();
303 //daymatrix->repaint(); 303 //daymatrix->repaint();
304} 304}
305 305
306 306
307void KDateNavigator::updateView() 307void KDateNavigator::updateView()
308{ 308{
309 309
310 setUpdatesEnabled( false ); 310 setUpdatesEnabled( false );
311 311
312 int i; 312 int i;
313 313
314// kdDebug() << "updateView() -> daymatrix->updateView()" << endl; 314// kdDebug() << "updateView() -> daymatrix->updateView()" << endl;
315 daymatrix->updateView(); 315 daymatrix->updateView();
316 316
317 // set the week numbers. 317 // set the week numbers.
318 for(i = 0; i < 6; i++) { 318 for(i = 0; i < 6; i++) {
319 QString weeknum; 319 QString weeknum;
320 // remember, according to ISO 8601, the first week of the year is the 320 // remember, according to ISO 8601, the first week of the year is the
321 // first week that contains a thursday. Thus we must subtract off 4, 321 // first week that contains a thursday. Thus we must subtract off 4,
322 // not just 1. 322 // not just 1.
323 323
324 //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear(); 324 //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear();
325 int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4))); 325 int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4)));
326 326
327 int add = 0; 327 int add = 0;
328 if ( ! KGlobal::locale()->weekStartsMonday() ) 328 if ( ! KGlobal::locale()->weekStartsMonday() )
329 ++add; 329 ++add;
330 if (dayOfYear % 7 != 0) 330 if (dayOfYear % 7 != 0)
331 weeknum.setNum(dayOfYear / 7 + 1+add); 331 weeknum.setNum(dayOfYear / 7 + 1+add);
332 else 332 else
333 weeknum.setNum(dayOfYear / 7 +add); 333 weeknum.setNum(dayOfYear / 7 +add);
334 weeknos[i]->setText(weeknum); 334 weeknos[i]->setText(weeknum);
335 } 335 }
336 336
337 setUpdatesEnabled( true ); 337 setUpdatesEnabled( true );
338// kdDebug() << "updateView() -> repaint()" << endl; 338// kdDebug() << "updateView() -> repaint()" << endl;
339 repaint(); 339 repaint();
340 // daymatrix->repaint(); 340 // daymatrix->repaint();
341} 341}
342 342
343void KDateNavigator::updateConfig() 343void KDateNavigator::updateConfig()
344{ 344{
345 int day; 345 int day;
346 for(int i=0; i<7; i++) { 346 for(int i=0; i<7; i++) {
347 // take the first letter of the day name to be the abbreviation 347 // take the first letter of the day name to be the abbreviation
348 if (KGlobal::locale()->weekStartsMonday()) { 348 if (KGlobal::locale()->weekStartsMonday()) {
349 day = i+1; 349 day = i+1;
350 } else { 350 } else {
351 if (i==0) day = 7; 351 if (i==0) day = 7;
352 else day = i; 352 else day = i;
353 } 353 }
354 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day, 354 QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day,
355 true ); 355 true );
356 if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 ); 356 if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 );
357 headings[i]->setText( dayName ); 357 headings[i]->setText( dayName );
358 } 358 }
359 updateDates(); 359 updateDates();
360 updateView(); 360 updateView();
361} 361}
362 362
363void KDateNavigator::setShowWeekNums(bool enabled) 363void KDateNavigator::setShowWeekNums(bool enabled)
364{ 364{
365 m_bShowWeekNums = enabled; 365 m_bShowWeekNums = enabled;
366 for(int i=0; i<6; i++) { 366 for(int i=0; i<6; i++) {
367 if(enabled) 367 if(enabled)
368 weeknos[i]->show(); 368 weeknos[i]->show();
369 else 369 else
370 weeknos[i]->hide(); 370 weeknos[i]->hide();
371 } 371 }
372 resize(size()); 372 resize(size());
373} 373}
374 374
375void KDateNavigator::selectDates(const DateList& dateList) 375void KDateNavigator::selectDates(const DateList& dateList)
376{ 376{
377 377
378 if (dateList.count() > 0) { 378 if (dateList.count() > 0) {
379 mNavigatorBar->selectDates( dateList ); 379 mNavigatorBar->selectDates( dateList );
380 mSelectedDates = dateList; 380 mSelectedDates = dateList;
381 381
382 // set our record of the month and year that this datetbl is 382 // set our record of the month and year that this datetbl is
383 // displaying. 383 // displaying.
384 m_MthYr = mSelectedDates.first(); 384 m_MthYr = mSelectedDates.first();
385 385
386 386
387 // set our record of the first day of the week of the current 387 // set our record of the first day of the week of the current
388 // month. This needs to be done before calling dayToIndex, since it 388 // month. This needs to be done before calling dayToIndex, since it
389 // relies on this information being up to date. 389 // relies on this information being up to date.
390 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); 390 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1);
391 m_fstDayOfWk = dayone.dayOfWeek(); 391 m_fstDayOfWk = dayone.dayOfWeek();
392 392
393 updateDates(); 393 updateDates();
394 394
395 daymatrix->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 395 daymatrix->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
396 396
397 updateView(); 397 updateView();
398 } 398 }
399} 399}
400 400
401int KDateNavigator::dayNum(int row, int col) 401int KDateNavigator::dayNum(int row, int col)
402{ 402{
403 return 7 * (row - 1) + (col + 1) - m_fstDayOfWk; 403 return 7 * (row - 1) + (col + 1) - m_fstDayOfWk;
404} 404}
405 405
406int KDateNavigator::dayToIndex(int dayNum) 406int KDateNavigator::dayToIndex(int dayNum)
407{ 407{
408 int row, col; 408 int row, col;
409 409
410 row = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) / 7; 410 row = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) / 7;
411 if (KGlobal::locale()->weekStartsMonday() && (m_fstDayOfWk == 1)) 411 if (KGlobal::locale()->weekStartsMonday() && (m_fstDayOfWk == 1))
412 row++; 412 row++;
413 col = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) % 7; 413 col = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) % 7;
414 return row * 7 + col; 414 return row * 7 + col;
415} 415}
416 416
417void KDateNavigator::wheelEvent (QWheelEvent *e) 417void KDateNavigator::wheelEvent (QWheelEvent *e)
418{ 418{
419 if(e->delta()>0) emit goPrevious(); 419 if(e->delta()>0) emit goPrevious();
420 else emit goNext(); 420 else emit goNext();
421 421
422 e->accept(); 422 e->accept();
423} 423}
424 424
425bool KDateNavigator::eventFilter (QObject *o,QEvent *e) 425bool KDateNavigator::eventFilter (QObject *o,QEvent *e)
426{ 426{
427 if (e->type() == QEvent::MouseButtonPress) { 427 if (e->type() == QEvent::MouseButtonPress) {
428 int i; 428 int i;
429 for(i=0;i<6;++i) { 429 for(i=0;i<6;++i) {
430 if (o == weeknos[i]) { 430 if (o == weeknos[i]) {
431 QDate weekstart = daymatrix->getDate(i*7); 431 QDate weekstart = daymatrix->getDate(i*7);
432 emit weekClicked(weekstart); 432 emit weekClicked(weekstart);
433 break; 433 break;
434 } 434 }
435 } 435 }
436 return true; 436 return true;
437 } else { 437 } else {
438 return false; 438 return false;
439 } 439 }
440} 440}
441 441
442//#include "kdatenavigator.moc" 442//#include "kdatenavigator.moc"
diff --git a/korganizer/kdatenavigator.h b/korganizer/kdatenavigator.h
index d1f32b6..77b9b7c 100644
--- a/korganizer/kdatenavigator.h
+++ b/korganizer/kdatenavigator.h
@@ -1,161 +1,161 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 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#ifndef KDATENAVIGATOR_H 23#ifndef KDATENAVIGATOR_H
24#define KDATENAVIGATOR_H 24#define KDATENAVIGATOR_H
25 25
26#include <qframe.h> 26#include <qframe.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qlabel.h> 28#include <qlabel.h>
29 29
30#include <libkcal/calendar.h> 30#include <libkcal/calendar.h>
31 31
32#include "kodaymatrix.h" 32#include "kodaymatrix.h"
33 33
34class QPushButton; 34class QPushButton;
35class QTimer; 35class QTimer;
36 36
37class KCalendarSystem; 37class KCalendarSystem;
38 38
39class NavigatorBar; 39class NavigatorBar;
40 40
41class KDateNavigator: public QFrame 41class KDateNavigator: public QFrame
42{ 42{
43 Q_OBJECT 43 Q_OBJECT
44 public: 44 public:
45 KDateNavigator( QWidget *parent = 0,const char *name = 0 ); 45 KDateNavigator( QWidget *parent = 0,const char *name = 0 );
46 ~KDateNavigator(); 46 ~KDateNavigator();
47 47
48 /** The DateNavigator automatically checks for 48 /** The DateNavigator automatically checks for
49 * the passage of midnight. If rollover type is 49 * the passage of midnight. If rollover type is
50 * set to None, no signals are emitted and no 50 * set to None, no signals are emitted and no
51 * processing is done. With rollover set to 51 * processing is done. With rollover set to
52 * FollowDay, the day highlighter changes at 52 * FollowDay, the day highlighter changes at
53 * midnight and dayPassed() is emitted. 53 * midnight and dayPassed() is emitted.
54 * With FollowMonth, it has the same effect 54 * With FollowMonth, it has the same effect
55 * as FollowDay but also adjusts the month that is 55 * as FollowDay but also adjusts the month that is
56 * visible and emits monthPassed() when the month changes. 56 * visible and emits monthPassed() when the month changes.
57 */ 57 */
58 enum RolloverType { None, FollowDay, FollowMonth } ; 58 enum RolloverType { None, FollowDay, FollowMonth } ;
59 void enableRollover( RolloverType ); 59 void enableRollover( RolloverType );
60 60
61 void setShowWeekNums( bool enabled ); 61 void setShowWeekNums( bool enabled );
62 void setCalendar( Calendar * ); 62 void setCalendar( Calendar * );
63 void setBaseDate( const QDate & , bool doRepaint = true ); 63 void setBaseDate( const QDate & , bool doRepaint = true );
64 KCal::DateList selectedDates() const { return mSelectedDates; } 64 KCal::DateList selectedDates() const { return mSelectedDates; }
65 NavigatorBar *navigatorBar() const { return mNavigatorBar; } 65 NavigatorBar *navigatorBar() const { return mNavigatorBar; }
66 void setMonthSignalOffset ( int off ) { mMonthSignalOffset = off;} 66 void setMonthSignalOffset ( int off ) { mMonthSignalOffset = off%12;}
67 QSize yourSizeHint() { return mySizeHint; } 67 QSize yourSizeHint() { return mySizeHint; }
68 QFont yourFontHint( QSize , bool * b); 68 QFont yourFontHint( QSize , bool * b);
69 bool fontChanged() {return mFontChanged; } 69 bool fontChanged() {return mFontChanged; }
70 void unsetFontChanged() { mFontChanged = false; } 70 void unsetFontChanged() { mFontChanged = false; }
71 KODayMatrix *dayMatrix() { return daymatrix ;} 71 KODayMatrix *dayMatrix() { return daymatrix ;}
72 QSize sizeHint() const; 72 QSize sizeHint() const;
73 QSize sizeHintTwoButtons() const; 73 QSize sizeHintTwoButtons() const;
74 void changeFont ( QFont fo ); 74 void changeFont ( QFont fo );
75 public slots: 75 public slots:
76 void selectDates( const KCal::DateList & ); 76 void selectDates( const KCal::DateList & );
77 void updateView(); 77 void updateView();
78 void updateConfig(); 78 void updateConfig();
79 void updateDayMatrix(); 79 void updateDayMatrix();
80 80
81 signals: 81 signals:
82 void datesSelected( const KCal::DateList & ); 82 void datesSelected( const KCal::DateList & );
83 void eventDropped( Event * ); 83 void eventDropped( Event * );
84 void weekClicked( const QDate &); 84 void weekClicked( const QDate &);
85 85
86 void goPrevious(); 86 void goPrevious();
87 void goNext(); 87 void goNext();
88 88
89 void goNextMonth(); 89 void goNextMonth();
90 void goPrevMonth(); 90 void goPrevMonth();
91 void goNextYear(); 91 void goNextYear();
92 void goPrevYear(); 92 void goPrevYear();
93 void monthSelected( int ); 93 void monthSelected( int );
94 94
95 // Signals emitted at midnight carrying the new date. 95 // Signals emitted at midnight carrying the new date.
96 void dayPassed( QDate ); 96 void dayPassed( QDate );
97 void monthPassed( QDate ); 97 void monthPassed( QDate );
98 98
99 protected slots: 99 protected slots:
100 100
101 /** 101 /**
102 * Called regularly to see if we need to update the view 102 * Called regularly to see if we need to update the view
103 * wrt. the today box and the month box. Only important 103 * wrt. the today box and the month box. Only important
104 * if you leave KOrganizer idle for long periods of time. 104 * if you leave KOrganizer idle for long periods of time.
105 * 105 *
106 * Until we have a reliable way of setting QTimers to go 106 * Until we have a reliable way of setting QTimers to go
107 * off at a particular wall-clock time, we need this, 107 * off at a particular wall-clock time, we need this,
108 * which calls passedMidnight() at the right moments. 108 * which calls passedMidnight() at the right moments.
109 */ 109 */
110 void possiblyPastMidnight(); 110 void possiblyPastMidnight();
111 111
112 /** handles updating the view when midnight has come by due to idle time. 112 /** handles updating the view when midnight has come by due to idle time.
113 * 113 *
114 */ 114 */
115 void passedMidnight(); 115 void passedMidnight();
116 void slotMonthSelected( int m ); 116 void slotMonthSelected( int m );
117 protected: 117 protected:
118 void updateDates(); 118 void updateDates();
119 119
120 void wheelEvent (QWheelEvent *); 120 void wheelEvent (QWheelEvent *);
121 121
122 bool eventFilter (QObject *,QEvent *); 122 bool eventFilter (QObject *,QEvent *);
123 123
124 private: 124 private:
125 QSize mySizeHint; 125 QSize mySizeHint;
126 bool mFontChanged; 126 bool mFontChanged;
127 int mMonthSignalOffset; 127 int mMonthSignalOffset;
128 NavigatorBar *mNavigatorBar; 128 NavigatorBar *mNavigatorBar;
129 129
130 QFrame *headingSep; 130 QFrame *headingSep;
131 QFrame *weeknumSep; 131 QFrame *weeknumSep;
132 QLabel *headings[7]; 132 QLabel *headings[7];
133 QLabel *weeknos[7]; 133 QLabel *weeknos[7];
134 KODayMatrix *daymatrix; 134 KODayMatrix *daymatrix;
135 135
136 KCal::DateList mSelectedDates; 136 KCal::DateList mSelectedDates;
137 QDate m_MthYr; 137 QDate m_MthYr;
138 int m_fstDayOfWk; 138 int m_fstDayOfWk;
139 bool m_bShowWeekNums; 139 bool m_bShowWeekNums;
140 140
141 int dayNum(int row, int col); 141 int dayNum(int row, int col);
142 int dayToIndex(int dayNum); 142 int dayToIndex(int dayNum);
143 143
144 Calendar *mCalendar; 144 Calendar *mCalendar;
145 KCalendarSystem *mCalendarSystem; 145 KCalendarSystem *mCalendarSystem;
146 146
147 const QString *curHeaders; 147 const QString *curHeaders;
148 148
149 /** used to update the day view periodically, in particular every 149 /** used to update the day view periodically, in particular every
150 * midnight to move the "today" rectangle. 150 * midnight to move the "today" rectangle.
151 */ 151 */
152 QTimer *updateTimer; 152 QTimer *updateTimer;
153 QDate lastDayChecked; 153 QDate lastDayChecked;
154 RolloverType updateRollover; 154 RolloverType updateRollover;
155 155
156 // Disabling copy constructor and assignment operator 156 // Disabling copy constructor and assignment operator
157 KDateNavigator(const KDateNavigator & ); 157 KDateNavigator(const KDateNavigator & );
158 KDateNavigator &operator=(const KDateNavigator &); 158 KDateNavigator &operator=(const KDateNavigator &);
159}; 159};
160 160
161#endif 161#endif
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 9baff20..493382d 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -30,890 +30,894 @@
30 30
31#include <kglobal.h> 31#include <kglobal.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35#include <libkcal/vcaldrag.h> 35#include <libkcal/vcaldrag.h>
36#include <libkcal/icaldrag.h> 36#include <libkcal/icaldrag.h>
37#include <libkcal/dndfactory.h> 37#include <libkcal/dndfactory.h>
38#include <libkcal/calendarresources.h> 38#include <libkcal/calendarresources.h>
39#include <libkcal/resourcecalendar.h> 39#include <libkcal/resourcecalendar.h>
40#include <kresources/resourceselectdialog.h> 40#include <kresources/resourceselectdialog.h>
41 41
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#ifndef KORG_NOPLUGINS 44#ifndef KORG_NOPLUGINS
45#include "kocore.h" 45#include "kocore.h"
46#endif 46#endif
47#include "koprefs.h" 47#include "koprefs.h"
48#include "koglobals.h" 48#include "koglobals.h"
49 49
50#include "kodaymatrix.h" 50#include "kodaymatrix.h"
51 51
52// ============================================================================ 52// ============================================================================
53// D Y N A M I C T I P 53// D Y N A M I C T I P
54// ============================================================================ 54// ============================================================================
55 55
56DynamicTip::DynamicTip( QWidget * parent ) 56DynamicTip::DynamicTip( QWidget * parent )
57 : QToolTip( parent ) 57 : QToolTip( parent )
58{ 58{
59 matrix = (KODayMatrix*)parent; 59 matrix = (KODayMatrix*)parent;
60} 60}
61 61
62class KODaymatrixWhatsThis :public QWhatsThis 62class KODaymatrixWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; 65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;};
66 ~KODaymatrixWhatsThis() { ; }; 66 ~KODaymatrixWhatsThis() { ; };
67 67
68protected: 68protected:
69 virtual QString text( const QPoint& p ) 69 virtual QString text( const QPoint& p )
70 { 70 {
71 return _view->getWhatsThisText( p ) ; 71 return _view->getWhatsThisText( p ) ;
72 } 72 }
73private: 73private:
74 KODayMatrix * _view; 74 KODayMatrix * _view;
75}; 75};
76 76
77void DynamicTip::maybeTip( const QPoint &pos ) 77void DynamicTip::maybeTip( const QPoint &pos )
78{ 78{
79 //calculate which cell of the matrix the mouse is in 79 //calculate which cell of the matrix the mouse is in
80 QRect sz = matrix->frameRect(); 80 QRect sz = matrix->frameRect();
81 int dheight = sz.height()*7 / 42; 81 int dheight = sz.height()*7 / 42;
82 int dwidth = sz.width() / 7; 82 int dwidth = sz.width() / 7;
83 int row = pos.y()/dheight; 83 int row = pos.y()/dheight;
84 int col = pos.x()/dwidth; 84 int col = pos.x()/dwidth;
85 85
86 QRect rct(col*dwidth, row*dheight, dwidth, dheight); 86 QRect rct(col*dwidth, row*dheight, dwidth, dheight);
87 87
88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" << 88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
89// col << "][" << row << "] => " <<(col+row*7) << endl; 89// col << "][" << row << "] => " <<(col+row*7) << endl;
90 90
91 //show holiday names only 91 //show holiday names only
92 QString str = matrix->getHolidayLabel(col+row*7); 92 QString str = matrix->getHolidayLabel(col+row*7);
93 if (str.isEmpty()) return; 93 if (str.isEmpty()) return;
94 tip(rct, str); 94 tip(rct, str);
95} 95}
96 96
97 97
98// ============================================================================ 98// ============================================================================
99// K O D A Y M A T R I X 99// K O D A Y M A T R I X
100// ============================================================================ 100// ============================================================================
101 101
102const int KODayMatrix::NOSELECTION = -1000; 102const int KODayMatrix::NOSELECTION = -1000;
103const int KODayMatrix::NUMDAYS = 42; 103const int KODayMatrix::NUMDAYS = 42;
104 104
105KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) 105KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
106 : QFrame( parent, name ), mCalendar( 0 ) 106 : QFrame( parent, name ), mCalendar( 0 )
107 107
108#if 0 108#if 0
109KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : 109KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) :
110 QFrame(parent, name) 110 QFrame(parent, name)
111#endif 111#endif
112{ 112{
113 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); 113 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this);
114 mPendingUpdateBeforeRepaint = false; 114 mPendingUpdateBeforeRepaint = false;
115 mouseDown = false; 115 mouseDown = false;
116 // initialize dynamic arrays 116 // initialize dynamic arrays
117 bDays.resize ( NUMDAYS ); 117 bDays.resize ( NUMDAYS );
118 days = new QDate[NUMDAYS]; 118 days = new QDate[NUMDAYS];
119 daylbls = new QString[NUMDAYS]; 119 daylbls = new QString[NUMDAYS];
120 events = new int[NUMDAYS]; 120 events = new int[NUMDAYS];
121 mToolTip = new DynamicTip(this); 121 mToolTip = new DynamicTip(this);
122 122
123 // set default values used for drawing the matrix 123 // set default values used for drawing the matrix
124 mDefaultBackColor = palette().active().base(); 124 mDefaultBackColor = palette().active().base();
125 mDefaultTextColor = palette().active().foreground(); 125 mDefaultTextColor = palette().active().foreground();
126 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 126 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
127 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); 127 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
128 mSelectedDaysColor = QColor("white"); 128 mSelectedDaysColor = QColor("white");
129 mTodayMarginWidth = 2; 129 mTodayMarginWidth = 2;
130 mSelEnd = mSelStart = NOSELECTION; 130 mSelEnd = mSelStart = NOSELECTION;
131 131
132 setAcceptDrops(true); 132 setAcceptDrops(true);
133 //setFont( QFont("Arial", 10) ); 133 //setFont( QFont("Arial", 10) );
134 134
135 mUpdateTimer = new QTimer( this ); 135 mUpdateTimer = new QTimer( this );
136 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); 136 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
137 mRepaintTimer = new QTimer( this ); 137 mRepaintTimer = new QTimer( this );
138 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); 138 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
139 mDayChanged = false; 139 mDayChanged = false;
140 updateView(); 140 updateView();
141} 141}
142QString KODayMatrix::getWhatsThisText( QPoint p ) 142QString KODayMatrix::getWhatsThisText( QPoint p )
143{ 143{
144 144
145 int tmp = getDayIndexFrom(p.x(), p.y()); 145 int tmp = getDayIndexFrom(p.x(), p.y());
146 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) 146 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar )
147 return QString(); 147 return QString();
148 QDate mDate = days[tmp]; 148 QDate mDate = days[tmp];
149 QPtrList<Event> eventlist = mCalendar->events(mDate); 149 QPtrList<Event> eventlist = mCalendar->events(mDate);
150 Event *event; 150 Event *event;
151 QStringList mToolTip; 151 QStringList mToolTip;
152 for(event=eventlist.first();event != 0;event=eventlist.next()) { 152 for(event=eventlist.first();event != 0;event=eventlist.next()) {
153 QString mToolTipText; 153 QString mToolTipText;
154 QString text; 154 QString text;
155 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 155 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
156 if (event->isMultiDay()) { 156 if (event->isMultiDay()) {
157 QString prefix = "<->";multiday = 2; 157 QString prefix = "<->";multiday = 2;
158 QString time; 158 QString time;
159 if ( event->doesRecur() ) { 159 if ( event->doesRecur() ) {
160 if ( event->recursOn( mDate) ) { 160 if ( event->recursOn( mDate) ) {
161 prefix ="->" ;multiday = 1; 161 prefix ="->" ;multiday = 1;
162 } 162 }
163 else { 163 else {
164 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 164 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
165 if ( event->recursOn( mDate.addDays( -days)) ) { 165 if ( event->recursOn( mDate.addDays( -days)) ) {
166 prefix ="<-" ;multiday = 3; 166 prefix ="<-" ;multiday = 3;
167 } 167 }
168 } 168 }
169 } else { 169 } else {
170 if (mDate == event->dtStart().date()) { 170 if (mDate == event->dtStart().date()) {
171 prefix ="->" ;multiday = 1; 171 prefix ="->" ;multiday = 1;
172 } else if (mDate == event->dtEnd().date()) { 172 } else if (mDate == event->dtEnd().date()) {
173 prefix ="<-" ;multiday = 3; 173 prefix ="<-" ;multiday = 3;
174 } 174 }
175 } 175 }
176 if ( !event->doesFloat() ) { 176 if ( !event->doesFloat() ) {
177 if ( mDate == event->dtStart().date () ) 177 if ( mDate == event->dtStart().date () )
178 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 178 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
179 else if ( mDate == event->dtEnd().date () ) 179 else if ( mDate == event->dtEnd().date () )
180 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 180 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
181 181
182 } 182 }
183 text = time + event->summary(); 183 text = time + event->summary();
184 mToolTipText += prefix + text; 184 mToolTipText += prefix + text;
185 } else { 185 } else {
186 if (event->doesFloat()) { 186 if (event->doesFloat()) {
187 text = event->summary(); 187 text = event->summary();
188 mToolTipText += text; 188 mToolTipText += text;
189 } 189 }
190 else { 190 else {
191 text = KGlobal::locale()->formatTime(event->dtStart().time()); 191 text = KGlobal::locale()->formatTime(event->dtStart().time());
192 text += " " + event->summary(); 192 text += " " + event->summary();
193 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 193 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
194 } 194 }
195 } 195 }
196 if ( !event->location().isEmpty() ) 196 if ( !event->location().isEmpty() )
197 mToolTipText += " (" + event->location() + ")"; 197 mToolTipText += " (" + event->location() + ")";
198#if QT_VERSION >= 0x030000 198#if QT_VERSION >= 0x030000
199 mToolTipText.replace( '<' , "&lt;" ); 199 mToolTipText.replace( '<' , "&lt;" );
200 mToolTipText.replace( '>' , "&gt;" ); 200 mToolTipText.replace( '>' , "&gt;" );
201#else 201#else
202 if ( mToolTipText.find ('<') > 0 ) { 202 if ( mToolTipText.find ('<') > 0 ) {
203 mToolTipText.replace( QRegExp("<") , "&lt;" ); 203 mToolTipText.replace( QRegExp("<") , "&lt;" );
204 } 204 }
205 if ( mToolTipText.find ('>') > 0 ) { 205 if ( mToolTipText.find ('>') > 0 ) {
206 mToolTipText.replace( QRegExp(">") , "&gt;" ); 206 mToolTipText.replace( QRegExp(">") , "&gt;" );
207 } 207 }
208#endif 208#endif
209 mToolTip.append( mToolTipText ); 209 mToolTip.append( mToolTipText );
210 } 210 }
211 mToolTip.sort(); 211 mToolTip.sort();
212 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); 212 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>");
213} 213}
214void KODayMatrix::setCalendar( Calendar *cal ) 214void KODayMatrix::setCalendar( Calendar *cal )
215{ 215{
216 mCalendar = cal; 216 mCalendar = cal;
217 217
218 setAcceptDrops( mCalendar ); 218 setAcceptDrops( mCalendar );
219 219
220 updateEvents(); 220 updateEvents();
221} 221}
222 222
223QColor KODayMatrix::getShadedColor(QColor color) 223QColor KODayMatrix::getShadedColor(QColor color)
224{ 224{
225 QColor shaded; 225 QColor shaded;
226 int h=0; 226 int h=0;
227 int s=0; 227 int s=0;
228 int v=0; 228 int v=0;
229 color.hsv(&h,&s,&v); 229 color.hsv(&h,&s,&v);
230 s = s/4; 230 s = s/4;
231 v = 192+v/4; 231 v = 192+v/4;
232 shaded.setHsv(h,s,v); 232 shaded.setHsv(h,s,v);
233 233
234 return shaded; 234 return shaded;
235} 235}
236 236
237KODayMatrix::~KODayMatrix() 237KODayMatrix::~KODayMatrix()
238{ 238{
239 // delete mKODaymatrixWhatsThis; 239 // delete mKODaymatrixWhatsThis;
240 delete [] days; 240 delete [] days;
241 delete [] daylbls; 241 delete [] daylbls;
242 delete [] events; 242 delete [] events;
243 delete mToolTip; 243 delete mToolTip;
244} 244}
245 245
246/* 246/*
247void KODayMatrix::setStartDate(QDate start) 247void KODayMatrix::setStartDate(QDate start)
248{ 248{
249 updateView(start); 249 updateView(start);
250} 250}
251*/ 251*/
252 252
253void KODayMatrix::addSelectedDaysTo(DateList& selDays) 253void KODayMatrix::addSelectedDaysTo(DateList& selDays)
254{ 254{
255 255
256 if (mSelStart == NOSELECTION) { 256 if (mSelStart == NOSELECTION) {
257 return; 257 return;
258 } 258 }
259 259
260 //cope with selection being out of matrix limits at top (< 0) 260 //cope with selection being out of matrix limits at top (< 0)
261 int i0 = mSelStart; 261 int i0 = mSelStart;
262 if (i0 < 0) { 262 if (i0 < 0) {
263 for (int i = i0; i < 0; i++) { 263 for (int i = i0; i < 0; i++) {
264 selDays.append(days[0].addDays(i)); 264 selDays.append(days[0].addDays(i));
265 } 265 }
266 i0 = 0; 266 i0 = 0;
267 } 267 }
268 268
269 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 269 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
270 if (mSelEnd > NUMDAYS-1) { 270 if (mSelEnd > NUMDAYS-1) {
271 for (int i = i0; i <= NUMDAYS-1; i++) { 271 for (int i = i0; i <= NUMDAYS-1; i++) {
272 selDays.append(days[i]); 272 selDays.append(days[i]);
273 } 273 }
274 for (int i = NUMDAYS; i < mSelEnd; i++) { 274 for (int i = NUMDAYS; i < mSelEnd; i++) {
275 selDays.append(days[0].addDays(i)); 275 selDays.append(days[0].addDays(i));
276 } 276 }
277 277
278 // apply normal routine to selection being entirely within matrix limits 278 // apply normal routine to selection being entirely within matrix limits
279 } else { 279 } else {
280 for (int i = i0; i <= mSelEnd; i++) { 280 for (int i = i0; i <= mSelEnd; i++) {
281 selDays.append(days[i]); 281 selDays.append(days[i]);
282 } 282 }
283 } 283 }
284} 284}
285 285
286void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 286void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
287{ 287{
288 mSelStart = startdate.daysTo(start); 288 mSelStart = startdate.daysTo(start);
289 if ( mSelStart < 0 ) 289 if ( mSelStart < 0 )
290 mSelStart = 0; 290 mSelStart = 0;
291 mSelEnd = startdate.daysTo(end); 291 mSelEnd = startdate.daysTo(end);
292 if ( mSelEnd < 0 ) 292 if ( mSelEnd < 0 )
293 clearSelection(); 293 clearSelection();
294} 294}
295void KODayMatrix::clearSelection() 295void KODayMatrix::clearSelection()
296{ 296{
297 mSelEnd = mSelStart = NOSELECTION; 297 mSelEnd = mSelStart = NOSELECTION;
298} 298}
299 299
300 300
301void KODayMatrix::recalculateToday() 301void KODayMatrix::recalculateToday()
302{ 302{
303 today = -1; 303 today = -1;
304 for (int i=0; i<NUMDAYS; i++) { 304 for (int i=0; i<NUMDAYS; i++) {
305 events[i] = 0; 305 events[i] = 0;
306 days[i] = startdate.addDays(i); 306 days[i] = startdate.addDays(i);
307 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 307 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
308 308
309 // if today is in the currently displayed month, hilight today 309 // if today is in the currently displayed month, hilight today
310 if (days[i].year() == QDate::currentDate().year() && 310 if (days[i].year() == QDate::currentDate().year() &&
311 days[i].month() == QDate::currentDate().month() && 311 days[i].month() == QDate::currentDate().month() &&
312 days[i].day() == QDate::currentDate().day()) { 312 days[i].day() == QDate::currentDate().day()) {
313 today = i; 313 today = i;
314 } 314 }
315 } 315 }
316 // qDebug(QString("Today is visible at %1.").arg(today)); 316 // qDebug(QString("Today is visible at %1.").arg(today));
317} 317}
318 318
319void KODayMatrix::updateView() 319void KODayMatrix::updateView()
320{ 320{
321 updateView(startdate); 321 updateView(startdate);
322} 322}
323void KODayMatrix::repaintViewTimed() 323void KODayMatrix::repaintViewTimed()
324{ 324{
325 mRepaintTimer->stop(); 325 mRepaintTimer->stop();
326 repaint(false); 326 repaint(false);
327} 327}
328void KODayMatrix::updateViewTimed() 328void KODayMatrix::updateViewTimed()
329{ 329{
330 mUpdateTimer->stop(); 330 mUpdateTimer->stop();
331 if ( !mCalendar ) { 331 if ( !mCalendar ) {
332 qDebug("NOT CAL "); 332 qDebug("NOT CAL ");
333 return; 333 return;
334 } 334 }
335 //qDebug("KODayMatrix::updateViewTimed "); 335 //qDebug("KODayMatrix::updateViewTimed ");
336 for(int i = 0; i < NUMDAYS; i++) { 336 for(int i = 0; i < NUMDAYS; i++) {
337 // if events are set for the day then remember to draw it bold 337 // if events are set for the day then remember to draw it bold
338 QPtrList<Event> eventlist = mCalendar->events(days[i]); 338 QPtrList<Event> eventlist = mCalendar->events(days[i]);
339 Event *event; 339 Event *event;
340 int numEvents = eventlist.count(); 340 int numEvents = eventlist.count();
341 QString holiStr = ""; 341 QString holiStr = "";
342 bDays.clearBit(i); 342 bDays.clearBit(i);
343 for(event=eventlist.first();event != 0;event=eventlist.next()) { 343 for(event=eventlist.first();event != 0;event=eventlist.next()) {
344 ushort recurType = event->recurrence()->doesRecur(); 344 ushort recurType = event->recurrence()->doesRecur();
345 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 345 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
346 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 346 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
347 numEvents--; 347 numEvents--;
348 } 348 }
349 if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) { 349 if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) {
350 if ( !holiStr.isEmpty() ) 350 if ( !holiStr.isEmpty() )
351 holiStr += "\n"; 351 holiStr += "\n";
352 holiStr += event->summary(); 352 holiStr += event->summary();
353 if ( !event->location().isEmpty() ) 353 if ( !event->location().isEmpty() )
354 holiStr += " (" + event->location() + ")"; 354 holiStr += " (" + event->location() + ")";
355 } 355 }
356 if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) { 356 if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) {
357 if ( !holiStr.isEmpty() ) 357 if ( !holiStr.isEmpty() )
358 holiStr += "\n"; 358 holiStr += "\n";
359 holiStr += i18n("Birthday") + ": "+event->summary(); 359 holiStr += i18n("Birthday") + ": "+event->summary();
360 if ( !event->location().isEmpty() ) 360 if ( !event->location().isEmpty() )
361 holiStr += " (" + event->location() + ")"; 361 holiStr += " (" + event->location() + ")";
362 bDays.setBit(i); 362 bDays.setBit(i);
363 } 363 }
364 } 364 }
365 events[i] = numEvents; 365 events[i] = numEvents;
366 //if it is a holy day then draw it red. Sundays are consider holidays, too 366 //if it is a holy day then draw it red. Sundays are consider holidays, too
367 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 367 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
368 !holiStr.isEmpty()) { 368 !holiStr.isEmpty()) {
369 mHolidays[i] = holiStr; 369 mHolidays[i] = holiStr;
370 } else { 370 } else {
371 mHolidays[i] = QString::null; 371 mHolidays[i] = QString::null;
372 } 372 }
373 } 373 }
374 if ( ! mPendingUpdateBeforeRepaint ) 374 if ( ! mPendingUpdateBeforeRepaint )
375 repaint(false); 375 repaint(false);
376} 376}
377void KODayMatrix::updateView(QDate actdate) 377void KODayMatrix::updateView(QDate actdate)
378{ 378{
379 379
380 if ( ! actdate.isValid() ) { 380 if ( ! actdate.isValid() ) {
381 //qDebug("date not valid "); 381 //qDebug("date not valid ");
382 return; 382 return;
383 } 383 }
384 mDayChanged = false; 384 mDayChanged = false;
385 //flag to indicate if the starting day of the matrix has changed by this call 385 //flag to indicate if the starting day of the matrix has changed by this call
386 //mDayChanged = false; 386 //mDayChanged = false;
387 // if a new startdate is to be set then apply Cornelius's calculation 387 // if a new startdate is to be set then apply Cornelius's calculation
388 // of the first day to be shown 388 // of the first day to be shown
389 if (actdate != startdate) { 389 if (actdate != startdate) {
390 // reset index of selection according to shift of starting date from startdate to actdate 390 // reset index of selection according to shift of starting date from startdate to actdate
391 if (mSelStart != NOSELECTION) { 391 if (mSelStart != NOSELECTION) {
392 int tmp = actdate.daysTo(startdate); 392 int tmp = actdate.daysTo(startdate);
393 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 393 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
394 // shift selection if new one would be visible at least partly ! 394 // shift selection if new one would be visible at least partly !
395 395
396 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 396 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
397 // nested if is required for next X display pushed from a different month - correction required 397 // nested if is required for next X display pushed from a different month - correction required
398 // otherwise, for month forward and backward, it must be avoided 398 // otherwise, for month forward and backward, it must be avoided
399 if( mSelStart > NUMDAYS || mSelStart < 0 ) 399 if( mSelStart > NUMDAYS || mSelStart < 0 )
400 mSelStart = mSelStart + tmp; 400 mSelStart = mSelStart + tmp;
401 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 401 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
402 mSelEnd = mSelEnd + tmp; 402 mSelEnd = mSelEnd + tmp;
403 } 403 }
404 } 404 }
405 startdate = actdate; 405 startdate = actdate;
406 mDayChanged = true; 406 mDayChanged = true;
407 recalculateToday(); 407 recalculateToday();
408 } 408 }
409 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 409 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
410 if ( !isVisible() ) { 410 if ( !isVisible() ) {
411 mPendingUpdateBeforeRepaint = true; 411 mPendingUpdateBeforeRepaint = true;
412 } else { 412 } else {
413#ifdef DESKTOP_VERSION 413#ifdef DESKTOP_VERSION
414 //mRepaintTimer->start( 150 ); 414 //mRepaintTimer->start( 100 );
415 mUpdateTimer->start( 150 ); 415 mUpdateTimer->start( 100 );
416#else 416#else
417 mRepaintTimer->start( 350 ); 417 mRepaintTimer->start( 350 );
418 mUpdateTimer->start( 1200 ); 418 mUpdateTimer->start( 1200 );
419#endif 419#endif
420 } 420 }
421} 421}
422void KODayMatrix::updateEvents() 422void KODayMatrix::updateEvents()
423{ 423{
424 if ( !mCalendar ) return; 424 if ( !mCalendar ) return;
425 425
426 for( int i = 0; i < NUMDAYS; i++ ) { 426 for( int i = 0; i < NUMDAYS; i++ ) {
427 // if events are set for the day then remember to draw it bold 427 // if events are set for the day then remember to draw it bold
428 QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); 428 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
429 int numEvents = eventlist.count(); 429 int numEvents = eventlist.count();
430 Event *event; 430 Event *event;
431 for( event = eventlist.first(); event != 0;event=eventlist.next()) { 431 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
432 ushort recurType = event->doesRecur(); 432 ushort recurType = event->doesRecur();
433 433
434 if ( ( recurType == Recurrence::rDaily && 434 if ( ( recurType == Recurrence::rDaily &&
435 !KOPrefs::instance()->mDailyRecur ) || 435 !KOPrefs::instance()->mDailyRecur ) ||
436 ( recurType == Recurrence::rWeekly && 436 ( recurType == Recurrence::rWeekly &&
437 !KOPrefs::instance()->mWeeklyRecur ) ) { 437 !KOPrefs::instance()->mWeeklyRecur ) ) {
438 numEvents--; 438 numEvents--;
439 } 439 }
440 } 440 }
441 events[ i ] = numEvents; 441 events[ i ] = numEvents;
442 } 442 }
443} 443}
444 444
445const QDate& KODayMatrix::getDate(int offset) 445const QDate& KODayMatrix::getDate(int offset)
446{ 446{
447 if (offset < 0 || offset > NUMDAYS-1) { 447 if (offset < 0 || offset > NUMDAYS-1) {
448 qDebug("Wrong offset2 %d", offset); 448 qDebug("Wrong offset2 %d", offset);
449 return days[0]; 449 return days[0];
450 } 450 }
451 return days[offset]; 451 return days[offset];
452} 452}
453 453
454QString KODayMatrix::getHolidayLabel(int offset) 454QString KODayMatrix::getHolidayLabel(int offset)
455{ 455{
456 if (offset < 0 || offset > NUMDAYS-1) { 456 if (offset < 0 || offset > NUMDAYS-1) {
457 qDebug("Wrong offset1 %d", offset); 457 qDebug("Wrong offset1 %d", offset);
458 return QString(); 458 return QString();
459 } 459 }
460 return mHolidays[offset]; 460 return mHolidays[offset];
461} 461}
462 462
463int KODayMatrix::getDayIndexFrom(int x, int y) 463int KODayMatrix::getDayIndexFrom(int x, int y)
464{ 464{
465 int colModulo = (width()-2) % 7; 465 int colModulo = (width()-2) % 7;
466 int rowModulo = (height()-2) % 6; 466 int rowModulo = (height()-2) % 6;
467#if 0 467#if 0
468 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 468 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
469 6 - x/daysize.width() : x/daysize.width()); 469 6 - x/daysize.width() : x/daysize.width());
470#endif 470#endif
471 int xVal = (x-colModulo/2-2)/daysize.width(); 471 int xVal = (x-colModulo/2-2)/daysize.width();
472 int yVal = (y-rowModulo/2-2)/daysize.height(); 472 int yVal = (y-rowModulo/2-2)/daysize.height();
473 473
474 474
475 return 7*(yVal) + xVal; 475 return 7*(yVal) + xVal;
476 476
477} 477}
478 478
479// ---------------------------------------------------------------------------- 479// ----------------------------------------------------------------------------
480// M O U S E E V E N T H A N D L I N G 480// M O U S E E V E N T H A N D L I N G
481// ---------------------------------------------------------------------------- 481// ----------------------------------------------------------------------------
482 482
483void KODayMatrix::mousePressEvent (QMouseEvent* e) 483void KODayMatrix::mousePressEvent (QMouseEvent* e)
484{ 484{
485 485
486 if ( e->button() == LeftButton ) 486 if ( e->button() == LeftButton )
487 mouseDown = true; 487 mouseDown = true;
488 mSelStart = getDayIndexFrom(e->x(), e->y()); 488 mSelStart = getDayIndexFrom(e->x(), e->y());
489 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 489 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
490 mSelInit = mSelStart; 490 mSelInit = mSelStart;
491 mSelEnd = mSelStart; 491 mSelEnd = mSelStart;
492 repaint(false); 492 repaint(false);
493} 493}
494 494
495void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 495void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
496{ 496{
497 if ( e->button() == LeftButton ) 497 if ( e->button() == LeftButton )
498 if ( ! mouseDown ) { 498 if ( ! mouseDown ) {
499 return; 499 return;
500 } 500 }
501 else 501 else
502 mouseDown = false; 502 mouseDown = false;
503 int tmp = getDayIndexFrom(e->x(), e->y()); 503 int tmp = getDayIndexFrom(e->x(), e->y());
504 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 504 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
505 505
506 if (mSelInit > tmp) { 506 if (mSelInit > tmp) {
507 mSelEnd = mSelInit; 507 mSelEnd = mSelInit;
508 if (tmp != mSelStart) { 508 if (tmp != mSelStart) {
509 mSelStart = tmp; 509 mSelStart = tmp;
510 repaint(false); 510 repaint(false);
511 } 511 }
512 } else { 512 } else {
513 mSelStart = mSelInit; 513 mSelStart = mSelInit;
514 514
515 //repaint only if selection has changed 515 //repaint only if selection has changed
516 if (tmp != mSelEnd) { 516 if (tmp != mSelEnd) {
517 mSelEnd = tmp; 517 mSelEnd = tmp;
518 repaint(false); 518 repaint(false);
519 } 519 }
520 } 520 }
521 521
522 DateList daylist; 522 DateList daylist;
523 if ( mSelStart < 0 ) 523 if ( mSelStart < 0 )
524 mSelStart = 0; 524 mSelStart = 0;
525 for (int i = mSelStart; i <= mSelEnd; i++) { 525 for (int i = mSelStart; i <= mSelEnd; i++) {
526 daylist.append(days[i]); 526 daylist.append(days[i]);
527 } 527 }
528 emit selected((const DateList)daylist); 528 emit selected((const DateList)daylist);
529 529
530} 530}
531 531
532void KODayMatrix::mouseMoveEvent (QMouseEvent* e) 532void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
533{ 533{
534 if ( ! mouseDown ) { 534 if ( ! mouseDown ) {
535 return; 535 return;
536 } 536 }
537 int tmp = getDayIndexFrom(e->x(), e->y()); 537 int tmp = getDayIndexFrom(e->x(), e->y());
538 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 538 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
539 539
540 if (mSelInit > tmp) { 540 if (mSelInit > tmp) {
541 mSelEnd = mSelInit; 541 mSelEnd = mSelInit;
542 if (tmp != mSelStart) { 542 if (tmp != mSelStart) {
543 mSelStart = tmp; 543 mSelStart = tmp;
544 repaint(false); 544 repaint(false);
545 } 545 }
546 } else { 546 } else {
547 mSelStart = mSelInit; 547 mSelStart = mSelInit;
548 548
549 //repaint only if selection has changed 549 //repaint only if selection has changed
550 if (tmp != mSelEnd) { 550 if (tmp != mSelEnd) {
551 mSelEnd = tmp; 551 mSelEnd = tmp;
552 repaint(false); 552 repaint(false);
553 } 553 }
554 } 554 }
555} 555}
556 556
557// ---------------------------------------------------------------------------- 557// ----------------------------------------------------------------------------
558// D R A G ' N D R O P H A N D L I N G 558// D R A G ' N D R O P H A N D L I N G
559// ---------------------------------------------------------------------------- 559// ----------------------------------------------------------------------------
560 560
561void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) 561void KODayMatrix::dragEnterEvent(QDragEnterEvent *e)
562{ 562{
563#ifndef KORG_NODND 563#ifndef KORG_NODND
564 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 564 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
565 e->ignore(); 565 e->ignore();
566 return; 566 return;
567 } 567 }
568 568
569 // some visual feedback 569 // some visual feedback
570// oldPalette = palette(); 570// oldPalette = palette();
571// setPalette(my_HilitePalette); 571// setPalette(my_HilitePalette);
572// update(); 572// update();
573#endif 573#endif
574} 574}
575 575
576void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) 576void KODayMatrix::dragMoveEvent(QDragMoveEvent *e)
577{ 577{
578#ifndef KORG_NODND 578#ifndef KORG_NODND
579 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 579 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
580 e->ignore(); 580 e->ignore();
581 return; 581 return;
582 } 582 }
583 583
584 e->accept(); 584 e->accept();
585#endif 585#endif
586} 586}
587 587
588void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) 588void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
589{ 589{
590#ifndef KORG_NODND 590#ifndef KORG_NODND
591// setPalette(oldPalette); 591// setPalette(oldPalette);
592// update(); 592// update();
593#endif 593#endif
594} 594}
595 595
596void KODayMatrix::dropEvent(QDropEvent *e) 596void KODayMatrix::dropEvent(QDropEvent *e)
597{ 597{
598#ifndef KORG_NODND 598#ifndef KORG_NODND
599// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; 599// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
600 600
601 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 601 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
602 e->ignore(); 602 e->ignore();
603 return; 603 return;
604 } 604 }
605 605
606 DndFactory factory( mCalendar ); 606 DndFactory factory( mCalendar );
607 Event *event = factory.createDrop(e); 607 Event *event = factory.createDrop(e);
608 608
609 if (event) { 609 if (event) {
610 e->acceptAction(); 610 e->acceptAction();
611 611
612 Event *existingEvent = mCalendar->event(event->uid()); 612 Event *existingEvent = mCalendar->event(event->uid());
613 613
614 if(existingEvent) { 614 if(existingEvent) {
615 // uniquify event 615 // uniquify event
616 event->recreate(); 616 event->recreate();
617/* 617/*
618 KMessageBox::sorry(this, 618 KMessageBox::sorry(this,
619 i18n("Event already exists in this calendar."), 619 i18n("Event already exists in this calendar."),
620 i18n("Drop Event")); 620 i18n("Drop Event"));
621 delete event; 621 delete event;
622 return; 622 return;
623*/ 623*/
624 } 624 }
625// kdDebug() << "Drop new Event" << endl; 625// kdDebug() << "Drop new Event" << endl;
626 // Adjust date 626 // Adjust date
627 QDateTime start = event->dtStart(); 627 QDateTime start = event->dtStart();
628 QDateTime end = event->dtEnd(); 628 QDateTime end = event->dtEnd();
629 int duration = start.daysTo(end); 629 int duration = start.daysTo(end);
630 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 630 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
631 631
632 start.setDate(days[idx]); 632 start.setDate(days[idx]);
633 end.setDate(days[idx].addDays(duration)); 633 end.setDate(days[idx].addDays(duration));
634 634
635 event->setDtStart(start); 635 event->setDtStart(start);
636 event->setDtEnd(end); 636 event->setDtEnd(end);
637 mCalendar->addEvent(event); 637 mCalendar->addEvent(event);
638 638
639 emit eventDropped(event); 639 emit eventDropped(event);
640 } else { 640 } else {
641// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 641// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
642 e->ignore(); 642 e->ignore();
643 } 643 }
644#endif 644#endif
645} 645}
646 646
647// ---------------------------------------------------------------------------- 647// ----------------------------------------------------------------------------
648// P A I N T E V E N T H A N D L I N G 648// P A I N T E V E N T H A N D L I N G
649// ---------------------------------------------------------------------------- 649// ----------------------------------------------------------------------------
650 650
651void KODayMatrix::paintEvent(QPaintEvent * pevent) 651void KODayMatrix::paintEvent(QPaintEvent * pevent)
652{ 652{
653 QRect sz = frameRect(); 653 QRect sz = frameRect();
654 if ( sz.width() <= 0 || sz.height() <= 0 ) 654 if ( sz.width() <= 0 || sz.height() <= 0 )
655 return; 655 return;
656 if ( mPendingUpdateBeforeRepaint ) { 656 if ( mPendingUpdateBeforeRepaint ) {
657 updateViewTimed(); 657 updateViewTimed();
658 mPendingUpdateBeforeRepaint = false; 658 mPendingUpdateBeforeRepaint = false;
659 } 659 }
660 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { 660 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) {
661 myPix.resize(sz.size() ); 661 myPix.resize(sz.size() );
662 } 662 }
663 QPainter p(&myPix); 663 QPainter p(&myPix);
664 p.setFont(font()); 664 p.setFont(font());
665 665
666 666
667 int dheight = daysize.height(); 667 int dheight = daysize.height();
668 int dwidth = daysize.width(); 668 int dwidth = daysize.width();
669 int row,col; 669 int row,col;
670 int selw, selh; 670 int selw, selh;
671 int xyOff = frameWidth(); 671 int xyOff = frameWidth();
672 int colModulo = sz.width() % 7; 672 int colModulo = sz.width() % 7;
673 int rowModulo = sz.height() % 6; 673 int rowModulo = sz.height() % 6;
674 //qDebug("col %d row %d ",colModulo,rowModulo ); 674 //qDebug("col %d row %d ",colModulo,rowModulo );
675 675
676 bool isRTL = KOGlobals::self()->reverseLayout(); 676 bool isRTL = KOGlobals::self()->reverseLayout();
677 677
678 // draw background and topleft frame 678 // draw background and topleft frame
679 p.fillRect(pevent->rect(), mDefaultBackColor); 679 p.fillRect(pevent->rect(), mDefaultBackColor);
680 p.setPen(mDefaultTextColor); 680 p.setPen(mDefaultTextColor);
681 p.drawRect(0, 0, sz.width()+1, sz.height()+1); 681 p.drawRect(0, 0, sz.width()+1, sz.height()+1);
682 int mSelStartT = mSelStart; 682 int mSelStartT = mSelStart;
683 int mSelEndT = mSelEnd; 683 int mSelEndT = mSelEnd;
684 if ( mSelEndT >= NUMDAYS ) 684 if ( mSelEndT >= NUMDAYS )
685 mSelEndT = NUMDAYS-1; 685 mSelEndT = NUMDAYS-1;
686 // draw selected days with highlighted background color 686 // draw selected days with highlighted background color
687 if (mSelStart != NOSELECTION) { 687 if (mSelStart != NOSELECTION) {
688 bool skip = false; 688 bool skip = false;
689 if ( ! mouseDown ) { 689 if ( ! mouseDown ) {
690 int mo = days[20].month(); 690 int mo = days[20].month();
691 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 691 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
692 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 692 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
693 if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { 693 if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) {
694 skip = true; 694 skip = true;
695 } else { 695 } else {
696 if ( days[mSelStartT].month() != mo ) { 696 if ( days[mSelStartT].month() != mo ) {
697 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 697 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
698 mSelStartT += add +1; 698 mSelStartT += add +1;
699 } 699 }
700 if ( days[mSelEndT].month() != mo ) { 700 if ( days[mSelEndT].month() != mo ) {
701 int sub = days[mSelEndT].day(); 701 int sub = days[mSelEndT].day();
702 mSelEndT -= sub ; 702 mSelEndT -= sub ;
703 } 703 }
704 } 704 }
705 } 705 }
706 if ( ! skip ) { 706 if ( ! skip ) {
707 row = mSelStartT/7; 707 row = mSelStartT/7;
708 col = mSelStartT -row*7; 708 col = mSelStartT -row*7;
709 QColor selcol = KOPrefs::instance()->mHighlightColor; 709 QColor selcol = KOPrefs::instance()->mHighlightColor;
710 int addCol = 0; 710 int addCol = 0;
711 int addRow = 0; 711 int addRow = 0;
712 int addRow2 = 0; 712 int addRow2 = 0;
713 int addCol2 = 0; 713 int addCol2 = 0;
714 if (row == mSelEndT/7) { 714 if (row == mSelEndT/7) {
715 if ( rowModulo ) { 715 if ( rowModulo ) {
716 if ( row >= 6 - rowModulo ) 716 if ( row >= 6 - rowModulo )
717 addRow = row - 5 + rowModulo; 717 addRow = row - 5 + rowModulo;
718 } 718 }
719 if ( colModulo ) { 719 if ( colModulo ) {
720 int colt1 = mSelEndT%7; 720 int colt1 = mSelEndT%7;
721 //qDebug("colt1 %d ", colt1 ); 721 //qDebug("colt1 %d ", colt1 );
722 if ( colt1 >= 7 - colModulo ) 722 if ( colt1 >= 7 - colModulo )
723 addCol = colt1 - 7 + colModulo+1; 723 addCol = colt1 - 7 + colModulo+1;
724 int colt = mSelStartT%7; 724 int colt = mSelStartT%7;
725 if ( colt >= 7 - colModulo ) 725 if ( colt >= 7 - colModulo )
726 addCol2 = colt - 7 + colModulo; 726 addCol2 = colt - 7 + colModulo;
727 addCol -= addCol2; 727 addCol -= addCol2;
728 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); 728 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 );
729 } 729 }
730 // Single row selection 730 // Single row selection
731 if ( row == 0) 731 if ( row == 0)
732 addRow = 1; 732 addRow = 1;
733 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, 733 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2,
734 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); 734 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol);
735 } else { 735 } else {
736 // draw first row to the right 736 // draw first row to the right
737 if ( colModulo ) { 737 if ( colModulo ) {
738 if ( col >= 7 - colModulo ) 738 if ( col >= 7 - colModulo )
739 addCol2 = col - 7 + colModulo; 739 addCol2 = col - 7 + colModulo;
740 } 740 }
741 if ( rowModulo ) { 741 if ( rowModulo ) {
742 if ( row >= 6 - rowModulo ) 742 if ( row >= 6 - rowModulo )
743 addRow = row - 5 + rowModulo; 743 addRow = row - 5 + rowModulo;
744 } 744 }
745 if ( row == 0) 745 if ( row == 0)
746 addRow = 1; 746 addRow = 1;
747 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo, 747 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo,
748 dheight+1, selcol); 748 dheight+1, selcol);
749 // draw full block till last line 749 // draw full block till last line
750 selh = mSelEndT/7-row; 750 selh = mSelEndT/7-row;
751 addRow = 0; 751 addRow = 0;
752 if ( rowModulo ) { 752 if ( rowModulo ) {
753 if ( mSelEndT/7 >= 6 - rowModulo ) 753 if ( mSelEndT/7 >= 6 - rowModulo )
754 addRow = mSelEndT/7 - 5 + rowModulo; 754 addRow = mSelEndT/7 - 5 + rowModulo;
755 } 755 }
756 if (selh > 1) { 756 if (selh > 1) {
757 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); 757 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol);
758 } 758 }
759 // draw last block from left to mSelEndT 759 // draw last block from left to mSelEndT
760 selw = mSelEndT-7*(mSelEndT/7)+1; 760 selw = mSelEndT-7*(mSelEndT/7)+1;
761 //qDebug("esl %d ",selw ); 761 //qDebug("esl %d ",selw );
762 int add = 0; 762 int add = 0;
763 if ( colModulo ) { 763 if ( colModulo ) {
764 add = 7 - colModulo; 764 add = 7 - colModulo;
765 if ( selw > add ) 765 if ( selw > add )
766 add = selw - add; 766 add = selw - add;
767 else 767 else
768 add = 0; 768 add = 0;
769 } 769 }
770 //qDebug("add %d ", add); 770 //qDebug("add %d ", add);
771 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, 771 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow,
772 selw*dwidth+add, dheight+1, selcol); 772 selw*dwidth+add, dheight+1, selcol);
773 } 773 }
774 } 774 }
775 } 775 }
776 776
777 // iterate over all days in the matrix and draw the day label in appropriate colors 777 // iterate over all days in the matrix and draw the day label in appropriate colors
778 QColor actcol = mDefaultTextColorShaded; 778 QColor actcol = mDefaultTextColorShaded;
779 p.setPen(actcol); 779 p.setPen(actcol);
780 QPen tmppen; 780 QPen tmppen;
781 for(int i = 0; i < NUMDAYS; i++) { 781 for(int i = 0; i < NUMDAYS; i++) {
782 row = i/7; 782 row = i/7;
783 col = isRTL ? 6-(i-row*7) : i-row*7; 783 col = isRTL ? 6-(i-row*7) : i-row*7;
784 784
785 // if it is the first day of a month switch color from normal to shaded and vice versa 785 // if it is the first day of a month switch color from normal to shaded and vice versa
786 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 786 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
787 if (actcol == mDefaultTextColorShaded) { 787 if (actcol == mDefaultTextColorShaded) {
788 actcol = mDefaultTextColor; 788 actcol = mDefaultTextColor;
789 } else { 789 } else {
790 actcol = mDefaultTextColorShaded; 790 actcol = mDefaultTextColorShaded;
791 } 791 }
792 p.setPen(actcol); 792 p.setPen(actcol);
793 } 793 }
794 if (actcol == mDefaultTextColorShaded) { 794 if (actcol == mDefaultTextColorShaded) {
795 if ( ! mouseDown ) { 795 if ( ! mouseDown ) {
796 continue; 796 continue;
797 } 797 }
798 } 798 }
799 //Reset pen color after selected days block 799 //Reset pen color after selected days block
800 if (i == mSelEndT+1) { 800 if (i == mSelEndT+1) {
801 p.setPen(actcol); 801 p.setPen(actcol);
802 } 802 }
803 803
804 // if today then draw rectangle around day 804 // if today then draw rectangle around day
805 if (today == i) { 805 if (today == i) {
806 tmppen = p.pen(); 806 tmppen = p.pen();
807 QPen mTodayPen(p.pen()); 807 QPen mTodayPen(p.pen());
808 if ( daysize.width() < 20 ) 808 if ( daysize.width() < 20 )
809 mTodayPen.setWidth(1); 809 mTodayPen.setWidth(1);
810 else 810 else
811 mTodayPen.setWidth(mTodayMarginWidth); 811 mTodayPen.setWidth(mTodayMarginWidth);
812 //draw red rectangle for holidays 812 //draw red rectangle for holidays
813 if (!mHolidays[i].isNull()) { 813 if (!mHolidays[i].isNull()) {
814 if (actcol == mDefaultTextColor) { 814 if (actcol == mDefaultTextColor) {
815 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); 815 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
816 } else { 816 } else {
817 mTodayPen.setColor(mHolidayColorShaded); 817 mTodayPen.setColor(mHolidayColorShaded);
818 } 818 }
819 } 819 }
820 //draw gray rectangle for today if in selection 820 //draw gray rectangle for today if in selection
821 if (i >= mSelStartT && i <= mSelEndT) { 821 if (i >= mSelStartT && i <= mSelEndT) {
822 QColor grey("grey"); 822 QColor grey("grey");
823 mTodayPen.setColor(grey); 823 mTodayPen.setColor(grey);
824 } 824 }
825 p.setPen(mTodayPen); 825 p.setPen(mTodayPen);
826 826
827 827
828 int addCol = 0; 828 int addCol = 0;
829 int addRow = 0; 829 int addRow = 0;
830 if (rowModulo) { 830 if (rowModulo) {
831 if ( row >= 6 - rowModulo ) 831 if ( row >= 6 - rowModulo )
832 addRow = row - 5 + rowModulo; 832 addRow = row - 5 + rowModulo;
833 } 833 }
834 if ( colModulo ) { 834 if ( colModulo ) {
835 if ( col >= 7 - colModulo ) 835 if ( col >= 7 - colModulo )
836 addCol = col - 6 + colModulo-1; 836 addCol = col - 6 + colModulo-1;
837 } 837 }
838 if ( col == 0 )
839 addCol = 1;
838 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1); 840 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1);
839 p.setPen(tmppen); 841 p.setPen(tmppen);
840 } 842 }
841 843
842 // if any events are on that day then draw it using a bold font 844 // if any events are on that day then draw it using a bold font
843 if (events[i] > 0) { 845 if (events[i] > 0) {
844 QFont myFont = font(); 846 QFont myFont = font();
845 myFont.setBold(true); 847 myFont.setBold(true);
846 p.setFont(myFont); 848 p.setFont(myFont);
847 } 849 }
848 850
849 // if it is a holiday then use the default holiday color 851 // if it is a holiday then use the default holiday color
850 if (!mHolidays[i].isNull()) { 852 if (!mHolidays[i].isNull()) {
851 if ( bDays.testBit(i) ) { 853 if ( bDays.testBit(i) ) {
852 p.setPen(Qt::green); 854 p.setPen(Qt::green);
853 } else { 855 } else {
854 if (actcol == mDefaultTextColor) { 856 if (actcol == mDefaultTextColor) {
855 p.setPen(KOPrefs::instance()->mHolidayColor); 857 p.setPen(KOPrefs::instance()->mHolidayColor);
856 } else { 858 } else {
857 p.setPen(mHolidayColorShaded); 859 p.setPen(mHolidayColorShaded);
858 } 860 }
859 } 861 }
860 } 862 }
861 863
862 // draw selected days with special color 864 // draw selected days with special color
863 // DO NOT specially highlight holidays in selection ! 865 // DO NOT specially highlight holidays in selection !
864 if (i >= mSelStartT && i <= mSelEndT) { 866 if (i >= mSelStartT && i <= mSelEndT) {
865 ;//p.setPen(mSelectedDaysColor); 867 ;//p.setPen(mSelectedDaysColor);
866 } 868 }
867 869
868 int addCol = 0; 870 int addCol = 0;
869 int addRow = 0; 871 int addRow = 0;
870 if ( colModulo ) { 872 if ( colModulo ) {
871 if ( col >= 7 - colModulo ) 873 if ( col >= 7 - colModulo )
872 addCol = col - 7 + colModulo; 874 addCol = col - 7 + colModulo;
873 } 875 }
874 if ( rowModulo ) { 876 if ( rowModulo ) {
875 if ( row >= 6 - rowModulo ) 877 if ( row >= 6 - rowModulo )
876 addRow = row - 5 + rowModulo; 878 addRow = row - 5 + rowModulo;
877 } 879 }
878 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); 880 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow);
879 ++addCol;//++addCol; 881 ++addCol;//++addCol;
882 if ( row == 0)
883 addRow = 1;
880 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, 884 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight,
881 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); 885 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
882 886
883 // reset color to actual color 887 // reset color to actual color
884 if (!mHolidays[i].isNull()) { 888 if (!mHolidays[i].isNull()) {
885 p.setPen(actcol); 889 p.setPen(actcol);
886 } 890 }
887 // reset bold font to plain font 891 // reset bold font to plain font
888 if (events[i] > 0) { 892 if (events[i] > 0) {
889 QFont myFont = font(); 893 QFont myFont = font();
890 myFont.setBold(false); 894 myFont.setBold(false);
891 p.setFont(myFont); 895 p.setFont(myFont);
892 } 896 }
893 } 897 }
894 int off = xyOff; 898 int off = xyOff;
895 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP); 899 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP);
896 //qDebug("ffffffffff %d ", off); 900 //qDebug("ffffffffff %d ", off);
897} 901}
898 902
899// ---------------------------------------------------------------------------- 903// ----------------------------------------------------------------------------
900// R E SI Z E E V E N T H A N D L I N G 904// R E SI Z E E V E N T H A N D L I N G
901// ---------------------------------------------------------------------------- 905// ----------------------------------------------------------------------------
902 906
903void KODayMatrix::resizeEvent(QResizeEvent *) 907void KODayMatrix::resizeEvent(QResizeEvent *)
904{ 908{
905 QRect sz = frameRect(); 909 QRect sz = frameRect();
906 daysize.setHeight(sz.height()*7 / NUMDAYS); 910 daysize.setHeight(sz.height()*7 / NUMDAYS);
907 daysize.setWidth(sz.width() / 7); 911 daysize.setWidth(sz.width() / 7);
908} 912}
909 913
910QSize KODayMatrix::sizeHint() const 914QSize KODayMatrix::sizeHint() const
911{ 915{
912 916
913 QFontMetrics fm ( font() ); 917 QFontMetrics fm ( font() );
914 int wid = fm.width( "30") *7+3; 918 int wid = fm.width( "30") *7+3;
915 int hei = fm.height() * 6+3; 919 int hei = fm.height() * 6+3;
916 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); 920 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
917 return QSize ( wid, hei ); 921 return QSize ( wid, hei );
918 922
919} 923}