]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Integration of Pop-up management.
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 15 May 2014 13:49:16 +0000 (17:49 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 15 May 2014 13:49:16 +0000 (17:49 +0400)
13 files changed:
src/PartSetPlugin/PartSetPlugin_Part.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_ContextMenuMgr.cpp [new file with mode: 0644]
src/XGUI/XGUI_ContextMenuMgr.h [new file with mode: 0644]
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_ObjectsBrowser.h
src/XGUI/XGUI_ViewWindow.cpp
src/XGUI/XGUI_Viewer.cpp
src/XGUI/XGUI_Viewer.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/edit.png [new file with mode: 0644]

index 25af3bea7bb586245b7c1def4c684911e9630114..25dc0e0ce7b3ac015483a4106a09ce2a557c3fc0 100644 (file)
@@ -36,6 +36,9 @@ public:
 
   /// Use plugin manager for features creation
   PartSetPlugin_Part();
+
+  /// Returns true if this feature must be displayed in the history (top level of Part tree)
+  PARTSETPLUGIN_EXPORT virtual bool isInHistory() {return false;}
 };
 
 #endif
index aad18bff78f4752c18dcde17c9696f89057e69c9..ea9af50b6bfd6138eea9e3575a077cf30d68ead6 100644 (file)
@@ -32,6 +32,7 @@ SET(PROJECT_HEADERS
     XGUI_ViewerProxy.h
     XGUI_ViewerPrs.h
     XGUI_PropertyPanel.h
+    XGUI_ContextMenuMgr.h
 )
 
 SET(PROJECT_AUTOMOC 
@@ -62,6 +63,7 @@ SET(PROJECT_SOURCES
     XGUI_ViewerProxy.cpp
     XGUI_ViewerPrs.cpp
     XGUI_PropertyPanel.cpp
+    XGUI_ContextMenuMgr.cpp
 )
 
 SET(PROJECT_RESOURCES 
diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp
new file mode 100644 (file)
index 0000000..b191e7f
--- /dev/null
@@ -0,0 +1,89 @@
+
+#include "XGUI_ContextMenuMgr.h"
+#include "XGUI_Workshop.h"
+#include "XGUI_ObjectsBrowser.h"
+#include "XGUI_SelectionMgr.h"
+
+#include <QAction>
+#include <QContextMenuEvent>
+#include <QMenu>
+
+XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent) :
+QObject(theParent), myWorkshop(theParent)
+{
+
+}
+
+XGUI_ContextMenuMgr::~XGUI_ContextMenuMgr()
+{
+}
+
+void XGUI_ContextMenuMgr::createActions()
+{
+  QAction* aAction = new QAction(QIcon(":pictures/edit.png"), tr("Edit..."), this);
+  addAction("EDIT_CMD", aAction);
+}
+
+void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
+{
+  if (myActions.contains(theId))
+    qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
+  theAction->setData(theId);
+  connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
+  myActions[theId] = theAction;
+}
+
+QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
+{
+  if (myActions.contains(theId))
+    return myActions[theId];
+  return 0;
+}
+
+QStringList XGUI_ContextMenuMgr::actionIds() const
+{
+  return myActions.keys();
+}
+
+void XGUI_ContextMenuMgr::onAction(bool isChecked)
+{
+  QAction* aAction = static_cast<QAction*>(sender());
+  emit actionTriggered(aAction->data().toString(), isChecked);
+}
+
+void XGUI_ContextMenuMgr::updateCommandsStatus()
+{
+}
+
+void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
+{
+  QMenu* aMenu = 0;
+  if (sender() == myWorkshop->objectBrowser())
+    aMenu = objectBrowserMenu();
+
+  if (aMenu) {
+    aMenu->exec(theEvent->globalPos());
+    delete aMenu;
+  }
+}
+
+QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
+{
+  XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
+  QFeatureList aFeatures = aSelMgr->selectedFeatures();
+  if (aFeatures.size() == 1) {
+    FeaturePtr aFeature = aFeatures.first();
+    if (aFeature->getKind() != "Part") {
+      QMenu* aMenu = new QMenu();
+      aMenu->addAction(action("EDIT_CMD"));
+      return aMenu;
+    }
+  }
+  return 0;
+}
+
+void XGUI_ContextMenuMgr::connectObjectBrowser() const
+{
+  connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), 
+    this, SLOT(onContextMenuRequest(QContextMenuEvent*)));
+}
\ No newline at end of file
diff --git a/src/XGUI/XGUI_ContextMenuMgr.h b/src/XGUI/XGUI_ContextMenuMgr.h
new file mode 100644 (file)
index 0000000..3ce0051
--- /dev/null
@@ -0,0 +1,50 @@
+
+#ifndef XGUI_ContextMenuMgr_H
+#define XGUI_ContextMenuMgr_H
+
+#include "XGUI.h"
+
+#include <QObject>
+#include <QMap>
+
+class XGUI_Workshop;
+class QAction;
+class QContextMenuEvent;
+class QMenu;
+
+class XGUI_EXPORT XGUI_ContextMenuMgr: public QObject
+{
+Q_OBJECT
+public:
+  XGUI_ContextMenuMgr(XGUI_Workshop* theParent);
+  virtual ~XGUI_ContextMenuMgr();
+
+  void createActions();
+
+  void addAction(const QString& theId, QAction* theAction);
+
+  QAction* action(const QString& theId) const;
+
+  QStringList actionIds() const;
+
+  void updateCommandsStatus();
+
+  void connectObjectBrowser() const;
+
+signals:
+  void actionTriggered(const QString& theId, bool isChecked);
+
+private slots:
+  void onAction(bool isChecked);
+
+  void onContextMenuRequest(QContextMenuEvent* theEvent);
+
+private:
+  QMenu* objectBrowserMenu() const;
+
+  QMap<QString, QAction*> myActions;
+
+  XGUI_Workshop* myWorkshop;
+};
+
+#endif
\ No newline at end of file
index fb43e76122572d1bcb6b7f84ebfad54b4d7f5986..15539c3e64ddfc0158ddff749d17a6d9559cc035 100644 (file)
@@ -43,4 +43,9 @@ void XGUI_ObjectsBrowser::mouseDoubleClickEvent(QMouseEvent* theEvent)
     setExpanded(aIndex, myDocModel->hasChildren(aIndex));
     emit activePartChanged(myDocModel->activePart());
   }
