From 05bc65ea5cb4c9d2ca2c90a1c6d193db25465c7e Mon Sep 17 00:00:00 2001 From: ouv Date: Mon, 8 Jul 2013 08:52:19 +0000 Subject: [PATCH] Immediate Selection mode. --- src/GraphicsView/GraphicsView_ViewPort.cxx | 3 ++- src/GraphicsView/GraphicsView_ViewPort.h | 3 ++- src/GraphicsView/GraphicsView_Viewer.cxx | 29 ++++++++++++++-------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 6eab70e08..026932eeb 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -151,7 +151,8 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) setInteractionFlags( EditFlags ); //setInteractionFlag( TraceBoundingRect ); //setInteractionFlag( DraggingByMiddleButton ); - //setInteractionFlag( ImmediateSelection ); + //setInteractionFlag( ImmediateContextMenu ); + setInteractionFlag( ImmediateSelection ); // background setBackgroundBrush( QBrush( Qt::white ) ); diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index 7261e4b86..a37ea0157 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -56,7 +56,8 @@ public: // advanced flags TraceBoundingRect = 0x0008, DraggingByMiddleButton = 0x0010, - ImmediateSelection = 0x0020 + ImmediateContextMenu = 0x0020, + ImmediateSelection = 0x0040, }; Q_DECLARE_FLAGS( InteractionFlags, InteractionFlag ) diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index 4321fc9bc..62caf9136 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -374,16 +374,8 @@ void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e ) { if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) { - if( e->button() == Qt::RightButton && - aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateSelection ) && - aViewPort->nbSelected() < 1 ) - { - // If the 'immediate selection' mode is enabled, - // try to perform selection before invoking context menu - bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() ); - getSelector()->select( QRectF(), append ); - } - else if( e->button() == Qt::LeftButton && + bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() ); + if( e->button() == Qt::LeftButton && aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) && !aViewPort->isSelectByRect() && !aViewPort->isDragging() && @@ -400,6 +392,23 @@ void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e ) QPoint p = aViewPort->mapFromScene( e->scenePos() ); aViewPort->startSelectByRect( p.x(), p.y() ); } + else if( !append && + e->button() != Qt::MidButton && + aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateSelection ) && + aViewPort->nbSelected() < 2 ) + { + // Do not perform 'immediate selection' if the multiple objects are already selected + getSelector()->select( QRectF(), append ); + } + else if( e->button() == Qt::RightButton && + aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu ) && + aViewPort->nbSelected() < 1 ) + { + // If the 'immediate context menu' mode is enabled, + // try to perform selection before invoking context menu + //bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() ); + getSelector()->select( QRectF(), append ); + } } } } -- 2.39.2