From: vsv Date: Fri, 6 Jun 2014 15:19:21 +0000 (+0400) Subject: Create pop-up menu in 3d viewer X-Git-Tag: V_0.4.4~303^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ba5252b2aa791ab16b93e89d4da65db73f63aa2c;p=modules%2Fshaper.git Create pop-up menu in 3d viewer --- diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index b114aa315..a02f1d2dc 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -4,6 +4,8 @@ #include "XGUI_ObjectsBrowser.h" #include "XGUI_SelectionMgr.h" #include "XGUI_Displayer.h" +#include "XGUI_MainWindow.h" +#include "XGUI_Viewer.h" #include "PartSetPlugin_Part.h" @@ -14,6 +16,7 @@ #include #include #include +#include XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent) : QObject(theParent), myWorkshop(theParent) @@ -81,8 +84,11 @@ void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent) QMenu* aMenu = 0; if (sender() == myWorkshop->objectBrowser()) aMenu = objectBrowserMenu(); - - if (aMenu) { + else if (sender() == myWorkshop->mainWindow()->viewer()) { + aMenu = viewerMenu(); + } + + if (aMenu && (aMenu->actions().size() > 0)) { aMenu->exec(theEvent->globalPos()); delete aMenu; } @@ -132,8 +138,38 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const return 0; } +QMenu* XGUI_ContextMenuMgr::viewerMenu() const +{ + QMenu* aMenu = new QMenu(); + XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); + QFeatureList aFeatures = aSelMgr->selectedFeatures(); + if (aFeatures.size() > 0) { + if (aFeatures.size() > 0) + aMenu->addAction(action("EDIT_CMD")); + aMenu->addAction(action("HIDE_CMD")); + aMenu->addAction(action("DELETE_CMD")); + } + QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea(); + if (aMDI->actions().size() > 0) { + QMenu* aSubMenu = aMenu->addMenu(tr("Windows")); + aSubMenu->addActions(aMDI->actions()); + } + if (aMenu->actions().size() > 0) { + return aMenu; + } + delete aMenu; + return 0; +} + void XGUI_ContextMenuMgr::connectObjectBrowser() const { connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), this, SLOT(onContextMenuRequest(QContextMenuEvent*))); -} \ No newline at end of file +} + +void XGUI_ContextMenuMgr::connectViewer() const +{ + // TODO: Adapt to SALOME mode + connect(myWorkshop->mainWindow()->viewer(), SIGNAL(contextMenuRequested(QContextMenuEvent*)), + this, SLOT(onContextMenuRequest(QContextMenuEvent*))); +} diff --git a/src/XGUI/XGUI_ContextMenuMgr.h b/src/XGUI/XGUI_ContextMenuMgr.h index 3ce0051fd..a8255ff0c 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.h +++ b/src/XGUI/XGUI_ContextMenuMgr.h @@ -31,6 +31,8 @@ public: void connectObjectBrowser() const; + void connectViewer() const; + signals: void actionTriggered(const QString& theId, bool isChecked); @@ -41,6 +43,7 @@ private slots: private: QMenu* objectBrowserMenu() const; + QMenu* viewerMenu() const; QMap myActions; diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index 7ce708e65..ced60958b 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -444,21 +444,22 @@ QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const if (part() == theFeature) return aIndex; - std::string aGroup = theFeature->getGroup(); + //std::string aGroup = theFeature->getGroup(); DocumentPtr aDoc = theFeature->document(); - int aNb = aDoc->size(aGroup); + int aNb = aDoc->size(FEATURES_GROUP); int aRow = -1; for (int i = 0; i < aNb; i++) { - if (aDoc->feature(aGroup, i) == theFeature) { + if (aDoc->feature(FEATURES_GROUP, i) == theFeature) { aRow = i; break; } } if (aRow != -1) { - if (aGroup.compare(PARAMETERS_GROUP) == 0) + return createIndex(aRow + 3, 0, (qint32) HistoryObject); +/* if (aGroup.compare(PARAMETERS_GROUP) == 0) return createIndex(aRow, 0, (qint32) ParamObject); if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0) - return createIndex(aRow, 0, (qint32) ConstructObject); + return createIndex(aRow, 0, (qint32) ConstructObject);*/ } } return aIndex; diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index db719599f..ff33f60eb 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -444,10 +444,10 @@ 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, SIGNAL( contextMenuRequested(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*))); @@ -590,29 +590,29 @@ void XGUI_Viewer::updateViewsDrawMode() const } //****************************************************** -void XGUI_Viewer::onContextMenuRequested(QContextMenuEvent* theEvent) -{ - XGUI_ViewWindow* aWnd = dynamic_cast(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 +//void XGUI_Viewer::onContextMenuRequested(QContextMenuEvent* theEvent) +//{ +// XGUI_ViewWindow* aWnd = dynamic_cast(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()); +//} diff --git a/src/XGUI/XGUI_Viewer.h b/src/XGUI/XGUI_Viewer.h index d85a160cf..664e58b2b 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -156,6 +156,8 @@ signals: void activated(XGUI_ViewWindow* theWindow); void selectionChanged(); + void contextMenuRequested(QContextMenuEvent*); + public slots: void onWindowMinimized(QMdiSubWindow*); void onWindowActivated(QMdiSubWindow*); @@ -165,7 +167,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); + //void onContextMenuRequested(QContextMenuEvent* theEvent); private: void addView(QMdiSubWindow* theView); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index ca06c5e1f..0cbafb045 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -433,6 +433,7 @@ void XGUI_Workshop::onNew() if (!isSalomeMode()) { myMainWindow->showPythonConsole(); QMdiSubWindow* aWnd = myMainWindow->viewer()->createView(); + myContextMenuMgr->connectViewer(); aWnd->showMaximized(); updateCommandStatus(); } @@ -832,8 +833,11 @@ void XGUI_Workshop::deleteFeatures(QFeatureList theList) aFeature = aObject->featureRef(); } } + if (myDisplayer->isVisible(aFeature)) + myDisplayer->erase(aFeature, false); aFeature->document()->removeFeature(aFeature); } + myDisplayer->updateViewer(); aMgr->rootDocument()->finishOperation(); } }