Salome HOME
Update Delete operation in pop-up
[modules/shaper.git] / src / XGUI / XGUI_ViewWindow.cpp
index 000e4b4ae31602285764dcf54194dca7809712fe..5a1a9ba4097ed64aeef7c13082fce24c09e0f8ae 100644 (file)
@@ -79,10 +79,14 @@ 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)
 {
-  //QApplication::syncX();
-  //printf("### ViewerToolbar::paintEvent\n");
   //QToolBar::paintEvent(theEvent);
   // Paint background
   QPainter aPainter(this);
@@ -93,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();
@@ -105,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();
@@ -115,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);
 }
 
@@ -158,6 +171,7 @@ XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
   aLay->setContentsMargins(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE);
   myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType);
   myViewPort->installEventFilter(this);
+  myViewPort->setCursor(Qt::ArrowCursor);
   aLay->addWidget(myViewPort);
 
   myPicture = new QLabel(this);
@@ -168,14 +182,30 @@ XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
   aLay->addWidget(myPicture);
   myPicture->hide();
 
+  QVBoxLayout* aVPLay = new QVBoxLayout(myViewPort);
+  aVPLay->setMargin(0);
+  aVPLay->setSpacing(0);
+  aVPLay->setContentsMargins(0,0,0,0);
+
+  QHBoxLayout* aToolLay = new QHBoxLayout();
+  aToolLay->setMargin(0);
+  aToolLay->setSpacing(0);
+  aToolLay->setContentsMargins(0,0,0,0);
+  aVPLay->addLayout(aToolLay);
+  aVPLay->addStretch(); 
+
   myGripWgt = new ViewerLabel(this, myViewPort);
   myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
-  myGripWgt->setGeometry(BORDER_SIZE + 2, BORDER_SIZE + 2, 19, 32);
   myGripWgt->setMouseTracking(true);
   myGripWgt->installEventFilter(this);
+  myGripWgt->setCursor(Qt::OpenHandCursor);
+  aToolLay->addWidget(myGripWgt);
 
     // Create Viewer management buttons
   myViewBar = new ViewerToolbar(this, myViewPort);
+  myViewBar->setCursor(Qt::PointingHandCursor);
+  aToolLay->addWidget(myViewBar); 
+  aToolLay->addStretch();
 
   QAction* aBtn;
 
@@ -242,6 +272,8 @@ XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
 
     // Create Window management buttons
   myWindowBar = new ViewerToolbar(this, myViewPort);
+  myWindowBar->setCursor(Qt::PointingHandCursor);
+  aToolLay->addWidget(myWindowBar);
 
   myMinimizeBtn = new QAction(myWindowBar);
   myMinimizeBtn->setIcon(MinimizeIco);
@@ -258,16 +290,11 @@ XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
   myWindowBar->addAction(aBtn);
   connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
 
-  //myViewBar->hide();
-  //myWindowBar->hide();
-  //myGripWgt->hide();
-
   //Support copy of background on updating of viewer
   connect(myViewPort, SIGNAL(vpTransformed()), this, SLOT(updateToolBar()));
   connect(myViewPort, SIGNAL(vpUpdated()), this, SLOT(updateToolBar()));
   connect(this, SIGNAL(vpTransformationFinished(XGUI_ViewWindow::OperationType)), 
           this, SLOT(updateToolBar()));
-
 }
 
 //****************************************************************
@@ -275,19 +302,12 @@ XGUI_ViewWindow::~XGUI_ViewWindow()
 {
 }
 
+
 //****************************************************************
-void XGUI_ViewWindow::resizeEvent(QResizeEvent* theEvent)
+void XGUI_ViewWindow::showEvent(QShowEvent* theEvent)
 {
-  QSize aSize = theEvent->size();
-  QSize aWndBarSize = myWindowBar->sizeHint();
-  QSize myViewBarSize = myViewBar->sizeHint();
-
-  myWindowBar->setGeometry(aSize.width() - aWndBarSize.width() - BORDER_SIZE - 4, BORDER_SIZE + 2,
-      aWndBarSize.width(), aWndBarSize.height());
-  int aViewBarWidth = aSize.width() - aWndBarSize.width() - myGripWgt->width() - 8;
-  if (aViewBarWidth > myViewBarSize.width())
-    aViewBarWidth = myViewBarSize.width();
-  myViewBar->setGeometry(BORDER_SIZE + 18, BORDER_SIZE + 2, aViewBarWidth, myViewBarSize.height());
+  QFrame::showEvent(theEvent);
+  myWindowBar->setFixedSize(myWindowBar->sizeHint());
 }
 
 //****************************************************************
