Salome HOME
Merge branch 'master' of newgeom:newgeom
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 13 May 2014 14:14:38 +0000 (18:14 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 13 May 2014 14:14:38 +0000 (18:14 +0400)
src/XGUI/XGUI_MainWindow.cpp
src/XGUI/XGUI_MainWindow.h
src/XGUI/XGUI_Viewer.cpp
src/XGUI/XGUI_Viewer.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/cascade_views.png [new file with mode: 0644]
src/XGUI/pictures/new_view.png [new file with mode: 0644]
src/XGUI/pictures/tile_views.png [new file with mode: 0644]

index cbc3e67f32994ff7338a1d2cceafdb534dc6bbf4..02971608f331e87376ad1045919c1a0643899ecf 100644 (file)
@@ -9,22 +9,10 @@
 #include <PyConsole_EnhInterp.h>
 
 #include <QMdiArea>
-#include <QTreeWidget>
-#include <QDockWidget>
-#include <QTextEdit>
-#include <QLabel>
-#include <QToolBar>
-#include <QToolButton>
-#include <QTreeWidgetItem>
-#include <QLayout>
-#include <QLineEdit>
-#include <QGroupBox>
-#include <QFormLayout>
-#include <QDoubleSpinBox>
-#include <QPushButton>
-#include <QScrollArea>
-#include <QComboBox>
+#include <QMdiSubWindow>
 #include <QAction>
+#include <QDockWidget>
+#include <QApplication>
 
 XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
     : QMainWindow(parent), 
@@ -34,9 +22,29 @@ XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
   myMenuBar = new XGUI_MainMenu(this);
 
   QMdiArea* aMdiArea = new QMdiArea(this);
+  aMdiArea->setContextMenuPolicy(Qt::ActionsContextMenu);
   setCentralWidget(aMdiArea);
+  connect(aMdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), 
+          this, SLOT(onViewActivated(QMdiSubWindow*)));
+
+  // Create actions of MDI area
+  QAction* aAction = new QAction(QIcon(":pictures/new_view.png"), tr("Create Window"), aMdiArea);
+  aMdiArea->addAction(aAction);
+  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(createSubWindow()));
+  
+  aAction = new QAction(QIcon(":pictures/tile_views.png"), tr("Tile"), aMdiArea);
+  aMdiArea->addAction(aAction);
+  connect(aAction, SIGNAL(triggered(bool)), aMdiArea, SLOT(tileSubWindows()));
+  
+  aAction = new QAction(QIcon(":pictures/cascade_views.png"), tr("Cascade"), aMdiArea);
+  aMdiArea->addAction(aAction);
+  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(cascadeWindows()));
 
   myViewer = new XGUI_Viewer(this);
+  connect(myViewer, SIGNAL(viewCreated(XGUI_ViewWindow*)), 
+          this, SLOT(onViewCreated(XGUI_ViewWindow*)));
+  connect(myViewer, SIGNAL(deleteView(XGUI_ViewWindow*)), 
+          this, SLOT(onViewCreated(XGUI_ViewWindow*)));
 }
 
 XGUI_MainWindow::~XGUI_MainWindow(void)
@@ -73,4 +81,117 @@ void XGUI_MainWindow::hidePythonConsole()
     myPythonConsole->parentWidget()->hide();
 }
 
+//******************************************************
+void XGUI_MainWindow::createSubWindow()
+{
+  viewer()->createView();
+}
 
