Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / XGUI / XGUI_ViewWindow.cpp
index 12c92e6fa62cfeae5fd87963ae58f66c41519dd0..c62a266524ab56dbe29c05f6a2c27b16d874c0b6 100644 (file)
@@ -112,6 +112,8 @@ void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
     style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &aOpt, &aPainter, this);
 }
 
+
+
 //**************************************************************************
 ViewerLabel::ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort)
   : QLabel(theParent), myVPort(thePort), myResize(false)
@@ -131,6 +133,7 @@ void ViewerLabel::paintEvent(QPaintEvent* theEvent)
   QImage aImg = myVPort->dumpView(aImgRect, myResize);
   if (!aImg.isNull())
     QPainter(this).drawImage(aRect, aImg);
+  myResize = false;
   QLabel::paintEvent(theEvent);
 }
 
@@ -154,7 +157,7 @@ XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
     myRotationPointSelection(false),
     myClosable(true),
     myStartX(0), myStartY(0), myCurrX(0), myCurrY(0), myCurScale(0.0), myCurSketch(0),
-    myDrawRect(false), myEnableDrawMode(true), myCursorIsHand(false), myEventStarted(false),
+    myDrawRect(false), myEnableDrawMode(false), myCursorIsHand(false), myEventStarted(false),
     myIsActive(false),
     myLastState(WindowNormalState), myOperation(NOTHING)
 {
@@ -292,7 +295,6 @@ XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
   connect(myViewPort, SIGNAL(vpUpdated()), this, SLOT(updateToolBar()));
   connect(this, SIGNAL(vpTransformationFinished(XGUI_ViewWindow::OperationType)), 
           this, SLOT(updateToolBar()));
-
 }
 
 //****************************************************************
@@ -674,6 +676,16 @@ void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
    l_mbPressEvent = new QMouseEvent( *theEvent );*/
 }
 
+//****************************************************************
+void XGUI_ViewWindow::contextMenuEvent(QContextMenuEvent* theEvent)
+{
+  if (theEvent->modifiers() == Qt::NoModifier) {
+    // Temporary: has to be removed when viewer popup will be defined
+    //QFrame::contextMenuEvent(theEvent);
+    emit contextMenuRequested(theEvent);
+  }
+}
+
 //****************************************************************
 void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
 {
@@ -690,10 +702,6 @@ void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
      }
      */
     emit mouseReleased(this, theEvent);
-    if (theEvent->button() == Qt::RightButton && prevState == -1) {
-      QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
-      emit contextMenuRequested(&aEvent);
-    }
   }
     break;
   case ROTATE:
@@ -719,7 +727,7 @@ void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
       myCurrX = theEvent->x();
       myCurrY = theEvent->y();
       drawRect();
-      QRect rect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
+      QRect rect = XGUI_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
       if (!rect.isEmpty())
         myViewPort->fitRect(rect);
       endDrawRect();
@@ -851,7 +859,7 @@ void XGUI_ViewWindow::drawRect()
   }
 
   myRectBand->setUpdatesEnabled(false);
-  QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
+  QRect aRect = XGUI_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
   myRectBand->initGeometry(aRect);
 
   if (!myRectBand->isVisible())
@@ -996,12 +1004,12 @@ void XGUI_ViewWindow::resetState()
   setTransformRequested(NOTHING);
 }
 
-XGUI_ViewBackground XGUI_ViewWindow::background() const
+Qtx::BackgroundData XGUI_ViewWindow::background() const
 {
-  return myViewPort ? myViewPort->background() : XGUI_ViewBackground();
+  return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
 }
 
-void XGUI_ViewWindow::setBackground(const XGUI_ViewBackground& theBackground)
+void XGUI_ViewWindow::setBackground(const Qtx::BackgroundData& theBackground)
 {
   if (myViewPort) 
        myViewPort->setBackground( theBackground );
@@ -1031,7 +1039,7 @@ void XGUI_ViewWindow::dumpView()
     QApplication::setOverrideCursor( Qt::WaitCursor );
     QImage aPicture = myViewPort->dumpView();
 
-    QString aFmt = extension(aFileName).toUpper();
+    QString aFmt = XGUI_Tools::extension(aFileName).toUpper();
     if( aFmt.isEmpty() )
       aFmt = QString( "BMP" ); // default format
     else if( aFmt == "JPG" )
@@ -1172,3 +1180,11 @@ void XGUI_ViewWindow::updateToolBar()
   myWindowBar->update();
 }
 
+/*!
+  \brief Update state of enable draw mode state.
+*/
+void XGUI_ViewWindow::updateEnabledDrawMode()
+{
+  myEnableDrawMode = myViewer->isSelectionEnabled() && 
+                     myViewer->isMultiSelectionEnabled();
+}