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>
20 #include <QLayoutItem>
21 #include <QToolButton>
22 #include <QVBoxLayout>
23 #include <QGridLayout>
25 #include <QToolButton>
32 XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
33 : ModuleBase_IPropertyPanel(theParent),
36 this->setWindowTitle(tr("Property Panel"));
37 QAction* aViewAct = this->toggleViewAction();
38 this->setObjectName(PROP_PANEL);
39 setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
41 QWidget* aContent = new QWidget(this);
42 myMainLayout = new QGridLayout(aContent);
43 const int kPanelColumn = 0;
45 myMainLayout->setContentsMargins(3, 3, 3, 3);
46 this->setWidget(aContent);
48 QFrame* aFrm = new QFrame(aContent);
49 aFrm->setFrameStyle(QFrame::Raised);
50 aFrm->setFrameShape(QFrame::Panel);
51 QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
52 ModuleBase_Tools::zeroMargins(aBtnLay);
53 myMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn);
55 QStringList aBtnNames;
56 aBtnNames << QString(PROP_PANEL_HELP)
57 << QString(PROP_PANEL_OK)
58 << QString(PROP_PANEL_CANCEL);
59 foreach(QString eachBtnName, aBtnNames) {
60 QToolButton* aBtn = new QToolButton(aFrm);
61 aBtn->setObjectName(eachBtnName);
62 aBtn->setAutoRaise(true);
63 aBtnLay->addWidget(aBtn);
65 aBtnLay->insertStretch(1, 1);
67 myCustomWidget = new QWidget(aContent);
68 myCustomWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
69 myMainLayout->addWidget(myCustomWidget, aPanelRow, kPanelColumn);
70 setStretchEnabled(true);
73 XGUI_PropertyPanel::~XGUI_PropertyPanel()
77 void XGUI_PropertyPanel::cleanContent()
80 myActiveWidget->deactivate();
82 qDeleteAll(myCustomWidget->children());
83 myActiveWidget = NULL;
84 setWindowTitle(tr("Property Panel"));
87 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
89 myWidgets = theWidgets;
90 if (theWidgets.empty()) return;
91 QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin();
92 for (; anIt != theWidgets.end(); anIt++) {
93 connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*)));
94 connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
95 this, SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
96 connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
97 this, SLOT(activateWidget(ModuleBase_ModelWidget*)));
99 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
101 QList<QWidget*> aControls = aLastWidget->getControls();
102 if (!aControls.empty()) {
103 QWidget* aLastControl = aControls.last();
105 QToolButton* anOkBtn = findChild<QToolButton*>(PROP_PANEL_OK);
106 QToolButton* aCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
108 setTabOrder(aLastControl, anOkBtn);
109 setTabOrder(anOkBtn, aCancelBtn);
114 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
119 QWidget* XGUI_PropertyPanel::contentWidget()
121 return myCustomWidget;
124 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
126 // Invalid feature case on abort of the operation
127 if (theFeature.get() == NULL)
129 if (theFeature->isAction() || !theFeature->data())
131 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets)
133 eachWidget->setFeature(theFeature);
134 eachWidget->restoreValue();
136 // the repaint is used here to immediately react in GUI to the values change.
140 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
142 // TO CHECK: Editing operation does not have automatical activation of widgets
143 if (isEditingMode()) {
144 activateWidget(NULL);
147 ModuleBase_ModelWidget* aNextWidget = 0;
148 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
149 bool isFoundWidget = false;
150 for (; anIt != aLast && !aNextWidget; anIt++) {
151 if (isFoundWidget || !theWidget) {
152 if ((*anIt)->focusTo()) {
156 isFoundWidget = (*anIt) == theWidget;
158 // Normaly focusTo is enough to activate widget
159 // here is a special case on mouse click in the viewer
160 //if(aNextWidget == NULL) {
161 activateWidget(aNextWidget);
165 void XGUI_PropertyPanel::setStretchEnabled(bool isEnabled)
167 int aStretchIdx = myMainLayout->rowCount() - 1;
170 myMainLayout->setRowStretch(aStretchIdx, isEnabled ? 1 : 0);
173 void XGUI_PropertyPanel::activateNextWidget()
175 activateNextWidget(myActiveWidget);
178 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
180 // Avoid activation of already actve widget. It could happen on focusIn event many times
181 if (theWidget == myActiveWidget)
184 myActiveWidget->deactivate();
185 myActiveWidget->setHighlighted(false);
189 emit beforeWidgetActivated(theWidget);
190 theWidget->activate();
191 theWidget->setHighlighted(true);
193 myActiveWidget = theWidget;
195 emit widgetActivated(theWidget);
196 else if (!isEditingMode())
197 emit noMoreWidgets();
200 void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)
202 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
203 anCancelBtn->setEnabled(theEnabled);
206 bool XGUI_PropertyPanel::isCancelEnabled() const
208 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
209 return anCancelBtn->isEnabled();
212 void XGUI_PropertyPanel::setEditingMode(bool isEditing)
214 ModuleBase_IPropertyPanel::setEditingMode(isEditing);
215 foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
216 aWgt->setEditingMode(isEditing);
220 void XGUI_PropertyPanel::setupActions(XGUI_ActionsMgr* theMgr)
222 QStringList aButtonNames;
223 aButtonNames << PROP_PANEL_OK << PROP_PANEL_CANCEL << PROP_PANEL_HELP;
224 QList<XGUI_ActionsMgr::OperationStateActionId> aActionIds;
225 aActionIds << XGUI_ActionsMgr::Accept << XGUI_ActionsMgr::Abort << XGUI_ActionsMgr::Help;
226 for (int i = 0; i < aButtonNames.size(); ++i) {
227 QToolButton* aBtn = findChild<QToolButton*>(aButtonNames.at(i));
228 QAction* anAct = theMgr->operationStateAction(aActionIds.at(i));
229 aBtn->setDefaultAction(anAct);