+//******************************************************
+void XGUI_MainWindow::cascadeWindows()
+{
+  QMdiArea* aMdiArea = static_cast<QMdiArea*>(centralWidget());
+  QList<QMdiSubWindow*> aWindows = aMdiArea->subWindowList();
+  
+  QSize aSize = aMdiArea->size();
+  QRect aRect = aMdiArea->geometry();
+  const int aOffset = 30;
+  int i = 0, j = 0;
+  int x, y;
+  int w = aSize.width() / 2;
+  int h = aSize.height() / 2;
+  QMdiSubWindow* aLastWnd;
+  foreach(QMdiSubWindow* aWnd, aWindows) {
+    aWnd->showNormal();
+    aWnd->raise();
+    x = aOffset * i;
+    if ((x + w) > aSize.width()) {
+      x = 0;
+      i = 0;
+    }
+    y = aOffset * j;
+    if ((y + h) > aSize.height()) {
+      y = 0;
+      j = 0;
+    }
+    aWnd->setGeometry(QStyle::visualRect(aWnd->layoutDirection(), aRect, 
+      QRect(x, y, w, h)));
+    i++;
+    j++;
+    viewer()->onWindowActivated(aWnd);
+    aLastWnd = aWnd;
+    QApplication::processEvents();
+  }
+  aLastWnd->setFocus();
+}
+
+void XGUI_MainWindow::onViewCreated(XGUI_ViewWindow* theWindow)
+{
+  QWidget* aSubWindow = theWindow->parentWidget();
+  QWidget* aMDIWidget = centralWidget();
+  QAction* aAction;
+  if (aMDIWidget->actions().size() == 3) {
+    aAction = new QAction(aMDIWidget);
+    aAction->setSeparator(true);
+    aMDIWidget->addAction(aAction);
+  }
+  aAction = new QAction(aSubWindow->windowTitle(), aMDIWidget);
+  aAction->setCheckable(true);
+  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(activateView()));
+  aMDIWidget->addAction(aAction);
+
+  QList<QAction*> aActions = aMDIWidget->actions();
+  foreach(QAction* aAct, aActions) {
+    if (aAct->isCheckable())
+      aAct->setChecked(false);
+  }
+  aAction->setChecked(true);
+}
+
+void XGUI_MainWindow::onDeleteView(XGUI_ViewWindow* theWindow)
+{
+  QWidget* aSubWindow = theWindow->parentWidget();
+  QString aTitle = aSubWindow->windowTitle();
+  QWidget* aMDIWidget = centralWidget();
+  QList<QAction*> aActions = aMDIWidget->actions();
+
+  QAction* aDelAct = 0;
+  foreach(QAction* aAct, aActions) {
+    if (aAct->text() == aTitle) {
+      aDelAct = aAct;
+      break;
+    }
+  }
+  aMDIWidget->removeAction(aDelAct);
+}
+
+void XGUI_MainWindow::activateView()
+{
+  QAction* aAction = static_cast<QAction*>(sender());
+  QString aWndTitle = aAction->text();
+  QMdiArea* aMdiArea = static_cast<QMdiArea*>(centralWidget());
+
+  QList<QMdiSubWindow*> aWndList = aMdiArea->subWindowList();
+  foreach(QMdiSubWindow* aWnd, aWndList) {
+    if (aWnd->windowTitle() == aWndTitle) {
+      aWnd->raise();
+      aWnd->activateWindow();
+      aWnd->setFocus();
+      break;
+    }
+  }
+  QApplication::processEvents();
+}
+
+void XGUI_MainWindow::onViewActivated(QMdiSubWindow* theSubWnd)
+{
+  if (!theSubWnd)
+    return;
+  QMdiArea* aMdiArea = static_cast<QMdiArea*>(centralWidget());
+  QString aWndTitle = theSubWnd->windowTitle();
+  QList<QAction*> aActionList = aMdiArea->actions();
+  foreach(QAction* aAct, aActionList) {
+    if (aAct->isCheckable())
+      aAct->setChecked(aAct->text() == aWndTitle);
+  }
+}
\ No newline at end of file
index 17357858d7a89abc248b8113be9392368966aaf0..9b29ec3ea17d48f77809ee283684e1e94e2b1b76 100644 (file)
@@ -7,7 +7,9 @@
 class XGUI_MainMenu;
 class XGUI_Viewer;
 class XGUI_ActionsMgr;
+class XGUI_ViewWindow;
 class QMdiArea;
