From: ouv Date: Mon, 11 Jul 2011 10:24:48 +0000 (+0000) Subject: Introducing interaction flags (Dragging and WheelScaling) X-Git-Tag: CTH_V17a~30 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3e056684350ab8a60b9c34913698edabf76a0f2e;p=modules%2Fgui.git Introducing interaction flags (Dragging and WheelScaling) --- diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 089b3442d..8d5641b35 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -145,6 +145,9 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) myFitAllGap = 40; myIsTraceBoundingRectEnabled = true; + // interaction flags + myInteractionFlags = All; + // background setBackgroundBrush( QBrush( Qt::white ) ); @@ -409,6 +412,33 @@ void GraphicsView_ViewPort::setTraceBoundingRectEnabled( bool theState ) myIsTraceBoundingRectEnabled = theState; } +//================================================================ +// Function : setInteractionFlags +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setInteractionFlags( const int theFlags ) +{ + myInteractionFlags |= theFlags; +} + +//================================================================ +// Function : clearInteractionFlags +// Purpose : +//================================================================ +void GraphicsView_ViewPort::clearInteractionFlags( const int theFlags ) +{ + myInteractionFlags &= ~theFlags; +} + +//================================================================ +// Function : testInteractionFlags +// Purpose : +//================================================================ +bool GraphicsView_ViewPort::testInteractionFlags( const int theFlags ) const +{ + return ( myInteractionFlags & theFlags ) == theFlags; +} + //================================================================ // Function : setViewNameEnabled // Purpose : @@ -1338,12 +1368,15 @@ void GraphicsView_ViewPort::onMouseEvent( QGraphicsSceneMouseEvent* e ) { case QEvent::GraphicsSceneMousePress: { - bool anAccel = e->modifiers() & GraphicsView_ViewTransformer::accelKey(); - if( ( getHighlightedObject() && - getHighlightedObject()->isMovable() && - !( anAccel || e->button() == Qt::RightButton ) ) || - ( nbSelected() && !anAccel && e->button() == Qt::MidButton ) ) - myIsDragging = true; + if( testInteractionFlags( Dragging ) ) + { + bool anAccel = e->modifiers() & GraphicsView_ViewTransformer::accelKey(); + if( ( getHighlightedObject() && + getHighlightedObject()->isMovable() && + !( anAccel || e->button() == Qt::RightButton ) ) || + ( nbSelected() && !anAccel && e->button() == Qt::MidButton ) ) + myIsDragging = true; + } break; } case QEvent::GraphicsSceneMouseMove: diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index 227040e30..bad817aec 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -46,6 +46,13 @@ class GRAPHICSVIEW_API GraphicsView_ViewPort : public QGraphicsView public: class NameLabel; + enum InteractionFlags + { + Dragging = 0x0001, + WheelScaling = 0x0002, + All = Dragging | WheelScaling + }; + enum BlockStatus { BS_NoBlock = 0x0000, @@ -84,6 +91,11 @@ public: void setFitAllGap( double theFitAllGap ); void setTraceBoundingRectEnabled( bool theState ); + // interaction flags + void setInteractionFlags( const int ); + void clearInteractionFlags( const int ); + bool testInteractionFlags( const int ) const; + // view name void setViewNamePosition( NamePosition thePosition, bool theIsForced = false ); @@ -222,6 +234,9 @@ private: bool myIsTraceBoundingRectEnabled; GraphicsView_ObjectList myObjects; + // interaction flags + int myInteractionFlags; + // view name NameLabel* myNameLabel; NamePosition myNamePosition; diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index 038fd8816..5526a0f7a 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -440,18 +440,21 @@ void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e ) { if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) { - bool anIsScaleUp = e->delta() > 0; - bool anIsCtrl = e->modifiers() & Qt::ControlModifier; + if( aViewPort->testInteractionFlags( GraphicsView_ViewPort::WheelScaling ) ) + { + bool anIsScaleUp = e->delta() > 0; + bool anIsCtrl = e->modifiers() & Qt::ControlModifier; - bool anIsScaleChanged = false; - for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() ) - if( GraphicsView_Object* anObject = aViewPort->selectedObject() ) - anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged; + bool anIsScaleChanged = false; + for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() ) + if( GraphicsView_Object* anObject = aViewPort->selectedObject() ) + anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged; - if( anIsScaleChanged ) - { - emit wheelScaleChanged(); - aViewPort->onBoundingRectChanged(); + if( anIsScaleChanged ) + { + emit wheelScaleChanged(); + aViewPort->onBoundingRectChanged(); + } } } }