2 #include "XGUI_ContextMenuMgr.h"
3 #include "XGUI_Workshop.h"
4 #include "XGUI_ObjectsBrowser.h"
5 #include "XGUI_SelectionMgr.h"
8 #include <QContextMenuEvent>
11 XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent) :
12 QObject(theParent), myWorkshop(theParent)
17 XGUI_ContextMenuMgr::~XGUI_ContextMenuMgr()
21 void XGUI_ContextMenuMgr::createActions()
23 QAction* aAction = new QAction(QIcon(":pictures/edit.png"), tr("Edit..."), this);
24 addAction("EDIT_CMD", aAction);
27 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
29 if (myActions.contains(theId))
30 qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
31 theAction->setData(theId);
32 connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
33 myActions[theId] = theAction;
36 QAction* XGUI_ContextMenuMgr::action(const QString& theId) const
38 if (myActions.contains(theId))
39 return myActions[theId];
43 QStringList XGUI_ContextMenuMgr::actionIds() const
45 return myActions.keys();
48 void XGUI_ContextMenuMgr::onAction(bool isChecked)
50 QAction* aAction = static_cast<QAction*>(sender());
51 emit actionTriggered(aAction->data().toString(), isChecked);
54 void XGUI_ContextMenuMgr::updateCommandsStatus()
58 void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
61 if (sender() == myWorkshop->objectBrowser())
62 aMenu = objectBrowserMenu();
65 aMenu->exec(theEvent->globalPos());
70 QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
72 XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
73 QFeatureList aFeatures = aSelMgr->selectedFeatures();
74 if (aFeatures.size() == 1) {
75 FeaturePtr aFeature = aFeatures.first();
76 if (aFeature->getKind() != "Part") {
77 QMenu* aMenu = new QMenu();
78 aMenu->addAction(action("EDIT_CMD"));
85 void XGUI_ContextMenuMgr::connectObjectBrowser() const
87 connect(myWorkshop->objectBrowser(), SIGNAL(contextMenuRequested(QContextMenuEvent*)),
88 this, SLOT(onContextMenuRequest(QContextMenuEvent*)));