author | umopapisdn <umopapisdn> | 2003-03-23 20:33:00 (UTC) |
---|---|---|
committer | umopapisdn <umopapisdn> | 2003-03-23 20:33:00 (UTC) |
commit | b5606a63c9f3524f9475b6ac79f0b6bcc7162fa6 (patch) (unidiff) | |
tree | d4c7bd2dbf63858d3ac70926514d91a4bd6d63e0 | |
parent | dfa17505b14011b50822d50c925cc6aa0299b1b4 (diff) | |
download | opie-b5606a63c9f3524f9475b6ac79f0b6bcc7162fa6.zip opie-b5606a63c9f3524f9475b6ac79f0b6bcc7162fa6.tar.gz opie-b5606a63c9f3524f9475b6ac79f0b6bcc7162fa6.tar.bz2 |
Bugfix: (bug #0000211) Events ending at mat the following day. Fix for dayview.
-rw-r--r-- | core/pim/datebook/datebookday.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index a6a1be3..42f026a 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp | |||
@@ -210,250 +210,252 @@ void DateBookDay::setJumpToCurTime( bool bJump ) | |||
210 | jumpToCurTime = bJump; | 210 | jumpToCurTime = bJump; |
211 | } | 211 | } |
212 | 212 | ||
213 | void DateBookDay::setRowStyle( int style ) | 213 | void DateBookDay::setRowStyle( int style ) |
214 | { | 214 | { |
215 | if (rowStyle != style) view->setRowStyle( style ); | 215 | if (rowStyle != style) view->setRowStyle( style ); |
216 | rowStyle = style; | 216 | rowStyle = style; |
217 | } | 217 | } |
218 | 218 | ||
219 | void DateBookDay::updateView( void ) | 219 | void DateBookDay::updateView( void ) |
220 | { | 220 | { |
221 | timeMarker->setTime( QTime::currentTime() ); | 221 | timeMarker->setTime( QTime::currentTime() ); |
222 | //need to find a way to update all DateBookDayWidgets | 222 | //need to find a way to update all DateBookDayWidgets |
223 | } | 223 | } |
224 | 224 | ||
225 | void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) | 225 | void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) |
226 | { | 226 | { |
227 | selectedWidget = w; | 227 | selectedWidget = w; |
228 | } | 228 | } |
229 | 229 | ||
230 | DateBookDayWidget * DateBookDay::getSelectedWidget( void ) | 230 | DateBookDayWidget * DateBookDay::getSelectedWidget( void ) |
231 | { | 231 | { |
232 | return selectedWidget; | 232 | return selectedWidget; |
233 | } | 233 | } |
234 | 234 | ||
235 | void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) | 235 | void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) |
236 | { | 236 | { |
237 | start.setDate( currDate ); | 237 | start.setDate( currDate ); |
238 | end.setDate( currDate ); | 238 | end.setDate( currDate ); |
239 | 239 | ||
240 | int sh=99,eh=-1; | 240 | int sh=99,eh=-1; |
241 | 241 | ||
242 | int n = dayView()->numSelections(); | 242 | int n = dayView()->numSelections(); |
243 | 243 | ||
244 | for (int i=0; i<n; i++) { | 244 | for (int i=0; i<n; i++) { |
245 | QTableSelection sel = dayView()->selection( i ); | 245 | QTableSelection sel = dayView()->selection( i ); |
246 | sh = QMIN(sh,sel.topRow()); | 246 | sh = QMIN(sh,sel.topRow()); |
247 | eh = QMAX(sh,sel.bottomRow()+1); | 247 | eh = QMAX(sh,sel.bottomRow()+1); |
248 | } | 248 | } |
249 | if (sh > 23 || eh < 1) { | 249 | if (sh > 23 || eh < 1) { |
250 | sh=8; | 250 | sh=8; |
251 | eh=9; | 251 | eh=9; |
252 | } | 252 | } |
253 | 253 | ||
254 | start.setTime( QTime( sh, 0, 0 ) ); | 254 | start.setTime( QTime( sh, 0, 0 ) ); |
255 | end.setTime( QTime( eh, 0, 0 ) ); | 255 | end.setTime( QTime( eh, 0, 0 ) ); |
256 | } | 256 | } |
257 | 257 | ||
258 | void DateBookDay::setDate( int y, int m, int d ) | 258 | void DateBookDay::setDate( int y, int m, int d ) |
259 | { | 259 | { |
260 | header->setDate( y, m, d ); | 260 | header->setDate( y, m, d ); |
261 | 261 | ||
262 | selectedWidget = 0; | 262 | selectedWidget = 0; |
263 | } | 263 | } |
264 | 264 | ||
265 | void DateBookDay::setDate( QDate d) | 265 | void DateBookDay::setDate( QDate d) |
266 | { | 266 | { |
267 | header->setDate( d.year(), d.month(), d.day() ); | 267 | header->setDate( d.year(), d.month(), d.day() ); |
268 | 268 | ||
269 | selectedWidget = 0; | 269 | selectedWidget = 0; |
270 | } | 270 | } |
271 | 271 | ||
272 | void DateBookDay::dateChanged( int y, int m, int d ) | 272 | void DateBookDay::dateChanged( int y, int m, int d ) |
273 | { | 273 | { |
274 | QDate date( y, m, d ); | 274 | QDate date( y, m, d ); |
275 | if ( currDate == date ) | 275 | if ( currDate == date ) |
276 | return; | 276 | return; |
277 | currDate.setYMD( y, m, d ); | 277 | currDate.setYMD( y, m, d ); |
278 | relayoutPage(); | 278 | relayoutPage(); |
279 | dayView()->clearSelection(); | 279 | dayView()->clearSelection(); |
280 | QTableSelection ts; | 280 | QTableSelection ts; |
281 | 281 | ||
282 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 282 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
283 | { | 283 | { |
284 | ts.init( QTime::currentTime().hour(), 0); | 284 | ts.init( QTime::currentTime().hour(), 0); |
285 | ts.expandTo( QTime::currentTime().hour(), 0); | 285 | ts.expandTo( QTime::currentTime().hour(), 0); |
286 | } else | 286 | } else |
287 | { | 287 | { |
288 | ts.init( startTime, 0 ); | 288 | ts.init( startTime, 0 ); |
289 | ts.expandTo( startTime, 0 ); | 289 | ts.expandTo( startTime, 0 ); |
290 | } | 290 | } |
291 | 291 | ||
292 | dayView()->addSelection( ts ); | 292 | dayView()->addSelection( ts ); |
293 | 293 | ||
294 | selectedWidget = 0; | 294 | selectedWidget = 0; |
295 | 295 | ||
296 | } | 296 | } |
297 | 297 | ||
298 | void DateBookDay::redraw() | 298 | void DateBookDay::redraw() |
299 | { | 299 | { |
300 | if ( isUpdatesEnabled() ) | 300 | if ( isUpdatesEnabled() ) |
301 | relayoutPage(); | 301 | relayoutPage(); |
302 | } | 302 | } |
303 | 303 | ||
304 | void DateBookDay::getEvents() | 304 | void DateBookDay::getEvents() |
305 | { | 305 | { |
306 | widgetList.clear(); | 306 | widgetList.clear(); |
307 | 307 | ||
308 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, | 308 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); |
309 | currDate ); | 309 | QValueListIterator<EffectiveEvent> it; |
310 | QValueListIterator<EffectiveEvent> it; | 310 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { |
311 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { | 311 | EffectiveEvent ev=*it; |
312 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); | 312 | if(!(ev.end().hour()==ev.start().hour() && ev.end().minute()==ev.start().minute())) {// Skip effective events with no duration. (i.e ending at 00:00) |
313 | connect( w, SIGNAL( deleteMe( const Event & ) ), | 313 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); |
314 | this, SIGNAL( removeEvent( const Event & ) ) ); | 314 | connect( w, SIGNAL( deleteMe( const Event & ) ), |
315 | connect( w, SIGNAL( editMe( const Event & ) ), | 315 | this, SIGNAL( removeEvent( const Event & ) ) ); |
316 | this, SIGNAL( editEvent( const Event & ) ) ); | 316 | connect( w, SIGNAL( editMe( const Event & ) ), |
317 | connect( w, SIGNAL( beamMe( const Event & ) ), | 317 | this, SIGNAL( editEvent( const Event & ) ) ); |
318 | this, SIGNAL( beamEvent( const Event & ) ) ); | 318 | connect( w, SIGNAL( beamMe( const Event & ) ), |
319 | widgetList.append( w ); | 319 | this, SIGNAL( beamEvent( const Event & ) ) ); |
320 | widgetList.append( w ); | ||
321 | } | ||
320 | } | 322 | } |
321 | 323 | ||
322 | } | 324 | } |
323 | 325 | ||
324 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) | 326 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) |
325 | { | 327 | { |
326 | int place = 0; | 328 | int place = 0; |
327 | int start = item->event().start().hour(); | 329 | int start = item->event().start().hour(); |
328 | QTime e = item->event().end(); | 330 | QTime e = item->event().end(); |
329 | int end = e.hour(); | 331 | int end = e.hour(); |
330 | if ( e.minute() < 5 ) | 332 | if ( e.minute() < 5 ) |
331 | end--; | 333 | end--; |
332 | if ( end < start ) | 334 | if ( end < start ) |
333 | end = start; | 335 | end = start; |
334 | while ( place < maxn ) { | 336 | while ( place < maxn ) { |
335 | bool free = TRUE; | 337 | bool free = TRUE; |
336 | int s = start; | 338 | int s = start; |
337 | while( s <= end ) { | 339 | while( s <= end ) { |
338 | if ( used[10*s+place] ) { | 340 | if ( used[10*s+place] ) { |
339 | free = FALSE; | 341 | free = FALSE; |
340 | break; | 342 | break; |
341 | } | 343 | } |
342 | s++; | 344 | s++; |
343 | } | 345 | } |
344 | if ( free ) break; | 346 | if ( free ) break; |
345 | place++; | 347 | place++; |
346 | } | 348 | } |
347 | if ( place == maxn ) { | 349 | if ( place == maxn ) { |
348 | return -1; | 350 | return -1; |
349 | } | 351 | } |
350 | while( start <= end ) { | 352 | while( start <= end ) { |
351 | used[10*start+place] = TRUE; | 353 | used[10*start+place] = TRUE; |
352 | start++; | 354 | start++; |
353 | } | 355 | } |
354 | return place; | 356 | return place; |
355 | } | 357 | } |
356 | 358 | ||
357 | 359 | ||
358 | void DateBookDay::relayoutPage( bool fromResize ) | 360 | void DateBookDay::relayoutPage( bool fromResize ) |
359 | { | 361 | { |
360 | setUpdatesEnabled( FALSE ); | 362 | setUpdatesEnabled( FALSE ); |
361 | if ( !fromResize ) | 363 | if ( !fromResize ) |
362 | getEvents(); // no need we already have them! | 364 | getEvents(); // no need we already have them! |
363 | 365 | ||
364 | widgetList.sort(); | 366 | widgetList.sort(); |
365 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning | 367 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning |
366 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view | 368 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view |
367 | 369 | ||
368 | int wCount = widgetList.count(); | 370 | int wCount = widgetList.count(); |
369 | int wid = view->columnWidth(0)-1; | 371 | int wid = view->columnWidth(0)-1; |
370 | int wd; | 372 | int wd; |
371 | int n = 1; | 373 | int n = 1; |
372 | 374 | ||
373 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget | 375 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget |
374 | 376 | ||
375 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); | 377 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); |
376 | 378 | ||
377 | if ( wCount < 20 ) { | 379 | if ( wCount < 20 ) { |
378 | 380 | ||
379 | QArray<QRect> geometries(wCount); | 381 | QArray<QRect> geometries(wCount); |
380 | for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector | 382 | for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector |
381 | 383 | ||
382 | for ( int i = 0; i < wCount; i++) | 384 | for ( int i = 0; i < wCount; i++) |
383 | { | 385 | { |
384 | QValueList<int> intersectedWidgets; | 386 | QValueList<int> intersectedWidgets; |
385 | 387 | ||
386 | //find all widgets intersecting with widgetList.at(i) | 388 | //find all widgets intersecting with widgetList.at(i) |
387 | for ( int j = 0; j < wCount; j++) | 389 | for ( int j = 0; j < wCount; j++) |
388 | if (i != j) | 390 | if (i != j) |
389 | if (geometries[j].intersects(geometries[i])) | 391 | if (geometries[j].intersects(geometries[i])) |
390 | intersectedWidgets.append(j); | 392 | intersectedWidgets.append(j); |
391 | 393 | ||
392 | //for each of these intersecting widgets find out how many widgets are they intersecting with | 394 | //for each of these intersecting widgets find out how many widgets are they intersecting with |
393 | for ( uint j = 0; j < intersectedWidgets.count(); j++) | 395 | for ( uint j = 0; j < intersectedWidgets.count(); j++) |
394 | { | 396 | { |
395 | QArray<int> inter(wCount); | 397 | QArray<int> inter(wCount); |
396 | inter[j]=1; | 398 | inter[j]=1; |
397 | 399 | ||
398 | if (intersectedWidgets[j] != -1) | 400 | if (intersectedWidgets[j] != -1) |
399 | for ( uint k = j; k < intersectedWidgets.count(); k++) | 401 | for ( uint k = j; k < intersectedWidgets.count(); k++) |
400 | if (j != k && intersectedWidgets[k] != -1) | 402 | if (j != k && intersectedWidgets[k] != -1) |
401 | if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) | 403 | if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) |
402 | { | 404 | { |
403 | inter[j]++; | 405 | inter[j]++; |
404 | intersectedWidgets[k] = -1; | 406 | intersectedWidgets[k] = -1; |
405 | } | 407 | } |
406 | if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; | 408 | if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; |
407 | } | 409 | } |
408 | 410 | ||
409 | if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; | 411 | if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; |
410 | } | 412 | } |
411 | 413 | ||
412 | 414 | ||
413 | for ( int i = 0; i < wCount; i++) { | 415 | for ( int i = 0; i < wCount; i++) { |
414 | DateBookDayWidget *w = widgetList.at(i); | 416 | DateBookDayWidget *w = widgetList.at(i); |
415 | QRect geom = w->geometry(); | 417 | QRect geom = w->geometry(); |
416 | 418 | ||
417 | geom.setX( 0 ); | 419 | geom.setX( 0 ); |
418 | 420 | ||
419 | wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); | 421 | wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); |
420 | 422 | ||
421 | geom.setWidth( wd ); | 423 | geom.setWidth( wd ); |
422 | 424 | ||
423 | while ( intersects( w, geom ) ) { | 425 | while ( intersects( w, geom ) ) { |
424 | geom.moveBy( wd + 2 + 1, 0 ); | 426 | geom.moveBy( wd + 2 + 1, 0 ); |
425 | } | 427 | } |
426 | w->setGeometry( geom ); | 428 | w->setGeometry( geom ); |
427 | } | 429 | } |
428 | 430 | ||
429 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 431 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
430 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour | 432 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour |
431 | else | 433 | else |
432 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); | 434 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); |
433 | 435 | ||
434 | 436 | ||
435 | } else { | 437 | } else { |
436 | 438 | ||
437 | 439 | ||
438 | int hours[24]; | 440 | int hours[24]; |
439 | memset( hours, 0, 24*sizeof( int ) ); | 441 | memset( hours, 0, 24*sizeof( int ) ); |
440 | bool overFlow = FALSE; | 442 | bool overFlow = FALSE; |
441 | for ( int i = 0; i < wCount; i++ ) { | 443 | for ( int i = 0; i < wCount; i++ ) { |
442 | DateBookDayWidget *w = widgetList.at(i); | 444 | DateBookDayWidget *w = widgetList.at(i); |
443 | int start = w->event().start().hour(); | 445 | int start = w->event().start().hour(); |
444 | QTime e = w->event().end(); | 446 | QTime e = w->event().end(); |
445 | int end = e.hour(); | 447 | int end = e.hour(); |
446 | if ( e.minute() < 5 ) | 448 | if ( e.minute() < 5 ) |
447 | end--; | 449 | end--; |
448 | if ( end < start ) | 450 | if ( end < start ) |
449 | end = start; | 451 | end = start; |
450 | while( start <= end ) { | 452 | while( start <= end ) { |
451 | hours[start]++; | 453 | hours[start]++; |
452 | if ( hours[start] >= 10 ) | 454 | if ( hours[start] >= 10 ) |
453 | overFlow = TRUE; | 455 | overFlow = TRUE; |
454 | ++start; | 456 | ++start; |
455 | } | 457 | } |
456 | if ( overFlow ) | 458 | if ( overFlow ) |
457 | break; | 459 | break; |
458 | } | 460 | } |
459 | for ( int i = 0; i < 24; i++ ) { | 461 | for ( int i = 0; i < 24; i++ ) { |