+class QMdiSubWindow;
 class PyConsole_EnhConsole;
 
 /**\class XGUI_MainWindow
@@ -42,6 +44,15 @@ public slots:
   void showPythonConsole();
   void hidePythonConsole();
 
+  void createSubWindow();
+  
+private slots:
+  void cascadeWindows();
+  void onViewCreated(XGUI_ViewWindow* theWindow);
+  void onDeleteView(XGUI_ViewWindow* theWindow);
+  void activateView();
+  void onViewActivated(QMdiSubWindow* theSubWnd);
+
 private:
   XGUI_MainMenu* myMenuBar;
   XGUI_Viewer* myViewer;
index 6fae264d21ecb374d75d66595d6f7495c2c42811..12eae6e4a4e550a648a410585fedb08536ae2803 100644 (file)
@@ -89,7 +89,8 @@ XGUI_Viewer::XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron)
     myIsRelative(true), 
     myInteractionStyle(XGUI::STANDARD), 
     myTrihedronSize(100),
-    myActiveView(0)
+    myActiveView(0),
+    myWndIdCount(0)
 {
   if (!isInitialized) {
     isInitialized = true;
@@ -185,9 +186,11 @@ QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType)
 
   QMdiArea* aMDI = myMainWindow->mdiArea();
   QMdiSubWindow* aWnd = aMDI->addSubWindow(view, Qt::FramelessWindowHint);
-    addView(aWnd);
+  addView(aWnd);
   aWnd->setGeometry(0, 0, aMDI->width() / 2, aMDI->height() / 2);
   aWnd->show();
+  aWnd->setWindowTitle(QString("Viewer #%1").arg(++myWndIdCount));
+  emit viewCreated(view);
   return aWnd;
 }
 
@@ -440,8 +443,11 @@ void XGUI_Viewer::addView(QMdiSubWindow* theView)
     connect(aWindow, SIGNAL(keyReleased(XGUI_ViewWindow*, QKeyEvent*)),
             this,    SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*)));
 
-//    connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )),
-//            this,    SLOT  (onContextMenuRequested( QContextMenuEvent* )));
+    //connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )),
+    //        this,    SLOT  (onContextMenuRequested( QContextMenuEvent* )));
+    //connect(aWindow, SIGNAL( contextMenuRequested(QContextMenuEvent*) ), 
+    //        this, SIGNAL( contextMenuRequested(QContextMenuEvent*) ) );
+
     connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)),
             this, SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*)));
 
@@ -457,6 +463,7 @@ void XGUI_Viewer::addView(QMdiSubWindow* theView)
 void XGUI_Viewer::onWindowActivated(QMdiSubWindow* view)
 {
   if (view && (view != myActiveView) && (!view->isMinimized())) {
+    qDebug("onWindowActivated");
     myActiveView = view;
     ((XGUI_ViewWindow*)myActiveView->widget())->windowActivated();
     QList<QMdiSubWindow*>::iterator aIt;
index 4031430a3dc36b11c830143f06bcb918f4a7ccc6..1eb2bd47ebee640af40ecba489046274a8a94629 100644 (file)
@@ -191,6 +191,9 @@ private:
 
   /// Points used for selection management
   QPoint myStartPnt, myEndPnt, myCurPnt;
+
+  // A counter of created windows
+  int myWndIdCount;
 };
 
 #endif
index 399af82303f76a2d005bc7a4f1b20d9e9a4c9065..1efefb0801060fbf0d75d8bd6973275844609fe6 100644 (file)
@@ -48,5 +48,9 @@
      <file>pictures/button_cancel.png</file>
      <file>pictures/button_help.png</file>
      <file>pictures/button_ok.png</file>
+   
+     <file>pictures/cascade_views.png</file>
+     <file>pictures/tile_views.png</file>
+     <file>pictures/new_view.png</file>
  </qresource>
  </RCC>
diff --git a/src/XGUI/pictures/cascade_views.png b/src/XGUI/pictures/cascade_views.png
new file mode 100644 (file)
index 0000000..db45111
Binary files /dev/null and b/src/XGUI/pictures/cascade_views.png differ
diff --git a/src/XGUI/pictures/new_view.png b/src/XGUI/pictures/new_view.png
new file mode 100644 (file)
index 0000000..352437d
Binary files /dev/null and b/src/XGUI/pictures/new_view.png differ
diff --git a/src/XGUI/pictures/tile_views.png b/src/XGUI/pictures/tile_views.png
new file mode 100644 (file)
index 0000000..fd9fece
Binary files /dev/null and b/src/XGUI/pictures/tile_views.png differ