//=======================================================================
GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent )
: QGraphicsView( theParent ),
+ myInteractionFlags( 0 ),
myNameLabel( 0 ),
myNamePosition( NP_None ),
myNameLayout( 0 ),
mySceneGap = 20;
myFitAllGap = 40;
- myIsTraceBoundingRectEnabled = false; // testing ImageViewer
// interaction flags
- myInteractionFlags = AllFlags;
+ setInteractionFlags( EditFlags );
+ //setInteractionFlag( TraceBoundingRect );
+ //setInteractionFlag( DraggingByMiddleButton );
+ //setInteractionFlag( ImmediateSelection );
// background
setBackgroundBrush( QBrush( Qt::white ) );
}
//================================================================
-// Function : setTraceBoundingRectEnabled
+// Function : interactionFlags
// Purpose :
//================================================================
-void GraphicsView_ViewPort::setTraceBoundingRectEnabled( bool theState )
+int GraphicsView_ViewPort::interactionFlags() const
{
- myIsTraceBoundingRectEnabled = theState;
+ return myInteractionFlags;
}
//================================================================
-// Function : setInteractionFlags
+// Function : hasInteractionFlag
// Purpose :
//================================================================
-void GraphicsView_ViewPort::setInteractionFlags( const int theFlags )
+bool GraphicsView_ViewPort::hasInteractionFlag( InteractionFlag theFlag )
{
- myInteractionFlags |= theFlags;
+ return ( interactionFlags() & theFlag ) == theFlag;
}
//================================================================
-// Function : clearInteractionFlags
+// Function : setInteractionFlag
// Purpose :
//================================================================
-void GraphicsView_ViewPort::clearInteractionFlags( const int theFlags )
+void GraphicsView_ViewPort::setInteractionFlag( InteractionFlag theFlag,
+ bool theIsEnabled )
{
- myInteractionFlags &= ~theFlags;
+ if( theIsEnabled )
+ setInteractionFlags( myInteractionFlags | theFlag );
+ else
+ setInteractionFlags( myInteractionFlags & ~theFlag );
}
//================================================================
-// Function : testInteractionFlags
+// Function : setInteractionFlags
// Purpose :
//================================================================
-bool GraphicsView_ViewPort::testInteractionFlags( const int theFlags ) const
+void GraphicsView_ViewPort::setInteractionFlags( InteractionFlags theFlags )
{
- return ( myInteractionFlags & theFlags ) == theFlags;
+ myInteractionFlags = theFlags;
}
//================================================================
else
anObjectsToMove.append( anObject );
}
- else if( nbSelected() && ( e->buttons() & Qt::MidButton ) )
+ else if( hasInteractionFlag( DraggingByMiddleButton ) &&
+ nbSelected() && ( e->buttons() & Qt::MidButton ) )
{
for( initSelected(); moreSelected(); nextSelected() )
if( GraphicsView_Object* aMovingObject = selectedObject() )
//================================================================
void GraphicsView_ViewPort::onBoundingRectChanged()
{
- if( myIsTraceBoundingRectEnabled )
+ if( hasInteractionFlag( TraceBoundingRect ) )
{
QRectF aRect = objectsBoundingRect();
myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) );
{
case QEvent::GraphicsSceneMousePress:
{
- if( testInteractionFlags( EditFlags ) && nbSelected() )
+ if( hasInteractionFlag( EditFlags ) && nbSelected() )
for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
if( GraphicsView_Object* anObject = selectedObject() )
anIsHandled = anObject->handleMousePress( e );
- if( !anIsHandled && testInteractionFlags( Dragging ) )
+ if( !anIsHandled && hasInteractionFlag( Dragging ) )
{
bool anAccel = e->modifiers() & GraphicsView_ViewTransformer::accelKey();
if( ( getHighlightedObject() &&
getHighlightedObject()->isMovable() &&
- !( anAccel || e->button() == Qt::RightButton ) ) ||
- ( nbSelected() && !anAccel && e->button() == Qt::MidButton ) )
+ !( anAccel || e->button() != Qt::LeftButton ) ) ||
+ ( hasInteractionFlag( DraggingByMiddleButton ) &&
+ nbSelected() && !anAccel && e->button() == Qt::MidButton ) )
{
myIsDragging = true;
myStoredCursor = cursor();
}
case QEvent::GraphicsSceneMouseMove:
{
- if( testInteractionFlags( EditFlags ) && nbSelected() )
+ if( hasInteractionFlag( EditFlags ) && nbSelected() )
for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
if( GraphicsView_Object* anObject = selectedObject() )
anIsHandled = anObject->handleMousePress( e );
}
case QEvent::GraphicsSceneMouseRelease:
{
- if( testInteractionFlags( EditFlags ) && nbSelected() )
+ if( hasInteractionFlag( EditFlags ) && nbSelected() )
for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
if( GraphicsView_Object* anObject = selectedObject() )
anIsHandled = anObject->handleMousePress( e );
public:
class NameLabel;
- enum InteractionFlags
+ enum InteractionFlag
{
- Highlighting = 0x0001, // not implemented yet
- Selecting = 0x0002, // not implemented yet
- Dragging = 0x0004,
- Pulling = 0x0008,
- WheelScaling = 0x0010,
- EditFlags = Dragging | Pulling | WheelScaling,
- AllFlags = Highlighting | Selecting | Dragging | Pulling | WheelScaling
+ // main flags
+ Dragging = 0x0001,
+ Pulling = 0x0002,
+ WheelScaling = 0x0004,
+ EditFlags = Dragging | Pulling | WheelScaling,
+ // advanced flags
+ TraceBoundingRect = 0x0008,
+ DraggingByMiddleButton = 0x0010,
+ ImmediateSelection = 0x0020
};
+ Q_DECLARE_FLAGS( InteractionFlags, InteractionFlag )
enum BlockStatus
{
// scene
void setSceneGap( double theSceneGap );
void setFitAllGap( double theFitAllGap );
- void setTraceBoundingRectEnabled( bool theState );
// interaction flags
- void setInteractionFlags( const int );
- void clearInteractionFlags( const int );
- bool testInteractionFlags( const int ) const;
+ int interactionFlags() const;
+ bool hasInteractionFlag( InteractionFlag theFlag );
+ void setInteractionFlag( InteractionFlag theFlag,
+ bool theIsEnabled = true );
+ void setInteractionFlags( InteractionFlags theFlags );
// view name
void setViewNamePosition( NamePosition thePosition,
GraphicsView_Scene* myScene;
double mySceneGap;
double myFitAllGap;
- bool myIsTraceBoundingRectEnabled;
GraphicsView_ObjectList myObjects;
// interaction flags
- int myInteractionFlags;
+ InteractionFlags myInteractionFlags;
// view name
NameLabel* myNameLabel;
QCursor myStoredCursor;
};
+Q_DECLARE_OPERATORS_FOR_FLAGS( GraphicsView_ViewPort::InteractionFlags )
+
#endif
: SUIT_ViewModel(),
mySelector( 0 ),
myTransformer( 0 ),
- myIsInitialized( false ),
- myIsImmediateSelectionEnabled( false )
+ myIsInitialized( false )
{
}
myIsInitialized = theFlag;
}
-//================================================================
-// Function : setIsImmediateSelectionEnabled
-// Purpose :
-//================================================================
-void GraphicsView_Viewer::setIsImmediateSelectionEnabled( bool theFlag )
-{
- myIsImmediateSelectionEnabled = theFlag;
-}
-
//================================================================
// Function : createTransformer
// Purpose :
if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
{
if( e->button() == Qt::RightButton &&
- isImmediateSelectionEnabled() &&
+ aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateSelection ) &&
aViewPort->nbSelected() < 1 )
{
// If the 'immediate selection' mode is enabled,
getSelector()->select( QRectF(), append );
}
else if( e->button() == Qt::LeftButton &&
- aViewPort->testInteractionFlags( GraphicsView_ViewPort::Pulling ) &&
+ aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
!aViewPort->isSelectByRect() &&
!aViewPort->isDragging() &&
aViewPort->startPulling( e->scenePos() ) )
aViewPort->drawPulling( e->scenePos() );
}
else if( e->button() == Qt::LeftButton &&
- aViewPort->testInteractionFlags( GraphicsView_ViewPort::Pulling ) &&
+ aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
!aViewPort->isSelectByRect() &&
!aViewPort->isDragging() &&
aViewPort->startPulling( e->scenePos() ) )
{
if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
{
- if( aViewPort->testInteractionFlags( GraphicsView_ViewPort::WheelScaling ) )
+ if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::WheelScaling ) )
{
bool anIsScaleUp = e->delta() > 0;
bool anIsCtrl = e->modifiers() & Qt::ControlModifier;