]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Create pop-up on ObjectBrowser root label (issue #23)
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 19 May 2014 13:04:20 +0000 (17:04 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 19 May 2014 13:04:20 +0000 (17:04 +0400)
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_ObjectsBrowser.h

index 753027907a5a02784ae85c35dc299e37a55d3fa4..4dc852f9a4d7178e80976f36d56dfbca31bf0ef0 100644 (file)
@@ -78,23 +78,34 @@ void XGUI_ContextMenuMgr::onContextMenuRequest(QContextMenuEvent* theEvent)
 
 QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
 {
+  QMenu* aMenu = new QMenu();
   XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
   QFeatureList aFeatures = aSelMgr->selectedFeatures();
   if (aFeatures.size() == 1) {
+    PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
     FeaturePtr aFeature = aFeatures.first();
-    QMenu* aMenu = new QMenu();
-    if (aFeature->getKind() == "Part") {
-      boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
-      boost::shared_ptr<ModelAPI_Document> aFeaDoc = aFeature->data()->docRef("PartDocument")->value();
-      if (aMgr->currentDocument() == aFeaDoc)
-        aMenu->addAction(action("DEACTIVATE_PART_CMD"));
-      else 
+    //Process Feature
+    if (aFeature) {
+      if (aFeature->getKind() == "Part") {
+        boost::shared_ptr<ModelAPI_Document> aFeaDoc = aFeature->data()->docRef("PartDocument")->value();
+        if (aMgr->currentDocument() == aFeaDoc)
+          aMenu->addAction(action("DEACTIVATE_PART_CMD"));
+        else 
+          aMenu->addAction(action("ACTIVATE_PART_CMD"));
+      } else {
+        aMenu->addAction(action("EDIT_CMD"));
+      }
+
+    // Process Root object (document)
+    } else { // If feature is 0 the it means that selected root object (document)
+      if (aMgr->currentDocument() != aMgr->rootDocument()) {
         aMenu->addAction(action("ACTIVATE_PART_CMD"));
-    } else {
-      aMenu->addAction(action("EDIT_CMD"));
+      }
     }
-    return aMenu;
   }
+  if (aMenu->actions().size() > 0)
+    return aMenu;
+  delete aMenu;
   return 0;
 }
 
index 8850213f7b14fede5cfe62c3cd049d4a37d40297..dd9706048148cb229bf52fb175284b58833feb2f 100644 (file)
@@ -102,6 +102,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
 
   myActiveDocLbl = new QLabel(tr("Part set"), aLabelWgt);
   myActiveDocLbl->setMargin(2);
+  myActiveDocLbl->setContextMenuPolicy(Qt::CustomContextMenu);
 
   myActiveDocLbl->installEventFilter(this);
 
@@ -119,8 +120,11 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
   connect(myTreeView, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
   connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(onActivePartChanged(FeaturePtr)));
   connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SIGNAL(activePartChanged(FeaturePtr)));
+
+  connect(myActiveDocLbl, SIGNAL(customContextMenuRequested(const QPoint&)), 
+          this, SLOT(onLabelContextMenuRequested(const QPoint&)));
   connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), 
-          this, SIGNAL(contextMenuRequested(QContextMenuEvent*)));
+          this, SLOT(onContextMenuRequested(QContextMenuEvent*)));
   
   onActivePartChanged(FeaturePtr());
 }
@@ -137,11 +141,11 @@ void XGUI_ObjectsBrowser::onActivePartChanged(FeaturePtr thePart)
   if (thePart) {
     //myActiveDocLbl->setText(tr("Activate Part set"));
     aPalet.setColor(QPalette::Foreground, Qt::black);
-    myActiveDocLbl->setCursor(Qt::PointingHandCursor);
+    //myActiveDocLbl->setCursor(Qt::PointingHandCursor);
   }  else {
     //myActiveDocLbl->setText(tr("Part set is active"));
     aPalet.setColor(QPalette::Foreground, QColor(0, 72, 140));
-    myActiveDocLbl->unsetCursor();
+    //myActiveDocLbl->unsetCursor();
   }
   myActiveDocLbl->setPalette(aPalet);
 }
@@ -170,9 +174,13 @@ void XGUI_ObjectsBrowser::activateCurrentPart(bool toActivate)
       myTreeView->setExpanded(myDocModel->activePartIndex(), false);
     }
     bool isChanged = myDocModel->activatedIndex(aIndex);
-    if ((isChanged) && (myDocModel->activePartIndex().isValid())) {
-      myTreeView->setExpanded(aIndex, true);
-      onActivePartChanged(myDocModel->feature(aIndex));
+    if (isChanged) {
+      if (myDocModel->activePartIndex().isValid()) {
+        myTreeView->setExpanded(aIndex, true);
+        onActivePartChanged(myDocModel->feature(aIndex));
+      } else {
+        onActivePartChanged(FeaturePtr());
+      }
     }
   } else {
     QModelIndex aIndex = myDocModel->activePartIndex();
@@ -182,4 +190,20 @@ void XGUI_ObjectsBrowser::activateCurrentPart(bool toActivate)
       onActivePartChanged(FeaturePtr());
     }
   }
+}
+
+void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent) 
+{
+  myFeaturesList = myTreeView->selectedFeatures();
+  emit contextMenuRequested(theEvent);
+}
+
+void XGUI_ObjectsBrowser::onLabelContextMenuRequested(const QPoint& thePnt)
+{
+  myFeaturesList.clear();
+  //Empty feature pointer means that selected root document
+  myFeaturesList.append(FeaturePtr()); 
+
+  QContextMenuEvent aEvent( QContextMenuEvent::Mouse, thePnt, myActiveDocLbl->mapToGlobal(thePnt) );
+  emit contextMenuRequested(&aEvent);
 }
\ No newline at end of file
index 18c03d2ccb7d3cd241c57738b876d84655d55f52..c1907e34d19c9a33a98dc76571e08fa1c8d9e41d 100644 (file)
@@ -61,7 +61,7 @@ public:
   XGUI_DocumentDataModel* dataModel() const { return myDocModel; }
 
   //! Returns list of currently selected features
-  QFeatureList selectedFeatures() const { return myTreeView->selectedFeatures(); }
+  QFeatureList selectedFeatures() const { return myFeaturesList; }
 
   //! Returns currently selected indexes
   QModelIndexList selectedIndexes() const { return myTreeView->selectionModel()->selectedIndexes(); }
@@ -87,6 +87,8 @@ protected:
 
 private slots:
   void onActivePartChanged(FeaturePtr thePart);
+  void onContextMenuRequested(QContextMenuEvent* theEvent);
+  void onLabelContextMenuRequested(const QPoint& thePnt);
 
 private:
   //! Internal model
@@ -94,6 +96,8 @@ private:
 
   QLabel* myActiveDocLbl;
   XGUI_DataTree* myTreeView;
+
+  QFeatureList myFeaturesList;
 };
 
 #endif
\ No newline at end of file