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);
106 myActiveDocLbl->installEventFilter(this);
108 aLabelLay->addWidget(myActiveDocLbl);
109 aLabelLay->setStretch(1,1);
111 myTreeView = new XGUI_DataTree(this);
112 aLayout->addWidget(myTreeView);
114 myDocModel = myTreeView->dataModel();
116 aLabelWgt->setFrameShape(myTreeView->frameShape());
117 aLabelWgt->setFrameShadow(myTreeView->frameShadow());
119 connect(myTreeView, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
120 connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(onActivePartChanged(FeaturePtr)));
121 connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SIGNAL(activePartChanged(FeaturePtr)));
122 connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)),
123 this, SIGNAL(contextMenuRequested(QContextMenuEvent*)));
125 onActivePartChanged(FeaturePtr());
129 XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser()
134 void XGUI_ObjectsBrowser::onActivePartChanged(FeaturePtr thePart)
136 QPalette aPalet = myActiveDocLbl->palette();
138 //myActiveDocLbl->setText(tr("Activate Part set"));
139 aPalet.setColor(QPalette::Foreground, Qt::black);
140 myActiveDocLbl->setCursor(Qt::PointingHandCursor);
142 //myActiveDocLbl->setText(tr("Part set is active"));
143 aPalet.setColor(QPalette::Foreground, QColor(0, 72, 140));
144 myActiveDocLbl->unsetCursor();
146 myActiveDocLbl->setPalette(aPalet);
149 bool XGUI_ObjectsBrowser::eventFilter(QObject* obj, QEvent* theEvent)
151 if (obj == myActiveDocLbl) {
152 if (theEvent->type() == QEvent::MouseButtonDblClick) {
153 if (myDocModel->activePartIndex().isValid()) {
154 myTreeView->setExpanded(myDocModel->activePartIndex(), false);
156 myDocModel->deactivatePart();
157 onActivePartChanged(FeaturePtr());
158 emit activePartChanged(FeaturePtr());
161 return QWidget::eventFilter(obj, theEvent);
164 void XGUI_ObjectsBrowser::activateCurrentPart(bool toActivate)
167 QModelIndex aIndex = myTreeView->currentIndex();
169 if ((myDocModel->activePartIndex() != aIndex) && myDocModel->activePartIndex().isValid()) {
170 myTreeView->setExpanded(myDocModel->activePartIndex(), false);
172 bool isChanged = myDocModel->activatedIndex(aIndex);
173 if ((isChanged) && (myDocModel->activePartIndex().isValid())) {
174 myTreeView->setExpanded(aIndex, true);
175 onActivePartChanged(myDocModel->feature(aIndex));
178 QModelIndex aIndex = myDocModel->activePartIndex();
179 if (aIndex.isValid()) {
180 myDocModel->activatedIndex(aIndex);
181 myTreeView->setExpanded(aIndex, false);
182 onActivePartChanged(FeaturePtr());