From dd23f15e4794d927de843b135eb7a2032fa06ea0 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 15 May 2014 17:49:16 +0400 Subject: [PATCH] Integration of Pop-up management. --- src/PartSetPlugin/PartSetPlugin_Part.h | 3 + src/XGUI/CMakeLists.txt | 2 + src/XGUI/XGUI_ContextMenuMgr.cpp | 89 +++++++++++++++++++++++++ src/XGUI/XGUI_ContextMenuMgr.h | 50 ++++++++++++++ src/XGUI/XGUI_ObjectsBrowser.cpp | 5 ++ src/XGUI/XGUI_ObjectsBrowser.h | 4 ++ src/XGUI/XGUI_ViewWindow.cpp | 3 +- src/XGUI/XGUI_Viewer.cpp | 35 +++++++++- src/XGUI/XGUI_Viewer.h | 13 +++- src/XGUI/XGUI_Workshop.cpp | 29 ++++---- src/XGUI/XGUI_Workshop.h | 5 ++ src/XGUI/XGUI_pictures.qrc | 2 +- src/XGUI/pictures/edit.png | Bin 0 -> 1052 bytes 13 files changed, 221 insertions(+), 19 deletions(-) create mode 100644 src/XGUI/XGUI_ContextMenuMgr.cpp create mode 100644 src/XGUI/XGUI_ContextMenuMgr.h create mode 100644 src/XGUI/pictures/edit.png diff --git a/src/PartSetPlugin/PartSetPlugin_Part.h b/src/PartSetPlugin/PartSetPlugin_Part.h index 25af3bea7..25dc0e0ce 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.h +++ b/src/PartSetPlugin/PartSetPlugin_Part.h @@ -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 diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index aad18bff7..ea9af50b6 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -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 index 000000000..b191e7fa3 --- /dev/null +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -0,0 +1,89 @@ + +#include "XGUI_ContextMenuMgr.h" +#include "XGUI_Workshop.h" +#include "XGUI_ObjectsBrowser.h" +#include "XGUI_SelectionMgr.h" + +#include +#include +#include + +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(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 index 000000000..3ce0051fd --- /dev/null +++ b/src/XGUI/XGUI_ContextMenuMgr.h @@ -0,0 +1,50 @@ + +#ifndef XGUI_ContextMenuMgr_H +#define XGUI_ContextMenuMgr_H + +#include "XGUI.h" + +#include +#include + +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 myActions; + + XGUI_Workshop* myWorkshop; +}; + +#endif \ No newline at end of file diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index fb43e7612..15539c3e6 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -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 diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index de43e5272..fd1adbed8 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -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 diff --git a/src/XGUI/XGUI_ViewWindow.cpp b/src/XGUI/XGUI_ViewWindow.cpp index bff1e923f..5a1a9ba40 100644 --- a/src/XGUI/XGUI_ViewWindow.cpp +++ b/src/XGUI/XGUI_ViewWindow.cpp @@ -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); } } diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index b5b5aaedc..78d9d841c 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include @@ -22,7 +24,6 @@ #include #include -#include #ifdef WIN32 #include @@ -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(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 diff --git a/src/XGUI/XGUI_Viewer.h b/src/XGUI/XGUI_Viewer.h index 1eb2bd47e..d85a160cf 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include @@ -14,7 +16,6 @@ #include #include -#include 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 myActions; }; #endif diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 577e6deca..5b3c5616b 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -19,6 +19,7 @@ #include "XGUI_ErrorDialog.h" #include "XGUI_ViewerProxy.h" #include "XGUI_PropertyPanel.h" +#include "XGUI_ContextMenuMgr.h" #include #include @@ -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 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; } diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 737b36876..f0121474b 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -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 myIcons; diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index 1efefb080..893d8d7b6 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -7,7 +7,6 @@ pictures/redo.png pictures/undo.png pictures/rebuild.png - pictures/occ_view_back.png pictures/occ_view_bottom.png @@ -52,5 +51,6 @@ pictures/cascade_views.png pictures/tile_views.png pictures/new_view.png + pictures/edit.png diff --git a/src/XGUI/pictures/edit.png b/src/XGUI/pictures/edit.png new file mode 100644 index 0000000000000000000000000000000000000000..43a31742074f2e6de3ef29126e3129afc34bdd60 GIT binary patch literal 1052 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b zK-vS0-A-oPfdtD69Mgd`SU*F|v9*U87?@o>T^vI!PUlYc%!nyvI9C7u?Ce^j%*hs+ zlV%>tIqUK^V5Mu0;lT$%TDnsn`T94Vc3fSd+2zI0)pSA0bxBi5p<+{pC%>+rZqTG< zQ)ZdWRPmkVV>R>4q?sw-o}T@5?|yS<#fRNB)AM)M%s=w~K=qq>Yp#0b9o4XXeKT2V zlFv3pQ>)KsZ`a65+x>Z=-dc0>|4)DW`Ih@d;wS&h-czuk(L^ENG6AV2W~+8&$v?XC*J9H5 zk5T#p-%VdFm)>Kp?)56(A;R)^?w1q)$_}SLteC6)*p-Wwd9@<1WM|#w$Xj#c9bMf0 ztv9%puKQp4^4R+DqVUGZ1lO7Im-p|nR6jG5iRa5L%U59rvm8!8eHrLJaZ;(vIiI(V zn}59X%X;>B;~e=JY)lSbE3ccp^jzOq!)j#dsIo9PMD@&8F5Q!UIoBjPq9TlVixX9a z8nVAPRw^)FN!=P0WvWw;o*Msx9_uz12h~{oYiH-L%zgvT<2IhO}Iryxn!q~hS~FVH&;eae(9pY zA;QQbcmMQT|2NsS8y6q-FjBtpdfLnHC$^YLcBYk2_Tb(W+3VwY;dY+kqY`tU{`h$- zLa&M}kc^Rw-*nda$E$_MbJE&@xT9>{;)Z=X`^SaPh>!dsqM^;C6hiLeR1S! zyjO#;hn9n_9CzFo|5Ca7mzmOP$~s3)k|gI&El?^i&$BeF&aQcS@Q?h#uTM{Ijas^c zwWWbcq3m3WeQDmar1J9P7c*YmI~G--C^loy76DE__e-50*d{QUZMS58(qI#Cmvcg6 z*a7wuhO48Lf?ousrjVMV;EJ?LWE=mPb3`Pcq z2D%1Dx`qZJ28LFK7FGs8t{IRlotD9iq9HdwB{QuOsKLNQ*T7iU&@{x*)XLDz%E$mdKI;Vst07Ov8asU7T literal 0 HcmV?d00001 -- 2.39.2