Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[modules/shaper.git] / src / XGUI / XGUI_ObjectsBrowser.cpp
index cf0e8577d5556843d6b32295085e96cbc24c443b..dd9706048148cb229bf52fb175284b58833feb2f 100644 (file)
@@ -81,21 +81,28 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
   aLayout->setContentsMargins(0, 0, 0, 0);
   aLayout->setSpacing(0);
 
-  QWidget* aLabelWgt = new QWidget(this);
+  QFrame* aLabelWgt = new QFrame(this);
+  aLabelWgt->setAutoFillBackground(true);
+  QPalette aPalet = aLabelWgt->palette();
+  aPalet.setColor(QPalette::Window, Qt::white);
+  aLabelWgt->setPalette(aPalet);
+
   aLayout->addWidget(aLabelWgt);
   QHBoxLayout* aLabelLay = new QHBoxLayout(aLabelWgt);
-  aLabelLay->setContentsMargins(3, 3, 3, 3);
+  aLabelLay->setContentsMargins(0, 0, 0, 0);
+  aLabelLay->setSpacing(0);
 
   QLabel* aLbl = new QLabel(aLabelWgt);
   aLbl->setPixmap(QPixmap(":pictures/assembly.png"));
-  aLabelLay->addWidget(aLbl);
+  aLbl->setMargin(2);
 
-  myActiveDocLbl = new QLabel("", aLabelWgt);
-  myActiveDocLbl->setAlignment(Qt::AlignHCenter);
+  aLbl->setAutoFillBackground(true);
 
-  QFont aFnt = myActiveDocLbl->font();
-  aFnt.setBold(true);
-  myActiveDocLbl->setFont(aFnt);
+  aLabelLay->addWidget(aLbl);
+
+  myActiveDocLbl = new QLabel(tr("Part set"), aLabelWgt);
+  myActiveDocLbl->setMargin(2);
+  myActiveDocLbl->setContextMenuPolicy(Qt::CustomContextMenu);
 
   myActiveDocLbl->installEventFilter(this);
 
@@ -107,11 +114,17 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
 
   myDocModel = myTreeView->dataModel();
 
+  aLabelWgt->setFrameShape(myTreeView->frameShape());
+  aLabelWgt->setFrameShadow(myTreeView->frameShadow());
+
   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());
 }
@@ -126,13 +139,13 @@ void XGUI_ObjectsBrowser::onActivePartChanged(FeaturePtr thePart)
 {
   QPalette aPalet = myActiveDocLbl->palette();
   if (thePart) {
-    myActiveDocLbl->setText(tr("Activate Part set"));
+    //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"));
+    //myActiveDocLbl->setText(tr("Part set is active"));
     aPalet.setColor(QPalette::Foreground, QColor(0, 72, 140));
-    myActiveDocLbl->unsetCursor();
+    //myActiveDocLbl->unsetCursor();
   }
   myActiveDocLbl->setPalette(aPalet);
 }
@@ -161,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();
@@ -173,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