+ QVBoxLayout* aLayout = new QVBoxLayout(this);
+ ModuleBase_Tools::zeroMargins(aLayout);
+ aLayout->setSpacing(0);
+
+ 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);
+ ModuleBase_Tools::zeroMargins(aLabelLay);
+ aLabelLay->setSpacing(0);
+
+ QLabel* aLbl = new QLabel(aLabelWgt);
+ aLbl->setPixmap(QPixmap(":pictures/assembly.png"));
+ aLbl->setMargin(2);
+
+ aLbl->setAutoFillBackground(true);
+
+ aLabelLay->addWidget(aLbl);
+
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aDoc = aMgr->moduleDocument();
+ // TODO: Find a name of the root document
+
+ myActiveDocLbl = new QLineEdit(tr("Part set"), aLabelWgt);
+ myActiveDocLbl->setReadOnly(true);
+ myActiveDocLbl->setFrame(false);
+ //myActiveDocLbl->setMargin(2);
+ myActiveDocLbl->setContextMenuPolicy(Qt::CustomContextMenu);
+
+ myActiveDocLbl->installEventFilter(this);
+
+ aLabelLay->addWidget(myActiveDocLbl);
+ aLabelLay->setStretch(1, 1);
+
+ myTreeView = new XGUI_DataTree(this);
+ aLayout->addWidget(myTreeView);
+
+ aLabelWgt->setFrameShape(myTreeView->frameShape());
+ aLabelWgt->setFrameShadow(myTreeView->frameShadow());
+
+#ifndef ModuleDataModel
+ myDocModel = new XGUI_DataModel(this);
+ myTreeView->setModel(myDocModel);
+ QItemSelectionModel* aSelMod = myTreeView->selectionModel();
+ connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
+ this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
+#endif
+
+ connect(myActiveDocLbl, SIGNAL(customContextMenuRequested(const QPoint&)), this,
+ SLOT(onLabelContextMenuRequested(const QPoint&)));
+ connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
+ SLOT(onContextMenuRequested(QContextMenuEvent*)));
+}
+
+//***************************************************
+XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser()
+{
+}
+
+//***************************************************
+bool XGUI_ObjectsBrowser::eventFilter(QObject* obj, QEvent* theEvent)
+{
+ if (obj == myActiveDocLbl) {
+ if (!myActiveDocLbl->isReadOnly()) {
+ // End of editing by mouse click
+ if (theEvent->type() == QEvent::MouseButtonRelease) {
+ QMouseEvent* aEvent = (QMouseEvent*) theEvent;
+ QPoint aPnt = mapFromGlobal(aEvent->globalPos());
+ if (childAt(aPnt) != myActiveDocLbl) {
+ closeDocNameEditing(true);
+ }
+ } else if (theEvent->type() == QEvent::KeyRelease) {
+ QKeyEvent* aEvent = (QKeyEvent*) theEvent;
+ switch (aEvent->key()) {
+ case Qt::Key_Return:
+ case Qt::Key_Enter: // Accept current input
+ closeDocNameEditing(true);
+ break;
+ case Qt::Key_Escape: // Cancel the input
+ closeDocNameEditing(false);
+ break;
+ }
+ }
+ } else {
+ if (theEvent->type() == QEvent::MouseButtonDblClick) {
+ emit headerMouseDblClicked(QModelIndex());
+ return true;
+ }
+ }
+ }
+ return QWidget::eventFilter(obj, theEvent);
+}
+
+//***************************************************
+void XGUI_ObjectsBrowser::closeDocNameEditing(bool toSave)
+{
+ myActiveDocLbl->deselect();
+ myActiveDocLbl->clearFocus();
+ myActiveDocLbl->releaseMouse();
+ myActiveDocLbl->setReadOnly(true);
+ if (toSave) {
+ // TODO: Save the name of root document
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aDoc = aMgr->moduleDocument();
+ } else {
+ myActiveDocLbl->setText(myActiveDocLbl->property("OldText").toString());
+ }
+}
+
+//***************************************************
+void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent)
+{
+ QModelIndexList aIndexes;
+ QObjectPtrList aSelectedData = selectedObjects(&aIndexes);
+ bool toEnable = false;
+ if (aSelectedData.size() == 1) {
+ Qt::ItemFlags aFlags = dataModel()->flags(aIndexes.first());
+ toEnable = ((aFlags & Qt::ItemIsEditable) != 0);
+ }
+ foreach(QAction* aCmd, actions()) {
+ aCmd->setEnabled(toEnable);
+ }