From: ouv Date: Fri, 15 Jul 2011 13:48:29 +0000 (+0000) Subject: 1) Small improvement of the highlight mechanism X-Git-Tag: CTH_V17a~27 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d43aa2cde8459851668ac0db3b49a049ce567209;p=modules%2Fgui.git 1) Small improvement of the highlight mechanism 2) Introduced possibility of handling mouse events by objects --- diff --git a/src/GraphicsView/GraphicsView_Object.cxx b/src/GraphicsView/GraphicsView_Object.cxx index a884e1bbf..33200c30d 100644 --- a/src/GraphicsView/GraphicsView_Object.cxx +++ b/src/GraphicsView/GraphicsView_Object.cxx @@ -31,6 +31,7 @@ GraphicsView_Object::GraphicsView_Object( QGraphicsItem* theParent ) : QGraphicsItemGroup( theParent ), myPriority( 0 ), + myIsOnTop( false ), myIsHighlighted( false ), myIsSelected( false ) { diff --git a/src/GraphicsView/GraphicsView_Object.h b/src/GraphicsView/GraphicsView_Object.h index c1e06cdfb..5fd908c34 100644 --- a/src/GraphicsView/GraphicsView_Object.h +++ b/src/GraphicsView/GraphicsView_Object.h @@ -44,6 +44,9 @@ public: virtual int getPriority() const { return myPriority; } + virtual bool isOnTop() const { return myIsOnTop; } + virtual void setIsOnTop( bool theIsOnTop ) { myIsOnTop = theIsOnTop; } + virtual bool isSelectable() const { return true; } virtual bool isMovable() const { return true; } @@ -72,6 +75,10 @@ public: virtual void finishPulling() {} virtual bool isPulling() { return false; } + virtual bool handleMousePress( QGraphicsSceneMouseEvent* ) { return false; } + virtual bool handleMouseMove( QGraphicsSceneMouseEvent* ) { return false; } + virtual bool handleMouseRelease( QGraphicsSceneMouseEvent* ) { return false; } + protected: virtual bool checkHighlight( double theX, double theY ) const; @@ -79,6 +86,7 @@ protected: QString myName; int myPriority; + bool myIsOnTop; bool myIsHighlighted; bool myIsSelected; diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 8d5641b35..a92833b6b 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -281,6 +281,7 @@ GraphicsView_ObjectList GraphicsView_ViewPort::getObjects( bool theIsSortSelecte // to append selected objects after their non-selected siblings with similar priority int aCurrentPriority = -1; GraphicsView_ObjectList aSelectedObjects; + GraphicsView_ObjectList aTopmostObjects; GraphicsView_ObjectList aList; GraphicsView_ObjectListIterator anIter( myObjects ); @@ -288,6 +289,12 @@ GraphicsView_ObjectList GraphicsView_ViewPort::getObjects( bool theIsSortSelecte { if( GraphicsView_Object* anObject = anIter.next() ) { + if( anObject->isOnTop() ) + { + aTopmostObjects.append( anObject ); + continue; + } + int aPriority = anObject->getPriority(); if( aPriority > aCurrentPriority ) { @@ -314,6 +321,8 @@ GraphicsView_ObjectList GraphicsView_ViewPort::getObjects( bool theIsSortSelecte aSelectedObjects.clear(); } + aList.append( aTopmostObjects ); + return aList; } @@ -1364,30 +1373,46 @@ void GraphicsView_ViewPort::onMouseEvent( QGraphicsSceneMouseEvent* e ) { emit vpMouseEvent( e ); + bool anIsHandled = false; switch( e->type() ) { case QEvent::GraphicsSceneMousePress: { - if( testInteractionFlags( Dragging ) ) + if( nbSelected() ) + for( initSelected(); moreSelected() && !anIsHandled; nextSelected() ) + if( GraphicsView_Object* anObject = selectedObject() ) + anIsHandled = anObject->handleMousePress( e ); + + if( !anIsHandled && 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; + myIsDragging = true; } break; } case QEvent::GraphicsSceneMouseMove: { - if( !isPulling() && myIsDragging ) + if( nbSelected() ) + for( initSelected(); moreSelected() && !anIsHandled; nextSelected() ) + if( GraphicsView_Object* anObject = selectedObject() ) + anIsHandled = anObject->handleMousePress( e ); + + if( !anIsHandled && !isPulling() && myIsDragging ) dragObjects( e ); break; } case QEvent::GraphicsSceneMouseRelease: { - if( !isPulling() && myIsDragging ) + if( nbSelected() ) + for( initSelected(); moreSelected() && !anIsHandled; nextSelected() ) + if( GraphicsView_Object* anObject = selectedObject() ) + anIsHandled = anObject->handleMousePress( e ); + + if( !anIsHandled && !isPulling() && myIsDragging ) { emit vpObjectBeforeMoving();