1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
4 * XGUI_PropertyPanel.cpp
6 * Created on: Apr 29, 2014
10 #include <XGUI_PropertyPanel.h>
11 #include <XGUI_ActionsMgr.h>
12 #include <XGUI_OperationMgr.h>
13 //#include <AppElements_Constants.h>
14 #include <ModuleBase_WidgetMultiSelector.h>
15 #include <ModuleBase_Tools.h>
16 #include <ModuleBase_PageBase.h>
17 #include <ModuleBase_PageWidget.h>
23 #include <QLayoutItem>
24 #include <QToolButton>
25 #include <QVBoxLayout>
26 #include <QGridLayout>
28 #include <QToolButton>
35 XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent, XGUI_OperationMgr* theMgr)
36 : ModuleBase_IPropertyPanel(theParent),
38 myPreselectionWidget(NULL),
40 myOperationMgr(theMgr)
42 this->setWindowTitle(tr("Property Panel"));
43 QAction* aViewAct = this->toggleViewAction();
44 this->setObjectName(PROP_PANEL);
45 setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
47 QWidget* aContent = new QWidget(this);
48 QGridLayout* aMainLayout = new QGridLayout(aContent);
49 const int kPanelColumn = 0;
51 aMainLayout->setContentsMargins(3, 3, 3, 3);
52 this->setWidget(aContent);
54 QFrame* aFrm = new QFrame(aContent);
55 aFrm->setFrameStyle(QFrame::Raised);
56 aFrm->setFrameShape(QFrame::Panel);
57 QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
58 ModuleBase_Tools::zeroMargins(aBtnLay);
59 aMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn);
61 myHeaderWidget = aFrm;
63 QStringList aBtnNames;
64 aBtnNames << QString(PROP_PANEL_HELP)
65 << QString(PROP_PANEL_OK)
66 << QString(PROP_PANEL_CANCEL);
67 foreach(QString eachBtnName, aBtnNames) {
68 QToolButton* aBtn = new QToolButton(aFrm);
69 aBtn->setObjectName(eachBtnName);
70 aBtn->setAutoRaise(true);
71 aBtnLay->addWidget(aBtn);
73 aBtnLay->insertStretch(1, 1);
75 myPanelPage = new ModuleBase_PageWidget(aContent);
76 myPanelPage->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
77 aMainLayout->addWidget(myPanelPage, aPanelRow, kPanelColumn);
80 XGUI_PropertyPanel::~XGUI_PropertyPanel()
84 void XGUI_PropertyPanel::cleanContent()
87 myActiveWidget->deactivate();
89 /// as the widgets are deleted later, it is important that the signals
90 /// of these widgets are not processed. An example of the error is issue 986.
91 /// In the given case, the property panel is firstly filled by new widgets
92 /// of restarted operation and after that the mouse release signal come from
93 /// the widget of the previous operation (Point2d widget about mouse is released
94 /// and focus is out of this widget)
95 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(),
96 aLast = myWidgets.end();
97 for (; anIt != aLast; anIt++) {
98 QWidget* aWidget = *anIt;
100 aWidget->blockSignals(true);
105 myPanelPage->clearPage();
106 myActiveWidget = NULL;
107 setWindowTitle(tr("Property Panel"));
110 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
112 myWidgets = theWidgets;
113 if (theWidgets.empty()) return;
114 foreach (ModuleBase_ModelWidget* aWidget, theWidgets) {
115 connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
116 this, SLOT(activateWidget(ModuleBase_ModelWidget*)));
117 connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
118 this, SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
119 connect(aWidget, SIGNAL(keyReleased(QKeyEvent*)),
120 this, SIGNAL(keyReleased(QKeyEvent*)));
123 QWidget* aLastControl = 0;
124 QList<QWidget*> aControls;
125 for (int i = myWidgets.size()-1; i >= 0 && !aLastControl; i--) {
126 aControls = myWidgets[i]->getControls();
127 for (int j = aControls.size()-1; j >= 0 && !aLastControl; j--) {
128 if (aControls[j]->focusPolicy() != Qt::NoFocus)
129 aLastControl = aControls[j];
133 QToolButton* anOkBtn = findChild<QToolButton*>(PROP_PANEL_OK);
134 QToolButton* aCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
136 setTabOrder(aLastControl, anOkBtn);
137 setTabOrder(anOkBtn, aCancelBtn);
141 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
146 ModuleBase_PageBase* XGUI_PropertyPanel::contentWidget()
149 return static_cast<ModuleBase_PageBase*>(myPanelPage);
152 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
154 // Invalid feature case on abort of the operation
155 if (theFeature.get() == NULL)
157 if (theFeature->isAction() || !theFeature->data())
159 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
160 if (!eachWidget->feature().get())
161 eachWidget->setFeature(theFeature);
162 eachWidget->restoreValue();
164 // the repaint is used here to immediately react in GUI to the values change.
168 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
170 // TO CHECK: Editing operation does not have automatical activation of widgets
171 if (isEditingMode()) {
172 activateWidget(NULL);
175 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
176 bool isFoundWidget = false;
178 for (; anIt != aLast; anIt++) {
179 if (isFoundWidget || !theWidget) {
180 if ((*anIt)->focusTo()) {
184 isFoundWidget = isFoundWidget || (*anIt) == theWidget;
186 activateWidget(NULL);
189 void XGUI_PropertyPanel::activateNextWidget()
191 activateNextWidget(myActiveWidget);
194 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
196 // Avoid activation of already actve widget. It could happen on focusIn event many times
197 if (theWidget == myActiveWidget) {
201 myActiveWidget->deactivate();
202 myActiveWidget->setHighlighted(false);
205 emit beforeWidgetActivated(theWidget);
206 theWidget->setHighlighted(true);
207 theWidget->activate();
209 myActiveWidget = theWidget;
210 if (myActiveWidget) {
211 emit widgetActivated(theWidget);
212 } else if (!isEditingMode()) {
213 emit noMoreWidgets();
214 setFocusOnOkButton();
218 void XGUI_PropertyPanel::setFocusOnOkButton()
220 QToolButton* anOkBtn = findChild<QToolButton*>(PROP_PANEL_OK);
224 void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)
226 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
227 anCancelBtn->setEnabled(theEnabled);
230 bool XGUI_PropertyPanel::isCancelEnabled() const
232 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
233 return anCancelBtn->isEnabled();
236 void XGUI_PropertyPanel::setEditingMode(bool isEditing)
238 ModuleBase_IPropertyPanel::setEditingMode(isEditing);
239 foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
240 aWgt->setEditingMode(isEditing);
244 void XGUI_PropertyPanel::setupActions(XGUI_ActionsMgr* theMgr)
246 QStringList aButtonNames;
247 aButtonNames << PROP_PANEL_OK << PROP_PANEL_CANCEL << PROP_PANEL_HELP;
248 QList<XGUI_ActionsMgr::OperationStateActionId> aActionIds;
249 aActionIds << XGUI_ActionsMgr::Accept << XGUI_ActionsMgr::Abort << XGUI_ActionsMgr::Help;
250 for (int i = 0; i < aButtonNames.size(); ++i) {
251 QToolButton* aBtn = findChild<QToolButton*>(aButtonNames.at(i));
252 QAction* anAct = theMgr->operationStateAction(aActionIds.at(i));
253 aBtn->setDefaultAction(anAct);
257 ModuleBase_ModelWidget* XGUI_PropertyPanel::preselectionWidget() const
259 return myPreselectionWidget;
262 void XGUI_PropertyPanel::setPreselectionWidget(ModuleBase_ModelWidget* theWidget)
264 myPreselectionWidget = theWidget;
268 void XGUI_PropertyPanel::closeEvent(QCloseEvent* theEvent)
270 ModuleBase_Operation* aOp = myOperationMgr->currentOperation();
272 if (myOperationMgr->canStopOperation(aOp)) {
273 myOperationMgr->abortAllOperations();
278 ModuleBase_IPropertyPanel::closeEvent(theEvent);