]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Escape key cancels the current operation (or clears the current selection).
authorouv <ouv@opencascade.com>
Fri, 5 Jul 2013 10:46:57 +0000 (10:46 +0000)
committerouv <ouv@opencascade.com>
Fri, 5 Jul 2013 10:46:57 +0000 (10:46 +0000)
src/GraphicsView/GraphicsView_Object.cxx
src/GraphicsView/GraphicsView_Object.h
src/GraphicsView/GraphicsView_PrsImage.cxx
src/GraphicsView/GraphicsView_PrsImage.h
src/GraphicsView/GraphicsView_PrsImageFrame.cxx
src/GraphicsView/GraphicsView_PrsImageFrame.h
src/GraphicsView/GraphicsView_ViewPort.cxx
src/GraphicsView/GraphicsView_ViewPort.h
src/GraphicsView/GraphicsView_Viewer.cxx

index 648f9d294709891c0e7377899127963f52ce3085..a290044d304accee3581ffbe109fa7ff396b23ae 100644 (file)
@@ -168,7 +168,7 @@ void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce )
 {
   if( theIsAtOnce )
   {
-    finishMove();
+    finishMove( true );
     return;
   }
 
@@ -180,11 +180,12 @@ void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce )
 // Function : finishMove
 // Purpose  : 
 //================================================================
-bool GraphicsView_Object::finishMove()
+bool GraphicsView_Object::finishMove( bool theStatus )
 {
   myIsMoving = false;
-  if( GraphicsView_Scene* aScene = dynamic_cast<GraphicsView_Scene*>( scene() ) )
-    aScene->processRectChanged();
+  if( theStatus )
+    if( GraphicsView_Scene* aScene = dynamic_cast<GraphicsView_Scene*>( scene() ) )
+      aScene->processRectChanged();
   return true;
 }
 
index b55386be6ba1ced7150ea0d988172118b0d181e2..14810d1e0a60c75c072d71467563c832b164c2ed 100644 (file)
@@ -73,7 +73,7 @@ public:
   virtual void               setSelected( bool theState ) { myIsSelected = theState; }
 
   virtual void               move( double theDX, double theDY, bool theIsAtOnce = false );
-  virtual bool               finishMove();
+  virtual bool               finishMove( bool theStatus );
   virtual bool               isMoving() const { return myIsMoving; }
   virtual bool               isMovingByXAllowed( double theDX ) { return true; }
   virtual bool               isMovingByYAllowed( double theDY ) { return true; }
@@ -86,7 +86,7 @@ public:
   virtual void               pull( const QPointF&,
                                    GraphicsView_Object*,
                                    const GraphicsView_ObjectList& ) {}
-  virtual void               finishPulling( const GraphicsView_ObjectList& ) {}
+  virtual void               finishPulling( bool, const GraphicsView_ObjectList& ) {}
   virtual bool               isPulling() { return false; }
 
   virtual bool               handleMousePress( QGraphicsSceneMouseEvent* ) { return false; }
