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*)));
122 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
124 QList<QWidget*> aControls = aLastWidget->getControls();
125 if (!aControls.empty()) {
126 QWidget* aLastControl = aControls.last();
128 QToolButton* anOkBtn = findChild<QToolButton*>(PROP_PANEL_OK);
129 QToolButton* aCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
131 setTabOrder(aLastControl, anOkBtn);
132 setTabOrder(anOkBtn, aCancelBtn);
137 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
142 ModuleBase_PageBase* XGUI_PropertyPanel::contentWidget()
145 return static_cast<ModuleBase_PageBase*>(myPanelPage);
148 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
150 // Invalid feature case on abort of the operation
151 if (theFeature.get() == NULL)
153 if (theFeature->isAction() || !theFeature->data())
155 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
156 if (!eachWidget->feature().get())
157 eachWidget->setFeature(theFeature);
158 eachWidget->restoreValue();
160 // the repaint is used here to immediately react in GUI to the values change.
164 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
166 // TO CHECK: Editing operation does not have automatical activation of widgets
167 if (isEditingMode()) {
168 activateWidget(NULL);
171 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
172 bool isFoundWidget = false;
174 for (; anIt != aLast; anIt++) {
175 if (isFoundWidget || !theWidget) {
176 if ((*anIt)->focusTo()) {
180 isFoundWidget = isFoundWidget || (*anIt) == theWidget;
182 activateWidget(NULL);
185 void XGUI_PropertyPanel::activateNextWidget()
187 activateNextWidget(myActiveWidget);
190 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
192 // Avoid activation of already actve widget. It could happen on focusIn event many times
193 if (theWidget == myActiveWidget) {
197 myActiveWidget->deactivate();
198 myActiveWidget->setHighlighted(false);
201 emit beforeWidgetActivated(theWidget);
202 theWidget->setHighlighted(true);
203 theWidget->activate();
205 myActiveWidget = theWidget;
206 if (myActiveWidget) {
207 emit widgetActivated(theWidget);
208 } else if (!isEditingMode()) {
209 emit noMoreWidgets();
210 setFocusOnOkButton();
214 void XGUI_PropertyPanel::setFocusOnOkButton()
216 QToolButton* anOkBtn = findChild<QToolButton*>(PROP_PANEL_OK);
220 void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)
222 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
223 anCancelBtn->setEnabled(theEnabled);
226 bool XGUI_PropertyPanel::isCancelEnabled() const
228 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
229 return anCancelBtn->isEnabled();
232 void XGUI_PropertyPanel::setEditingMode(bool isEditing)
234 ModuleBase_IPropertyPanel::setEditingMode(isEditing);
235 foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
236 aWgt->setEditingMode(isEditing);
240 void XGUI_PropertyPanel::setupActions(XGUI_ActionsMgr* theMgr)
242 QStringList aButtonNames;
243 aButtonNames << PROP_PANEL_OK << PROP_PANEL_CANCEL << PROP_PANEL_HELP;
244 QList<XGUI_ActionsMgr::OperationStateActionId> aActionIds;
245 aActionIds << XGUI_ActionsMgr::Accept << XGUI_ActionsMgr::Abort << XGUI_ActionsMgr::Help;
246 for (int i = 0; i < aButtonNames.size(); ++i) {
247 QToolButton* aBtn = findChild<QToolButton*>(aButtonNames.at(i));
248 QAction* anAct = theMgr->operationStateAction(aActionIds.at(i));
249 aBtn->setDefaultAction(anAct);
253 ModuleBase_ModelWidget* XGUI_PropertyPanel::preselectionWidget() const
255 return myPreselectionWidget;
258 void XGUI_PropertyPanel::setPreselectionWidget(ModuleBase_ModelWidget* theWidget)
260 myPreselectionWidget = theWidget;
264 void XGUI_PropertyPanel::closeEvent(QCloseEvent* theEvent)
266 ModuleBase_Operation* aOp = myOperationMgr->currentOperation();
268 if (myOperationMgr->canStopOperation(aOp)) {
269 myOperationMgr->abortAllOperations();
274 ModuleBase_IPropertyPanel::closeEvent(theEvent);