summaryrefslogtreecommitdiff
path: root/core/pim/datebook/datebookweek.cpp
authoralwin <alwin>2005-03-17 14:01:23 (UTC)
committer alwin <alwin>2005-03-17 14:01:23 (UTC)
commit8752141a5341877369f89a42fa1f0b5d08f56dbd (patch) (unidiff)
tree63dc48ee207a4e9fbb6b9e8abddb239ec724c155 /core/pim/datebook/datebookweek.cpp
parentafee05f4b4c1e8dab8463e3423fcfc8f9d45aa8b (diff)
downloadopie-8752141a5341877369f89a42fa1f0b5d08f56dbd.zip
opie-8752141a5341877369f89a42fa1f0b5d08f56dbd.tar.gz
opie-8752141a5341877369f89a42fa1f0b5d08f56dbd.tar.bz2
1. datebookweeklist - a week has SEVEN days, not SIX. I'm wondering why
events on sunday never showed there ;) 2. extra file datebooktypes contains some special classes used by datebook so other classes must not include the big mainheader file. 3. added support for holiday-plugins to week-views. Month view is a little bit more tricky 'cause TT has never heard about virtual methods and so I have the choice between complete copy the monthview and make the modifications or changing the interface of datebookdb-class to virtual. both isn't nice.
Diffstat (limited to 'core/pim/datebook/datebookweek.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebookweek.cpp489
1 files changed, 245 insertions, 244 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp
index 7503751..a509d89 100644
--- a/core/pim/datebook/datebookweek.cpp
+++ b/core/pim/datebook/datebookweek.cpp
@@ -19,6 +19,7 @@
19**********************************************************************/ 19**********************************************************************/
20#include "datebookweek.h" 20#include "datebookweek.h"
21#include "datebookweekheaderimpl.h" 21#include "datebookweekheaderimpl.h"
22#include "datebooktypes.h"
22 23
23#include <qpe/datebookdb.h> 24#include <qpe/datebookdb.h>
24#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
@@ -52,7 +53,7 @@ void DateBookWeekItem::setGeometry( int x, int y, int w, int h )
52//------------------=--------------------------------------------- 53//------------------=---------------------------------------------
53 54
54DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, 55DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday,
55 QWidget *parent, const char *name ) 56 QWidget *parent, const char *name )
56 : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), 57 : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ),
57 showingEvent( false ) 58 showingEvent( false )
58{ 59{
@@ -72,7 +73,7 @@ DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday,
72 connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); 73 connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) );
73 74
74 QObject::connect(qApp, SIGNAL(clockChanged(bool)), 75 QObject::connect(qApp, SIGNAL(clockChanged(bool)),
75 this, SLOT(slotChangeClock(bool))); 76 this, SLOT(slotChangeClock(bool)));
76 77
77 QFontMetrics fm( font() ); 78 QFontMetrics fm( font() );
78 rowHeight = fm.height()+2; 79 rowHeight = fm.height()+2;
@@ -85,32 +86,32 @@ void DateBookWeekView::initNames()
85 86
86 static bool bFirst = true; 87 static bool bFirst = true;
87 if ( bFirst ) { 88 if ( bFirst ) {
88 if ( bOnMonday ) { 89 if ( bOnMonday ) {
89 for ( int i = 1; i<=7; i++ ) { 90 for ( int i = 1; i<=7; i++ ) {
90 header->addLabel( Calendar::nameOfDay( i ) ); 91 header->addLabel( Calendar::nameOfDay( i ) );
91 } 92 }
92 93
93 } else { 94 } else {
94 header->addLabel( Calendar::nameOfDay( 7 ) ); 95 header->addLabel( Calendar::nameOfDay( 7 ) );
95 for ( int i = 1; i<7; i++ ) { 96 for ( int i = 1; i<7; i++ ) {
96 header->addLabel( Calendar::nameOfDay( i ) ); 97 header->addLabel( Calendar::nameOfDay( i ) );
97 } 98 }
98 } 99 }
99 bFirst = false; 100 bFirst = false;
100 } else { 101 } else {
101 // we are change things... 102 // we are change things...
102 if ( bOnMonday ) { 103 if ( bOnMonday ) {
103 for ( int i = 1; i<=7; i++ ) { 104 for ( int i = 1; i<=7; i++ ) {
104 header->setLabel( i, Calendar::nameOfDay( i ) ); 105 header->setLabel( i, Calendar::nameOfDay( i ) );
105 } 106 }
106 107
107 } else { 108 } else {
108 header->setLabel( 1, Calendar::nameOfDay( 7 ) ); 109 header->setLabel( 1, Calendar::nameOfDay( 7 ) );
109 for ( int i = 1; i<7; i++ ) { 110 for ( int i = 1; i<7; i++ ) {
110 header->setLabel( i+1, Calendar::nameOfDay( i ) ); 111 header->setLabel( i+1, Calendar::nameOfDay( i ) );
111 } 112 }
112 113
113 } 114 }
114 } 115 }
115} 116}
116 117
@@ -118,16 +119,16 @@ void DateBookWeekView::initNames()
118 119
119void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) 120void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev )
120{ 121{
121 items.clear(); 122 items.clear();
122 QValueListIterator<EffectiveEvent> it; 123 QValueListIterator<EffectiveEvent> it;
123 for ( it = ev.begin(); it != ev.end(); ++it ) { 124 for ( it = ev.begin(); it != ev.end(); ++it ) {
124 DateBookWeekItem *i = new DateBookWeekItem( *it ); 125 DateBookWeekItem *i = new DateBookWeekItem( *it );
125 if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) {// Skip events ending at 00:00 starting at another day. 126 if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) { // Skip events ending at 00:00 starting at another day.
126 positionItem( i ); 127 positionItem( i );
127 items.append( i ); 128 items.append( i );
128 } 129 }
129 } 130 }
130 viewport()->update(); 131 viewport()->update();
131} 132}
132 133
133void DateBookWeekView::moveToHour( int h ) 134void DateBookWeekView::moveToHour( int h )
@@ -150,11 +151,11 @@ void DateBookWeekView::slotChangeClock( bool c )
150static inline int db_round30min( int m ) 151static inline int db_round30min( int m )
151{ 152{
152 if ( m < 15 ) 153 if ( m < 15 )
153 m = 0; 154 m = 0;
154 else if ( m < 45 ) 155 else if ( m < 45 )
155 m = 1; 156 m = 1;
156 else 157 else
157 m = 2; 158 m = 2;
158 159
159 return m; 160 return m;
160} 161}
@@ -162,7 +163,7 @@ static inline int db_round30min( int m )
162void DateBookWeekView::alterDay( int day ) 163void DateBookWeekView::alterDay( int day )
163{ 164{
164 if ( !bOnMonday ) { 165 if ( !bOnMonday ) {
165 day--; 166 day--;
166 } 167 }
167 emit showDay( day ); 168 emit showDay( day );
168} 169}
@@ -184,27 +185,27 @@ void DateBookWeekView::positionItem( DateBookWeekItem *i )
184 185
185 int h; 186 int h;
186 if ( ev.event().type() == Event::AllDay ) { 187 if ( ev.event().type() == Event::AllDay ) {
187 h = (48 * rowHeight) / 2; 188 h = (48 * rowHeight) / 2;
188 y = 0; 189 y = 0;
189 } else { 190 } else {
190 h=y2-y; 191 h=y2-y;
191 if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2; 192 if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2;
192 } 193 }
193 194
194 int dow = ev.date().dayOfWeek(); 195 int dow = ev.date().dayOfWeek();
195 if ( !bOnMonday ) { 196 if ( !bOnMonday ) {
196 if ( dow == 7 ) 197 if ( dow == 7 )
197 dow = 1; 198 dow = 1;
198 else 199 else
199 dow++; 200 dow++;
200 } 201 }
201 int x = header->sectionPos( dow ) - 1; 202 int x = header->sectionPos( dow ) - 1;
202 int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); 203 int xlim = header->sectionPos( dow ) + header->sectionSize( dow );
203 DateBookWeekItem *isect = 0; 204 DateBookWeekItem *isect = 0;
204 do { 205 do {
205 i->setGeometry( x, y, Width, h ); 206 i->setGeometry( x, y, Width, h );
206 isect = intersects( i ); 207 isect = intersects( i );
207 x += Width - 1; 208 x += Width - 1;
208 } while ( isect && x < xlim ); 209 } while ( isect && x < xlim );
209} 210}
210 211
@@ -218,12 +219,12 @@ DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item )
218 219
219 QListIterator<DateBookWeekItem> it(items); 220 QListIterator<DateBookWeekItem> it(items);
220 for ( ; it.current(); ++it ) { 221 for ( ; it.current(); ++it ) {
221 DateBookWeekItem *i = it.current(); 222 DateBookWeekItem *i = it.current();
222 if ( i != item ) { 223 if ( i != item ) {
223 if ( i->geometry().intersects( geom ) ) { 224 if ( i->geometry().intersects( geom ) ) {
224 return i; 225 return i;
225 } 226 }
226 } 227 }
227 } 228 }
228 229
229 return 0; 230 return 0;
@@ -233,27 +234,27 @@ void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e )
233{ 234{
234 QListIterator<DateBookWeekItem> it(items); 235 QListIterator<DateBookWeekItem> it(items);
235 for ( ; it.current(); ++it ) { 236 for ( ; it.current(); ++it ) {
236 DateBookWeekItem *i = it.current(); 237 DateBookWeekItem *i = it.current();
237 if ( i->geometry().contains( e->pos() ) ) { 238 if ( i->geometry().contains( e->pos() ) ) {
238 showingEvent = true; 239 showingEvent = true;
239 emit signalShowEvent( i->event() ); 240 emit signalShowEvent( i->event() );
240 break; 241 break;
241 } 242 }
242 } 243 }
243} 244}
244 245
245void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) 246void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e )
246{ 247{
247 if ( showingEvent ) { 248 if ( showingEvent ) {
248 showingEvent = false; 249 showingEvent = false;
249 emit signalHideEvent(); 250 emit signalHideEvent();
250 } else { 251 } else {
251 int d = header->sectionAt( e->pos().x() ); 252 int d = header->sectionAt( e->pos().x() );
252 if ( d > 0 ) { 253 if ( d > 0 ) {
253 // if ( !bOnMonday ) 254// if ( !bOnMonday )
254 // d--; 255// d--;
255 emit showDay( d ); 256 emit showDay( d );
256 } 257 }
257 } 258 }
258} 259}
259 260
@@ -262,47 +263,47 @@ void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch
262 QRect ur( cx, cy, cw, ch ); 263 QRect ur( cx, cy, cw, ch );
263 p->setPen( lightGray ); 264 p->setPen( lightGray );
264 for ( int i = 1; i <= 7; i++ ) 265 for ( int i = 1; i <= 7; i++ )
265 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); 266 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch );
266 267
267 p->setPen( black ); 268 p->setPen( black );
268 for ( int t = 0; t < 24; t++ ) { 269 for ( int t = 0; t < 24; t++ ) {
269 int y = t*rowHeight; 270 int y = t*rowHeight;
270 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { 271 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) {
271 QString s; 272 QString s;
272 if ( ampm ) { 273 if ( ampm ) {
273 if ( t == 0 ) 274 if ( t == 0 )
274 s = QString::number( 12 ); 275 s = QString::number( 12 );
275 else if ( t == 12 ) 276 else if ( t == 12 )
276 s = QString::number(12) + tr( "p" ); 277 s = QString::number(12) + tr( "p" );
277 else if ( t > 12 ) { 278 else if ( t > 12 ) {
278 if ( t - 12 < 10 ) 279 if ( t - 12 < 10 )
279 s = " "; 280 s = " ";
280 else 281 else
281 s = ""; 282 s = "";
282 s += QString::number( t - 12 ) + tr("p"); 283 s += QString::number( t - 12 ) + tr("p");
283 } else { 284 } else {
284 if ( 12 - t < 3 ) 285 if ( 12 - t < 3 )
285 s = ""; 286 s = "";
286 else 287 else
287 s = " "; 288 s = " ";
288 s += QString::number( t ); 289 s += QString::number( t );
289 } 290 }
290 } else { 291 } else {
291 s = QString::number( t ); 292 s = QString::number( t );
292 if ( s.length() == 1 ) 293 if ( s.length() == 1 )
293 s.prepend( "0" ); 294 s.prepend( "0" );
294 } 295 }
295 p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); 296 p->drawText( 1, y+p->fontMetrics().ascent()+1, s );
296 } 297 }
297 } 298 }
298 299
299 QListIterator<DateBookWeekItem> it(items); 300 QListIterator<DateBookWeekItem> it(items);
300 for ( ; it.current(); ++it ) { 301 for ( ; it.current(); ++it ) {
301 DateBookWeekItem *i = it.current(); 302 DateBookWeekItem *i = it.current();
302 if ( i->geometry().intersects( ur ) ) { 303 if ( i->geometry().intersects( ur ) ) {
303 p->setBrush( i->color() ); 304 p->setBrush( i->color() );
304 p->drawRect( i->geometry() ); 305 p->drawRect( i->geometry() );
305 } 306 }
306 } 307 }
307} 308}
308 309
@@ -316,7 +317,7 @@ void DateBookWeekView::resizeEvent( QResizeEvent *e )
316 /* 317 /*
317 int avail = visibleWidth(); 318 int avail = visibleWidth();
318 header->setGeometry( leftMargin()+frameWidth()+frameRect().left() , frameWidth(), 319 header->setGeometry( leftMargin()+frameWidth()+frameRect().left() , frameWidth(),
319 visibleWidth(), header->sizeHint().height() ); 320 visibleWidth(), header->sizeHint().height() );
320 setMargins( 0, header->sizeHint().height(), 0, 0 ); 321 setMargins( 0, header->sizeHint().height(), 0, 0 );
321 */ 322 */
322 //BRANCH_1_0 323 //BRANCH_1_0
@@ -328,7 +329,7 @@ void DateBookWeekView::resizeEvent( QResizeEvent *e )
328 header->resizeSection( 0, hourWidth ); 329 header->resizeSection( 0, hourWidth );
329 int sw = (avail - hourWidth) / 7; 330 int sw = (avail - hourWidth) / 7;
330 for ( int i = 1; i < 7; i++ ) 331 for ( int i = 1; i < 7; i++ )
331 header->resizeSection( i, sw ); 332 header->resizeSection( i, sw );
332 header->resizeSection( 7, avail - hourWidth - sw*6 ); 333 header->resizeSection( 7, avail - hourWidth - sw*6 );
333} 334}
334 335
@@ -340,121 +341,121 @@ void DateBookWeekView::setStartOfWeek( bool bStartOnMonday )
340 341
341//------------------------------------------------------------------- 342//-------------------------------------------------------------------
342 343
343DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, 344DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDBHoliday *newDB,
344 QWidget *parent, const char *name ) 345 QWidget *parent, const char *name )
345 : QWidget( parent, name ), 346 : QWidget( parent, name ),
346 db( newDB ), 347 db( newDB ),
347 startTime( 0 ), 348 startTime( 0 ),
348 ampm( ap ), 349 ampm( ap ),
349 bStartOnMonday( startOnMonday ) 350 bStartOnMonday( startOnMonday )
350{ 351{
351 setFocusPolicy(StrongFocus); 352 setFocusPolicy(StrongFocus);
352 QVBoxLayout *vb = new QVBoxLayout( this ); 353 QVBoxLayout *vb = new QVBoxLayout( this );
353 header = new DateBookWeekHeader( bStartOnMonday, this ); 354 header = new DateBookWeekHeader( bStartOnMonday, this );
354 view = new DateBookWeekView( ampm, startOnMonday, this ); 355 view = new DateBookWeekView( ampm, startOnMonday, this );
355 vb->addWidget( header ); 356 vb->addWidget( header );
356 vb->addWidget( view ); 357 vb->addWidget( view );
357 358
358 lblDesc = new QLabel( this, "event label" ); 359 lblDesc = new QLabel( this, "event label" );
359 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); 360 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box );
360 lblDesc->setBackgroundColor( yellow ); 361 lblDesc->setBackgroundColor( yellow );
361 lblDesc->hide(); 362 lblDesc->hide();
362 363
363 tHide = new QTimer( this ); 364 tHide = new QTimer( this );
364 365
365 connect( view, SIGNAL( showDay(int) ), this, SLOT( showDay(int) ) ); 366 connect( view, SIGNAL( showDay(int) ), this, SLOT( showDay(int) ) );
366 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); 367 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) );
367 connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); 368 connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) );
368 connect( header, SIGNAL( dateChanged(QDate&) ), this, SLOT( dateChanged(QDate&) ) ); 369 connect( header, SIGNAL( dateChanged(QDate&) ), this, SLOT( dateChanged(QDate&) ) );
369 connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); 370 connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) );
370 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); 371 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) );
371 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); 372 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool)));
372 setDate(QDate::currentDate()); 373 setDate(QDate::currentDate());
373} 374}
374 375
375void DateBookWeek::keyPressEvent(QKeyEvent *e) 376void DateBookWeek::keyPressEvent(QKeyEvent *e)
376{ 377{
377 switch(e->key()) { 378 switch(e->key()) {
378 case Key_Up: 379 case Key_Up:
379 view->scrollBy(0, -20); 380 view->scrollBy(0, -20);
380 break; 381 break;
381 case Key_Down: 382 case Key_Down:
382 view->scrollBy(0, 20); 383 view->scrollBy(0, 20);
383 break; 384 break;
384 case Key_Left: 385 case Key_Left:
385 setDate(date().addDays(-7)); 386 setDate(date().addDays(-7));
386 break; 387 break;
387 case Key_Right: 388 case Key_Right:
388 setDate(date().addDays(7)); 389 setDate(date().addDays(7));
389 break; 390 break;
390 default: 391 default:
391 e->ignore(); 392 e->ignore();
392 } 393 }
393} 394}
394 395
395void DateBookWeek::showDay( int day ) 396void DateBookWeek::showDay( int day )
396{ 397{
397 QDate d=bdate; 398 QDate d=bdate;
398 399
399 // Calculate offset to first day of week. 400 // Calculate offset to first day of week.
400 int dayoffset=d.dayOfWeek() % 7; 401 int dayoffset=d.dayOfWeek() % 7;
401 402
402 if(bStartOnMonday) dayoffset--; 403 if(bStartOnMonday) dayoffset--;
403 404
404 day--; 405 day--;
405 d=d.addDays(day-dayoffset); 406 d=d.addDays(day-dayoffset);
406 emit showDate( d.year(), d.month(), d.day() ); 407 emit showDate( d.year(), d.month(), d.day() );
407} 408}
408 409
409void DateBookWeek::setDate( int y, int m, int d ) 410void DateBookWeek::setDate( int y, int m, int d )
410{ 411{
411 setDate(QDate(y, m, d)); 412 setDate(QDate(y, m, d));
412} 413}
413 414
414void DateBookWeek::setDate(QDate newdate) 415void DateBookWeek::setDate(QDate newdate)
415{ 416{
416 bdate=newdate; 417 bdate=newdate;
417 dow = newdate.dayOfWeek(); 418 dow = newdate.dayOfWeek();
418 header->setDate( newdate ); 419 header->setDate( newdate );
419} 420}
420 421
421void DateBookWeek::dateChanged( QDate &newdate ) 422void DateBookWeek::dateChanged( QDate &newdate )
422{ 423{
423 bdate=newdate; 424 bdate=newdate;
424 getEvents(); 425 getEvents();
425} 426}
426 427
427QDate DateBookWeek::date() const 428QDate DateBookWeek::date() const
428{ 429{
429 return bdate; 430 return bdate;
430} 431}
431 432
432void DateBookWeek::getEvents() 433void DateBookWeek::getEvents()
433{ 434{
434 QDate startWeek = weekDate(); 435 QDate startWeek = weekDate();
435 436
436 QDate endWeek = startWeek.addDays( 6 ); 437 QDate endWeek = startWeek.addDays( 6 );
437 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); 438 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek);
438 view->showEvents( eventList ); 439 view->showEvents( eventList );
439 view->moveToHour( startTime ); 440 view->moveToHour( startTime );
440} 441}
441 442
442void DateBookWeek::generateAllDayTooltext( QString& text ) { 443void DateBookWeek::generateAllDayTooltext( QString& text ) {
443 text += "<b>" + tr("This is an all day event.") + "</b><br>"; 444 text += "<b>" + tr("This is an all day event.") + "</b><br>";
444} 445}
445 446
446void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { 447void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) {
447 str += "<b>" + QObject::tr("Start") + "</b>: "; 448 str += "<b>" + QObject::tr("Start") + "</b>: ";
448 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); 449 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE );
449 if( ev.startDate()!=ev.endDate() ) { 450 if( ev.startDate()!=ev.endDate() ) {
450 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; 451 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>";
451 } 452 }
452 str += "<br>"; 453 str += "<br>";
453 str += "<b>" + QObject::tr("End") + "</b>: "; 454 str += "<b>" + QObject::tr("End") + "</b>: ";
454 str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); 455 str += TimeString::timeString( ev.event().end().time(), ampm, FALSE );
455 if( ev.startDate()!=ev.endDate() ) { 456 if( ev.startDate()!=ev.endDate() ) {
456 str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; 457 str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>";
457 } 458 }
458} 459}
459 460
460void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) 461void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
@@ -467,9 +468,9 @@ void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
467 QString strDesc = ev.description(); 468 QString strDesc = ev.description();
468 int where = strDesc.find( "<" ); 469 int where = strDesc.find( "<" );
469 while ( where != -1 ) { 470 while ( where != -1 ) {
470 strDesc.remove( where, 1 ); 471 strDesc.remove( where, 1 );
471 strDesc.insert( where, "&#60;" ); 472 strDesc.insert( where, "&#60;" );
472 where = strDesc.find( "<", where ); 473 where = strDesc.find( "<", where );
473 } 474 }
474 475
475 QString strCat; 476 QString strCat;
@@ -477,31 +478,31 @@ void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
477// QString strCat = ev.category(); 478// QString strCat = ev.category();
478// where = strCat.find( "<" ); 479// where = strCat.find( "<" );
479// while ( where != -1 ) { 480// while ( where != -1 ) {
480 // strCat.remove( where, 1 ); 481// strCat.remove( where, 1 );
481 // strCat.insert( where, "&#60;" ); 482// strCat.insert( where, "&#60;" );
482 // where = strCat.find( "<", where ); 483// where = strCat.find( "<", where );
483// } 484// }
484 485
485 QString strLocation = ev.location(); 486 QString strLocation = ev.location();
486 while ( where != -1 ) { 487 while ( where != -1 ) {
487 strLocation.remove( where, 1 ); 488 strLocation.remove( where, 1 );
488 strLocation.insert( where, "&#60;" ); 489 strLocation.insert( where, "&#60;" );
489 where = strLocation.find( "<", where ); 490 where = strLocation.find( "<", where );
490 } 491 }
491 492
492 QString strNote = ev.notes(); 493 QString strNote = ev.notes();
493 where = strNote.find( "<" ); 494 where = strNote.find( "<" );
494 while ( where != -1 ) { 495 while ( where != -1 ) {
495 strNote.remove( where, 1 ); 496 strNote.remove( where, 1 );
496 strNote.insert( where, "&#60;" ); 497 strNote.insert( where, "&#60;" );
497 where = strNote.find( "<", where ); 498 where = strNote.find( "<", where );
498 } 499 }
499 500
500 QString str = "<b>" + strDesc + "</b><br>" 501 QString str = "<b>" + strDesc + "</b><br>"
501 + strLocation + "<br>" 502 + strLocation + "<br>"
502 + "<i>" + strCat + "</i>" 503 + "<i>" + strCat + "</i>"
503 + "<br>" + TimeString::longDateString( ev.date() ) 504 + "<br>" + TimeString::longDateString( ev.date() )
504 + "<br>"; 505 + "<br>";
505 506
506 if (ev.event().type() == Event::Normal ) 507 if (ev.event().type() == Event::Normal )
507 generateNormalTooltext( str, ev ); 508 generateNormalTooltext( str, ev );
@@ -540,41 +541,41 @@ void DateBookWeek::redraw()
540 541
541void DateBookWeek::slotYearChanged( int y ) 542void DateBookWeek::slotYearChanged( int y )
542{ 543{
543 int totWeek; 544 int totWeek;
544 QDate d( y, 12, 31 ); 545 QDate d( y, 12, 31 );
545 int throwAway; 546 int throwAway;
546 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 547 calcWeek( d, totWeek, throwAway, bStartOnMonday );
547 while ( totWeek == 1 ) { 548 while ( totWeek == 1 ) {
548 d = d.addDays( -1 ); 549 d = d.addDays( -1 );
549 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 550 calcWeek( d, totWeek, throwAway, bStartOnMonday );
550 } 551 }
551} 552}
552 553
553void DateBookWeek::slotWeekChanged( bool onMonday ) 554void DateBookWeek::slotWeekChanged( bool onMonday )
554{ 555{
555 bStartOnMonday = onMonday; 556 bStartOnMonday = onMonday;
556 view->setStartOfWeek( bStartOnMonday ); 557 view->setStartOfWeek( bStartOnMonday );
557 header->setStartOfWeek( bStartOnMonday ); 558 header->setStartOfWeek( bStartOnMonday );
558 redraw(); 559 redraw();
559} 560}
560 561
561void DateBookWeek::slotClockChanged( bool ap ) 562void DateBookWeek::slotClockChanged( bool ap )
562{ 563{
563 ampm = ap; 564 ampm = ap;
564} 565}
565 566
566// return the date at the beginning of the week... 567// return the date at the beginning of the week...
567QDate DateBookWeek::weekDate() const 568QDate DateBookWeek::weekDate() const
568{ 569{
569 QDate d=bdate; 570 QDate d=bdate;
570 571
571 // Calculate offset to first day of week. 572 // Calculate offset to first day of week.
572 int dayoffset=d.dayOfWeek(); 573 int dayoffset=d.dayOfWeek();
573 if(bStartOnMonday) dayoffset--; 574 if(bStartOnMonday) dayoffset--;
574 else if( dayoffset == 7 ) 575 else if( dayoffset == 7 )
575 dayoffset = 0; 576 dayoffset = 0;
576 577
577 return d.addDays(-dayoffset); 578 return d.addDays(-dayoffset);
578} 579}
579 580
580// this used to only be needed by datebook.cpp, but now we need it inside 581// this used to only be needed by datebook.cpp, but now we need it inside
@@ -600,7 +601,7 @@ QDate DateBookWeek::weekDate() const
600// week... 601// week...
601 602
602bool calcWeek( const QDate &d, int &week, int &year, 603bool calcWeek( const QDate &d, int &week, int &year,
603 bool startOnMonday ) 604 bool startOnMonday )
604{ 605{
605 int weekNumber; 606 int weekNumber;
606 int yearNumber; 607 int yearNumber;
@@ -611,62 +612,62 @@ bool calcWeek( const QDate &d, int &week, int &year,
611 int dayOfWeek = d.dayOfWeek(); 612 int dayOfWeek = d.dayOfWeek();
612 613
613 if ( !d.isValid() ) 614 if ( !d.isValid() )
614 return false; 615 return false;
615 616
616 if ( startOnMonday ) { 617 if ( startOnMonday ) {
617 // find the Jan1Weekday; 618 // find the Jan1Weekday;
618 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { 619 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) {
619 yearNumber = d.year() - 1; 620 yearNumber = d.year() - 1;
620 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) 621 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) )
621 weekNumber = 53; 622 weekNumber = 53;
622 else 623 else
623 weekNumber = 52; 624 weekNumber = 52;
624 } else 625 } else
625 yearNumber = d.year(); 626 yearNumber = d.year();
626 if ( yearNumber == d.year() ) { 627 if ( yearNumber == d.year() ) {
627 int totalDays = 365; 628 int totalDays = 365;
628 if ( QDate::leapYear(yearNumber) ) 629 if ( QDate::leapYear(yearNumber) )
629 totalDays++; 630 totalDays++;
630 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) 631 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) )
631 || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { 632 || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) {
632 yearNumber++; 633 yearNumber++;
633 weekNumber = 1; 634 weekNumber = 1;
634 } 635 }
635 } 636 }
636 if ( yearNumber == d.year() ) { 637 if ( yearNumber == d.year() ) {
637 int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); 638 int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 );
638 weekNumber = j / 7; 639 weekNumber = j / 7;
639 if ( jan1WeekDay > 4 ) 640 if ( jan1WeekDay > 4 )
640 weekNumber--; 641 weekNumber--;
641 } 642 }
642 } else { 643 } else {
643 // it's better to keep these cases separate... 644 // it's better to keep these cases separate...
644 if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 645 if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4
645 && jan1WeekDay != 7 ) { 646 && jan1WeekDay != 7 ) {
646 yearNumber = d.year() - 1; 647 yearNumber = d.year() - 1;
647 if ( jan1WeekDay == 6 648 if ( jan1WeekDay == 6
648 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { 649 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) {
649 weekNumber = 53; 650 weekNumber = 53;
650 }else 651 }else
651 weekNumber = 52; 652 weekNumber = 52;
652 } else 653 } else
653 yearNumber = d.year(); 654 yearNumber = d.year();
654 if ( yearNumber == d.year() ) { 655 if ( yearNumber == d.year() ) {
655 int totalDays = 365; 656 int totalDays = 365;
656 if ( QDate::leapYear( yearNumber ) ) 657 if ( QDate::leapYear( yearNumber ) )
657 totalDays++; 658 totalDays++;
658 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { 659 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) {
659 yearNumber++; 660 yearNumber++;
660 weekNumber = 1; 661 weekNumber = 1;
661 } 662 }
662 } 663 }
663 if ( yearNumber == d.year() ) { 664 if ( yearNumber == d.year() ) {
664 int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); 665 int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 );
665 weekNumber = j / 7; 666 weekNumber = j / 7;
666 if ( jan1WeekDay > 4 ) { 667 if ( jan1WeekDay > 4 ) {
667 weekNumber--; 668 weekNumber--;
668 } 669 }
669 } 670 }
670 } 671 }
671 year = yearNumber; 672 year = yearNumber;
672 week = weekNumber; 673 week = weekNumber;