index 45cefcd63c9a68ef7bb37fa7fc37b052c66a146f..6be39005df2b7c8347723275034563ac0e1c8ed8 100644 (file)
@@ -355,7 +355,7 @@ void GraphicsView_PrsImage::move( double theDX, double theDY, bool theIsAtOnce )
 {
   if( theIsAtOnce )
   {
-    finishMove();
+    finishMove( true );
     return;
   }
 
@@ -373,17 +373,19 @@ void GraphicsView_PrsImage::move( double theDX, double theDY, bool theIsAtOnce )
 // Function : finishMove
 // Purpose  : 
 //================================================================
-bool GraphicsView_PrsImage::finishMove()
+bool GraphicsView_PrsImage::finishMove( bool theStatus )
 {
   if( myIsMoving )
   {
-    myPosX = myPreviewPosX;
-    myPosY = myPreviewPosY;
-    updateTransform();
-
+    if( theStatus )
+    {
+      myPosX = myPreviewPosX;
+      myPosY = myPreviewPosY;
+      updateTransform();
+    }
     enablePreview( false );
   }
-  return GraphicsView_Object::finishMove();
+  return GraphicsView_Object::finishMove( theStatus );
 }
 
 //================================================================
index b30999ee7258b31a0f2067d3eced5599761b7e81..e9ae9887d7bda20a3b209669fab2a7ceff4aa7ea 100644 (file)
@@ -79,7 +79,7 @@ public:
   virtual void                    setSelected( bool theState );
 
   virtual void                    move( double theDX, double theDY, bool theIsAtOnce = false );
-  virtual bool                    finishMove();
+  virtual bool                    finishMove( bool theStatus );
 
 protected:
   void                            processResize( const int theAnchor,
index 14951a3b91a031d06185f595fbfe9b8ada81ad08..2ffb80911a092aaca7386484faca4ac70e693beb 100644 (file)
@@ -269,11 +269,18 @@ void GraphicsView_PrsImageFrame::pull( const QPointF& thePoint,
 // Function : finishPulling
 // Purpose  : 
 //================================================================
-void GraphicsView_PrsImageFrame::finishPulling( const GraphicsView_ObjectList& theSyncObjects )
+void GraphicsView_PrsImageFrame::finishPulling( bool theStatus,
+                                                const GraphicsView_ObjectList& theSyncObjects )
 {
   if( !myPrsImage )
     return;
 
+  if( !theStatus )
+  {
+    myPrsImage->enablePreview( false );
+    return;
+  }
+
   if( myPullingAnchor >= Top && myPullingAnchor <= BottomRight )
     myPrsImage->finishResize();
   else if( myPullingAnchor == TopMost )
index 350a73a950de6d07c4f4822d999a93993d60987f..e5d42ec720eb4ca29b01ed996caa308662ccc16c 100644 (file)
@@ -69,7 +69,7 @@ public:
   virtual void                    pull( const QPointF&,
                                         GraphicsView_Object*,
                                         const GraphicsView_ObjectList& );
-  virtual void                    finishPulling( const GraphicsView_ObjectList& );
+  virtual void                    finishPulling( bool, const GraphicsView_ObjectList& );
   virtual bool                    isPulling() { return myIsPulling; }
 
 public:
index 5384abef6e991f963d246584cd44959323dac3af..962756819c0e5e905d8883236679ac27c26c708c 100644 (file)
@@ -129,6 +129,7 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent )
   myHighlightedObject( 0 ),
   myHighlightX( 0 ),
   myHighlightY( 0 ),
+  myIsHighlighting( false ),
   mySelectionIterator( 0 ),
   myRectBand( 0 ),
   myAreSelectionPointsInitialized( false ),
@@ -932,6 +933,7 @@ GraphicsView_ViewPort::BlockStatus GraphicsView_ViewPort::currentBlock()
 //================================================================
 void GraphicsView_ViewPort::highlight( double theX, double theY )
 {
+  myIsHighlighting = true;
   myHighlightX = theX;
   myHighlightY = theY;
 
@@ -1018,6 +1020,9 @@ void GraphicsView_ViewPort::clearHighlighted()
 //================================================================
 int GraphicsView_ViewPort::select( const QRectF& theRect, bool theIsAppend )
 {
+  if( !myIsHighlighting )
+    return GVSS_NoChanged;
+
   GV_SelectionStatus aStatus = GVSS_Invalid;
   if( theRect.isNull() ) // point selection
   {
@@ -1109,7 +1114,7 @@ int GraphicsView_ViewPort::select( const QRectF& theRect, bool theIsAppend )
         {
           bool anIsSelected = false;
           QRectF aRect = anObject->getRect();
-          if( theRect.contains( aRect ) )
+          if( theRect.contains( aRect ) && myIsHighlighting )
             anIsSelected = anObject->select( myHighlightX, myHighlightY, theRect );
 
           if( anIsSelected && mySelectedObjects.indexOf( anObject ) == -1 )
@@ -1418,13 +1423,47 @@ void GraphicsView_ViewPort::drawPulling( const QPointF& thePoint )
 // Function : finishPulling
 // Purpose  : 
 //================================================================
-void GraphicsView_ViewPort::finishPulling()
+void GraphicsView_ViewPort::finishPulling( bool theStatus )
 {
   myIsPulling = false;
-  myPullingObject->finishPulling( getSelectedObjects() );
+  myPullingObject->finishPulling( theStatus, getSelectedObjects() );
   setCursor( *getDefaultCursor() );
 }
 
+//================================================================
+// Function : cancelCurrentOperation
+// Purpose  : 
+//================================================================
+bool GraphicsView_ViewPort::cancelCurrentOperation()
+{
+  myIsHighlighting = false;
+
+  if( isDragging() )
+  {
+    for( initSelected(); moreSelected(); nextSelected() )
+      if( GraphicsView_Object* aMovingObject = selectedObject() )
+        aMovingObject->finishMove( false );
+
+    if( GraphicsView_Object* aMovingObject = getHighlightedObject() )
+      aMovingObject->finishMove( false );
+
+    myIsDragging = false;
+    myDragPosition = QPointF();
+    //setCursor( myStoredCursor );
+    setCursor( *getDefaultCursor() );
+
+    return true;
+  }
+
+  if( isPulling() )
+  {
+    finishPulling( false );
+    return true;
+  }
+
+  return false;
+}
+
 //================================================================
 // Function : onBoundingRectChanged
 // Purpose  : 
@@ -1505,10 +1544,10 @@ void GraphicsView_ViewPort::onMouseEvent( QGraphicsSceneMouseEvent* e )
         bool anIsMoved = false;
         for( initSelected(); moreSelected(); nextSelected() )
           if( GraphicsView_Object* aMovingObject = selectedObject() )
-            anIsMoved = aMovingObject->finishMove() || anIsMoved;
+            anIsMoved = aMovingObject->finishMove( true ) || anIsMoved;
 
         if( GraphicsView_Object* aMovingObject = getHighlightedObject() )
-          anIsMoved = aMovingObject->finishMove() || anIsMoved;
+          anIsMoved = aMovingObject->finishMove( true ) || anIsMoved;
 
         myIsDragging = false;
         myDragPosition = QPointF();
index 6943c8d9c951b80f72eb7775f68a471f1c3564f6..75d420e0370a14681f365ad9b546eed34b6e9d88 100644 (file)
@@ -186,9 +186,12 @@ public:
   // pulling
   bool                             startPulling( const QPointF& );
   void                             drawPulling( const QPointF& );
-  void                             finishPulling();
+  void                             finishPulling( bool theStatus );
   bool                             isPulling() const { return myIsPulling; }
 
+  // other
+  bool                             cancelCurrentOperation();
+
 public:
   static void                      createCursors();
   static void                      destroyCursors();
@@ -273,6 +276,7 @@ private:
   GraphicsView_Object*             myHighlightedObject;
   double                           myHighlightX;
   double                           myHighlightY;
+  bool                             myIsHighlighting;
 
   // selection
   GraphicsView_ObjectList          mySelectedObjects;
index cace48376fa72bdaf4a7811217fdb8b45e0d3227..ddc24dabe3724a59d7f6844fb265f58852ae85cf 100644 (file)
@@ -334,6 +334,27 @@ void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e )
 //================================================================
 void GraphicsView_Viewer::handleKeyPress( QKeyEvent* e )
 {
+  if( e->key() == Qt::Key_Escape )
+  {
+    // Cancel current operation
+    bool anIsCancelled = false;
+    if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+    {
+      anIsCancelled = aViewPort->cancelCurrentOperation();
+
+      // Unselect all objects (if there is no operation to cancel)
+      if( !anIsCancelled )
+      {
+        aViewPort->finishSelectByRect();
+        aViewPort->clearSelected();
+      }
+    }
+
+    // Emit unselection signal
+    if( !anIsCancelled )
+      if( GraphicsView_Selector* aSelector = getSelector() )
+        aSelector->unselectAll();
+  }
 }
 
 //================================================================
@@ -455,7 +476,7 @@ void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e )
   {
     if( aViewPort->isPulling() )
     {
-      aViewPort->finishPulling();
+      aViewPort->finishPulling( true );
     }
     else if( !aViewPort->getHighlightedObject() )
     {
@@ -572,15 +593,13 @@ void GraphicsView_Viewer::onRemoveImages()
 {
   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
   {
-    for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() )
+    GraphicsView_ObjectListIterator anIter( aViewPort->getSelectedObjects() );
+    while( anIter.hasNext() )
     {
-      if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
+      if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anIter.next() ) )
       {
-        if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anObject ) )
-        {
-          aViewPort->removeItem( aPrs );
-          delete aPrs;
-        }
+        aViewPort->removeItem( aPrs );
+        delete aPrs;
       }
     }
   }