+}
+
+void XGUI_ObjectsBrowser::contextMenuEvent(QContextMenuEvent* theEvent)
+{
+  emit contextMenuRequested(theEvent);
 }
\ No newline at end of file
index de43e5272f7b6466f61286cb464559ab8f9d5ec7..fd1adbed8b1cc6b1852fecc7e96706b1fb9fc00a 100644 (file)
@@ -30,9 +30,13 @@ signals:
   //! Emited when selection is changed
   void selectionChanged();
   void activePartChanged(FeaturePtr thePart); 
+  //! Emited on context menu request
+  void contextMenuRequested(QContextMenuEvent* theEvent);
 
 protected:
   virtual void mouseDoubleClickEvent(QMouseEvent* theEvent);
+  virtual void contextMenuEvent(QContextMenuEvent* theEvent);
 
 private slots:
   //! Called when selection in Data Tree is changed
index bff1e923f5451a5e8226e17ee41cc45be1f5c4da..5a1a9ba4097ed64aeef7c13082fce24c09e0f8ae 100644 (file)
@@ -680,7 +680,8 @@ void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
 void XGUI_ViewWindow::contextMenuEvent(QContextMenuEvent* theEvent)
 {
   if (theEvent->modifiers() == Qt::NoModifier) {
-    QFrame::contextMenuEvent(theEvent);
+    // Temporary: has to be removed when viewer popup will be defined
+    //QFrame::contextMenuEvent(theEvent);
     emit contextMenuRequested(theEvent);
   }
 }
index b5b5aaedccec41b460b3aa7b6d4f6ba5b63ee8bf..78d9d841ccd01c6ba2f8407fc096e46d36e14e44 100644 (file)
@@ -6,6 +6,8 @@
 #include <QMdiArea>
 #include <QMdiSubWindow>
 #include <QApplication>
