Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / XGUI / XGUI_ViewWindow.cpp
index b8b90d69637663fbf9218e1515549e5d185f221c..5a1a9ba4097ed64aeef7c13082fce24c09e0f8ae 100644 (file)
@@ -79,9 +79,15 @@ const char* imageCrossCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c
     "................................", "................................" };
 
 
+ViewerToolbar::ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort)
+  : QToolBar(theParent), myVPort(thePort), myResize(false)
+{
+  connect(myVPort, SIGNAL(resized()), this, SLOT(onViewPortResized()));
+}
+
 void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
 {
-  //qDebug("### ViewerToolbar::paintEvent  %i\n", AA++);
+  //QToolBar::paintEvent(theEvent);
   // Paint background
   QPainter aPainter(this);
   QRect aRect = rect();
@@ -91,7 +97,10 @@ void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
 
   QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
                        aRect.width(), aRect.height()));
-  aPainter.drawImage(aRect, myVPort->dumpView(aImgRect, false));
+  QImage aImg = myVPort->dumpView(aImgRect, myResize);
+  if (!aImg.isNull())
+    aPainter.drawImage(aRect, aImg);
+  myResize = false;
 
   // Paint foreground
   QStyle *style = this->style();
@@ -103,8 +112,16 @@ void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
     style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &aOpt, &aPainter, this);
 }
 
+
+
 //**************************************************************************
-void ViewerLabel::repaintBackground()
+ViewerLabel::ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort)
+  : QLabel(theParent), myVPort(thePort), myResize(false)
+{
+  connect(myVPort, SIGNAL(resized()), this, SLOT(onViewPortResized()));
+}
+
+void ViewerLabel::paintEvent(QPaintEvent* theEvent)
 {
   QRect aRect = rect();
   QRect aVPRect = myVPort->rect();
@@ -113,12 +130,10 @@ void ViewerLabel::repaintBackground()
 
   QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), 
                  aRect.width(), aRect.height()));
-  QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
-}
-
-void ViewerLabel::paintEvent(QPaintEvent* theEvent)
-{
-  repaintBackground();
+  QImage aImg = myVPort->dumpView(aImgRect, myResize);
+  if (!aImg.isNull())
+    QPainter(this).drawImage(aRect, aImg);
+  myResize = false;
   QLabel::paintEvent(theEvent);
 }
 
@@ -142,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)
 {
@@ -175,7 +190,7 @@ XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
   QHBoxLayout* aToolLay = new QHBoxLayout();
   aToolLay->setMargin(0);
   aToolLay->setSpacing(0);
-  aVPLay->setContentsMargins(0,0,0,0);
+  aToolLay->setContentsMargins(0,0,0,0);
   aVPLay->addLayout(aToolLay);
   aVPLay->addStretch(); 
 
@@ -259,7 +274,6 @@ XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
   myWindowBar = new ViewerToolbar(this, myViewPort);
   myWindowBar->setCursor(Qt::PointingHandCursor);
   aToolLay->addWidget(myWindowBar);
-  myWindowBar->setFixedWidth(100);
 
   myMinimizeBtn = new QAction(myWindowBar);
   myMinimizeBtn->setIcon(MinimizeIco);
@@ -281,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()));
-
 }
 
 //****************************************************************
@@ -289,6 +302,14 @@ XGUI_ViewWindow::~XGUI_ViewWindow()
 {
 }
 
+
+//****************************************************************
+void XGUI_ViewWindow::showEvent(QShowEvent* theEvent)
+{
+  QFrame::showEvent(theEvent);
+  myWindowBar->setFixedSize(myWindowBar->sizeHint());
+}
+
 //****************************************************************
 void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
 {
@@ -333,7 +354,8 @@ void XGUI_ViewWindow::windowActivated()
     }
     myViewBar->show();
     myWindowBar->show();
-    myGripWgt->setVisible(!(isMaximized() || isMinimized()));
+    myGripWgt->setVisible(!(isMaximized() || isMinimized() ||
+        parentWidget()->isMaximized() || parentWidget()->isMinimized()));
   } else 
     myIsActive = false;
 }
@@ -402,6 +424,9 @@ void XGUI_ViewWindow::onMaximize()
   }
   parentWidget()->activateWindow();
   myMinimizeBtn->setIcon(MinimizeIco);
+  
+  //  In order to avoid frosen background in toolbars when it shown as a second view
+  QTimer::singleShot(50, parentWidget(), SLOT(setFocus()));
 }
 
 //****************************************************************
@@ -451,8 +476,11 @@ bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
       } else {
         showNormal();
       }
-      raise();
       myViewer->onWindowActivated((QMdiSubWindow*)parentWidget());
+
+      //  In order to avoid frosen background in toolbars when it shown as a second view
+      QTimer::singleShot(20, parentWidget(), SLOT(setFocus()));
+
       return true;
     }
   }
@@ -504,6 +532,10 @@ bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
     if (processViewPort(theEvent)) {
       return true;
     }
+    if (theEvent->type() == QEvent::KeyRelease) {
+      emit keyReleased(this, (QKeyEvent*) theEvent);
+      return true;
+    }
   }
   return QFrame::eventFilter(theObj, theEvent);
 }
@@ -644,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)
 {
@@ -660,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:
@@ -985,7 +1023,11 @@ void XGUI_ViewWindow::cloneView()
   QMdiSubWindow* vw = myViewer->createView();
   XGUI_ViewWindow* aNewWnd = static_cast<XGUI_ViewWindow*>(vw->widget());
   aNewWnd->viewPort()->syncronizeWith(myViewPort);
+
   emit viewCloned( vw );
+
+  //  In order to avoid frosen background in toolbars when it shown as a second view
+  QTimer::singleShot(20, vw, SLOT(setFocus()));
 }
 
 void XGUI_ViewWindow::dumpView()
@@ -1136,13 +1178,13 @@ void XGUI_ViewWindow::updateToolBar()
   myGripWgt->update();
   myViewBar->update();
   myWindowBar->update();
-  //QTimer::singleShot(50, Qt::VeryCoarseTimer, this, SLOT(repaintToolBar()));
 }
 
-/*void XGUI_ViewWindow::repaintToolBar()
+/*!
+  \brief Update state of enable draw mode state.
+*/
+void XGUI_ViewWindow::updateEnabledDrawMode()
 {
-  QApplication::sync();
-  myGripWgt->repaint();
-  myViewBar->repaint();
-  myWindowBar->repaint();
-}*/
+  myEnableDrawMode = myViewer->isSelectionEnabled() && 
+                     myViewer->isMultiSelectionEnabled();
+}