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 <AppElements_Constants.h>
13 #include <ModuleBase_WidgetMultiSelector.h>
14 #include <ModuleBase_Tools.h>
15 #include <ModuleBase_PageBase.h>
16 #include <ModuleBase_PageWidget.h>
22 #include <QLayoutItem>
23 #include <QToolButton>
24 #include <QVBoxLayout>
25 #include <QGridLayout>
27 #include <QToolButton>
34 XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
35 : ModuleBase_IPropertyPanel(theParent),
37 myPreselectionWidget(NULL),
40 this->setWindowTitle(tr("Property Panel"));
41 QAction* aViewAct = this->toggleViewAction();
42 this->setObjectName(PROP_PANEL);
43 setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
45 QWidget* aContent = new QWidget(this);
46 QGridLayout* aMainLayout = new QGridLayout(aContent);
47 const int kPanelColumn = 0;
49 aMainLayout->setContentsMargins(3, 3, 3, 3);
50 this->setWidget(aContent);
52 QFrame* aFrm = new QFrame(aContent);
53 aFrm->setFrameStyle(QFrame::Raised);
54 aFrm->setFrameShape(QFrame::Panel);
55 QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
56 ModuleBase_Tools::zeroMargins(aBtnLay);
57 aMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn);
59 myHeaderWidget = aFrm;
61 QStringList aBtnNames;
62 aBtnNames << QString(PROP_PANEL_HELP)
63 << QString(PROP_PANEL_OK)
64 << QString(PROP_PANEL_CANCEL);
65 foreach(QString eachBtnName, aBtnNames) {
66 QToolButton* aBtn = new QToolButton(aFrm);
67 aBtn->setObjectName(eachBtnName);
68 aBtn->setAutoRaise(true);
69 aBtnLay->addWidget(aBtn);
71 aBtnLay->insertStretch(1, 1);
73 myPanelPage = new ModuleBase_PageWidget(aContent);
74 myPanelPage->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
75 aMainLayout->addWidget(myPanelPage, aPanelRow, kPanelColumn);
78 XGUI_PropertyPanel::~XGUI_PropertyPanel()
82 void XGUI_PropertyPanel::cleanContent()
85 myActiveWidget->deactivate();
87 /// as the widgets are deleted later, it is important that the signals
88 /// of these widgets are not processed. An example of the error is issue 986.
89 /// In the given case, the property panel is firstly filled by new widgets
90 /// of restarted operation and after that the mouse release signal come from
91 /// the widget of the previous operation (Point2d widget about mouse is released
92 /// and focus is out of this widget)
93 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(),
94 aLast = myWidgets.end();
95 for (; anIt != aLast; anIt++) {
96 QWidget* aWidget = *anIt;
98 aWidget->blockSignals(true);
103 myPanelPage->clearPage();
104 myActiveWidget = NULL;
105 setWindowTitle(tr("Property Panel"));
108 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
110 myWidgets = theWidgets;
111 if (theWidgets.empty()) return;
112 foreach (ModuleBase_ModelWidget* aWidget, theWidgets) {
113 connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
114 this, SLOT(activateWidget(ModuleBase_ModelWidget*)));
115 connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
116 this, SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
117 connect(aWidget, SIGNAL(keyReleased(QKeyEvent*)),
118 this, SIGNAL(keyReleased(QKeyEvent*)));
120 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
122 QList<QWidget*> aControls = aLastWidget->getControls();
123 if (!aControls.empty()) {
124 QWidget* aLastControl = aControls.last();
126 QToolButton* anOkBtn = findChild<QToolButton*>(PROP_PANEL_OK);
127 QToolButton* aCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
129 setTabOrder(aLastControl, anOkBtn);
130 setTabOrder(anOkBtn, aCancelBtn);
135 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
140 ModuleBase_PageBase* XGUI_PropertyPanel::contentWidget()
143 return static_cast<ModuleBase_PageBase*>(myPanelPage);
146 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
148 // Invalid feature case on abort of the operation
149 if (theFeature.get() == NULL)
151 if (theFeature->isAction() || !theFeature->data())
153 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
154 if (!eachWidget->feature().get())
155 eachWidget->setFeature(theFeature);
156 eachWidget->restoreValue();
158 // the repaint is used here to immediately react in GUI to the values change.
162 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
164 // TO CHECK: Editing operation does not have automatical activation of widgets
165 if (isEditingMode()) {
166 activateWidget(NULL);
169 ModuleBase_ModelWidget* aNextWidget = 0;
170 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
171 bool isFoundWidget = false;
173 for (; anIt != aLast && !aNextWidget; anIt++) {
174 if (isFoundWidget || !theWidget) {
175 if ((*anIt)->focusTo()) {
179 isFoundWidget = (*anIt) == theWidget;
181 // Normaly focusTo is enough to activate widget
182 // here is a special case on mouse click in the viewer
183 if(aNextWidget == NULL) {
184 activateWidget(aNextWidget);
188 void XGUI_PropertyPanel::activateNextWidget()
190 activateNextWidget(myActiveWidget);
193 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
195 // Avoid activation of already actve widget. It could happen on focusIn event many times
196 if (theWidget == myActiveWidget) {
200 myActiveWidget->deactivate();
201 myActiveWidget->setHighlighted(false);
204 emit beforeWidgetActivated(theWidget);
205 theWidget->setHighlighted(true);
206 theWidget->activate();
208 myActiveWidget = theWidget;
209 if (myActiveWidget) {
210 emit widgetActivated(theWidget);
211 } else if (!isEditingMode()) {
212 emit noMoreWidgets();
216 void XGUI_PropertyPanel::setFocusOnOkButton()
218 QToolButton* anOkBtn = findChild<QToolButton*>(PROP_PANEL_OK);
222 void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)
224 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
225 anCancelBtn->setEnabled(theEnabled);
228 bool XGUI_PropertyPanel::isCancelEnabled() const
230 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
231 return anCancelBtn->isEnabled();
234 void XGUI_PropertyPanel::setEditingMode(bool isEditing)
236 ModuleBase_IPropertyPanel::setEditingMode(isEditing);
237 foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
238 aWgt->setEditingMode(isEditing);
242 void XGUI_PropertyPanel::setupActions(XGUI_ActionsMgr* theMgr)
244 QStringList aButtonNames;
245 aButtonNames << PROP_PANEL_OK << PROP_PANEL_CANCEL << PROP_PANEL_HELP;
246 QList<XGUI_ActionsMgr::OperationStateActionId> aActionIds;
247 aActionIds << XGUI_ActionsMgr::Accept << XGUI_ActionsMgr::Abort << XGUI_ActionsMgr::Help;
248 for (int i = 0; i < aButtonNames.size(); ++i) {
249 QToolButton* aBtn = findChild<QToolButton*>(aButtonNames.at(i));
250 QAction* anAct = theMgr->operationStateAction(aActionIds.at(i));
251 aBtn->setDefaultAction(anAct);
255 ModuleBase_ModelWidget* XGUI_PropertyPanel::preselectionWidget() const
257 return myPreselectionWidget;
260 void XGUI_PropertyPanel::setPreselectionWidget(ModuleBase_ModelWidget* theWidget)
262 myPreselectionWidget = theWidget;