summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagenda.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp
index faddac4..ce73168 100644
--- a/korganizer/koagenda.cpp
+++ b/korganizer/koagenda.cpp
@@ -351,281 +351,289 @@ void KOAgenda::changeColumns(int columns)
351 return; 351 return;
352 } 352 }
353 clear(); 353 clear();
354 mColumns = columns; 354 mColumns = columns;
355 computeSizes(); 355 computeSizes();
356} 356}
357 357
358/* 358/*
359 This is the eventFilter function, which gets all events from the KOAgendaItems 359 This is the eventFilter function, which gets all events from the KOAgendaItems
360 contained in the agenda. It has to handle moving and resizing for all items. 360 contained in the agenda. It has to handle moving and resizing for all items.
361*/ 361*/
362bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) 362bool KOAgenda::eventFilter ( QObject *object, QEvent *event )
363{ 363{
364 // kdDebug() << "KOAgenda::eventFilter" << endl; 364 // kdDebug() << "KOAgenda::eventFilter" << endl;
365 switch(event->type()) { 365 switch(event->type()) {
366 case QEvent::MouseButtonPress: 366 case QEvent::MouseButtonPress:
367 case QEvent::MouseButtonDblClick: 367 case QEvent::MouseButtonDblClick:
368 case QEvent::MouseButtonRelease: 368 case QEvent::MouseButtonRelease:
369 case QEvent::MouseMove: 369 case QEvent::MouseMove:
370 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); 370 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event));
371 371
372 case (QEvent::Leave): 372 case (QEvent::Leave):
373 if (!mActionItem) 373 if (!mActionItem)
374 setCursor(arrowCursor); 374 setCursor(arrowCursor);
375 return true; 375 return true;
376 376
377 default: 377 default:
378 return QScrollView::eventFilter(object,event); 378 return QScrollView::eventFilter(object,event);
379 } 379 }
380} 380}
381void KOAgenda::popupMenu() 381void KOAgenda::popupMenu()
382{ 382{
383 mPopupTimer->stop(); 383 mPopupTimer->stop();
384 if ( mPopupKind == 1 || mPopupKind == 3 ) { 384 if ( mPopupKind == 1 || mPopupKind == 3 ) {
385 if (mActionItem ) { 385 if (mActionItem ) {
386 endItemAction(); 386 endItemAction();
387 } 387 }
388 mLeftMouseDown = false; // no more leftMouse computation 388 mLeftMouseDown = false; // no more leftMouse computation
389 if (mPopupItem) { 389 if (mPopupItem) {
390 //mClickedItem = mPopupItem; 390 //mClickedItem = mPopupItem;
391 selectItem(mPopupItem); 391 selectItem(mPopupItem);
392 if ( mAllAgendaPopup && KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 1 ) 392 if ( mAllAgendaPopup && KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 1 )
393 mAllAgendaPopup->installEventFilter( this ); 393 mAllAgendaPopup->installEventFilter( this );
394 emit showIncidencePopupSignal(mPopupItem->incidence()); 394 emit showIncidencePopupSignal(mPopupItem->incidence());
395 395
396 } 396 }
397 } else if ( mPopupKind == 2 || mPopupKind == 4 ) { 397 } else if ( mPopupKind == 2 || mPopupKind == 4 ) {
398 if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action 398 if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action
399 endSelectAction( false ); // do not emit new event signal 399 endSelectAction( false ); // do not emit new event signal
400 mLeftMouseDown = false; // no more leftMouse computation 400 mLeftMouseDown = false; // no more leftMouse computation
401 } 401 }
402 if ( KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 2 ) 402 if ( KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 2 )
403 mNewItemPopup->installEventFilter( this ); 403 mNewItemPopup->installEventFilter( this );
404 mNewItemPopup->popup( mPopupPos); 404 mNewItemPopup->popup( mPopupPos);
405 405
406 } 406 }
407 mLeftMouseDown = false; 407 mLeftMouseDown = false;
408 mPopupItem = 0; 408 mPopupItem = 0;
409 mPopupKind = 0; 409 mPopupKind = 0;
410} 410}
411 411
412bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) 412bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
413{ 413{
414 static int startX = 0; 414 static int startX = 0;
415 static int startY = 0; 415 static int startY = 0;
416 int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 7 : 9 ); 416 int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 7 : 9 );
417 static bool blockMoving = true; 417 static bool blockMoving = true;
418 418
419 //qDebug("KOAgenda::eventFilter_mous "); 419 //qDebug("KOAgenda::eventFilter_mous ");
420 if ( object == mNewItemPopup ) { 420 if ( object == mNewItemPopup ) {
421 //qDebug("mNewItemPopup "); 421 //qDebug("mNewItemPopup ");
422 if ( me->type() == QEvent::MouseButtonRelease ) { 422 if ( me->type() == QEvent::MouseButtonRelease ) {
423 mNewItemPopup->removeEventFilter( this ); 423 mNewItemPopup->removeEventFilter( this );
424 int dX = me->globalPos().x() - mPopupPos.x();; 424 int dX = me->globalPos().x() - mPopupPos.x();;
425 if ( dX < 0 ) 425 if ( dX < 0 )
426 dX = -dX; 426 dX = -dX;
427 int dY = me->globalPos().y() - mPopupPos.y(); 427 int dY = me->globalPos().y() - mPopupPos.y();
428 if ( dY < 0 ) 428 if ( dY < 0 )
429 dY = -dY; 429 dY = -dY;
430 if ( dX > blockmoveDist || dY > blockmoveDist ) { 430 if ( dX > blockmoveDist || dY > blockmoveDist ) {
431 mNewItemPopup->hide(); 431 mNewItemPopup->hide();
432 } 432 }
433 } 433 }
434 return true; 434 return true;
435 } 435 }
436 if ( object == mAllAgendaPopup ) { 436 if ( object == mAllAgendaPopup ) {
437 //qDebug(" mAllAgendaPopup "); 437 //qDebug(" mAllAgendaPopup ");
438 if ( me->type() == QEvent::MouseButtonRelease ) { 438 if ( me->type() == QEvent::MouseButtonRelease ) {
439 mAllAgendaPopup->removeEventFilter( this ); 439 mAllAgendaPopup->removeEventFilter( this );
440 int dX = me->globalPos().x() - mPopupPos.x();; 440 int dX = me->globalPos().x() - mPopupPos.x();;
441 if ( dX < 0 ) 441 if ( dX < 0 )
442 dX = -dX; 442 dX = -dX;
443 int dY = me->globalPos().y() - mPopupPos.y(); 443 int dY = me->globalPos().y() - mPopupPos.y();
444 if ( dY < 0 ) 444 if ( dY < 0 )
445 dY = -dY; 445 dY = -dY;
446 if ( dX > blockmoveDist || dY > blockmoveDist ) { 446 if ( dX > blockmoveDist || dY > blockmoveDist ) {
447 mAllAgendaPopup->hide(); 447 mAllAgendaPopup->hide();
448 } 448 }
449 } 449 }
450 return true; 450 return true;
451 } 451 }
452 QPoint viewportPos; 452 QPoint viewportPos;
453 if (object != viewport()) { 453 if (object != viewport()) {
454 blockmoveDist = blockmoveDist*2; 454 blockmoveDist = blockmoveDist*2;
455 viewportPos = ((QWidget *)object)->mapToParent(me->pos()); 455 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
456 } else { 456 } else {
457 viewportPos = me->pos(); 457 viewportPos = me->pos();
458 } 458 }
459 bool objIsNotViewport = (object != viewport()); 459 bool objIsNotViewport = (object != viewport());
460 bool leftButt = false; 460 bool leftButt = false;
461#ifdef DESKTOP_VERSION 461#ifdef DESKTOP_VERSION
462 leftButt = (me->button() == LeftButton); 462 leftButt = (me->button() == LeftButton);
463#endif 463#endif
464 switch (me->type()) { 464 switch (me->type()) {
465 case QEvent::MouseButtonPress: 465 case QEvent::MouseButtonPress:
466 if (me->button() == LeftButton) { 466 if (me->button() == LeftButton) {
467 mPopupTimer->start( 600 ); 467 mPopupTimer->start( 600 );
468 mLeftMouseDown = true; 468 mLeftMouseDown = true;
469 } 469 }
470 blockMoving = true; 470 blockMoving = true;
471 startX = viewportPos.x(); 471 startX = viewportPos.x();
472 startY = viewportPos.y(); 472 startY = viewportPos.y();
473 mPopupPos = me->globalPos(); 473 mPopupPos = me->globalPos();
474 if ( objIsNotViewport && !leftButt ) { 474 if ( objIsNotViewport && !leftButt ) {
475 KOAgendaItem * tempItem = (KOAgendaItem *)object; 475 KOAgendaItem * tempItem = (KOAgendaItem *)object;
476 if (mAllDayMode) { 476 if (mAllDayMode) {
477 if ( tempItem->height() > 10 ) { 477 if ( tempItem->height() > 10 ) {
478 int minV = tempItem->height()/4; 478 int minV = tempItem->height()/4;
479 if ( minV > (blockmoveDist/2)-2 ) 479 if ( minV > (blockmoveDist/2)-2 ) {
480 minV = (blockmoveDist/2)-2; 480 if ( minV > blockmoveDist )
481 minV = blockmoveDist;
482 else
483 minV = (blockmoveDist/2);
484 }
481 bool border = false; 485 bool border = false;
482 int diff = tempItem->y() - viewportPos.y(); 486 int diff = tempItem->y() - viewportPos.y();
483 if ( diff < 0 ) 487 if ( diff < 0 )
484 diff *= -1; 488 diff *= -1;
485 if ( diff < minV ) { 489 if ( diff < minV ) {
486 border = true; 490 border = true;
487 objIsNotViewport = false; 491 objIsNotViewport = false;
488 } 492 }
489 if ( ! border ) { 493 if ( ! border ) {
490 diff = tempItem->y() + tempItem->height()- viewportPos.y(); 494 diff = tempItem->y() + tempItem->height()- viewportPos.y();
491 if ( diff < 0 ) 495 if ( diff < 0 )
492 diff *= -1; 496 diff *= -1;
493 if ( diff < minV ) { 497 if ( diff < minV ) {
494 border = true; 498 border = true;
495 objIsNotViewport = false; 499 objIsNotViewport = false;
496 } 500 }
497 } 501 }
498 } 502 }
499 } else { // not allday 503 } else { // not allday
500 if ( tempItem->width() > 10 ) { 504 if ( tempItem->width() > 10 ) {
501 int minH = tempItem->width()/4; 505 int minH = tempItem->width()/4;
502 if ( minH > (blockmoveDist/2)-2 ) 506 if ( minH > (blockmoveDist/2)-2 ) {
503 minH = (blockmoveDist/2)-2; 507 if ( minH > blockmoveDist )
508 minH = blockmoveDist;
509 else
510 minH = (blockmoveDist/2);
511 }
504 bool border = false; 512 bool border = false;
505 int diff = tempItem->x() - viewportPos.x(); 513 int diff = tempItem->x() - viewportPos.x();
506 if ( diff < 0 ) 514 if ( diff < 0 )
507 diff *= -1; 515 diff *= -1;
508 if ( diff < minH ) { 516 if ( diff < minH ) {
509 border = true; 517 border = true;
510 objIsNotViewport = false; 518 objIsNotViewport = false;
511 } 519 }
512 if ( ! border ) { 520 if ( ! border ) {
513 diff = tempItem->x() + tempItem->width() - viewportPos.x(); 521 diff = tempItem->x() + tempItem->width() - viewportPos.x();
514 if ( diff < 0 ) 522 if ( diff < 0 )
515 diff *= -1; 523 diff *= -1;
516 if ( diff < minH ) { 524 if ( diff < minH ) {
517 border = true; 525 border = true;
518 objIsNotViewport = false; 526 objIsNotViewport = false;
519 } 527 }
520 } 528 }
521 } 529 }
522 } 530 }
523 } 531 }
524 if ( objIsNotViewport ) { 532 if ( objIsNotViewport ) {
525 mPopupItem = (KOAgendaItem *)object; 533 mPopupItem = (KOAgendaItem *)object;
526 mPopupKind = 1; 534 mPopupKind = 1;
527 if (me->button() == RightButton) { 535 if (me->button() == RightButton) {
528 mPopupKind = 3; 536 mPopupKind = 3;
529 popupMenu(); 537 popupMenu();
530 } else if (me->button() == LeftButton) { 538 } else if (me->button() == LeftButton) {
531 mActionItem = (KOAgendaItem *)object; 539 mActionItem = (KOAgendaItem *)object;
532 if (mActionItem) { 540 if (mActionItem) {
533 emit signalClearSelection(); 541 emit signalClearSelection();
534 slotClearSelection(); 542 slotClearSelection();
535 selectItem(mActionItem); 543 selectItem(mActionItem);
536 Incidence *incidence = mActionItem->incidence(); 544 Incidence *incidence = mActionItem->incidence();
537 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { 545 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) {
538 mActionItem = 0; 546 mActionItem = 0;
539 } else { 547 } else {
540 startItemAction(viewportPos); 548 startItemAction(viewportPos);
541 } 549 }
542 } 550 }
543 } 551 }
544 } else { // ---------- viewport() 552 } else { // ---------- viewport()
545 mPopupItem = 0; 553 mPopupItem = 0;
546 mPopupKind = 2; 554 mPopupKind = 2;
547 selectItem(0); 555 selectItem(0);
548 mActionItem = 0; 556 mActionItem = 0;
549 if (me->button() == RightButton) { 557 if (me->button() == RightButton) {
550 int x,y; 558 int x,y;
551 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 559 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
552 int gx,gy; 560 int gx,gy;
553 contentsToGrid(x,y,gx,gy); 561 contentsToGrid(x,y,gx,gy);
554 mCurrentCellX = gx; 562 mCurrentCellX = gx;
555 mCurrentCellY = gy; 563 mCurrentCellY = gy;
556 mStartCellX = gx; 564 mStartCellX = gx;
557 mStartCellY = gy; 565 mStartCellY = gy;
558 mPopupKind = 4; 566 mPopupKind = 4;
559 popupMenu(); 567 popupMenu();
560 } else if (me->button() == LeftButton) { 568 } else if (me->button() == LeftButton) {
561 setCursor(arrowCursor); 569 setCursor(arrowCursor);
562 startSelectAction(viewportPos); 570 startSelectAction(viewportPos);
563 } 571 }
564 } 572 }
565 break; 573 break;
566 574
567 case QEvent::MouseButtonRelease: 575 case QEvent::MouseButtonRelease:
568 if (me->button() == LeftButton ) { 576 if (me->button() == LeftButton ) {
569 mPopupTimer->stop(); 577 mPopupTimer->stop();
570 } 578 }
571 if (object != viewport()) { 579 if (object != viewport()) {
572 if (me->button() == LeftButton && mLeftMouseDown) { 580 if (me->button() == LeftButton && mLeftMouseDown) {
573 if (mActionItem) { 581 if (mActionItem) {
574 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 582 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos));
575 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); 583 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 );
576 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { 584 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) {
577 mScrollUpTimer.stop(); 585 mScrollUpTimer.stop();
578 mScrollDownTimer.stop(); 586 mScrollDownTimer.stop();
579 mActionItem->resetMove(); 587 mActionItem->resetMove();
580 placeSubCells( mActionItem ); 588 placeSubCells( mActionItem );
581 // emit startDragSignal( mActionItem->incidence() ); 589 // emit startDragSignal( mActionItem->incidence() );
582 setCursor( arrowCursor ); 590 setCursor( arrowCursor );
583 mActionItem = 0; 591 mActionItem = 0;
584 mActionType = NOP; 592 mActionType = NOP;
585 mItemMoved = 0; 593 mItemMoved = 0;
586 mLeftMouseDown = false; 594 mLeftMouseDown = false;
587 return true; 595 return true;
588 } 596 }
589 endItemAction(); 597 endItemAction();
590 } 598 }
591 } 599 }
592 600
593 } else { // ---------- viewport() 601 } else { // ---------- viewport()
594 if (me->button() == LeftButton && mLeftMouseDown ) { //left click 602 if (me->button() == LeftButton && mLeftMouseDown ) { //left click
595 endSelectAction( true ); // emit new event signal 603 endSelectAction( true ); // emit new event signal
596 } 604 }
597 } 605 }
598 if (me->button() == LeftButton) 606 if (me->button() == LeftButton)
599 mLeftMouseDown = false; 607 mLeftMouseDown = false;
600 608
601 break; 609 break;
602 610
603 case QEvent::MouseMove: 611 case QEvent::MouseMove:
604 //qDebug("mm "); 612 //qDebug("mm ");
605 if ( !mLeftMouseDown ) 613 if ( !mLeftMouseDown )
606 return false; 614 return false;
607 if ( blockMoving ) { 615 if ( blockMoving ) {
608 int dX, dY; 616 int dX, dY;
609 dX = startX - viewportPos.x(); 617 dX = startX - viewportPos.x();
610 if ( dX < 0 ) 618 if ( dX < 0 )
611 dX = -dX; 619 dX = -dX;
612 dY = viewportPos.y() - startY; 620 dY = viewportPos.y() - startY;
613 if ( dY < 0 ) 621 if ( dY < 0 )
614 dY = -dY; 622 dY = -dY;
615 //qDebug("%d %d %d ", dX, dY , blockmoveDist ); 623 //qDebug("%d %d %d ", dX, dY , blockmoveDist );
616 if ( dX > blockmoveDist || dY > blockmoveDist ) { 624 if ( dX > blockmoveDist || dY > blockmoveDist ) {
617 blockMoving = false; 625 blockMoving = false;
618 } 626 }
619 } 627 }
620 if ( ! blockMoving ) 628 if ( ! blockMoving )
621 mPopupTimer->stop(); 629 mPopupTimer->stop();
622 if (object != viewport()) { 630 if (object != viewport()) {
623 KOAgendaItem *moveItem = (KOAgendaItem *)object; 631 KOAgendaItem *moveItem = (KOAgendaItem *)object;
624 if (!moveItem->incidence()->isReadOnly() ) { 632 if (!moveItem->incidence()->isReadOnly() ) {
625 if (!mActionItem) 633 if (!mActionItem)
626 setNoActionCursor(moveItem,viewportPos); 634 setNoActionCursor(moveItem,viewportPos);
627 else { 635 else {
628 if ( !blockMoving ) 636 if ( !blockMoving )
629 performItemAction(viewportPos); 637 performItemAction(viewportPos);
630 } 638 }
631 } 639 }