From fc9bbad61518ca4f1a226fbed4fd1c29613c1388 Mon Sep 17 00:00:00 2001 From: mkr Date: Tue, 5 Dec 2017 18:23:37 +0300 Subject: [PATCH] refs #1468: patch to customize dragging of several selected objects with left mouse button. --- src/GraphicsView/GraphicsView_ViewPort.cxx | 20 ++++++++++++++++---- src/GraphicsView/GraphicsView_ViewPort.h | 4 ++++ src/GraphicsView/GraphicsView_Viewer.cxx | 4 +++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 93e75b461..f18cd1e6c 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -147,6 +147,7 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) myIsSketchingByPath( false ), myIsDragging( false ), myIsDragPositionInitialized( false ), + myDraggingSelectedByLeftButton( false ), myIsPulling( false ), myPullingObject( 0 ), myStoredCursor( Qt::ArrowCursor ), @@ -1508,6 +1509,15 @@ bool GraphicsView_ViewPort::isSketching( bool* theIsPath ) const return myIsSketching; } +//================================================================ +// Function : setDraggingSelectedByLeftButton +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setDraggingSelectedByLeftButton( const bool& theValue ) +{ + myDraggingSelectedByLeftButton = theValue; +} + //================================================================ // Function : dragObjects // Purpose : @@ -1535,8 +1545,9 @@ void GraphicsView_ViewPort::dragObjects( QGraphicsSceneMouseEvent* e ) else anObjectsToMove.append( anObject ); } - else if( hasInteractionFlag( DraggingByMiddleButton ) && - nbSelected() && ( e->buttons() & Qt::MidButton ) ) + else if( ( hasInteractionFlag( DraggingByMiddleButton ) && ( e->buttons() & Qt::MidButton ) || + isDraggingSelectedByLeftButton() && ( e->buttons() & Qt::LeftButton ) ) && + nbSelected() ) { for( initSelected(); moreSelected(); nextSelected() ) if( GraphicsView_Object* aMovingObject = selectedObject() ) @@ -1731,8 +1742,9 @@ void GraphicsView_ViewPort::onMouseEvent( QGraphicsSceneMouseEvent* e ) if( ( getHighlightedObject() && getHighlightedObject()->isMovable() && !( anAccel || e->button() != Qt::LeftButton ) ) || - ( hasInteractionFlag( DraggingByMiddleButton ) && - nbSelected() && !anAccel && e->button() == Qt::MidButton ) ) + ( ( hasInteractionFlag( DraggingByMiddleButton ) && e->button() == Qt::MidButton || + isDraggingSelectedByLeftButton() && e->button() == Qt::LeftButton ) && + nbSelected() && !anAccel ) ) { myIsDragging = true; myStoredCursor = cursor(); diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index 51b3f53de..1d66b0ac2 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -205,6 +205,9 @@ public: // dragging bool isDragging() { return myIsDragging; } + bool isDraggingSelectedByLeftButton() const { return myDraggingSelectedByLeftButton; } + void setDraggingSelectedByLeftButton( const bool& theValue ); + // pulling bool startPulling( const QPointF& ); void drawPulling( const QPointF& ); @@ -327,6 +330,7 @@ private: int myIsDragging; QPointF myDragPosition; bool myIsDragPositionInitialized; + bool myDraggingSelectedByLeftButton; // pulling bool myIsPulling; diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index 9b51d0019..9cdb2d74d 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -404,7 +404,9 @@ void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e ) } else if( e->button() == Qt::LeftButton && !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) && - !aViewPort->getHighlightedObject() ) + !aViewPort->getHighlightedObject() && + ( !aViewPort->isDraggingSelectedByLeftButton() || + aViewPort->isDraggingSelectedByLeftButton() && aViewPort->nbSelected() == 0 ) ) { // Start rectangular selection if pulling was not started QPoint p = aViewPort->mapFromScene( e->scenePos() ); -- 2.39.2