author | umopapisdn <umopapisdn> | 2003-05-13 22:58:18 (UTC) |
---|---|---|
committer | umopapisdn <umopapisdn> | 2003-05-13 22:58:18 (UTC) |
commit | 1e0e2f57472538bd880967ebe061c8f39a7e270b (patch) (unidiff) | |
tree | fcc070d53148385f93c0dc6ab5443d5100be0d26 | |
parent | 45c0386de12b107e54e4d020d54eb05517a9efac (diff) | |
download | opie-1e0e2f57472538bd880967ebe061c8f39a7e270b.zip opie-1e0e2f57472538bd880967ebe061c8f39a7e270b.tar.gz opie-1e0e2f57472538bd880967ebe061c8f39a7e270b.tar.bz2 |
Bugfix: (Bug #0000902) Adding events in weekview shouldn't create them as events on the first day of the week but rather the last visited day.
-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 47 | ||||
-rw-r--r-- | core/pim/datebook/datebookweek.h | 6 | ||||
-rw-r--r-- | core/pim/datebook/datebookweekheaderimpl.cpp | 26 | ||||
-rw-r--r-- | core/pim/datebook/datebookweekheaderimpl.h | 4 | ||||
-rw-r--r-- | core/pim/datebook/datebookweeklst.cpp | 76 | ||||
-rw-r--r-- | core/pim/datebook/datebookweeklst.h | 11 |
6 files changed, 66 insertions, 104 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index 3ae4610..12f57a0 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp | |||
@@ -181,499 +181,498 @@ void DateBookWeekView::alterDay( int day ) | |||
181 | if ( !bOnMonday ) { | 181 | if ( !bOnMonday ) { |
182 | day--; | 182 | day--; |
183 | } | 183 | } |
184 | emit showDay( day ); | 184 | emit showDay( day ); |
185 | } | 185 | } |
186 | 186 | ||
187 | void DateBookWeekView::positionItem( DateBookWeekItem *i ) | 187 | void DateBookWeekView::positionItem( DateBookWeekItem *i ) |
188 | { | 188 | { |
189 | const int Width = 8; | 189 | const int Width = 8; |
190 | const EffectiveEvent ev = i->event(); | 190 | const EffectiveEvent ev = i->event(); |
191 | 191 | ||
192 | // 30 minute intervals | 192 | // 30 minute intervals |
193 | int y = ev.start().hour() * 2; | 193 | int y = ev.start().hour() * 2; |
194 | y += db_round30min( ev.start().minute() ); | 194 | y += db_round30min( ev.start().minute() ); |
195 | int y2 = ev.end().hour() * 2; | 195 | int y2 = ev.end().hour() * 2; |
196 | y2 += db_round30min( ev.end().minute() ); | 196 | y2 += db_round30min( ev.end().minute() ); |
197 | if ( y > 47 ) y = 47; | 197 | if ( y > 47 ) y = 47; |
198 | if ( y2 > 48 ) y2 = 48; | 198 | if ( y2 > 48 ) y2 = 48; |
199 | y = (y * rowHeight) / 2; | 199 | y = (y * rowHeight) / 2; |
200 | y2 = (y2 * rowHeight) / 2; | 200 | y2 = (y2 * rowHeight) / 2; |
201 | 201 | ||
202 | int h; | 202 | int h; |
203 | if ( ev.event().type() == Event::AllDay ) { | 203 | if ( ev.event().type() == Event::AllDay ) { |
204 | h = (48 * rowHeight) / 2; | 204 | h = (48 * rowHeight) / 2; |
205 | y = 0; | 205 | y = 0; |
206 | } else { | 206 | } else { |
207 | h=y2-y; | 207 | h=y2-y; |
208 | if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2; | 208 | if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2; |
209 | } | 209 | } |
210 | 210 | ||
211 | int dow = ev.date().dayOfWeek(); | 211 | int dow = ev.date().dayOfWeek(); |
212 | if ( !bOnMonday ) { | 212 | if ( !bOnMonday ) { |
213 | if ( dow == 7 ) | 213 | if ( dow == 7 ) |
214 | dow = 1; | 214 | dow = 1; |
215 | else | 215 | else |
216 | dow++; | 216 | dow++; |
217 | } | 217 | } |
218 | int x = header->sectionPos( dow ) - 1; | 218 | int x = header->sectionPos( dow ) - 1; |
219 | int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); | 219 | int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); |
220 | DateBookWeekItem *isect = 0; | 220 | DateBookWeekItem *isect = 0; |
221 | do { | 221 | do { |
222 | i->setGeometry( x, y, Width, h ); | 222 | i->setGeometry( x, y, Width, h ); |
223 | isect = intersects( i ); | 223 | isect = intersects( i ); |
224 | x += Width - 1; | 224 | x += Width - 1; |
225 | } while ( isect && x < xlim ); | 225 | } while ( isect && x < xlim ); |
226 | } | 226 | } |
227 | 227 | ||
228 | DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) | 228 | DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) |
229 | { | 229 | { |
230 | QRect geom = item->geometry(); | 230 | QRect geom = item->geometry(); |
231 | 231 | ||
232 | // We allow the edges to overlap | 232 | // We allow the edges to overlap |
233 | geom.moveBy( 1, 1 ); | 233 | geom.moveBy( 1, 1 ); |
234 | geom.setSize( geom.size()-QSize(2,2) ); | 234 | geom.setSize( geom.size()-QSize(2,2) ); |
235 | 235 | ||
236 | QListIterator<DateBookWeekItem> it(items); | 236 | QListIterator<DateBookWeekItem> it(items); |
237 | for ( ; it.current(); ++it ) { | 237 | for ( ; it.current(); ++it ) { |
238 | DateBookWeekItem *i = it.current(); | 238 | DateBookWeekItem *i = it.current(); |
239 | if ( i != item ) { | 239 | if ( i != item ) { |
240 | if ( i->geometry().intersects( geom ) ) { | 240 | if ( i->geometry().intersects( geom ) ) { |
241 | return i; | 241 | return i; |
242 | } | 242 | } |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | return 0; | 246 | return 0; |
247 | } | 247 | } |
248 | 248 | ||
249 | void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) | 249 | void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) |
250 | { | 250 | { |
251 | QListIterator<DateBookWeekItem> it(items); | 251 | QListIterator<DateBookWeekItem> it(items); |
252 | for ( ; it.current(); ++it ) { | 252 | for ( ; it.current(); ++it ) { |
253 | DateBookWeekItem *i = it.current(); | 253 | DateBookWeekItem *i = it.current(); |
254 | if ( i->geometry().contains( e->pos() ) ) { | 254 | if ( i->geometry().contains( e->pos() ) ) { |
255 | showingEvent = true; | 255 | showingEvent = true; |
256 | emit signalShowEvent( i->event() ); | 256 | emit signalShowEvent( i->event() ); |
257 | break; | 257 | break; |
258 | } | 258 | } |
259 | } | 259 | } |
260 | } | 260 | } |
261 | 261 | ||
262 | void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) | 262 | void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) |
263 | { | 263 | { |
264 | if ( showingEvent ) { | 264 | if ( showingEvent ) { |
265 | showingEvent = false; | 265 | showingEvent = false; |
266 | emit signalHideEvent(); | 266 | emit signalHideEvent(); |
267 | } else { | 267 | } else { |
268 | int d = header->sectionAt( e->pos().x() ); | 268 | int d = header->sectionAt( e->pos().x() ); |
269 | if ( d > 0 ) { | 269 | if ( d > 0 ) { |
270 | // if ( !bOnMonday ) | 270 | // if ( !bOnMonday ) |
271 | // d--; | 271 | // d--; |
272 | emit showDay( d ); | 272 | emit showDay( d ); |
273 | } | 273 | } |
274 | } | 274 | } |
275 | } | 275 | } |
276 | 276 | ||
277 | void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) | 277 | void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) |
278 | { | 278 | { |
279 | QRect ur( cx, cy, cw, ch ); | 279 | QRect ur( cx, cy, cw, ch ); |
280 | p->setPen( lightGray ); | 280 | p->setPen( lightGray ); |
281 | for ( int i = 1; i <= 7; i++ ) | 281 | for ( int i = 1; i <= 7; i++ ) |
282 | p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); | 282 | p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); |
283 | 283 | ||
284 | p->setPen( black ); | 284 | p->setPen( black ); |
285 | for ( int t = 0; t < 24; t++ ) { | 285 | for ( int t = 0; t < 24; t++ ) { |
286 | int y = t*rowHeight; | 286 | int y = t*rowHeight; |
287 | if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { | 287 | if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { |
288 | QString s; | 288 | QString s; |
289 | if ( ampm ) { | 289 | if ( ampm ) { |
290 | if ( t == 0 ) | 290 | if ( t == 0 ) |
291 | s = QString::number( 12 ); | 291 | s = QString::number( 12 ); |
292 | else if ( t == 12 ) | 292 | else if ( t == 12 ) |
293 | s = QString::number(12) + tr( "p" ); | 293 | s = QString::number(12) + tr( "p" ); |
294 | else if ( t > 12 ) { | 294 | else if ( t > 12 ) { |
295 | if ( t - 12 < 10 ) | 295 | if ( t - 12 < 10 ) |
296 | s = " "; | 296 | s = " "; |
297 | else | 297 | else |
298 | s = ""; | 298 | s = ""; |
299 | s += QString::number( t - 12 ) + tr("p"); | 299 | s += QString::number( t - 12 ) + tr("p"); |
300 | } else { | 300 | } else { |
301 | if ( 12 - t < 3 ) | 301 | if ( 12 - t < 3 ) |
302 | s = ""; | 302 | s = ""; |
303 | else | 303 | else |
304 | s = " "; | 304 | s = " "; |
305 | s += QString::number( t ); | 305 | s += QString::number( t ); |
306 | } | 306 | } |
307 | } else { | 307 | } else { |
308 | s = QString::number( t ); | 308 | s = QString::number( t ); |
309 | if ( s.length() == 1 ) | 309 | if ( s.length() == 1 ) |
310 | s.prepend( "0" ); | 310 | s.prepend( "0" ); |
311 | } | 311 | } |
312 | p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); | 312 | p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); |
313 | } | 313 | } |
314 | } | 314 | } |
315 | 315 | ||
316 | QListIterator<DateBookWeekItem> it(items); | 316 | QListIterator<DateBookWeekItem> it(items); |
317 | for ( ; it.current(); ++it ) { | 317 | for ( ; it.current(); ++it ) { |
318 | DateBookWeekItem *i = it.current(); | 318 | DateBookWeekItem *i = it.current(); |
319 | if ( i->geometry().intersects( ur ) ) { | 319 | if ( i->geometry().intersects( ur ) ) { |
320 | p->setBrush( i->color() ); | 320 | p->setBrush( i->color() ); |
321 | p->drawRect( i->geometry() ); | 321 | p->drawRect( i->geometry() ); |
322 | } | 322 | } |
323 | } | 323 | } |
324 | } | 324 | } |
325 | 325 | ||
326 | void DateBookWeekView::resizeEvent( QResizeEvent *e ) | 326 | void DateBookWeekView::resizeEvent( QResizeEvent *e ) |
327 | { | 327 | { |
328 | const int hourWidth = 20; | 328 | const int hourWidth = 20; |
329 | QScrollView::resizeEvent( e ); | 329 | QScrollView::resizeEvent( e ); |
330 | int avail = width()-qApp->style().scrollBarExtent().width()-1; | 330 | int avail = width()-qApp->style().scrollBarExtent().width()-1; |
331 | header->setGeometry( 0, 0, avail, header->sizeHint().height() ); | 331 | header->setGeometry( 0, 0, avail, header->sizeHint().height() ); |
332 | setMargins( 0, header->height(), 0, 0 ); | 332 | setMargins( 0, header->height(), 0, 0 ); |
333 | header->resizeSection( 0, hourWidth ); | 333 | header->resizeSection( 0, hourWidth ); |
334 | int sw = (avail - hourWidth) / 7; | 334 | int sw = (avail - hourWidth) / 7; |
335 | for ( int i = 1; i < 7; i++ ) | 335 | for ( int i = 1; i < 7; i++ ) |
336 | header->resizeSection( i, sw ); | 336 | header->resizeSection( i, sw ); |
337 | header->resizeSection( 7, avail - hourWidth - sw*6 ); | 337 | header->resizeSection( 7, avail - hourWidth - sw*6 ); |
338 | } | 338 | } |
339 | 339 | ||
340 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) | 340 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) |
341 | { | 341 | { |
342 | bOnMonday = bStartOnMonday; | 342 | bOnMonday = bStartOnMonday; |
343 | initNames(); | 343 | initNames(); |
344 | } | 344 | } |
345 | 345 | ||
346 | //------------------------------------------------------------------- | 346 | //------------------------------------------------------------------- |
347 | 347 | ||
348 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, | 348 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, |
349 | QWidget *parent, const char *name ) | 349 | QWidget *parent, const char *name ) |
350 | : QWidget( parent, name ), | 350 | : QWidget( parent, name ), |
351 | db( newDB ), | 351 | db( newDB ), |
352 | startTime( 0 ), | 352 | startTime( 0 ), |
353 | ampm( ap ), | 353 | ampm( ap ), |
354 | bStartOnMonday( startOnMonday ) | 354 | bStartOnMonday( startOnMonday ) |
355 | { | 355 | { |
356 | setFocusPolicy(StrongFocus); | 356 | setFocusPolicy(StrongFocus); |
357 | QVBoxLayout *vb = new QVBoxLayout( this ); | 357 | QVBoxLayout *vb = new QVBoxLayout( this ); |
358 | header = new DateBookWeekHeader( bStartOnMonday, this ); | 358 | header = new DateBookWeekHeader( bStartOnMonday, this ); |
359 | view = new DateBookWeekView( ampm, startOnMonday, this ); | 359 | view = new DateBookWeekView( ampm, startOnMonday, this ); |
360 | vb->addWidget( header ); | 360 | vb->addWidget( header ); |
361 | vb->addWidget( view ); | 361 | vb->addWidget( view ); |
362 | 362 | ||
363 | lblDesc = new QLabel( this, "event label" ); | 363 | lblDesc = new QLabel( this, "event label" ); |
364 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); | 364 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); |
365 | lblDesc->setBackgroundColor( yellow ); | 365 | lblDesc->setBackgroundColor( yellow ); |
366 | lblDesc->hide(); | 366 | lblDesc->hide(); |
367 | 367 | ||
368 | tHide = new QTimer( this ); | 368 | tHide = new QTimer( this ); |
369 | 369 | ||
370 | connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); | 370 | connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); |
371 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); | 371 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); |
372 | connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); | 372 | connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); |
373 | connect( header, SIGNAL( dateChanged( int, int ) ), this, SLOT( dateChanged( int, int ) ) ); | 373 | connect( header, SIGNAL( dateChanged( QDate &) ), this, SLOT( dateChanged( QDate &) ) ); |
374 | connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); | 374 | connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); |
375 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); | 375 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); |
376 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); | 376 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); |
377 | setDate(QDate::currentDate()); | 377 | setDate(QDate::currentDate()); |
378 | } | 378 | } |
379 | 379 | ||
380 | void DateBookWeek::keyPressEvent(QKeyEvent *e) | 380 | void DateBookWeek::keyPressEvent(QKeyEvent *e) |
381 | { | 381 | { |
382 | switch(e->key()) { | 382 | switch(e->key()) { |
383 | case Key_Up: | 383 | case Key_Up: |
384 | view->scrollBy(0, -20); | 384 | view->scrollBy(0, -20); |
385 | break; | 385 | break; |
386 | case Key_Down: | 386 | case Key_Down: |
387 | view->scrollBy(0, 20); | 387 | view->scrollBy(0, 20); |
388 | break; | 388 | break; |
389 | case Key_Left: | 389 | case Key_Left: |
390 | setDate(date().addDays(-7)); | 390 | setDate(date().addDays(-7)); |
391 | break; | 391 | break; |
392 | case Key_Right: | 392 | case Key_Right: |
393 | setDate(date().addDays(7)); | 393 | setDate(date().addDays(7)); |
394 | break; | 394 | break; |
395 | default: | 395 | default: |
396 | e->ignore(); | 396 | e->ignore(); |
397 | } | 397 | } |
398 | } | 398 | } |
399 | 399 | ||
400 | void DateBookWeek::showDay( int day ) | 400 | void DateBookWeek::showDay( int day ) |
401 | { | 401 | { |
402 | QDate d; | 402 | QDate d=bdate; |
403 | d = dateFromWeek( _week, year, bStartOnMonday ); | 403 | |
404 | // Calculate offset to first day of week. | ||
405 | int dayoffset=d.dayOfWeek(); | ||
406 | if(bStartOnMonday) dayoffset--; | ||
407 | |||
404 | day--; | 408 | day--; |
405 | d = d.addDays( day ); | 409 | d=d.addDays(day-dayoffset); |
406 | emit showDate( d.year(), d.month(), d.day() ); | 410 | emit showDate( d.year(), d.month(), d.day() ); |
411 | qDebug("%4d-%02d-%02d / Day %d\n",d.year(),d.month(),d.day(),day); | ||
407 | } | 412 | } |
408 | 413 | ||
409 | void DateBookWeek::setDate( int y, int m, int d ) | 414 | void DateBookWeek::setDate( int y, int m, int d ) |
410 | { | 415 | { |
411 | setDate(QDate(y, m, d)); | 416 | setDate(QDate(y, m, d)); |
412 | } | 417 | } |
413 | 418 | ||
414 | void DateBookWeek::setDate(QDate date) | 419 | void DateBookWeek::setDate(QDate newdate) |
415 | { | 420 | { |
416 | dow = date.dayOfWeek(); | 421 | bdate=newdate; |
417 | int w, y; | 422 | dow = newdate.dayOfWeek(); |
418 | calcWeek( date, w, y, bStartOnMonday ); | 423 | header->setDate( newdate ); |
419 | header->setDate( date ); | ||
420 | } | 424 | } |
421 | 425 | ||
422 | void DateBookWeek::dateChanged( int y, int w ) | 426 | void DateBookWeek::dateChanged( QDate &newdate ) |
423 | { | 427 | { |
424 | year = y; | 428 | bdate=newdate; |
425 | _week = w; | ||
426 | getEvents(); | 429 | getEvents(); |
427 | } | 430 | } |
428 | 431 | ||
429 | QDate DateBookWeek::date() const | 432 | QDate DateBookWeek::date() const |
430 | { | 433 | { |
431 | QDate d; | 434 | return bdate; |
432 | d = dateFromWeek( _week - 1, year, bStartOnMonday ); | ||
433 | if ( bStartOnMonday ) | ||
434 | d = d.addDays( 7 + dow - 1 ); | ||
435 | else { | ||
436 | if ( dow == 7 ) | ||
437 | d = d.addDays( dow ); | ||
438 | else | ||
439 | d = d.addDays( 7 + dow ); | ||
440 | } | ||
441 | return d; | ||
442 | } | 435 | } |
443 | 436 | ||
444 | void DateBookWeek::getEvents() | 437 | void DateBookWeek::getEvents() |
445 | { | 438 | { |
446 | QDate startWeek = weekDate(); | 439 | QDate startWeek = weekDate(); |
447 | 440 | ||
448 | QDate endWeek = startWeek.addDays( 6 ); | 441 | QDate endWeek = startWeek.addDays( 6 ); |
449 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); | 442 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); |
450 | view->showEvents( eventList ); | 443 | view->showEvents( eventList ); |
451 | view->moveToHour( startTime ); | 444 | view->moveToHour( startTime ); |
452 | } | 445 | } |
453 | 446 | ||
454 | void DateBookWeek::generateAllDayTooltext( QString& text ) { | 447 | void DateBookWeek::generateAllDayTooltext( QString& text ) { |
455 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; | 448 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; |
456 | } | 449 | } |
457 | 450 | ||
458 | void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { | 451 | void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { |
459 | str += "<b>" + QObject::tr("Start") + "</b>: "; | 452 | str += "<b>" + QObject::tr("Start") + "</b>: "; |
460 | str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); | 453 | str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); |
461 | if( ev.startDate()!=ev.endDate() ) { | 454 | if( ev.startDate()!=ev.endDate() ) { |
462 | str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; | 455 | str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; |
463 | } | 456 | } |
464 | str += "<br>"; | 457 | str += "<br>"; |
465 | str += "<b>" + QObject::tr("End") + "</b>: "; | 458 | str += "<b>" + QObject::tr("End") + "</b>: "; |
466 | str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); | 459 | str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); |
467 | if( ev.startDate()!=ev.endDate() ) { | 460 | if( ev.startDate()!=ev.endDate() ) { |
468 | str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; | 461 | str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; |
469 | } | 462 | } |
470 | } | 463 | } |
471 | 464 | ||
472 | void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) | 465 | void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) |
473 | { | 466 | { |
474 | if ( tHide->isActive() ) | 467 | if ( tHide->isActive() ) |
475 | tHide->stop(); | 468 | tHide->stop(); |
476 | 469 | ||
477 | // why would someone use "<"? Oh well, fix it up... | 470 | // why would someone use "<"? Oh well, fix it up... |
478 | // I wonder what other things may be messed up... | 471 | // I wonder what other things may be messed up... |
479 | QString strDesc = ev.description(); | 472 | QString strDesc = ev.description(); |
480 | int where = strDesc.find( "<" ); | 473 | int where = strDesc.find( "<" ); |
481 | while ( where != -1 ) { | 474 | while ( where != -1 ) { |
482 | strDesc.remove( where, 1 ); | 475 | strDesc.remove( where, 1 ); |
483 | strDesc.insert( where, "<" ); | 476 | strDesc.insert( where, "<" ); |
484 | where = strDesc.find( "<", where ); | 477 | where = strDesc.find( "<", where ); |
485 | } | 478 | } |
486 | 479 | ||
487 | QString strCat; | 480 | QString strCat; |
488 | // ### FIX later... | 481 | // ### FIX later... |
489 | // QString strCat = ev.category(); | 482 | // QString strCat = ev.category(); |
490 | // where = strCat.find( "<" ); | 483 | // where = strCat.find( "<" ); |
491 | // while ( where != -1 ) { | 484 | // while ( where != -1 ) { |
492 | // strCat.remove( where, 1 ); | 485 | // strCat.remove( where, 1 ); |
493 | // strCat.insert( where, "<" ); | 486 | // strCat.insert( where, "<" ); |
494 | // where = strCat.find( "<", where ); | 487 | // where = strCat.find( "<", where ); |
495 | // } | 488 | // } |
496 | 489 | ||
497 | QString strLocation = ev.location(); | 490 | QString strLocation = ev.location(); |
498 | while ( where != -1 ) { | 491 | while ( where != -1 ) { |
499 | strLocation.remove( where, 1 ); | 492 | strLocation.remove( where, 1 ); |
500 | strLocation.insert( where, "<" ); | 493 | strLocation.insert( where, "<" ); |
501 | where = strLocation.find( "<", where ); | 494 | where = strLocation.find( "<", where ); |
502 | } | 495 | } |
503 | 496 | ||
504 | QString strNote = ev.notes(); | 497 | QString strNote = ev.notes(); |
505 | where = strNote.find( "<" ); | 498 | where = strNote.find( "<" ); |
506 | while ( where != -1 ) { | 499 | while ( where != -1 ) { |
507 | strNote.remove( where, 1 ); | 500 | strNote.remove( where, 1 ); |
508 | strNote.insert( where, "<" ); | 501 | strNote.insert( where, "<" ); |
509 | where = strNote.find( "<", where ); | 502 | where = strNote.find( "<", where ); |
510 | } | 503 | } |
511 | 504 | ||
512 | QString str = "<b>" + strDesc + "</b><br>" | 505 | QString str = "<b>" + strDesc + "</b><br>" |
513 | + strLocation + "<br>" | 506 | + strLocation + "<br>" |
514 | + "<i>" + strCat + "</i>" | 507 | + "<i>" + strCat + "</i>" |
515 | + "<br>" + TimeString::longDateString( ev.date() ) | 508 | + "<br>" + TimeString::longDateString( ev.date() ) |
516 | + "<br>"; | 509 | + "<br>"; |
517 | 510 | ||
518 | if (ev.event().type() == Event::Normal ) | 511 | if (ev.event().type() == Event::Normal ) |
519 | generateNormalTooltext( str, ev ); | 512 | generateNormalTooltext( str, ev ); |
520 | else | 513 | else |
521 | generateAllDayTooltext( str ); | 514 | generateAllDayTooltext( str ); |
522 | 515 | ||
523 | str += "<br><br>" + strNote; | 516 | str += "<br><br>" + strNote; |
524 | 517 | ||
525 | lblDesc->setText( str ); | 518 | lblDesc->setText( str ); |
526 | lblDesc->resize( lblDesc->sizeHint() ); | 519 | lblDesc->resize( lblDesc->sizeHint() ); |
527 | // move the label so it is "centerd" horizontally... | 520 | // move the label so it is "centerd" horizontally... |
528 | lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 ); | 521 | lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 ); |
529 | lblDesc->show(); | 522 | lblDesc->show(); |
530 | } | 523 | } |
531 | 524 | ||
532 | void DateBookWeek::slotHideEvent() | 525 | void DateBookWeek::slotHideEvent() |
533 | { | 526 | { |
534 | tHide->start( 2000, true ); | 527 | tHide->start( 2000, true ); |
535 | } | 528 | } |
536 | 529 | ||
537 | void DateBookWeek::setStartViewTime( int startHere ) | 530 | void DateBookWeek::setStartViewTime( int startHere ) |
538 | { | 531 | { |
539 | startTime = startHere; | 532 | startTime = startHere; |
540 | view->moveToHour( startTime ); | 533 | view->moveToHour( startTime ); |
541 | } | 534 | } |
542 | 535 | ||
543 | int DateBookWeek::startViewTime() const | 536 | int DateBookWeek::startViewTime() const |
544 | { | 537 | { |
545 | return startTime; | 538 | return startTime; |
546 | } | 539 | } |
547 | 540 | ||
548 | void DateBookWeek::redraw() | 541 | void DateBookWeek::redraw() |
549 | { | 542 | { |
550 | getEvents(); | 543 | getEvents(); |
551 | } | 544 | } |
552 | 545 | ||
553 | void DateBookWeek::slotYearChanged( int y ) | 546 | void DateBookWeek::slotYearChanged( int y ) |
554 | { | 547 | { |
555 | int totWeek; | 548 | int totWeek; |
556 | QDate d( y, 12, 31 ); | 549 | QDate d( y, 12, 31 ); |
557 | int throwAway; | 550 | int throwAway; |
558 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); | 551 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); |
559 | while ( totWeek == 1 ) { | 552 | while ( totWeek == 1 ) { |
560 | d = d.addDays( -1 ); | 553 | d = d.addDays( -1 ); |
561 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); | 554 | calcWeek( d, totWeek, throwAway, bStartOnMonday ); |
562 | } | 555 | } |
563 | } | 556 | } |
564 | 557 | ||
565 | void DateBookWeek::slotWeekChanged( bool onMonday ) | 558 | void DateBookWeek::slotWeekChanged( bool onMonday ) |
566 | { | 559 | { |
567 | bStartOnMonday = onMonday; | 560 | bStartOnMonday = onMonday; |
568 | view->setStartOfWeek( bStartOnMonday ); | 561 | view->setStartOfWeek( bStartOnMonday ); |
569 | header->setStartOfWeek( bStartOnMonday ); | 562 | header->setStartOfWeek( bStartOnMonday ); |
570 | redraw(); | 563 | redraw(); |
571 | } | 564 | } |
572 | 565 | ||
573 | void DateBookWeek::slotClockChanged( bool ap ) | 566 | void DateBookWeek::slotClockChanged( bool ap ) |
574 | { | 567 | { |
575 | ampm = ap; | 568 | ampm = ap; |
576 | } | 569 | } |
577 | 570 | ||
578 | // return the date at the beginning of the week... | 571 | // return the date at the beginning of the week... |
579 | QDate DateBookWeek::weekDate() const | 572 | QDate DateBookWeek::weekDate() const |
580 | { | 573 | { |
581 | return dateFromWeek( _week, year, bStartOnMonday ); | 574 | QDate d=bdate; |
575 | |||
576 | // Calculate offset to first day of week. | ||
577 | int dayoffset=d.dayOfWeek(); | ||
578 | if(bStartOnMonday) dayoffset--; | ||
579 | |||
580 | return d.addDays(-dayoffset); | ||
582 | } | 581 | } |
583 | 582 | ||
584 | // this used to only be needed by datebook.cpp, but now we need it inside | 583 | // this used to only be needed by datebook.cpp, but now we need it inside |
585 | // week view since | 584 | // week view since |
586 | // we need to be able to figure out our total number of weeks on the fly... | 585 | // we need to be able to figure out our total number of weeks on the fly... |
587 | // this is probably the best place to put it.. | 586 | // this is probably the best place to put it.. |
588 | 587 | ||
589 | // For Weeks that start on Monday... (EASY!) | 588 | // For Weeks that start on Monday... (EASY!) |
590 | // At the moment we will use ISO 8601 method for computing | 589 | // At the moment we will use ISO 8601 method for computing |
591 | // the week. Granted, other countries use other methods, | 590 | // the week. Granted, other countries use other methods, |
592 | // bet we aren't doing any Locale stuff at the moment. So, | 591 | // bet we aren't doing any Locale stuff at the moment. So, |
593 | // this should pass. This Algorithim is public domain and | 592 | // this should pass. This Algorithim is public domain and |
594 | // available at: | 593 | // available at: |
595 | // http://personal.ecu.edu/mccartyr/ISOwdALG.txt | 594 | // http://personal.ecu.edu/mccartyr/ISOwdALG.txt |
596 | // the week number is return, and the year number is returned in year | 595 | // the week number is return, and the year number is returned in year |
597 | // for Instance 2001/12/31 is actually the first week in 2002. | 596 | // for Instance 2001/12/31 is actually the first week in 2002. |
598 | // There is a more mathematical definition, but I will implement it when | 597 | // There is a more mathematical definition, but I will implement it when |
599 | // we are pass our deadline. | 598 | // we are pass our deadline. |
600 | 599 | ||
601 | // For Weeks that start on Sunday... (ahh... home rolled) | 600 | // For Weeks that start on Sunday... (ahh... home rolled) |
602 | // okay, if Jan 1 is on Friday or Saturday, | 601 | // okay, if Jan 1 is on Friday or Saturday, |
603 | // it will go to the pervious | 602 | // it will go to the pervious |
604 | // week... | 603 | // week... |
605 | 604 | ||
606 | bool calcWeek( const QDate &d, int &week, int &year, | 605 | bool calcWeek( const QDate &d, int &week, int &year, |
607 | bool startOnMonday ) | 606 | bool startOnMonday ) |
608 | { | 607 | { |
609 | int weekNumber; | 608 | int weekNumber; |
610 | int yearNumber; | 609 | int yearNumber; |
611 | 610 | ||
612 | // remove a pesky warning, (Optimizations on g++) | 611 | // remove a pesky warning, (Optimizations on g++) |
613 | weekNumber = -1; | 612 | weekNumber = -1; |
614 | int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); | 613 | int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); |
615 | int dayOfWeek = d.dayOfWeek(); | 614 | int dayOfWeek = d.dayOfWeek(); |
616 | 615 | ||
617 | if ( !d.isValid() ) | 616 | if ( !d.isValid() ) |
618 | return false; | 617 | return false; |
619 | 618 | ||
620 | if ( startOnMonday ) { | 619 | if ( startOnMonday ) { |
621 | // find the Jan1Weekday; | 620 | // find the Jan1Weekday; |
622 | if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { | 621 | if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { |
623 | yearNumber = d.year() - 1; | 622 | yearNumber = d.year() - 1; |
624 | if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) | 623 | if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) |
625 | weekNumber = 53; | 624 | weekNumber = 53; |
626 | else | 625 | else |
627 | weekNumber = 52; | 626 | weekNumber = 52; |
628 | } else | 627 | } else |
629 | yearNumber = d.year(); | 628 | yearNumber = d.year(); |
630 | if ( yearNumber == d.year() ) { | 629 | if ( yearNumber == d.year() ) { |
631 | int totalDays = 365; | 630 | int totalDays = 365; |
632 | if ( QDate::leapYear(yearNumber) ) | 631 | if ( QDate::leapYear(yearNumber) ) |
633 | totalDays++; | 632 | totalDays++; |
634 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) | 633 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) |
635 | || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { | 634 | || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { |
636 | yearNumber++; | 635 | yearNumber++; |
637 | weekNumber = 1; | 636 | weekNumber = 1; |
638 | } | 637 | } |
639 | } | 638 | } |
640 | if ( yearNumber == d.year() ) { | 639 | if ( yearNumber == d.year() ) { |
641 | int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); | 640 | int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); |
642 | weekNumber = j / 7; | 641 | weekNumber = j / 7; |
643 | if ( jan1WeekDay > 4 ) | 642 | if ( jan1WeekDay > 4 ) |
644 | weekNumber--; | 643 | weekNumber--; |
645 | } | 644 | } |
646 | } else { | 645 | } else { |
647 | // it's better to keep these cases separate... | 646 | // it's better to keep these cases separate... |
648 | if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 | 647 | if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 |
649 | && jan1WeekDay != 7 ) { | 648 | && jan1WeekDay != 7 ) { |
650 | yearNumber = d.year() - 1; | 649 | yearNumber = d.year() - 1; |
651 | if ( jan1WeekDay == 6 | 650 | if ( jan1WeekDay == 6 |
652 | || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { | 651 | || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { |
653 | weekNumber = 53; | 652 | weekNumber = 53; |
654 | }else | 653 | }else |
655 | weekNumber = 52; | 654 | weekNumber = 52; |
656 | } else | 655 | } else |
657 | yearNumber = d.year(); | 656 | yearNumber = d.year(); |
658 | if ( yearNumber == d.year() ) { | 657 | if ( yearNumber == d.year() ) { |
659 | int totalDays = 365; | 658 | int totalDays = 365; |
660 | if ( QDate::leapYear( yearNumber ) ) | 659 | if ( QDate::leapYear( yearNumber ) ) |
661 | totalDays++; | 660 | totalDays++; |
662 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { | 661 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { |
663 | yearNumber++; | 662 | yearNumber++; |
664 | weekNumber = 1; | 663 | weekNumber = 1; |
665 | } | 664 | } |
666 | } | 665 | } |
667 | if ( yearNumber == d.year() ) { | 666 | if ( yearNumber == d.year() ) { |
668 | int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); | 667 | int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); |
669 | weekNumber = j / 7; | 668 | weekNumber = j / 7; |
670 | if ( jan1WeekDay > 4 ) { | 669 | if ( jan1WeekDay > 4 ) { |
671 | weekNumber--; | 670 | weekNumber--; |
672 | } | 671 | } |
673 | } | 672 | } |
674 | } | 673 | } |
675 | year = yearNumber; | 674 | year = yearNumber; |
676 | week = weekNumber; | 675 | week = weekNumber; |
677 | return true; | 676 | return true; |
678 | } | 677 | } |
679 | 678 | ||
diff --git a/core/pim/datebook/datebookweek.h b/core/pim/datebook/datebookweek.h index 8c5e06d..c273e30 100644 --- a/core/pim/datebook/datebookweek.h +++ b/core/pim/datebook/datebookweek.h | |||
@@ -1,166 +1,166 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef DATEBOOKWEEK | 20 | #ifndef DATEBOOKWEEK |
21 | #define DATEBOOKWEEK | 21 | #define DATEBOOKWEEK |
22 | 22 | ||
23 | #include <qpe/event.h> | 23 | #include <qpe/event.h> |
24 | 24 | ||
25 | #include <qlist.h> | 25 | #include <qlist.h> |
26 | #include <qscrollview.h> | 26 | #include <qscrollview.h> |
27 | #include <qstring.h> | 27 | #include <qstring.h> |
28 | #include <qvaluelist.h> | 28 | #include <qvaluelist.h> |
29 | 29 | ||
30 | class DateBookDB; | 30 | class DateBookDB; |
31 | class DateBookWeekHeader; | 31 | class DateBookWeekHeader; |
32 | class QDate; | 32 | class QDate; |
33 | class QLabel; | 33 | class QLabel; |
34 | class QResizeEvent; | 34 | class QResizeEvent; |
35 | class QSpinBox; | 35 | class QSpinBox; |
36 | class QTimer; | 36 | class QTimer; |
37 | class QHeader; | 37 | class QHeader; |
38 | 38 | ||
39 | class DateBookWeekItem | 39 | class DateBookWeekItem |
40 | { | 40 | { |
41 | public: | 41 | public: |
42 | DateBookWeekItem( const EffectiveEvent e ); | 42 | DateBookWeekItem( const EffectiveEvent e ); |
43 | 43 | ||
44 | void setGeometry( int x, int y, int w, int h ); | 44 | void setGeometry( int x, int y, int w, int h ); |
45 | QRect geometry() const { return r; } | 45 | QRect geometry() const { return r; } |
46 | 46 | ||
47 | const QColor &color() const { return c; } | 47 | const QColor &color() const { return c; } |
48 | const EffectiveEvent event() const { return ev; } | 48 | const EffectiveEvent event() const { return ev; } |
49 | 49 | ||
50 | private: | 50 | private: |
51 | const EffectiveEvent ev; | 51 | const EffectiveEvent ev; |
52 | QRect r; | 52 | QRect r; |
53 | QColor c; | 53 | QColor c; |
54 | }; | 54 | }; |
55 | 55 | ||
56 | class DateBookWeekView : public QScrollView | 56 | class DateBookWeekView : public QScrollView |
57 | { | 57 | { |
58 | Q_OBJECT | 58 | Q_OBJECT |
59 | public: | 59 | public: |
60 | DateBookWeekView( bool ampm, bool weekOnMonday, QWidget *parent = 0, | 60 | DateBookWeekView( bool ampm, bool weekOnMonday, QWidget *parent = 0, |
61 | const char *name = 0 ); | 61 | const char *name = 0 ); |
62 | 62 | ||
63 | bool whichClock() const; | 63 | bool whichClock() const; |
64 | void showEvents( QValueList<EffectiveEvent> &ev ); | 64 | void showEvents( QValueList<EffectiveEvent> &ev ); |
65 | void moveToHour( int h ); | 65 | void moveToHour( int h ); |
66 | void setStartOfWeek( bool bOnMonday ); | 66 | void setStartOfWeek( bool bOnMonday ); |
67 | 67 | ||
68 | signals: | 68 | signals: |
69 | void showDay( int d ); | 69 | void showDay( int d ); |
70 | void signalShowEvent( const EffectiveEvent & ); | 70 | void signalShowEvent( const EffectiveEvent & ); |
71 | void signalHideEvent(); | 71 | void signalHideEvent(); |
72 | 72 | ||
73 | protected slots: | 73 | protected slots: |
74 | void keyPressEvent(QKeyEvent *); | 74 | void keyPressEvent(QKeyEvent *); |
75 | 75 | ||
76 | private slots: | 76 | private slots: |
77 | void slotChangeClock( bool ); | 77 | void slotChangeClock( bool ); |
78 | void alterDay( int ); | 78 | void alterDay( int ); |
79 | 79 | ||
80 | private: | 80 | private: |
81 | void positionItem( DateBookWeekItem *i ); | 81 | void positionItem( DateBookWeekItem *i ); |
82 | DateBookWeekItem *intersects( const DateBookWeekItem * ); | 82 | DateBookWeekItem *intersects( const DateBookWeekItem * ); |
83 | void drawContents( QPainter *p, int cx, int cy, int cw, int ch ); | 83 | void drawContents( QPainter *p, int cx, int cy, int cw, int ch ); |
84 | void contentsMousePressEvent( QMouseEvent * ); | 84 | void contentsMousePressEvent( QMouseEvent * ); |
85 | void contentsMouseReleaseEvent( QMouseEvent * ); | 85 | void contentsMouseReleaseEvent( QMouseEvent * ); |
86 | void resizeEvent( QResizeEvent * ); | 86 | void resizeEvent( QResizeEvent * ); |
87 | void initNames(); | 87 | void initNames(); |
88 | 88 | ||
89 | private: | 89 | private: |
90 | bool ampm; | 90 | bool ampm; |
91 | bool bOnMonday; | 91 | bool bOnMonday; |
92 | QHeader *header; | 92 | QHeader *header; |
93 | QList<DateBookWeekItem> items; | 93 | QList<DateBookWeekItem> items; |
94 | int rowHeight; | 94 | int rowHeight; |
95 | bool showingEvent; | 95 | bool showingEvent; |
96 | }; | 96 | }; |
97 | 97 | ||
98 | class DateBookWeek : public QWidget | 98 | class DateBookWeek : public QWidget |
99 | { | 99 | { |
100 | Q_OBJECT | 100 | Q_OBJECT |
101 | 101 | ||
102 | public: | 102 | public: |
103 | DateBookWeek( bool ampm, bool weekOnMonday, DateBookDB *newDB, | 103 | DateBookWeek( bool ampm, bool weekOnMonday, DateBookDB *newDB, |
104 | QWidget *parent = 0, const char *name = 0 ); | 104 | QWidget *parent = 0, const char *name = 0 ); |
105 | void setDate( int y, int m, int d ); | 105 | void setDate( int y, int m, int d ); |
106 | void setDate( QDate d ); | 106 | void setDate( QDate d ); |
107 | QDate date() const; | 107 | QDate date() const; |
108 | DateBookWeekView *weekView() const { return view; } | 108 | DateBookWeekView *weekView() const { return view; } |
109 | void setStartViewTime( int startHere ); | 109 | void setStartViewTime( int startHere ); |
110 | int startViewTime() const; | 110 | int startViewTime() const; |
111 | int week() const { return _week; }; | 111 | int week() const { return _week; }; |
112 | QDate weekDate() const; | 112 | QDate weekDate() const; |
113 | 113 | ||
114 | public slots: | 114 | public slots: |
115 | void redraw(); | 115 | void redraw(); |
116 | void slotWeekChanged( bool bStartOnMonday ); | 116 | void slotWeekChanged( bool bStartOnMonday ); |
117 | void slotClockChanged( bool a ); | 117 | void slotClockChanged( bool a ); |
118 | 118 | ||
119 | signals: | 119 | signals: |
120 | void showDate( int y, int m, int d ); | 120 | void showDate( int y, int m, int d ); |
121 | 121 | ||
122 | protected slots: | 122 | protected slots: |
123 | void keyPressEvent(QKeyEvent *); | 123 | void keyPressEvent(QKeyEvent *); |
124 | 124 | ||
125 | private slots: | 125 | private slots: |
126 | void showDay( int day ); | 126 | void showDay( int day ); |
127 | void dateChanged( int y, int w ); | 127 | void dateChanged( QDate &newdate ); |
128 | void slotShowEvent( const EffectiveEvent & ); | 128 | void slotShowEvent( const EffectiveEvent & ); |
129 | void slotHideEvent(); | 129 | void slotHideEvent(); |
130 | void slotYearChanged( int ); | 130 | void slotYearChanged( int ); |
131 | 131 | ||
132 | private: | 132 | private: |
133 | void getEvents(); | 133 | void getEvents(); |
134 | 134 | ||
135 | /** | 135 | /** |
136 | * Wow that's a hell lot of code duplication | 136 | * Wow that's a hell lot of code duplication |
137 | * in datebook. I vote for a common base class | 137 | * in datebook. I vote for a common base class |
138 | * but never the less. This add a note | 138 | * but never the less. This add a note |
139 | * that the Event is an all day event | 139 | * that the Event is an all day event |
140 | * | 140 | * |
141 | */ | 141 | */ |
142 | void generateAllDayTooltext( QString& text ); | 142 | void generateAllDayTooltext( QString& text ); |
143 | 143 | ||
144 | /** | 144 | /** |
145 | * This will add the times to the text | 145 | * This will add the times to the text |
146 | * It will be shown in the Tooltip bubble | 146 | * It will be shown in the Tooltip bubble |
147 | */ | 147 | */ |
148 | void generateNormalTooltext( QString& text, | 148 | void generateNormalTooltext( QString& text, |
149 | const EffectiveEvent &ev); | 149 | const EffectiveEvent &ev); |
150 | int year; | 150 | int year; |
151 | int _week; | 151 | int _week; |
152 | int dow; | 152 | int dow; |
153 | QDate bdate; | ||
153 | DateBookWeekHeader *header; | 154 | DateBookWeekHeader *header; |
154 | DateBookWeekView *view; | 155 | DateBookWeekView *view; |
155 | DateBookDB *db; | 156 | DateBookDB *db; |
156 | QLabel *lblDesc; | 157 | QLabel *lblDesc; |
157 | QTimer *tHide; | 158 | QTimer *tHide; |
158 | int startTime; | 159 | int startTime; |
159 | bool ampm; | 160 | bool ampm; |
160 | bool bStartOnMonday; | 161 | bool bStartOnMonday; |
161 | }; | 162 | }; |
162 | 163 | ||
163 | 164 | ||
164 | bool calcWeek( const QDate &d, int &week, int &year, | 165 | bool calcWeek( const QDate &d, int &week, int &year, bool startOnMonday = false ); |
165 | bool startOnMonday = false ); | ||
166 | #endif | 166 | #endif |
diff --git a/core/pim/datebook/datebookweekheaderimpl.cpp b/core/pim/datebook/datebookweekheaderimpl.cpp index fd792e2..ff7626f 100644 --- a/core/pim/datebook/datebookweekheaderimpl.cpp +++ b/core/pim/datebook/datebookweekheaderimpl.cpp | |||
@@ -1,139 +1,115 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "datebookweekheaderimpl.h" | 20 | #include "datebookweekheaderimpl.h" |
21 | #include "datebookweekheader.h" | 21 | #include "datebookweekheader.h" |
22 | #include "datebookweek.h" | 22 | #include "datebookweek.h" |
23 | #include <qlabel.h> | 23 | #include <qlabel.h> |
24 | #include <qspinbox.h> | 24 | #include <qspinbox.h> |
25 | #include <qdatetime.h> | 25 | #include <qdatetime.h> |
26 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
27 | #include <qpe/datebookmonth.h> | 27 | #include <qpe/datebookmonth.h> |
28 | 28 | ||
29 | #include <qtoolbutton.h> | 29 | #include <qtoolbutton.h> |
30 | 30 | ||
31 | /* | 31 | /* |
32 | * Constructs a DateBookWeekHeader which is a child of 'parent', with the | 32 | * Constructs a DateBookWeekHeader which is a child of 'parent', with the |
33 | * name 'name' and widget flags set to 'f' | 33 | * name 'name' and widget flags set to 'f' |
34 | */ | 34 | */ |
35 | DateBookWeekHeader::DateBookWeekHeader( bool startOnMonday, QWidget* parent, const char* name, WFlags fl ) | 35 | DateBookWeekHeader::DateBookWeekHeader( bool startOnMonday, QWidget* parent, const char* name, WFlags fl ) |
36 | : DateBookWeekHeaderBase( parent, name, fl ), | 36 | : DateBookWeekHeaderBase( parent, name, fl ), |
37 | bStartOnMonday( startOnMonday ) | 37 | bStartOnMonday( startOnMonday ) |
38 | { | 38 | { |
39 | setBackgroundMode( PaletteButton ); | 39 | setBackgroundMode( PaletteButton ); |
40 | labelDate->setBackgroundMode( PaletteButton ); | 40 | labelDate->setBackgroundMode( PaletteButton ); |
41 | backmonth->setPixmap( Resource::loadPixmap("fastback") ); | 41 | backmonth->setPixmap( Resource::loadPixmap("fastback") ); |
42 | backweek->setPixmap( Resource::loadPixmap("back") ); | 42 | backweek->setPixmap( Resource::loadPixmap("back") ); |
43 | forwardweek->setPixmap( Resource::loadPixmap("forward") ); | 43 | forwardweek->setPixmap( Resource::loadPixmap("forward") ); |
44 | forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); | 44 | forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); |
45 | } | 45 | } |
46 | 46 | ||
47 | /* | 47 | /* |
48 | * Destroys the object and frees any allocated resources | 48 | * Destroys the object and frees any allocated resources |
49 | */ | 49 | */ |
50 | DateBookWeekHeader::~DateBookWeekHeader() | 50 | DateBookWeekHeader::~DateBookWeekHeader() |
51 | { | 51 | { |
52 | // no need to delete child widgets, Qt does it all for us | 52 | // no need to delete child widgets, Qt does it all for us |
53 | } | 53 | } |
54 | 54 | ||
55 | void DateBookWeekHeader::pickDate() | 55 | void DateBookWeekHeader::pickDate() |
56 | { | 56 | { |
57 | static QPopupMenu *m1 = 0; | 57 | static QPopupMenu *m1 = 0; |
58 | static DateBookMonth *picker = 0; | 58 | static DateBookMonth *picker = 0; |
59 | if ( !m1 ) { | 59 | if ( !m1 ) { |
60 | m1 = new QPopupMenu( this ); | 60 | m1 = new QPopupMenu( this ); |
61 | picker = new DateBookMonth( m1, 0, TRUE ); | 61 | picker = new DateBookMonth( m1, 0, TRUE ); |
62 | m1->insertItem( picker ); | 62 | m1->insertItem( picker ); |
63 | connect( picker, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( setDate( int, int, int ) ) ); | 63 | connect( picker, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( setDate( int, int, int ) ) ); |
64 | // connect( m1, SIGNAL( aboutToHide() ), this, SLOT( gotHide() ) ); | 64 | // connect( m1, SIGNAL( aboutToHide() ), this, SLOT( gotHide() ) ); |
65 | } | 65 | } |
66 | picker->setDate( date.year(), date.month(), date.day() ); | 66 | picker->setDate( date.year(), date.month(), date.day() ); |
67 | m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); | 67 | m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); |
68 | picker->setFocus(); | 68 | picker->setFocus(); |
69 | } | 69 | } |
70 | 70 | ||
71 | void DateBookWeekHeader::nextMonth() | 71 | void DateBookWeekHeader::nextMonth() |
72 | { | 72 | { |
73 | setDate(date.addDays(28)); | 73 | setDate(date.addDays(28)); |
74 | } | 74 | } |
75 | void DateBookWeekHeader::prevMonth() | 75 | void DateBookWeekHeader::prevMonth() |
76 | { | 76 | { |
77 | setDate(date.addDays(-28)); | 77 | setDate(date.addDays(-28)); |
78 | } | 78 | } |
79 | void DateBookWeekHeader::nextWeek() | 79 | void DateBookWeekHeader::nextWeek() |
80 | { | 80 | { |
81 | setDate(date.addDays(7)); | 81 | setDate(date.addDays(7)); |
82 | } | 82 | } |
83 | void DateBookWeekHeader::prevWeek() | 83 | void DateBookWeekHeader::prevWeek() |
84 | { | 84 | { |
85 | setDate(date.addDays(-7)); | 85 | setDate(date.addDays(-7)); |
86 | } | 86 | } |
87 | 87 | ||
88 | void DateBookWeekHeader::setDate( int y, int m, int d ) | 88 | void DateBookWeekHeader::setDate( int y, int m, int d ) |
89 | { | 89 | { |
90 | setDate(QDate(y,m,d)); | 90 | setDate(QDate(y,m,d)); |
91 | } | 91 | } |
92 | 92 | ||
93 | void DateBookWeekHeader::setDate(const QDate &d) { | 93 | void DateBookWeekHeader::setDate(const QDate &d) { |
94 | int year,week,dayofweek; | 94 | int year,week,dayofweek; |
95 | date=d; | 95 | date=d; |
96 | dayofweek=d.dayOfWeek(); | 96 | dayofweek=d.dayOfWeek(); |
97 | if(bStartOnMonday) dayofweek--; | 97 | if(bStartOnMonday) dayofweek--; |
98 | date=date.addDays(-dayofweek); | 98 | date=date.addDays(-dayofweek); |
99 | 99 | ||
100 | calcWeek(date,week,year,bStartOnMonday); | 100 | calcWeek(date,week,year,bStartOnMonday); |
101 | QDate start=date; | 101 | QDate start=date; |
102 | QDate stop=start.addDays(6); | 102 | QDate stop=start.addDays(6); |
103 | labelDate->setText( QString::number(start.day()) + "." + | 103 | labelDate->setText( QString::number(start.day()) + "." + |
104 | start.monthName(start.month()) + "-" + | 104 | start.monthName(start.month()) + "-" + |
105 | QString::number(stop.day()) + "." + | 105 | QString::number(stop.day()) + "." + |
106 | start.monthName(stop.month()) +" ("+ | 106 | start.monthName(stop.month()) +" ("+ |
107 | tr("w")+":"+QString::number( week ) +")"); | 107 | tr("w")+":"+QString::number( week ) +")"); |
108 | emit dateChanged(year,week); | 108 | emit dateChanged(date); |
109 | } | 109 | } |
110 | 110 | ||
111 | void DateBookWeekHeader::setStartOfWeek( bool onMonday ) | 111 | void DateBookWeekHeader::setStartOfWeek( bool onMonday ) |
112 | { | 112 | { |
113 | bStartOnMonday = onMonday; | 113 | bStartOnMonday = onMonday; |
114 | setDate( date ); | 114 | setDate( date ); |
115 | } | 115 | } |
116 | |||
117 | // dateFromWeek | ||
118 | // compute the date from the week in the year | ||
119 | QDate dateFromWeek( int week, int year, bool startOnMonday ) | ||
120 | { | ||
121 | QDate d; | ||
122 | d.setYMD( year, 1, 1 ); | ||
123 | int dayOfWeek = d.dayOfWeek(); | ||
124 | if ( startOnMonday ) { | ||
125 | if ( dayOfWeek <= 4 ) { | ||
126 | d = d.addDays( ( week - 1 ) * 7 - dayOfWeek + 1 ); | ||
127 | } else { | ||
128 | d = d.addDays( (week) * 7 - dayOfWeek + 1 ); | ||
129 | } | ||
130 | } else { | ||
131 | if ( dayOfWeek <= 4 || dayOfWeek == 7) { | ||
132 | d = d.addDays( ( week - 1 ) * 7 - dayOfWeek % 7 ); | ||
133 | } else { | ||
134 | d = d.addDays( ( week ) * 7 - dayOfWeek % 7 ); | ||
135 | } | ||
136 | } | ||
137 | return d; | ||
138 | } | ||
139 | |||
diff --git a/core/pim/datebook/datebookweekheaderimpl.h b/core/pim/datebook/datebookweekheaderimpl.h index 1ab1d52..d8dce90 100644 --- a/core/pim/datebook/datebookweekheaderimpl.h +++ b/core/pim/datebook/datebookweekheaderimpl.h | |||
@@ -1,59 +1,57 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef DATEBOOKDAYHEADER_H | 20 | #ifndef DATEBOOKDAYHEADER_H |
21 | #define DATEBOOKDAYHEADER_H | 21 | #define DATEBOOKDAYHEADER_H |
22 | #include <qdatetime.h> | 22 | #include <qdatetime.h> |
23 | #include "datebookweekheader.h" | 23 | #include "datebookweekheader.h" |
24 | 24 | ||
25 | 25 | ||
26 | class DateBookWeekHeader : public DateBookWeekHeaderBase | 26 | class DateBookWeekHeader : public DateBookWeekHeaderBase |
27 | { | 27 | { |
28 | Q_OBJECT | 28 | Q_OBJECT |
29 | 29 | ||
30 | public: | 30 | public: |
31 | DateBookWeekHeader( bool startOnMonday, QWidget* parent = 0, | 31 | DateBookWeekHeader( bool startOnMonday, QWidget* parent = 0, |
32 | const char* name = 0, WFlags fl = 0 ); | 32 | const char* name = 0, WFlags fl = 0 ); |
33 | ~DateBookWeekHeader(); | 33 | ~DateBookWeekHeader(); |
34 | 34 | ||
35 | void setDate(const QDate &d); | 35 | void setDate(const QDate &d); |
36 | void setStartOfWeek( bool onMonday ); | 36 | void setStartOfWeek( bool onMonday ); |
37 | 37 | ||
38 | signals: | 38 | signals: |
39 | void dateChanged( int y, int w ); | 39 | void dateChanged( QDate &date ); |
40 | 40 | ||
41 | public slots: | 41 | public slots: |
42 | void pickDate(); | 42 | void pickDate(); |
43 | void nextMonth(); | 43 | void nextMonth(); |
44 | void prevMonth(); | 44 | void prevMonth(); |
45 | void nextWeek(); | 45 | void nextWeek(); |
46 | void prevWeek(); | 46 | void prevWeek(); |
47 | void setDate( int y, int m, int d); | 47 | void setDate( int y, int m, int d); |
48 | 48 | ||
49 | protected slots: | 49 | protected slots: |
50 | void keyPressEvent(QKeyEvent *e) { e->ignore(); } | 50 | void keyPressEvent(QKeyEvent *e) { e->ignore(); } |
51 | 51 | ||
52 | private: | 52 | private: |
53 | QDate date; | 53 | QDate date; |
54 | bool bStartOnMonday; | 54 | bool bStartOnMonday; |
55 | }; | 55 | }; |
56 | 56 | ||
57 | QDate dateFromWeek( int week, int year, bool startOnMonday ); | ||
58 | |||
59 | #endif // DATEBOOKDAYHEADER_H | 57 | #endif // DATEBOOKDAYHEADER_H |
diff --git a/core/pim/datebook/datebookweeklst.cpp b/core/pim/datebook/datebookweeklst.cpp index a39ff40..7817042 100644 --- a/core/pim/datebook/datebookweeklst.cpp +++ b/core/pim/datebook/datebookweeklst.cpp | |||
@@ -1,398 +1,386 @@ | |||
1 | #include "datebookweeklst.h" | 1 | #include "datebookweeklst.h" |
2 | 2 | ||
3 | #include "datebookweekheaderimpl.h" | 3 | #include "datebookweekheaderimpl.h" |
4 | 4 | ||
5 | #include "datebook.h" | 5 | #include "datebook.h" |
6 | 6 | ||
7 | #include <qpe/calendar.h> | 7 | #include <qpe/calendar.h> |
8 | #include <qpe/datebookdb.h> | 8 | #include <qpe/datebookdb.h> |
9 | #include <qpe/event.h> | 9 | #include <qpe/event.h> |
10 | #include <qpe/qpeapplication.h> | 10 | #include <qpe/qpeapplication.h> |
11 | #include <qpe/timestring.h> | 11 | #include <qpe/timestring.h> |
12 | #include <qpe/datebookmonth.h> | 12 | #include <qpe/datebookmonth.h> |
13 | #include <qpe/config.h> | 13 | #include <qpe/config.h> |
14 | #include <qpe/resource.h> | 14 | #include <qpe/resource.h> |
15 | 15 | ||
16 | #include <qdatetime.h> | 16 | #include <qdatetime.h> |
17 | #include <qheader.h> | 17 | #include <qheader.h> |
18 | #include <qlabel.h> | 18 | #include <qlabel.h> |
19 | #include <qlayout.h> | 19 | #include <qlayout.h> |
20 | #include <qpainter.h> | 20 | #include <qpainter.h> |
21 | #include <qpopupmenu.h> | 21 | #include <qpopupmenu.h> |
22 | #include <qtimer.h> | 22 | #include <qtimer.h> |
23 | #include <qstyle.h> | 23 | #include <qstyle.h> |
24 | #include <qtoolbutton.h> | 24 | #include <qtoolbutton.h> |
25 | #include <qvbox.h> | 25 | #include <qvbox.h> |
26 | #include <qsizepolicy.h> | 26 | #include <qsizepolicy.h> |
27 | #include <qabstractlayout.h> | 27 | #include <qabstractlayout.h> |
28 | #include <qtl.h> | 28 | #include <qtl.h> |
29 | 29 | ||
30 | bool calcWeek(const QDate &d, int &week, int &year,bool startOnMonday = false); | 30 | bool calcWeek(const QDate &d, int &week, int &year,bool startOnMonday = false); |
31 | 31 | ||
32 | DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, const char* name, WFlags fl) | 32 | DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, const char* name, WFlags fl) |
33 | : DateBookWeekLstHeaderBase(parent, name, fl) | 33 | : DateBookWeekLstHeaderBase(parent, name, fl) |
34 | { | 34 | { |
35 | setBackgroundMode( PaletteButton ); | 35 | setBackgroundMode( PaletteButton ); |
36 | labelDate->setBackgroundMode( PaletteButton ); | 36 | labelDate->setBackgroundMode( PaletteButton ); |
37 | forwardweek->setBackgroundMode( PaletteButton ); | 37 | forwardweek->setBackgroundMode( PaletteButton ); |
38 | forwardweek->setPixmap( Resource::loadPixmap("forward") ); | 38 | forwardweek->setPixmap( Resource::loadPixmap("forward") ); |
39 | forwardmonth->setBackgroundMode( PaletteButton ); | 39 | forwardmonth->setBackgroundMode( PaletteButton ); |
40 | forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); | 40 | forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); |
41 | backweek->setBackgroundMode( PaletteButton ); | 41 | backweek->setBackgroundMode( PaletteButton ); |
42 | backweek->setPixmap( Resource::loadPixmap("back") ); | 42 | backweek->setPixmap( Resource::loadPixmap("back") ); |
43 | backmonth->setBackgroundMode( PaletteButton ); | 43 | backmonth->setBackgroundMode( PaletteButton ); |
44 | backmonth->setPixmap( Resource::loadPixmap("fastback") ); | 44 | backmonth->setPixmap( Resource::loadPixmap("fastback") ); |
45 | DateBookWeekLstHeaderBaseLayout->setSpacing(0); | 45 | DateBookWeekLstHeaderBaseLayout->setSpacing(0); |
46 | DateBookWeekLstHeaderBaseLayout->setMargin(0); | 46 | DateBookWeekLstHeaderBaseLayout->setMargin(0); |
47 | //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); | 47 | //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); |
48 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); | 48 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); |
49 | 49 | ||
50 | connect(backmonth, SIGNAL(clicked()), this, SLOT(prevMonth())); | 50 | connect(backmonth, SIGNAL(clicked()), this, SLOT(prevMonth())); |
51 | connect(backweek, SIGNAL(clicked()), this, SLOT(prevWeek())); | 51 | connect(backweek, SIGNAL(clicked()), this, SLOT(prevWeek())); |
52 | connect(forwardweek, SIGNAL(clicked()), this, SLOT(nextWeek())); | 52 | connect(forwardweek, SIGNAL(clicked()), this, SLOT(nextWeek())); |
53 | connect(forwardmonth, SIGNAL(clicked()), this, SLOT(nextMonth())); | 53 | connect(forwardmonth, SIGNAL(clicked()), this, SLOT(nextMonth())); |
54 | connect(labelDate, SIGNAL(clicked()), this, SLOT(pickDate())); | 54 | connect(labelDate, SIGNAL(clicked()), this, SLOT(pickDate())); |
55 | connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); | 55 | connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); |
56 | bStartOnMonday=onM; | 56 | bStartOnMonday=onM; |
57 | } | 57 | } |
58 | DateBookWeekLstHeader::~DateBookWeekLstHeader(){} | 58 | DateBookWeekLstHeader::~DateBookWeekLstHeader(){} |
59 | 59 | ||
60 | void DateBookWeekLstHeader::setDate(const QDate &d) { | 60 | void DateBookWeekLstHeader::setDate(const QDate &d) { |
61 | int year,week,dayofweek; | 61 | int year,week,dayofweek; |
62 | date=d; | 62 | date=d; |
63 | dayofweek=d.dayOfWeek(); | 63 | dayofweek=d.dayOfWeek(); |
64 | if(bStartOnMonday) dayofweek--; | 64 | if(bStartOnMonday) dayofweek--; |
65 | date=date.addDays(-dayofweek); | 65 | date=date.addDays(-dayofweek); |
66 | 66 | ||
67 | calcWeek(date,week,year,bStartOnMonday); | 67 | calcWeek(date,week,year,bStartOnMonday); |
68 | QDate start=date; | 68 | QDate start=date; |
69 | QDate stop=start.addDays(6); | 69 | QDate stop=start.addDays(6); |
70 | labelDate->setText( QString::number(start.day()) + "." + | 70 | labelDate->setText( QString::number(start.day()) + "." + |
71 | start.monthName(start.month()) + "-" + | 71 | start.monthName(start.month()) + "-" + |
72 | QString::number(stop.day()) + "." + | 72 | QString::number(stop.day()) + "." + |
73 | start.monthName(stop.month()) +" ("+ | 73 | start.monthName(stop.month()) +" ("+ |
74 | tr("w")+":"+QString::number( week ) +")"); | 74 | tr("w")+":"+QString::number( week ) +")"); |
75 | emit dateChanged(year,week); | 75 | emit dateChanged(date); |
76 | } | 76 | } |
77 | 77 | ||
78 | void DateBookWeekLstHeader::pickDate() { | 78 | void DateBookWeekLstHeader::pickDate() { |
79 | static QPopupMenu *m1 = 0; | 79 | static QPopupMenu *m1 = 0; |
80 | static DateBookMonth *picker = 0; | 80 | static DateBookMonth *picker = 0; |
81 | if ( !m1 ) { | 81 | if ( !m1 ) { |
82 | m1 = new QPopupMenu( this ); | 82 | m1 = new QPopupMenu( this ); |
83 | picker = new DateBookMonth( m1, 0, TRUE ); | 83 | picker = new DateBookMonth( m1, 0, TRUE ); |
84 | m1->insertItem( picker ); | 84 | m1->insertItem( picker ); |
85 | connect( picker, SIGNAL( dateClicked( int, int, int ) ),this, SLOT( setDate( int, int, int ) ) ); | 85 | connect( picker, SIGNAL( dateClicked( int, int, int ) ),this, SLOT( setDate( int, int, int ) ) ); |
86 | //connect( m1, SIGNAL( aboutToHide() ), | 86 | //connect( m1, SIGNAL( aboutToHide() ), |
87 | //this, SLOT( gotHide() ) ); | 87 | //this, SLOT( gotHide() ) ); |
88 | } | 88 | } |
89 | picker->setDate( date.year(), date.month(), date.day() ); | 89 | picker->setDate( date.year(), date.month(), date.day() ); |
90 | m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); | 90 | m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); |
91 | picker->setFocus(); | 91 | picker->setFocus(); |
92 | } | 92 | } |
93 | void DateBookWeekLstHeader::setDate(int y, int m, int d) { | 93 | void DateBookWeekLstHeader::setDate(int y, int m, int d) { |
94 | setDate(QDate(y,m,d)); | 94 | setDate(QDate(y,m,d)); |
95 | } | 95 | } |
96 | 96 | ||
97 | void DateBookWeekLstHeader::nextWeek() { | 97 | void DateBookWeekLstHeader::nextWeek() { |
98 | setDate(date.addDays(7)); | 98 | setDate(date.addDays(7)); |
99 | } | 99 | } |
100 | void DateBookWeekLstHeader::prevWeek() { | 100 | void DateBookWeekLstHeader::prevWeek() { |
101 | setDate(date.addDays(-7)); | 101 | setDate(date.addDays(-7)); |
102 | } | 102 | } |
103 | void DateBookWeekLstHeader::nextMonth() | 103 | void DateBookWeekLstHeader::nextMonth() |
104 | { | 104 | { |
105 | setDate(date.addDays(28)); | 105 | setDate(date.addDays(28)); |
106 | } | 106 | } |
107 | void DateBookWeekLstHeader::prevMonth() | 107 | void DateBookWeekLstHeader::prevMonth() |
108 | { | 108 | { |
109 | setDate(date.addDays(-28)); | 109 | setDate(date.addDays(-28)); |
110 | } | 110 | } |
111 | 111 | ||
112 | DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/, | 112 | DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /* onM */, |
113 | QWidget* parent, | 113 | QWidget* parent, |
114 | const char* name, | 114 | const char* name, |
115 | WFlags fl ) | 115 | WFlags fl ) |
116 | : DateBookWeekLstDayHdrBase(parent, name, fl) { | 116 | : DateBookWeekLstDayHdrBase(parent, name, fl) { |
117 | 117 | ||
118 | date=d; | 118 | date=d; |
119 | 119 | ||
120 | static const char *wdays={"MTWTFSS"}; | 120 | static const char *wdays={"MTWTFSSM"}; |
121 | char day=wdays[d.dayOfWeek()-1]; | 121 | char day=wdays[d.dayOfWeek()-1]; |
122 | 122 | ||
123 | label->setText( QString(QObject::tr(QString(QChar(day)))) + " " +QString::number(d.day()) ); | 123 | label->setText( QString(QObject::tr(QString(QChar(day)))) + " " +QString::number(d.day()) ); |
124 | add->setText("+"); | 124 | add->setText("+"); |
125 | 125 | ||
126 | if (d == QDate::currentDate()) { | 126 | if (d == QDate::currentDate()) { |
127 | QPalette pal=label->palette(); | 127 | QPalette pal=label->palette(); |
128 | pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); | 128 | pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); |
129 | label->setPalette(pal); | 129 | label->setPalette(pal); |
130 | 130 | ||
131 | /* | 131 | /* |
132 | QFont f=label->font(); | 132 | QFont f=label->font(); |
133 | f.setItalic(true); | 133 | f.setItalic(true); |
134 | label->setFont(f); | 134 | label->setFont(f); |
135 | label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); | 135 | label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); |
136 | */ | 136 | */ |
137 | } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday | 137 | } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday |
138 | QPalette pal=label->palette(); | 138 | QPalette pal=label->palette(); |
139 | pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); | 139 | pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); |
140 | label->setPalette(pal); | 140 | label->setPalette(pal); |
141 | } | 141 | } |
142 | 142 | ||
143 | connect (label, SIGNAL(clicked()), this, SLOT(showDay())); | 143 | connect (label, SIGNAL(clicked()), this, SLOT(showDay())); |
144 | connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); | 144 | connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); |
145 | } | 145 | } |
146 | 146 | ||
147 | void DateBookWeekLstDayHdr::showDay() { | 147 | void DateBookWeekLstDayHdr::showDay() { |
148 | emit showDate(date.year(), date.month(), date.day()); | 148 | emit showDate(date.year(), date.month(), date.day()); |
149 | } | 149 | } |
150 | 150 | ||
151 | void DateBookWeekLstDayHdr::newEvent() { | 151 | void DateBookWeekLstDayHdr::newEvent() { |
152 | QDateTime start, stop; | 152 | QDateTime start, stop; |
153 | start=stop=date; | 153 | start=stop=date; |
154 | start.setTime(QTime(10,0)); | 154 | start.setTime(QTime(10,0)); |
155 | stop.setTime(QTime(12,0)); | 155 | stop.setTime(QTime(12,0)); |
156 | 156 | ||
157 | emit addEvent(start,stop,"",0); | 157 | emit addEvent(start,stop,"",0); |
158 | } | 158 | } |
159 | DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev, | 159 | DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev, |
160 | int weeklistviewconfig, | 160 | int weeklistviewconfig, |
161 | QWidget* parent, | 161 | QWidget* parent, |
162 | const char* name, | 162 | const char* name, |
163 | WFlags fl ) : OClickableLabel(parent,name,fl), event(ev) | 163 | WFlags fl ) : OClickableLabel(parent,name,fl), event(ev) |
164 | { | 164 | { |
165 | // old values... lastday = "__|__", middle=" |---", Firstday="00:00", | 165 | // old values... lastday = "__|__", middle=" |---", Firstday="00:00", |
166 | QString s,start,middle,end,day; | 166 | QString s,start,middle,end,day; |
167 | 167 | ||
168 | qDebug("weeklistviewconfig=%d",weeklistviewconfig); | 168 | qDebug("weeklistviewconfig=%d",weeklistviewconfig); |
169 | if(weeklistviewconfig==NONE) {// No times displayed. | 169 | if(weeklistviewconfig==NONE) {// No times displayed. |
170 | // start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute()); | 170 | // start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute()); |
171 | // middle.sprintf("<--->"); | 171 | // middle.sprintf("<--->"); |
172 | // end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute()); | 172 | // end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute()); |
173 | // day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute()); | 173 | // day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute()); |
174 | } else if(weeklistviewconfig==NORMAL) {// "Normal", only display start time. | 174 | } else if(weeklistviewconfig==NORMAL) {// "Normal", only display start time. |
175 | start.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute()); | 175 | start.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute()); |
176 | middle.sprintf(" |---"); | 176 | middle.sprintf(" |---"); |
177 | end.sprintf("__|__"); | 177 | end.sprintf("__|__"); |
178 | day.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute()); | 178 | day.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute()); |
179 | } else if(weeklistviewconfig==EXTENDED) { // Extended mode, display start and end times. | 179 | } else if(weeklistviewconfig==EXTENDED) { // Extended mode, display start and end times. |
180 | start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute()); | 180 | start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute()); |
181 | middle.sprintf("<--->"); | 181 | middle.sprintf("<--->"); |
182 | end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute()); | 182 | end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute()); |
183 | day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute()); | 183 | day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute()); |
184 | } | 184 | } |
185 | 185 | ||
186 | if(ev.event().type() == Event::Normal) { | 186 | if(ev.event().type() == Event::Normal) { |
187 | if(ev.startDate()==ev.date() && ev.endDate()==ev.date()) {// day event. | 187 | if(ev.startDate()==ev.date() && ev.endDate()==ev.date()) {// day event. |
188 | s=day; | 188 | s=day; |
189 | } else if(ev.startDate()==ev.date()) {// start event. | 189 | } else if(ev.startDate()==ev.date()) {// start event. |
190 | s=start; | 190 | s=start; |
191 | } else if(ev.endDate()==ev.date()) { // end event. | 191 | } else if(ev.endDate()==ev.date()) { // end event. |
192 | s=end; | 192 | s=end; |
193 | } else {// middle day. | 193 | } else {// middle day. |
194 | s=middle; | 194 | s=middle; |
195 | } | 195 | } |
196 | } else { | 196 | } else { |
197 | s=""; | 197 | s=""; |
198 | } | 198 | } |
199 | setText(QString(s) + " " + ev.description()); | 199 | setText(QString(s) + " " + ev.description()); |
200 | connect(this, SIGNAL(clicked()), this, SLOT(editMe())); | 200 | connect(this, SIGNAL(clicked()), this, SLOT(editMe())); |
201 | setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); | 201 | setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); |
202 | } | 202 | } |
203 | void DateBookWeekLstEvent::editMe() { | 203 | void DateBookWeekLstEvent::editMe() { |
204 | emit editEvent(event.event()); | 204 | emit editEvent(event.event()); |
205 | } | 205 | } |
206 | 206 | ||
207 | 207 | ||
208 | DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, | 208 | DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, |
209 | const QDate &d, bool onM, | 209 | const QDate &d, bool onM, |
210 | QWidget* parent, | 210 | QWidget* parent, |
211 | const char* name, WFlags fl) | 211 | const char* name, WFlags fl) |
212 | : QWidget( parent, name, fl ) | 212 | : QWidget( parent, name, fl ) |
213 | { | 213 | { |
214 | Config config("DateBook"); | 214 | Config config("DateBook"); |
215 | config.setGroup("Main"); | 215 | config.setGroup("Main"); |
216 | int weeklistviewconfig=config.readNumEntry("weeklistviewconfig", NORMAL); | 216 | int weeklistviewconfig=config.readNumEntry("weeklistviewconfig", NORMAL); |
217 | qDebug("Read weeklistviewconfig: %d",weeklistviewconfig); | 217 | qDebug("Read weeklistviewconfig: %d",weeklistviewconfig); |
218 | 218 | ||
219 | bStartOnMonday=onM; | 219 | bStartOnMonday=onM; |
220 | setPalette(white); | 220 | setPalette(white); |
221 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); | 221 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); |
222 | 222 | ||
223 | QVBoxLayout *layout = new QVBoxLayout( this ); | 223 | QVBoxLayout *layout = new QVBoxLayout( this ); |
224 | 224 | ||
225 | qBubbleSort(ev); | 225 | qBubbleSort(ev); |
226 | QValueListIterator<EffectiveEvent> it; | 226 | QValueListIterator<EffectiveEvent> it; |
227 | it=ev.begin(); | 227 | it=ev.begin(); |
228 | 228 | ||
229 | int dayOrder[7]; | 229 | int dayOrder[7]; |
230 | if (bStartOnMonday) { | 230 | if (bStartOnMonday) { |
231 | for (int d=0; d<7; d++) dayOrder[d]=d+1; | 231 | for (int d=0; d<7; d++) dayOrder[d]=d+1; |
232 | } else { | 232 | } else { |
233 | for (int d=0; d<7; d++) dayOrder[d]=d; | 233 | for (int d=0; d<7; d++) dayOrder[d]=d; |
234 | dayOrder[0]=7; | 234 | dayOrder[0]=7; |
235 | } | 235 | } |
236 | 236 | ||
237 | for (int i=0; i<7; i++) { | 237 | // Calculate offset to first day of week. |
238 | int dayoffset=d.dayOfWeek(); | ||
239 | if(bStartOnMonday) dayoffset--; | ||
240 | |||
241 | for (int i=0; i<7; i++) { | ||
238 | // Header | 242 | // Header |
239 | DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i), bStartOnMonday,this); | 243 | DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i-dayoffset), bStartOnMonday,this); |
240 | connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); | 244 | connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); |
241 | connect(hdr, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), | 245 | connect(hdr, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), |
242 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); | 246 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); |
243 | layout->addWidget(hdr); | 247 | layout->addWidget(hdr); |
244 | 248 | ||
245 | // Events | 249 | // Events |
246 | while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { | 250 | while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { |
247 | if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) {// Skip events ending at 00:00 starting at another day. | 251 | if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) {// Skip events ending at 00:00 starting at another day. |
248 | DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,this); | 252 | DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,this); |
249 | layout->addWidget(l); | 253 | layout->addWidget(l); |
250 | connect (l, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); | 254 | connect (l, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); |
255 | } | ||
256 | it++; | ||
251 | } | 257 | } |
252 | it++; | 258 | layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); |
253 | } | ||
254 | |||
255 | layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); | ||
256 | } | 259 | } |
257 | } | 260 | } |
258 | DateBookWeekLstView::~DateBookWeekLstView(){} | 261 | DateBookWeekLstView::~DateBookWeekLstView(){} |
259 | void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} | 262 | void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} |
260 | 263 | ||
261 | DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, | 264 | DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, |
262 | QValueList<EffectiveEvent> &ev2, | 265 | QValueList<EffectiveEvent> &ev2, |
263 | QDate &d, bool onM, | 266 | QDate &d, bool onM, |
264 | QWidget* parent, | 267 | QWidget* parent, |
265 | const char* name, WFlags fl) | 268 | const char* name, WFlags fl) |
266 | : QWidget( parent, name, fl ) | 269 | : QWidget( parent, name, fl ) |
267 | { | 270 | { |
268 | QHBoxLayout *layout = new QHBoxLayout( this ); | 271 | QHBoxLayout *layout = new QHBoxLayout( this ); |
269 | 272 | ||
270 | DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this); | 273 | DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this); |
271 | layout->addWidget(w); | 274 | layout->addWidget(w); |
272 | connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); | 275 | connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); |
273 | connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); | 276 | connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); |
274 | connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &,const QString &)), | 277 | connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &,const QString &)), |
275 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); | 278 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); |
276 | 279 | ||
277 | 280 | ||
278 | w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); | 281 | w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); |
279 | layout->addWidget(w); | 282 | layout->addWidget(w); |
280 | connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); | 283 | connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); |
281 | connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); | 284 | connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); |
282 | connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), | 285 | connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), |
283 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); | 286 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); |
284 | } | 287 | } |
285 | 288 | ||
286 | DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, | 289 | DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, |
287 | QWidget *parent, | 290 | QWidget *parent, |
288 | const char *name ) | 291 | const char *name ) |
289 | : QWidget( parent, name ), | 292 | : QWidget( parent, name ), |
290 | db( newDB ), | 293 | db( newDB ), |
291 | startTime( 0 ), | 294 | startTime( 0 ), |
292 | ampm( ap ), | 295 | ampm( ap ), |
293 | bStartOnMonday(onM) | 296 | bStartOnMonday(onM) |
294 | { | 297 | { |
295 | setFocusPolicy(StrongFocus); | 298 | setFocusPolicy(StrongFocus); |
296 | layout = new QVBoxLayout( this ); | 299 | layout = new QVBoxLayout( this ); |
297 | layout->setMargin(0); | 300 | layout->setMargin(0); |
298 | 301 | ||
299 | header=new DateBookWeekLstHeader(onM, this); | 302 | header=new DateBookWeekLstHeader(onM, this); |
300 | layout->addWidget( header ); | 303 | layout->addWidget( header ); |
301 | connect(header, SIGNAL(dateChanged(int,int)), this, SLOT(dateChanged(int,int))); | 304 | connect(header, SIGNAL(dateChanged(QDate &)), this, SLOT(dateChanged(QDate &))); |
302 | connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); | 305 | connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); |
303 | 306 | ||
304 | scroll=new QScrollView(this); | 307 | scroll=new QScrollView(this); |
305 | scroll->setResizePolicy(QScrollView::AutoOneFit); | 308 | scroll->setResizePolicy(QScrollView::AutoOneFit); |
306 | layout->addWidget(scroll); | 309 | layout->addWidget(scroll); |
307 | 310 | ||
308 | view=NULL; | 311 | view=NULL; |
309 | Config config("DateBook"); | 312 | Config config("DateBook"); |
310 | config.setGroup("Main"); | 313 | config.setGroup("Main"); |
311 | dbl=config.readBoolEntry("weeklst_dbl", false); | 314 | dbl=config.readBoolEntry("weeklst_dbl", false); |
312 | header->dbl->setOn(dbl); | 315 | header->dbl->setOn(dbl); |
313 | } | 316 | } |
314 | DateBookWeekLst::~DateBookWeekLst(){ | 317 | DateBookWeekLst::~DateBookWeekLst(){ |
315 | Config config("DateBook"); | 318 | Config config("DateBook"); |
316 | config.setGroup("Main"); | 319 | config.setGroup("Main"); |
317 | config.writeEntry("weeklst_dbl", dbl); | 320 | config.writeEntry("weeklst_dbl", dbl); |
318 | } | 321 | } |
319 | 322 | ||
320 | void DateBookWeekLst::setDate(const QDate &d) { | 323 | void DateBookWeekLst::setDate(const QDate &d) { |
321 | int w,y; | 324 | bdate=d; |
322 | calcWeek(d,w,y,bStartOnMonday); | 325 | header->setDate(d); |
323 | year=y; | ||
324 | _week=w; | ||
325 | header->setDate(date()); | ||
326 | } | 326 | } |
327 | |||
327 | void DateBookWeekLst::setDbl(bool on) { | 328 | void DateBookWeekLst::setDbl(bool on) { |
328 | dbl=on; | 329 | dbl=on; |
329 | redraw(); | 330 | redraw(); |
330 | } | 331 | } |
331 | void DateBookWeekLst::redraw() {getEvents();} | 332 | void DateBookWeekLst::redraw() {getEvents();} |
332 | 333 | ||
333 | QDate DateBookWeekLst::date() const { | 334 | QDate DateBookWeekLst::date() { |
334 | QDate d; | 335 | return bdate; |
335 | d.setYMD(year,1,1); | ||
336 | |||
337 | int dow= d.dayOfWeek(); | ||
338 | if (!bStartOnMonday) | ||
339 | if (dow==7) { | ||
340 | dow=1; | ||
341 | } else { | ||
342 | dow++; | ||
343 | } | ||
344 | |||
345 | d=d.addDays( (_week-1)*7 - dow + 1 ); | ||
346 | return d; | ||
347 | } | 336 | } |
348 | 337 | ||
349 | void DateBookWeekLst::getEvents() { | 338 | void DateBookWeekLst::getEvents() { |
350 | QDate start = date(); | 339 | QDate start = date(); |
351 | QDate stop = start.addDays(6); | 340 | QDate stop = start.addDays(6); |
352 | QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); | 341 | QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); |
353 | 342 | ||
354 | if (view) delete view; | 343 | if (view) delete view; |
355 | if (dbl) { | 344 | if (dbl) { |
356 | QDate start2=start.addDays(7); | 345 | QDate start2=start.addDays(7); |
357 | stop=start2.addDays(6); | 346 | stop=start2.addDays(6); |
358 | QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); | 347 | QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); |
359 | view=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll); | 348 | view=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll); |
360 | } else { | 349 | } else { |
361 | view=new DateBookWeekLstView(el,start,bStartOnMonday,scroll); | 350 | view=new DateBookWeekLstView(el,start,bStartOnMonday,scroll); |
362 | } | 351 | } |
363 | 352 | ||
364 | connect (view, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); | 353 | connect (view, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); |
365 | connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); | 354 | connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); |
366 | connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), | 355 | connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), |
367 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); | 356 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); |
368 | 357 | ||
369 | scroll->addChild(view); | 358 | scroll->addChild(view); |
370 | view->show(); | 359 | view->show(); |
371 | scroll->updateScrollBars(); | 360 | scroll->updateScrollBars(); |
372 | } | 361 | } |
373 | 362 | ||
374 | void DateBookWeekLst::dateChanged(int y, int w) { | 363 | void DateBookWeekLst::dateChanged(QDate &newdate) { |
375 | year=y; | 364 | bdate=newdate; |
376 | _week=w; | ||
377 | getEvents(); | 365 | getEvents(); |
378 | } | 366 | } |
379 | 367 | ||
380 | void DateBookWeekLst::keyPressEvent(QKeyEvent *e) | 368 | void DateBookWeekLst::keyPressEvent(QKeyEvent *e) |
381 | { | 369 | { |
382 | switch(e->key()) { | 370 | switch(e->key()) { |
383 | case Key_Up: | 371 | case Key_Up: |
384 | scroll->scrollBy(0, -20); | 372 | scroll->scrollBy(0, -20); |
385 | break; | 373 | break; |
386 | case Key_Down: | 374 | case Key_Down: |
387 | scroll->scrollBy(0, 20); | 375 | scroll->scrollBy(0, 20); |
388 | break; | 376 | break; |
389 | case Key_Left: | 377 | case Key_Left: |
390 | header->prevWeek(); | 378 | header->prevWeek(); |
391 | break; | 379 | break; |
392 | case Key_Right: | 380 | case Key_Right: |
393 | header->nextWeek(); | 381 | header->nextWeek(); |
394 | break; | 382 | break; |
395 | default: | 383 | default: |
396 | e->ignore(); | 384 | e->ignore(); |
397 | } | 385 | } |
398 | } \ No newline at end of file | 386 | } |
diff --git a/core/pim/datebook/datebookweeklst.h b/core/pim/datebook/datebookweeklst.h index f858c4f..0bfbcda 100644 --- a/core/pim/datebook/datebookweeklst.h +++ b/core/pim/datebook/datebookweeklst.h | |||
@@ -1,154 +1,155 @@ | |||
1 | #ifndef DATEBOOKWEEKLST | 1 | #ifndef DATEBOOKWEEKLST |
2 | #define DATEBOOKWEEKLST | 2 | #define DATEBOOKWEEKLST |
3 | 3 | ||
4 | #include <qwidget.h> | 4 | #include <qwidget.h> |
5 | #include <qdatetime.h> | 5 | #include <qdatetime.h> |
6 | #include <qpe/event.h> | 6 | #include <qpe/event.h> |
7 | #include <qlabel.h> | 7 | #include <qlabel.h> |
8 | #include <qscrollview.h> | 8 | #include <qscrollview.h> |
9 | 9 | ||
10 | #include "datebookweeklstheader.h" | 10 | #include "datebookweeklstheader.h" |
11 | #include "datebookweeklstdayhdr.h" | 11 | #include "datebookweeklstdayhdr.h" |
12 | 12 | ||
13 | #include <opie/oclickablelabel.h> | 13 | #include <opie/oclickablelabel.h> |
14 | 14 | ||
15 | class QDateTime; | 15 | class QDateTime; |
16 | class DateBookDB; | 16 | class DateBookDB; |
17 | 17 | ||
18 | class DateBookWeekLstHeader: public DateBookWeekLstHeaderBase | 18 | class DateBookWeekLstHeader: public DateBookWeekLstHeaderBase |
19 | { | 19 | { |
20 | Q_OBJECT | 20 | Q_OBJECT |
21 | public: | 21 | public: |
22 | DateBookWeekLstHeader(bool onM, QWidget* parent = 0, const char* name = 0, | 22 | DateBookWeekLstHeader(bool onM, QWidget* parent = 0, const char* name = 0, |
23 | WFlags fl = 0 ); | 23 | WFlags fl = 0 ); |
24 | ~DateBookWeekLstHeader(); | 24 | ~DateBookWeekLstHeader(); |
25 | void setDate(const QDate &d); | 25 | void setDate(const QDate &d); |
26 | 26 | ||
27 | public slots: | 27 | public slots: |
28 | void nextWeek(); | 28 | void nextWeek(); |
29 | void prevWeek(); | 29 | void prevWeek(); |
30 | void nextMonth(); | 30 | void nextMonth(); |
31 | void prevMonth(); | 31 | void prevMonth(); |
32 | void pickDate(); | 32 | void pickDate(); |
33 | void setDate(int y, int m, int d); | 33 | void setDate(int y, int m, int d); |
34 | signals: | 34 | signals: |
35 | void dateChanged(int y, int w); | 35 | void dateChanged(QDate &newdate); |
36 | void setDbl(bool on); | 36 | void setDbl(bool on); |
37 | private: | 37 | private: |
38 | QDate date; | 38 | QDate date; |
39 | //bool onMonday; | 39 | //bool onMonday; |
40 | bool bStartOnMonday; | 40 | bool bStartOnMonday; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | class DateBookWeekLstDayHdr: public DateBookWeekLstDayHdrBase | 43 | class DateBookWeekLstDayHdr: public DateBookWeekLstDayHdrBase |
44 | { | 44 | { |
45 | Q_OBJECT | 45 | Q_OBJECT |
46 | public: | 46 | public: |
47 | DateBookWeekLstDayHdr(const QDate &d, bool onM, | 47 | DateBookWeekLstDayHdr(const QDate &d, bool onM, |
48 | QWidget* parent = 0, const char* name = 0, | 48 | QWidget* parent = 0, const char* name = 0, |
49 | WFlags fl = 0 ); | 49 | WFlags fl = 0 ); |
50 | public slots: | 50 | public slots: |
51 | void showDay(); | 51 | void showDay(); |
52 | void newEvent(); | 52 | void newEvent(); |
53 | signals: | 53 | signals: |
54 | void showDate(int y, int m, int d); | 54 | void showDate(int y, int m, int d); |
55 | void addEvent(const QDateTime &start, const QDateTime &stop, | 55 | void addEvent(const QDateTime &start, const QDateTime &stop, |
56 | const QString &str, const QString &location); | 56 | const QString &str, const QString &location); |
57 | private: | 57 | private: |
58 | QDate date; | 58 | QDate date; |
59 | }; | 59 | }; |
60 | 60 | ||
61 | class DateBookWeekLstEvent: public OClickableLabel | 61 | class DateBookWeekLstEvent: public OClickableLabel |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | DateBookWeekLstEvent(const EffectiveEvent &ev, int weeklistviewconfig =1, | 65 | DateBookWeekLstEvent(const EffectiveEvent &ev, int weeklistviewconfig =1, |
66 | QWidget* parent = 0, const char* name = 0, | 66 | QWidget* parent = 0, const char* name = 0, |
67 | WFlags fl = 0); | 67 | WFlags fl = 0); |
68 | signals: | 68 | signals: |
69 | void editEvent(const Event &e); | 69 | void editEvent(const Event &e); |
70 | private slots: | 70 | private slots: |
71 | void editMe(); | 71 | void editMe(); |
72 | private: | 72 | private: |
73 | const EffectiveEvent event; | 73 | const EffectiveEvent event; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | class DateBookWeekLstView: public QWidget | 76 | class DateBookWeekLstView: public QWidget |
77 | { | 77 | { |
78 | Q_OBJECT | 78 | Q_OBJECT |
79 | public: | 79 | public: |
80 | DateBookWeekLstView(QValueList<EffectiveEvent> &ev, const QDate &d, bool onM, | 80 | DateBookWeekLstView(QValueList<EffectiveEvent> &ev, const QDate &d, bool onM, |
81 | QWidget* parent = 0, const char* name = 0, | 81 | QWidget* parent = 0, const char* name = 0, |
82 | WFlags fl = 0 ); | 82 | WFlags fl = 0 ); |
83 | ~DateBookWeekLstView(); | 83 | ~DateBookWeekLstView(); |
84 | signals: | 84 | signals: |
85 | void editEvent(const Event &e); | 85 | void editEvent(const Event &e); |
86 | void showDate(int y, int m, int d); | 86 | void showDate(int y, int m, int d); |
87 | void addEvent(const QDateTime &start, const QDateTime &stop, | 87 | void addEvent(const QDateTime &start, const QDateTime &stop, |
88 | const QString &str, const QString &location); | 88 | const QString &str, const QString &location); |
89 | private: | 89 | private: |
90 | bool bStartOnMonday; | 90 | bool bStartOnMonday; |
91 | protected slots: | 91 | protected slots: |
92 | void keyPressEvent(QKeyEvent *); | 92 | void keyPressEvent(QKeyEvent *); |
93 | }; | 93 | }; |
94 | 94 | ||
95 | class DateBookWeekLstDblView: public QWidget { | 95 | class DateBookWeekLstDblView: public QWidget { |
96 | Q_OBJECT | 96 | Q_OBJECT |
97 | public: | 97 | public: |
98 | DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, | 98 | DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, |
99 | QValueList<EffectiveEvent> &ev2, | 99 | QValueList<EffectiveEvent> &ev2, |
100 | QDate &d, bool onM, | 100 | QDate &d, bool onM, |
101 | QWidget* parent = 0, const char* name = 0, | 101 | QWidget* parent = 0, const char* name = 0, |
102 | WFlags fl = 0 ); | 102 | WFlags fl = 0 ); |
103 | signals: | 103 | signals: |
104 | void editEvent(const Event &e); | 104 | void editEvent(const Event &e); |
105 | void showDate(int y, int m, int d); | 105 | void showDate(int y, int m, int d); |
106 | void addEvent(const QDateTime &start, const QDateTime &stop, | 106 | void addEvent(const QDateTime &start, const QDateTime &stop, |
107 | const QString &str, const QString &location); | 107 | const QString &str, const QString &location); |
108 | }; | 108 | }; |
109 | 109 | ||
110 | class DateBookWeekLst : public QWidget | 110 | class DateBookWeekLst : public QWidget |
111 | { | 111 | { |
112 | Q_OBJECT | 112 | Q_OBJECT |
113 | 113 | ||
114 | public: | 114 | public: |
115 | DateBookWeekLst( bool ampm, bool onM, DateBookDB *newDB, | 115 | DateBookWeekLst( bool ampm, bool onM, DateBookDB *newDB, |
116 | QWidget *parent = 0, | 116 | QWidget *parent = 0, |
117 | const char *name = 0 ); | 117 | const char *name = 0 ); |
118 | ~DateBookWeekLst(); | 118 | ~DateBookWeekLst(); |
119 | void setDate( int y, int w ); | 119 | void setDate( int y, int w ); |
120 | void setDate(const QDate &d ); | 120 | void setDate(const QDate &d ); |
121 | int week() const { return _week; }; | 121 | int week() const { return _week; }; |
122 | QDate date() const; | 122 | QDate date(); |
123 | 123 | ||
124 | public slots: | 124 | public slots: |
125 | void redraw(); | 125 | void redraw(); |
126 | void dateChanged(int y, int w); | 126 | void dateChanged(QDate &date); |
127 | 127 | ||
128 | protected slots: | 128 | protected slots: |
129 | void keyPressEvent(QKeyEvent *); | 129 | void keyPressEvent(QKeyEvent *); |
130 | void setDbl(bool on); | 130 | void setDbl(bool on); |
131 | 131 | ||
132 | signals: | 132 | signals: |
133 | void showDate(int y, int m, int d); | 133 | void showDate(int y, int m, int d); |
134 | void addEvent(const QDateTime &start, const QDateTime &stop, | 134 | void addEvent(const QDateTime &start, const QDateTime &stop, |
135 | const QString &str, const QString &location); | 135 | const QString &str, const QString &location); |
136 | void editEvent(const Event &e); | 136 | void editEvent(const Event &e); |
137 | 137 | ||
138 | private: | 138 | private: |
139 | DateBookDB *db; | 139 | DateBookDB *db; |
140 | int startTime; | 140 | int startTime; |
141 | bool ampm; | 141 | bool ampm; |
142 | bool bStartOnMonday; | 142 | bool bStartOnMonday; |
143 | bool dbl; | 143 | bool dbl; |
144 | int year, _week; | 144 | QDate bdate; |
145 | int year, _week,dow; | ||
145 | DateBookWeekLstHeader *header; | 146 | DateBookWeekLstHeader *header; |
146 | QWidget *view; | 147 | QWidget *view; |
147 | QVBoxLayout *layout; | 148 | QVBoxLayout *layout; |
148 | QScrollView *scroll; | 149 | QScrollView *scroll; |
149 | 150 | ||
150 | void getEvents(); | 151 | void getEvents(); |
151 | }; | 152 | }; |
152 | 153 | ||
153 | #endif | 154 | #endif |
154 | 155 | ||