@@ -325,32 +345,34 @@ void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
 //****************************************************************
 void XGUI_ViewWindow::windowActivated()
 {
-  myIsActive = true;
-  if (!isMinimized()) {
-    myViewBar->show();
-    myWindowBar->show();
-    myGripWgt->setVisible(!(isMaximized() || isMinimized()));
-    if (isMaximized()) {
+  if (!(isMinimized() || parentWidget()->isMinimized())) {
+    myIsActive = true;
+    if (isMaximized() || parentWidget()->isMaximized()) {
       myMaximizeBtn->setIcon(RestoreIco);
     } else {
       myMaximizeBtn->setIcon(MaximizeIco);
     }
-  }
+    myViewBar->show();
+    myWindowBar->show();
+    myGripWgt->setVisible(!(isMaximized() || isMinimized() ||
+        parentWidget()->isMaximized() || parentWidget()->isMinimized()));
+  } else 
+    myIsActive = false;
 }
 
 //****************************************************************
 void XGUI_ViewWindow::windowDeactivated()
 {
   myIsActive = false;
-  if (!isMinimized()) {
-    myViewBar->hide();
-    myWindowBar->hide();
-    myGripWgt->hide(); 
-    if (isMaximized()) {
+  if (!(isMinimized() || parentWidget()->isMinimized())) {
+    if (isMaximized() || parentWidget()->isMaximized()) {
       myMaximizeBtn->setIcon(RestoreIco);
     } else {
       myMaximizeBtn->setIcon(MaximizeIco);
     }
+    myViewBar->hide();
+    myWindowBar->hide();
+    myGripWgt->hide(); 
   }
 }
 
@@ -367,25 +389,6 @@ void XGUI_ViewWindow::onClose()
   }
 }
 
-//****************************************************************
-/*void XGUI_ViewWindow::enterEvent(QEvent* theEvent)
-{
-  if (!isMinimized()) {
-    myViewBar->show();
-    myWindowBar->show();
-    if (!isMaximized())
-      myGripWgt->show();
-  }
-}
-
-//****************************************************************
-void XGUI_ViewWindow::leaveEvent(QEvent* theEvent)
-{
-  myViewBar->hide();
-  myGripWgt->hide();
-  myWindowBar->hide();
-}*/
-
 //****************************************************************
 void XGUI_ViewWindow::onMinimize()
 {
@@ -397,9 +400,12 @@ void XGUI_ViewWindow::onMinimize()
   myPicture->setPixmap(aPMap.scaled(100,  aNewH));
 
   myLastState = (isMaximized() || parentWidget()->isMaximized()) ? MaximizedState : WindowNormalState;
-  //parentWidget()->showMinimized();
   showMinimized();
+  parentWidget()->showMinimized();
   parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), 100, aNewH);
+  parentWidget()->lower();
+  windowDeactivated();
+  myViewer->onWindowMinimized((QMdiSubWindow*)parentWidget());
 }
 
 //****************************************************************
@@ -414,8 +420,13 @@ void XGUI_ViewWindow::onMaximize()
     myMaximizeBtn->setIcon(RestoreIco);
     myGripWgt->hide();
     showMaximized();
+    parentWidget()->showMaximized();
   }
+  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()));
 }
 
 //****************************************************************
@@ -460,10 +471,16 @@ bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
   case QEvent::MouseButtonDblClick:
     if (theObj == myPicture) {
       myMoving = false;
-      if (myLastState == MaximizedState)
+      if (myLastState == MaximizedState) {
         showMaximized();
-      else
+      } else {
         showNormal();
+      }
+      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;
     }
   }
@@ -515,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);
 }
@@ -655,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)
 {
@@ -671,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:
@@ -996,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()
@@ -1147,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();
+}