Diffstat (limited to 'core/pim/datebook/datebookday.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/pim/datebook/datebookday.cpp | 123 |
1 files changed, 117 insertions, 6 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index 0b213e9..f4008e9 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp | |||
@@ -1,47 +1,48 @@ | |||
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 <qmessagebox.h> | 20 | #include <qmessagebox.h> |
21 | 21 | ||
22 | #include "datebookday.h" | 22 | #include "datebookday.h" |
23 | #include "datebookdayheaderimpl.h" | 23 | #include "datebookdayheaderimpl.h" |
24 | #include "datebookdayallday.h" | ||
24 | 25 | ||
25 | #include <qpe/datebookdb.h> | 26 | #include <qpe/datebookdb.h> |
26 | #include <qpe/resource.h> | 27 | #include <qpe/resource.h> |
27 | #include <qpe/event.h> | 28 | #include <qpe/event.h> |
28 | #include <qpe/qpeapplication.h> | 29 | #include <qpe/qpeapplication.h> |
29 | #include <qpe/timestring.h> | 30 | #include <qpe/timestring.h> |
30 | #include <qpe/qpedebug.h> | 31 | #include <qpe/qpedebug.h> |
31 | #include <qpe/ir.h> | 32 | #include <qpe/ir.h> |
32 | 33 | ||
33 | #include <qheader.h> | 34 | #include <qheader.h> |
34 | #include <qdatetime.h> | 35 | #include <qdatetime.h> |
35 | #include <qpainter.h> | 36 | #include <qpainter.h> |
36 | #include <qsimplerichtext.h> | 37 | #include <qsimplerichtext.h> |
37 | #include <qpopupmenu.h> | 38 | #include <qpopupmenu.h> |
38 | #include <qtextcodec.h> | 39 | #include <qtextcodec.h> |
39 | #include <qpalette.h> | 40 | #include <qpalette.h> |
40 | 41 | ||
41 | #include <qlineedit.h> | 42 | #include <qlineedit.h> |
42 | 43 | ||
43 | #include <qtimer.h> | 44 | #include <qtimer.h> |
44 | 45 | ||
45 | DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, const char *name ) | 46 | DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, const char *name ) |
46 | : QTable( 24, 1, parent, name ), ampm( whichClock ), currDate( QDate::currentDate() ) | 47 | : QTable( 24, 1, parent, name ), ampm( whichClock ), currDate( QDate::currentDate() ) |
47 | { | 48 | { |
@@ -190,82 +191,91 @@ void DateBookDayView::contentsMouseReleaseEvent( QMouseEvent *e ) | |||
190 | quickLineEdit->setGeometry(0,0,this->columnWidth(0)-1,this->rowHeight(0)); | 191 | quickLineEdit->setGeometry(0,0,this->columnWidth(0)-1,this->rowHeight(0)); |
191 | this->moveChild(quickLineEdit,0,sh*this->rowHeight(0)); | 192 | this->moveChild(quickLineEdit,0,sh*this->rowHeight(0)); |
192 | quickLineEdit->setFocus(); | 193 | quickLineEdit->setFocus(); |
193 | quickLineEdit->show(); | 194 | quickLineEdit->show(); |
194 | } | 195 | } |
195 | 196 | ||
196 | //=========================================================================== | 197 | //=========================================================================== |
197 | 198 | ||
198 | DateBookDayViewQuickLineEdit::DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name) : QLineEdit(parent,name) | 199 | DateBookDayViewQuickLineEdit::DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name) : QLineEdit(parent,name) |
199 | { | 200 | { |
200 | active=1; | 201 | active=1; |
201 | quickEvent.setStart(start); | 202 | quickEvent.setStart(start); |
202 | quickEvent.setEnd(end); | 203 | quickEvent.setEnd(end); |
203 | connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed())); | 204 | connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed())); |
204 | } | 205 | } |
205 | 206 | ||
206 | void DateBookDayViewQuickLineEdit::slotReturnPressed() | 207 | void DateBookDayViewQuickLineEdit::slotReturnPressed() |
207 | { | 208 | { |
208 | if(active && (!this->text().isEmpty())) {// Fix to avoid having this event beeing added multiple times. | 209 | if(active && (!this->text().isEmpty())) {// Fix to avoid having this event beeing added multiple times. |
209 | quickEvent.setDescription(this->text()); | 210 | quickEvent.setDescription(this->text()); |
210 | connect(this,SIGNAL(insertEvent(const Event &)),this->topLevelWidget(),SLOT(insertEvent(const Event &))); | 211 | connect(this,SIGNAL(insertEvent(const Event &)),this->topLevelWidget(),SLOT(insertEvent(const Event &))); |
211 | emit(insertEvent(quickEvent)); | 212 | emit(insertEvent(quickEvent)); |
212 | active=0; | 213 | active=0; |
213 | } | 214 | } |
214 | this->close(true);// Close and also delete this widget | 215 | /* we need to return to this object.. */ |
216 | QTimer::singleShot(500, this, SLOT(finallyCallClose()) );// Close and also delete this widget | ||
217 | } | ||
218 | void DateBookDayViewQuickLineEdit::finallyCallClose() { | ||
219 | close(true); // also deletes this widget... | ||
215 | } | 220 | } |
216 | 221 | ||
217 | void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent * e ) | 222 | void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent * e ) |
218 | { | 223 | { |
219 | slotReturnPressed(); // Reuse code to add event and close this widget. | 224 | slotReturnPressed(); // Reuse code to add event and close this widget. |
220 | } | 225 | } |
221 | 226 | ||
222 | //=========================================================================== | 227 | //=========================================================================== |
223 | 228 | ||
224 | DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name ) | 229 | DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name ) |
225 | : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 ) | 230 | : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 ) |
226 | { | 231 | { |
227 | widgetList.setAutoDelete( true ); | 232 | widgetList.setAutoDelete( true ); |
228 | header = new DateBookDayHeader( startOnMonday, this, "day header" ); | 233 | header = new DateBookDayHeader( startOnMonday, this, "day header" ); |
229 | header->setDate( currDate.year(), currDate.month(), currDate.day() ); | 234 | header->setDate( currDate.year(), currDate.month(), currDate.day() ); |
235 | |||
236 | m_allDays = new DatebookdayAllday(newDb, this, "all day event list" ); | ||
237 | m_allDays->hide(); | ||
238 | |||
230 | view = new DateBookDayView( ampm, this, "day view" ); | 239 | view = new DateBookDayView( ampm, this, "day view" ); |
231 | 240 | ||
232 | connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( int, int, int ) ) ); | 241 | connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( int, int, int ) ) ); |
233 | connect( header, SIGNAL( dateChanged( int, int, int ) ), view, SLOT( slotDateChanged( int, int, int ) ) ); | 242 | connect( header, SIGNAL( dateChanged( int, int, int ) ), view, SLOT( slotDateChanged( int, int, int ) ) ); |
234 | connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) ); | 243 | connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) ); |
235 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); | 244 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); |
236 | connect( view, SIGNAL(sigCapturedKey(const QString &)), this, SIGNAL(sigNewEvent(const QString&)) ); | 245 | connect( view, SIGNAL(sigCapturedKey(const QString &)), this, SIGNAL(sigNewEvent(const QString&)) ); |
237 | 246 | ||
238 | QTimer *timer = new QTimer( this ); | 247 | QTimer *timer = new QTimer( this ); |
239 | 248 | ||
240 | connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors | 249 | connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors |
241 | timer->start( 1000*60*5, FALSE ); //update every 5min | 250 | timer->start( 1000*60*5, FALSE ); //update every 5min |
242 | 251 | ||
243 | selectedWidget = 0; | 252 | selectedWidget = 0; |
244 | 253 | ||
245 | timeMarker = new DateBookDayTimeMarker( this ); | 254 | timeMarker = new DateBookDayTimeMarker( this ); |
246 | timeMarker->setTime( QTime::currentTime() ); | 255 | timeMarker->setTime( QTime::currentTime() ); |
247 | rowStyle = -1; // initialize with bogus values | 256 | rowStyle = -1; // initialize with bogus values |
257 | jumpToCurTime = false; | ||
248 | } | 258 | } |
249 | 259 | ||
250 | void DateBookDay::setJumpToCurTime( bool bJump ) | 260 | void DateBookDay::setJumpToCurTime( bool bJump ) |
251 | { | 261 | { |
252 | jumpToCurTime = bJump; | 262 | jumpToCurTime = bJump; |
253 | } | 263 | } |
254 | 264 | ||
255 | void DateBookDay::setRowStyle( int style ) | 265 | void DateBookDay::setRowStyle( int style ) |
256 | { | 266 | { |
257 | if (rowStyle != style) view->setRowStyle( style ); | 267 | if (rowStyle != style) view->setRowStyle( style ); |
258 | rowStyle = style; | 268 | rowStyle = style; |
259 | } | 269 | } |
260 | 270 | ||
261 | void DateBookDay::updateView( void ) | 271 | void DateBookDay::updateView( void ) |
262 | { | 272 | { |
263 | timeMarker->setTime( QTime::currentTime() ); | 273 | timeMarker->setTime( QTime::currentTime() ); |
264 | //need to find a way to update all DateBookDayWidgets | 274 | //need to find a way to update all DateBookDayWidgets |
265 | } | 275 | } |
266 | 276 | ||
267 | void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) | 277 | void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) |
268 | { | 278 | { |
269 | selectedWidget = w; | 279 | selectedWidget = w; |
270 | } | 280 | } |
271 | 281 | ||
@@ -322,104 +332,125 @@ void DateBookDay::dateChanged( int y, int m, int d ) | |||
322 | 332 | ||
323 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 333 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
324 | { | 334 | { |
325 | ts.init( QTime::currentTime().hour(), 0); | 335 | ts.init( QTime::currentTime().hour(), 0); |
326 | ts.expandTo( QTime::currentTime().hour(), 0); | 336 | ts.expandTo( QTime::currentTime().hour(), 0); |
327 | } else { | 337 | } else { |
328 | ts.init( startTime, 0 ); | 338 | ts.init( startTime, 0 ); |
329 | ts.expandTo( startTime, 0 ); | 339 | ts.expandTo( startTime, 0 ); |
330 | } | 340 | } |
331 | 341 | ||
332 | dayView()->addSelection( ts ); | 342 | dayView()->addSelection( ts ); |
333 | selectedWidget = 0; | 343 | selectedWidget = 0; |
334 | } | 344 | } |
335 | 345 | ||
336 | void DateBookDay::redraw() | 346 | void DateBookDay::redraw() |
337 | { | 347 | { |
338 | if ( isUpdatesEnabled() ) | 348 | if ( isUpdatesEnabled() ) |
339 | relayoutPage(); | 349 | relayoutPage(); |
340 | } | 350 | } |
341 | 351 | ||
342 | void DateBookDay::getEvents() | 352 | void DateBookDay::getEvents() |
343 | { | 353 | { |
344 | widgetList.clear(); | 354 | widgetList.clear(); |
345 | 355 | ||
356 | /* clear the AllDay List */ | ||
357 | m_allDays->hide(); // just in case | ||
358 | m_allDays->removeAllEvents(); | ||
359 | |||
346 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); | 360 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); |
347 | QValueListIterator<EffectiveEvent> it; | 361 | QValueListIterator<EffectiveEvent> it; |
362 | QObject* object = 0; | ||
348 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { | 363 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { |
349 | EffectiveEvent ev=*it; | 364 | EffectiveEvent ev=*it; |
350 | if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) {// Skip events ending at 00:00 starting at another day. | 365 | if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) {// Skip events ending at 00:00 starting at another day. |
366 | if (ev.event().type() == Event::AllDay ) { | ||
367 | object = m_allDays->addEvent( ev ); | ||
368 | if (!object) | ||
369 | continue; | ||
370 | }else { | ||
351 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); | 371 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); |
352 | connect( w, SIGNAL( deleteMe( const Event & ) ), this, SIGNAL( removeEvent( const Event & ) ) ); | ||
353 | connect( w, SIGNAL( duplicateMe( const Event & ) ), this, SIGNAL( duplicateEvent( const Event & ) ) ); | ||
354 | connect( w, SIGNAL( editMe( const Event & ) ), this, SIGNAL( editEvent( const Event & ) ) ); | ||
355 | connect( w, SIGNAL( beamMe( const Event & ) ), this, SIGNAL( beamEvent( const Event & ) ) ); | ||
356 | widgetList.append( w ); | 372 | widgetList.append( w ); |
373 | object = w; | ||
374 | } | ||
375 | |||
376 | connect( object, SIGNAL( deleteMe( const Event & ) ), this, SIGNAL( removeEvent( const Event & ) ) ); | ||
377 | connect( object, SIGNAL( duplicateMe( const Event & ) ), this, SIGNAL( duplicateEvent( const Event & ) ) ); | ||
378 | connect( object, SIGNAL( editMe( const Event & ) ), this, SIGNAL( editEvent( const Event & ) ) ); | ||
379 | connect( object, SIGNAL( beamMe( const Event & ) ), this, SIGNAL( beamEvent( const Event & ) ) ); | ||
380 | |||
357 | } | 381 | } |
358 | } | 382 | } |
359 | } | 383 | } |
360 | 384 | ||
361 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) | 385 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) |
362 | { | 386 | { |
363 | int place = 0; | 387 | int place = 0; |
364 | int start = item->event().start().hour(); | 388 | int start = item->event().start().hour(); |
365 | QTime e = item->event().end(); | 389 | QTime e = item->event().end(); |
366 | int end = e.hour(); | 390 | int end = e.hour(); |
367 | if ( e.minute() < 5 ) | 391 | if ( e.minute() < 5 ) |
368 | end--; | 392 | end--; |
369 | if ( end < start ) | 393 | if ( end < start ) |
370 | end = start; | 394 | end = start; |
371 | while ( place < maxn ) { | 395 | while ( place < maxn ) { |
372 | bool free = TRUE; | 396 | bool free = TRUE; |
373 | int s = start; | 397 | int s = start; |
374 | while( s <= end ) { | 398 | while( s <= end ) { |
375 | if ( used[10*s+place] ) { | 399 | if ( used[10*s+place] ) { |
376 | free = FALSE; | 400 | free = FALSE; |
377 | break; | 401 | break; |
378 | } | 402 | } |
379 | s++; | 403 | s++; |
380 | } | 404 | } |
381 | if ( free ) | 405 | if ( free ) |
382 | break; | 406 | break; |
383 | place++; | 407 | place++; |
384 | } | 408 | } |
385 | if ( place == maxn ) { | 409 | if ( place == maxn ) { |
386 | return -1; | 410 | return -1; |
387 | } | 411 | } |
388 | while( start <= end ) { | 412 | while( start <= end ) { |
389 | used[10*start+place] = TRUE; | 413 | used[10*start+place] = TRUE; |
390 | start++; | 414 | start++; |
391 | } | 415 | } |
392 | return place; | 416 | return place; |
393 | } | 417 | } |
394 | 418 | ||
395 | 419 | ||
396 | void DateBookDay::relayoutPage( bool fromResize ) | 420 | void DateBookDay::relayoutPage( bool fromResize ) |
397 | { | 421 | { |
398 | setUpdatesEnabled( FALSE ); | 422 | setUpdatesEnabled( FALSE ); |
399 | if ( !fromResize ) | 423 | if ( !fromResize ) { |
400 | getEvents(); // no need we already have them! | 424 | getEvents(); // no need we already have them! |
401 | 425 | ||
426 | if (m_allDays->items() > 0 ) | ||
427 | m_allDays->show(); | ||
428 | /* | ||
429 | * else if ( m_allDays->items() == 0 ) already hide in getEvents | ||
430 | */ | ||
431 | } | ||
432 | |||
402 | widgetList.sort(); | 433 | widgetList.sort(); |
403 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning | 434 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning |
404 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view | 435 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view |
405 | 436 | ||
406 | int wCount = widgetList.count(); | 437 | int wCount = widgetList.count(); |
407 | int wid = view->columnWidth(0)-1; | 438 | int wid = view->columnWidth(0)-1; |
408 | int wd; | 439 | int wd; |
409 | int n = 1; | 440 | int n = 1; |
410 | 441 | ||
411 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget | 442 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget |
412 | 443 | ||
413 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); | 444 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); |
414 | 445 | ||
415 | if ( wCount < 20 ) { | 446 | if ( wCount < 20 ) { |
416 | 447 | ||
417 | QArray<QRect> geometries(wCount); | 448 | QArray<QRect> geometries(wCount); |
418 | for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector | 449 | for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector |
419 | 450 | ||
420 | for ( int i = 0; i < wCount; i++) { | 451 | for ( int i = 0; i < wCount; i++) { |
421 | QValueList<int> intersectedWidgets; | 452 | QValueList<int> intersectedWidgets; |
422 | 453 | ||
423 | //find all widgets intersecting with widgetList.at(i) | 454 | //find all widgets intersecting with widgetList.at(i) |
424 | for ( int j = 0; j < wCount; j++) { | 455 | for ( int j = 0; j < wCount; j++) { |
425 | if (i != j) | 456 | if (i != j) |
@@ -709,74 +740,154 @@ void DateBookDayWidget::paintEvent( QPaintEvent *e ) | |||
709 | p.drawRect(rect()); | 740 | p.drawRect(rect()); |
710 | 741 | ||
711 | // p.drawRect(0,0, 5, height()); | 742 | // p.drawRect(0,0, 5, height()); |
712 | 743 | ||
713 | int y = 0; | 744 | int y = 0; |
714 | int d = 0; | 745 | int d = 0; |
715 | 746 | ||
716 | if ( ev.event().hasAlarm() ) { | 747 | if ( ev.event().hasAlarm() ) { |
717 | p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); | 748 | p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); |
718 | y = 20; | 749 | y = 20; |
719 | d = 20; | 750 | d = 20; |
720 | } | 751 | } |
721 | 752 | ||
722 | if ( ev.event().hasRepeat() ) { | 753 | if ( ev.event().hasRepeat() ) { |
723 | p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); | 754 | p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); |
724 | d = 20; | 755 | d = 20; |
725 | y += 20; | 756 | y += 20; |
726 | } | 757 | } |
727 | 758 | ||
728 | QSimpleRichText rt( text, font() ); | 759 | QSimpleRichText rt( text, font() ); |
729 | rt.setWidth( geom.width() - d - 6 ); | 760 | rt.setWidth( geom.width() - d - 6 ); |
730 | rt.draw( &p, 7, 0, e->region(), colorGroup() ); | 761 | rt.draw( &p, 7, 0, e->region(), colorGroup() ); |
731 | } | 762 | } |
732 | 763 | ||
764 | /* | ||
765 | * we need to find the real start date for a uid | ||
766 | * we need to check from one day to another... | ||
767 | */ | ||
768 | QDate DateBookDay::findRealStart( int uid, const QDate& isIncluded , DateBookDB* db) { | ||
769 | QDate dt( isIncluded ); | ||
770 | QDate fnd = dt; | ||
771 | |||
772 | bool doAgain = true; | ||
773 | do{ | ||
774 | dt = dt.addDays( -1 ); | ||
775 | QValueList<EffectiveEvent> events = db->getEffectiveEvents( dt, dt ); | ||
776 | for (QValueList<EffectiveEvent>::Iterator it = events.begin(); it != events.end(); ++it ) { | ||
777 | EffectiveEvent ev = (*it); | ||
778 | if ( uid == ev.event().uid() && ev.start() != QTime(0, 0, 0 ) ) | ||
779 | return ev.date(); | ||
780 | } | ||
781 | }while (doAgain ); | ||
782 | |||
783 | return fnd; | ||
784 | } | ||
785 | |||
733 | void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) | 786 | void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) |
734 | { | 787 | { |
735 | DateBookDayWidget *item; | 788 | DateBookDayWidget *item; |
736 | 789 | ||
737 | item = dateBook->getSelectedWidget(); | 790 | item = dateBook->getSelectedWidget(); |
738 | if (item) | 791 | if (item) |
739 | item->update(); | 792 | item->update(); |
740 | 793 | ||
741 | dateBook->setSelectedWidget(this); | 794 | dateBook->setSelectedWidget(this); |
742 | update(); | 795 | update(); |
743 | dateBook->repaint(); | 796 | dateBook->repaint(); |
744 | 797 | ||
745 | QPopupMenu m; | 798 | QPopupMenu m; |
746 | m.insertItem( tr( "Edit" ), 1 ); | 799 | m.insertItem( tr( "Edit" ), 1 ); |
747 | m.insertItem( tr( "Duplicate" ), 4 ); | 800 | m.insertItem( tr( "Duplicate" ), 4 ); |
748 | m.insertItem( tr( "Delete" ), 2 ); | 801 | m.insertItem( tr( "Delete" ), 2 ); |
749 | if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); | 802 | if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); |
803 | if(Ir::supported() && ev.event().doRepeat() ) m.insertItem( tr( "Beam this occurence"), 5 ); | ||
750 | int r = m.exec( e->globalPos() ); | 804 | int r = m.exec( e->globalPos() ); |
751 | if ( r == 1 ) { | 805 | if ( r == 1 ) { |
752 | emit editMe( ev.event() ); | 806 | emit editMe( ev.event() ); |
753 | } else if ( r == 2 ) { | 807 | } else if ( r == 2 ) { |
754 | emit deleteMe( ev.event() ); | 808 | emit deleteMe( ev.event() ); |
755 | } else if ( r == 3 ) { | 809 | } else if ( r == 3 ) { |
756 | emit beamMe( ev.event() ); | 810 | emit beamMe( ev.event() ); |
757 | } else if ( r == 4 ) { | 811 | } else if ( r == 4 ) { |
758 | emit duplicateMe( ev.event() ); | 812 | emit duplicateMe( ev.event() ); |
813 | } else if ( r == 5 ) { | ||
814 | // create an Event and beam it... | ||
815 | /* | ||
816 | * Start with the easy stuff. If start and end date is the same we can just use | ||
817 | * the values of effective events | ||
818 | * If it is a multi day event we need to find the real start and end date... | ||
819 | */ | ||
820 | if ( ev.event().start().date() == ev.event().end().date() ) { | ||
821 | Event event( ev.event() ); | ||
822 | |||
823 | QDateTime dt( ev.date(), ev.start() ); | ||
824 | event.setStart( dt ); | ||
825 | |||
826 | dt.setTime( ev.end() ); | ||
827 | event.setEnd( dt ); | ||
828 | emit beamMe( event ); | ||
829 | }else { | ||
830 | /* | ||
831 | * at least the the Times are right now | ||
832 | */ | ||
833 | QDateTime start( ev.event().start() ); | ||
834 | QDateTime end ( ev.event().end () ); | ||
835 | |||
836 | |||
837 | /* | ||
838 | * ok we know the start date or we need to find it | ||
839 | */ | ||
840 | if ( ev.start() != QTime( 0, 0, 0 ) ) { | ||
841 | start.setDate( ev.date() ); | ||
842 | }else { | ||
843 | QDate dt = DateBookDay::findRealStart( ev.event().uid(), ev.date(), dateBook->db ); | ||
844 | start.setDate( dt ); | ||
845 | } | ||
846 | |||
847 | |||
848 | /* | ||
849 | * ok we know now the end date... | ||
850 | * else | ||
851 | * get to know the offset btw the real start and real end | ||
852 | * and then add it to the new start date... | ||
853 | */ | ||
854 | if ( ev.end() != QTime(23, 59, 59 ) ) { | ||
855 | end.setDate( ev.date() ); | ||
856 | }else{ | ||
857 | int days = ev.event().start().date().daysTo( ev.event().end().date() ); | ||
858 | end.setDate( start.date().addDays( days ) ); | ||
859 | } | ||
860 | |||
861 | |||
862 | |||
863 | Event event( ev.event() ); | ||
864 | event.setStart( start ); | ||
865 | event.setEnd ( end ); | ||
866 | |||
867 | |||
868 | emit beamMe( event ); | ||
869 | } | ||
759 | } | 870 | } |
760 | } | 871 | } |
761 | 872 | ||
762 | void DateBookDayWidget::setGeometry( const QRect &r ) | 873 | void DateBookDayWidget::setGeometry( const QRect &r ) |
763 | { | 874 | { |
764 | geom = r; | 875 | geom = r; |
765 | setFixedSize( r.width()+1, r.height()+1 ); | 876 | setFixedSize( r.width()+1, r.height()+1 ); |
766 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); | 877 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); |
767 | show(); | 878 | show(); |
768 | } | 879 | } |
769 | 880 | ||
770 | 881 | ||
771 | //--------------------------------------------------------------------------------------------- | 882 | //--------------------------------------------------------------------------------------------- |
772 | //--------------------------------------------------------------------------------------------- | 883 | //--------------------------------------------------------------------------------------------- |
773 | 884 | ||
774 | 885 | ||
775 | DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) | 886 | DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) |
776 | : QWidget( db->dayView()->viewport() ), dateBook( db ) | 887 | : QWidget( db->dayView()->viewport() ), dateBook( db ) |
777 | { | 888 | { |
778 | setBackgroundMode( PaletteBase ); | 889 | setBackgroundMode( PaletteBase ); |
779 | } | 890 | } |
780 | 891 | ||
781 | DateBookDayTimeMarker::~DateBookDayTimeMarker() | 892 | DateBookDayTimeMarker::~DateBookDayTimeMarker() |
782 | { | 893 | { |