1 #include "XGUI_ObjectsBrowser.h"
2 #include "XGUI_DocumentDataModel.h"
4 #include <ModelAPI_Data.h>
10 #include <QMouseEvent>
14 XGUI_DataTree::XGUI_DataTree(QWidget* theParent)
15 : QTreeView(theParent)
17 setHeaderHidden(true);
18 setModel(new XGUI_DocumentDataModel(this));
20 connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
21 this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
24 XGUI_DataTree::~XGUI_DataTree()
28 XGUI_DocumentDataModel* XGUI_DataTree::dataModel() const
30 return static_cast<XGUI_DocumentDataModel*>(model());
34 void XGUI_DataTree::onSelectionChanged(const QItemSelection& theSelected,
35 const QItemSelection& theDeselected)
37 mySelectedData.clear();
38 QModelIndexList aIndexes = selectionModel()->selectedIndexes();
39 XGUI_DocumentDataModel* aModel = dataModel();
40 QModelIndexList::const_iterator aIt;
41 for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) {
42 FeaturePtr aFeature = aModel->feature(*aIt);
44 mySelectedData.append(aFeature);
46 emit selectionChanged();
49 void XGUI_DataTree::mouseDoubleClickEvent(QMouseEvent* theEvent)
51 if (theEvent->button() == Qt::LeftButton) {
52 QModelIndex aIndex = currentIndex();
53 XGUI_DocumentDataModel* aModel = dataModel();
55 if ((aModel->activePartIndex() != aIndex) && aModel->activePartIndex().isValid()) {
56 setExpanded(aModel->activePartIndex(), false);
58 bool isChanged = aModel->activatedIndex(aIndex);
59 QTreeView::mouseDoubleClickEvent(theEvent);
61 if (aModel->activePartIndex().isValid())
62 setExpanded(aIndex, true);
63 emit activePartChanged(aModel->activePart());
66 QTreeView::mouseDoubleClickEvent(theEvent);
69 void XGUI_DataTree::contextMenuEvent(QContextMenuEvent* theEvent)
71 emit contextMenuRequested(theEvent);
74 //********************************************************************
75 //********************************************************************
76 //********************************************************************
77 XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
80 QVBoxLayout* aLayout = new QVBoxLayout(this);
81 aLayout->setContentsMargins(0, 0, 0, 0);
82 aLayout->setSpacing(0);
84 QFrame* aLabelWgt = new QFrame(this);
85 aLabelWgt->setAutoFillBackground(true);
86 QPalette aPalet = aLabelWgt->palette();
87 aPalet.setColor(QPalette::Window, Qt::white);
88 aLabelWgt->setPalette(aPalet);
90 aLayout->addWidget(aLabelWgt);
91 QHBoxLayout* aLabelLay = new QHBoxLayout(aLabelWgt);
92 aLabelLay->setContentsMargins(0, 0, 0, 0);
93 aLabelLay->setSpacing(0);
95 QLabel* aLbl = new QLabel(aLabelWgt);
96 aLbl->setPixmap(QPixmap(":pictures/assembly.png"));
99 aLbl->setAutoFillBackground(true);
101 aLabelLay->addWidget(aLbl);
103 myActiveDocLbl = new QLabel(tr("Part set"), aLabelWgt);
104 myActiveDocLbl->setMargin(2);
105 myActiveDocLbl->setContextMenuPolicy(Qt::CustomContextMenu);
107 myActiveDocLbl->installEventFilter(this);
109 aLabelLay->addWidget(myActiveDocLbl);
110 aLabelLay->setStretch(1,1);
112 myTreeView = new XGUI_DataTree(this);
113 aLayout->addWidget(myTreeView);
115 myDocModel = myTreeView->dataModel();
117 aLabelWgt->setFrameShape(myTreeView->frameShape());
118 aLabelWgt->setFrameShadow(myTreeView->frameShadow());
120 connect(myTreeView, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
121 connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(onActivePartChanged(FeaturePtr)));
122 connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SIGNAL(activePartChanged(FeaturePtr)));
124 connect(myActiveDocLbl, SIGNAL(customContextMenuRequested(const QPoint&)),
125 this, SLOT(onLabelContextMenuRequested(const QPoint&)));
126 connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)),
127 this, SLOT(onContextMenuRequested(QContextMenuEvent*)));
129 onActivePartChanged(FeaturePtr());
133 XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser()
138 void XGUI_ObjectsBrowser::onActivePartChanged(FeaturePtr thePart)
140 QPalette aPalet = myActiveDocLbl->palette();
142 //myActiveDocLbl->setText(tr("Activate Part set"));
143 aPalet.setColor(QPalette::Foreground, Qt::black);
144 //myActiveDocLbl->setCursor(Qt::PointingHandCursor);
146 //myActiveDocLbl->setText(tr("Part set is active"));
147 aPalet.setColor(QPalette::Foreground, QColor(0, 72, 140));
148 //myActiveDocLbl->unsetCursor();
150 myActiveDocLbl->setPalette(aPalet);
153 bool XGUI_ObjectsBrowser::eventFilter(QObject* obj, QEvent* theEvent)
155 if (obj == myActiveDocLbl) {
156 if (theEvent->type() == QEvent::MouseButtonDblClick) {
157 if (myDocModel->activePartIndex().isValid()) {
158 myTreeView->setExpanded(myDocModel->activePartIndex(), false);
160 myDocModel->deactivatePart();
161 onActivePartChanged(FeaturePtr());
162 emit activePartChanged(FeaturePtr());
165 return QWidget::eventFilter(obj, theEvent);
168 void XGUI_ObjectsBrowser::activateCurrentPart(bool toActivate)
171 QModelIndex aIndex = myTreeView->currentIndex();
173 if ((myDocModel->activePartIndex() != aIndex) && myDocModel->activePartIndex().isValid()) {
174 myTreeView->setExpanded(myDocModel->activePartIndex(), false);
176 bool isChanged = myDocModel->activatedIndex(aIndex);
178 if (myDocModel->activePartIndex().isValid()) {
179 myTreeView->setExpanded(aIndex, true);
180 onActivePartChanged(myDocModel->feature(aIndex));
182 onActivePartChanged(FeaturePtr());
186 QModelIndex aIndex = myDocModel->activePartIndex();
187 if (aIndex.isValid()) {
188 myDocModel->activatedIndex(aIndex);
189 myTreeView->setExpanded(aIndex, false);
190 onActivePartChanged(FeaturePtr());
195 void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent)
197 myFeaturesList = myTreeView->selectedFeatures();
198 emit contextMenuRequested(theEvent);
201 void XGUI_ObjectsBrowser::onLabelContextMenuRequested(const QPoint& thePnt)
203 myFeaturesList.clear();
204 //Empty feature pointer means that selected root document
205 myFeaturesList.append(FeaturePtr());
207 QContextMenuEvent aEvent( QContextMenuEvent::Mouse, thePnt, myActiveDocLbl->mapToGlobal(thePnt) );
208 emit contextMenuRequested(&aEvent);