+#include <QMouseEvent>
+#include <QMenu>
 
 #include <V3d_View.hxx>
 
@@ -22,7 +24,6 @@
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <AIS_Shape.hxx>
 
-#include <QMouseEvent>
 
 #ifdef WIN32
 #include <WNT_Window.hxx>
@@ -443,8 +444,8 @@ 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*) ) );
 
@@ -583,3 +584,31 @@ void XGUI_Viewer::updateViewsDrawMode() const
     aView->updateEnabledDrawMode();
   }
 }
+
+//******************************************************
+void XGUI_Viewer::onContextMenuRequested(QContextMenuEvent* theEvent)
+{
+  XGUI_ViewWindow* aWnd = dynamic_cast<XGUI_ViewWindow*>(sender());
+  if (!aWnd) return;
+
+  QMenu aMenu;
+
+  // Include Viewer actions
+  if (myActions.size() > 0) {
+    aMenu.addActions(myActions);
+    aMenu.addSeparator();
+  }
+  if (aWnd->actions().size() > 0) {
+    aMenu.addActions(aWnd->actions());
+    aMenu.addSeparator();
+  }
+
+  QMdiArea* aMDI = myMainWindow->mdiArea();
+  if (aMenu.actions().size() > 0) {
+    QMenu* aSubMenu = aMenu.addMenu(tr("Windows"));
+    aSubMenu->addActions(aMDI->actions());
+  } else {
+    aMenu.addActions(aMDI->actions());
+  }
+  aMenu.exec(theEvent->globalPos());
+}
\ No newline at end of file
index 1eb2bd47ebee640af40ecba489046274a8a94629..d85a160cf9edbf96c33e98cdce185eb2e4aec4be 100644 (file)
@@ -7,6 +7,8 @@
 #include <QObject>
 #include <QMap>
 #include <QList>
+#include <QPoint>
+#include <QAction>
 
 #include <V3d_Viewer.hxx>
 #include <AIS_InteractiveContext.hxx>
@@ -14,7 +16,6 @@
 #include <NCollection_List.hxx>
 #include <TopoDS_Shape.hxx>
 
-#include <QPoint>
 
 class XGUI_MainWindow;
 class QMdiSubWindow;
@@ -123,6 +124,10 @@ public:
   //! Compute trihedron size dependent on 3d scene size
   bool computeTrihedronSize(double& theNewSize, double& theSize);
 
+  //! Add action to the viewer
+  void addAction(QAction* theAction) { myActions.append(theAction); }
+
+
   static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
                            Qt::KeyboardModifiers theState, Qt::MouseButtons theButton);
   static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
@@ -160,6 +165,7 @@ private slots:
   void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
   void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
   void onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
+  void onContextMenuRequested(QContextMenuEvent* theEvent);
 
 private:
   void addView(QMdiSubWindow* theView);
@@ -192,8 +198,11 @@ private:
   /// Points used for selection management
   QPoint myStartPnt, myEndPnt, myCurPnt;
 
-  // A counter of created windows
+  /// A counter of created windows
   int myWndIdCount;
+
+  /// List of Viewer actions
+  QList<QAction*> myActions;
 };
 
 #endif
index 577e6decae9422acb5def9a2c2e92719452320aa..5b3c5616b5108684154eb253f0542ca9d77115f9 100644 (file)
@@ -19,6 +19,7 @@
 #include "XGUI_ErrorDialog.h"
 #include "XGUI_ViewerProxy.h"
 #include "XGUI_PropertyPanel.h"
+#include "XGUI_ContextMenuMgr.h"
 
 #include <Model_Events.h>
 #include <ModelAPI_PluginManager.h>
@@ -83,6 +84,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   myOperationMgr = new XGUI_OperationMgr(this);
   myActionsMgr = new XGUI_ActionsMgr(this);
   myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
+  myContextMenuMgr = new XGUI_ContextMenuMgr(this);
 
   myViewerProxy = new XGUI_ViewerProxy(this);
 
@@ -177,6 +179,7 @@ void XGUI_Workshop::initMenu()
                                 QIcon(":pictures/close.png"), QKeySequence::Close);
   aCommand->connectTo(this, SLOT(onExit()));
 
