From b5bda890052848c3427691c0baa6e6d2db68ba9c Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Mon, 17 Oct 2011 15:41:30 +0300 Subject: [PATCH] SANKORE-139 refactoring mouse scroll processing for View and GraphicsItems --- src/board/UBBoardView.cpp | 29 ++++++++++++++++++++++----- src/domain/UBGraphicsItemDelegate.cpp | 4 ++-- src/domain/UBGraphicsProxyWidget.cpp | 3 +++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 372eba7e..2eed5112 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -634,18 +634,38 @@ UBBoardView::mouseDoubleClickEvent (QMouseEvent *event) } void -UBBoardView::wheelEvent (QWheelEvent *event) +UBBoardView::wheelEvent (QWheelEvent *wheelEvent) { - if (isInteractive () && event->orientation () == Qt::Vertical) + if (isInteractive () && wheelEvent->orientation () == Qt::Vertical) { // Too many wheelEvent are sent, how should we handle them to "smoothly" zoom ? // something like zoom( pow(zoomFactor, event->delta() / 120) ) + // use DateTime man, store last event time, and if if less than 300ms than this is one big scroll // and move scroll with one const speed. // so, you no will related with scroll event count } -// event->accept (); - QGraphicsView::wheelEvent(event); + + QList selItemsList = scene()->selectedItems(); + // if NO have selected items, than no need process mouse wheel. just exist + if( selItemsList.count() > 0 ) + { + // only one selected item possible, so we will work with first item only + QGraphicsItem * selItem = selItemsList[0]; + + // get items list under mouse cursor + QPointF scenePos = mapToScene(wheelEvent->pos()); + QList itemsList = scene()->items(scenePos); + + QBool isSlectedAndMouseHower = itemsList.contains(selItem); + if(isSlectedAndMouseHower) + { + wheelEvent->accept(); + QGraphicsView::wheelEvent(wheelEvent); + } + + } + } void @@ -895,4 +915,3 @@ UBBoardView::setToolCursor (int tool) } } - diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 5f2d24ad..00f1f200 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -195,12 +195,12 @@ bool UBGraphicsItemDelegate::weelEvent(QGraphicsSceneWheelEvent *event) { if( mDelegated->isSelected() ) { - event->accept(); +// event->accept(); return true; } else { - event->ignore(); +// event->ignore(); return false; } } diff --git a/src/domain/UBGraphicsProxyWidget.cpp b/src/domain/UBGraphicsProxyWidget.cpp index f3b3cc10..48242b99 100644 --- a/src/domain/UBGraphicsProxyWidget.cpp +++ b/src/domain/UBGraphicsProxyWidget.cpp @@ -105,7 +105,10 @@ void UBGraphicsProxyWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsProxyWidget::wheelEvent(QGraphicsSceneWheelEvent *event) { if( mDelegate->weelEvent(event) ) + { QGraphicsProxyWidget::wheelEvent(event); + event->accept(); + } }