+  myContextMenuMgr->createActions();
 }
 
 //******************************************************
@@ -571,25 +574,25 @@ void XGUI_Workshop::updateCommandStatus()
   if (aMgr->hasRootDocument()) {
     XGUI_Command* aUndoCmd;
     XGUI_Command* aRedoCmd;
-    for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) {
-      if ((*aIt)->id() == "UNDO_CMD")
-        aUndoCmd = (*aIt);
-      else if ((*aIt)->id() == "REDO_CMD")
-        aRedoCmd = (*aIt);
+    foreach(XGUI_Command* aCmd, aCommands) {
+      if (aCmd->id() == "UNDO_CMD")
+        aUndoCmd = aCmd;
+      else if (aCmd->id() == "REDO_CMD")
+        aRedoCmd = aCmd;
       else // Enable all commands
-        (*aIt)->enable();
+        aCmd->enable();
     }
     boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
     aUndoCmd->setEnabled(aDoc->canUndo());
     aRedoCmd->setEnabled(aDoc->canRedo());
   } else {
-    for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) {
-      if ((*aIt)->id() == "NEW_CMD")
-        (*aIt)->enable();
-      else if ((*aIt)->id() == "EXIT_CMD")
-        (*aIt)->enable();
+    foreach(XGUI_Command* aCmd, aCommands) {
+      if (aCmd->id() == "NEW_CMD")
+        aCmd->enable();
+      else if (aCmd->id() == "EXIT_CMD")
+        aCmd->enable();
       else 
-        (*aIt)->disable();
+        aCmd->disable();
     }
   }
 }
@@ -603,6 +606,8 @@ QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
   connect(myObjectBrowser, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(changeCurrentDocument(FeaturePtr)));
   aObjDock->setWidget(myObjectBrowser);
+
+  myContextMenuMgr->connectObjectBrowser();
   return aObjDock;
 }
 
index 737b36876a9c792dbb27f2cd8740bc31ae0c954c..f0121474b608056a73f56fff7444d7ca5f8748c8 100644 (file)
@@ -24,6 +24,7 @@ class XGUI_ErrorDialog;
 class XGUI_SalomeViewer;
 class XGUI_ViewerProxy;
 class XGUI_PropertyPanel;
+class XGUI_ContextMenuMgr;
 
 class ModuleBase_Operation;
 
@@ -69,6 +70,9 @@ public:
   //! Returns property panel widget
   XGUI_PropertyPanel* propertyPanel() const { return myPropertyPanel; }
 
+  //! Returns context menu manager object
+  XGUI_ContextMenuMgr* contextMenuMgr() const { return myContextMenuMgr; }
+
   //! Creates and adds a new workbench (menu group) with the given name and returns it
   XGUI_Workbench* addWorkbench(const QString& theName);
 
@@ -159,6 +163,7 @@ private:
   XGUI_SalomeConnector* mySalomeConnector;
   XGUI_ErrorDialog* myErrorDlg;
   XGUI_ViewerProxy* myViewerProxy;
+  XGUI_ContextMenuMgr* myContextMenuMgr;
 
   static QMap<QString, QString> myIcons;
 
index 1efefb0801060fbf0d75d8bd6973275844609fe6..893d8d7b6b2a0442e8eaad115d2ea915630b6309 100644 (file)
@@ -7,7 +7,6 @@
      <file>pictures/redo.png</file>
      <file>pictures/undo.png</file>
      <file>pictures/rebuild.png</file>
-     <!--For test purposes-->
 
      <file>pictures/occ_view_back.png</file>
      <file>pictures/occ_view_bottom.png</file>
@@ -52,5 +51,6 @@
      <file>pictures/cascade_views.png</file>
      <file>pictures/tile_views.png</file>
      <file>pictures/new_view.png</file>
+     <file>pictures/edit.png</file>
  </qresource>
  </RCC>
diff --git a/src/XGUI/pictures/edit.png b/src/XGUI/pictures/edit.png
new file mode 100644 (file)
index 0000000..43a3174
Binary files /dev/null and b/src/XGUI/pictures/edit.png differ