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 <AppElements_Constants.h>
12 #include <ModuleBase_WidgetMultiSelector.h>
15 #include <QVBoxLayout>
17 #include <QPushButton>
19 #include <QVBoxLayout>
22 #include <QLayoutItem>
28 XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
29 : ModuleBase_IPropertyPanel(theParent),
32 this->setWindowTitle(tr("Property Panel"));
33 QAction* aViewAct = this->toggleViewAction();
34 this->setObjectName(PROP_PANEL);
35 setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
37 QWidget* aContent = new QWidget(this);
38 myMainLayout = new QVBoxLayout(aContent);
39 myMainLayout->setContentsMargins(3, 3, 3, 3);
40 this->setWidget(aContent);
42 QFrame* aFrm = new QFrame(aContent);
43 aFrm->setFrameStyle(QFrame::Sunken);
44 aFrm->setFrameShape(QFrame::Panel);
45 QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
46 aBtnLay->setContentsMargins(0, 0, 0, 0);
47 myMainLayout->addWidget(aFrm);
49 QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
51 aBtnLay->addWidget(aBtn);
52 aBtnLay->addStretch(1);
53 aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
54 aBtn->setObjectName(PROP_PANEL_OK);
55 aBtn->setToolTip(tr("Ok"));
57 aBtnLay->addWidget(aBtn);
59 aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
60 aBtn->setToolTip(tr("Cancel"));
61 aBtn->setObjectName(PROP_PANEL_CANCEL);
63 aBtn->setShortcut(QKeySequence(Qt::Key_Escape));
64 aBtnLay->addWidget(aBtn);
66 myCustomWidget = new QWidget(aContent);
67 myMainLayout->addWidget(myCustomWidget);
68 setStretchEnabled(true);
71 XGUI_PropertyPanel::~XGUI_PropertyPanel()
75 void XGUI_PropertyPanel::cleanContent()
78 myActiveWidget->deactivate();
80 qDeleteAll(myCustomWidget->children());
81 myActiveWidget = NULL;
82 setWindowTitle(tr("Property Panel"));
85 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
87 myWidgets = theWidgets;
88 if (theWidgets.empty()) return;
89 bool isEnableStretch = true;
90 QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast =
92 for (; anIt != aLast; 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_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
101 // connect(aPointWidget, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
102 // SIGNAL(storedPoint2D(ObjectPtr, const std::string&)))
105 if (!isEnableStretch) continue;
106 foreach(QWidget* eachWidget, (*anIt)->getControls()) {
107 QSizePolicy::Policy aVPolicy = eachWidget->sizePolicy().verticalPolicy();
108 if(aVPolicy == QSizePolicy::Expanding ||
109 aVPolicy == QSizePolicy::MinimumExpanding) {
110 isEnableStretch = false;
114 setStretchEnabled(isEnableStretch);
115 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
117 QList<QWidget*> aControls = aLastWidget->getControls();
118 if (!aControls.empty()) {
119 QWidget* aLastControl = aControls.last();
121 QPushButton* anOkBtn = findChild<QPushButton*>(PROP_PANEL_OK);
122 QPushButton* aCancelBtn = findChild<QPushButton*>(PROP_PANEL_CANCEL);
124 setTabOrder(aLastControl, anOkBtn);
125 setTabOrder(anOkBtn, aCancelBtn);
130 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
135 QWidget* XGUI_PropertyPanel::contentWidget()
137 return myCustomWidget;
140 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
142 // Invalid feature case on abort of the operation
143 if (theFeature.get() == NULL)
145 if (theFeature->isAction() || !theFeature->data())
147 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets)
149 eachWidget->setFeature(theFeature);
150 eachWidget->restoreValue();
152 // the repaint is used here to immediately react in GUI to the values change.
156 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
158 // TO CHECK: Editing operation does not have automatical activation of widgets
159 if (isEditingMode()) {
160 activateWidget(NULL);
163 ModuleBase_ModelWidget* aNextWidget = 0;
164 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
165 bool isFoundWidget = false;
166 for (; anIt != aLast && !aNextWidget; anIt++) {
167 if (isFoundWidget || !theWidget) {
168 if ((*anIt)->focusTo()) {
172 isFoundWidget = (*anIt) == theWidget;
174 // Normaly focusTo is enough to activate widget
175 // here is a special case on mouse click in the viewer
176 //if(aNextWidget == NULL) {
177 activateWidget(aNextWidget);
181 void XGUI_PropertyPanel::setStretchEnabled(bool isEnabled)
183 if (myMainLayout->count() == 0)
185 int aStretchIdx = myMainLayout->count() - 1;
186 bool hasStretch = myMainLayout->itemAt(aStretchIdx)->spacerItem() != NULL;
189 if (!hasStretch) myMainLayout->addStretch(1);
190 } else if (hasStretch) {
191 aChild = myMainLayout->takeAt(aStretchIdx);
196 void XGUI_PropertyPanel::activateNextWidget()
198 activateNextWidget(myActiveWidget);
201 void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
203 QPushButton* anOkBtn = findChild<QPushButton*>(PROP_PANEL_OK);
204 anOkBtn->setEnabled(isEnabled);
207 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
209 // Avoid activation of already actve widget. It could happen on focusIn event many times
210 if (theWidget == myActiveWidget)
213 myActiveWidget->deactivate();
214 myActiveWidget->setHighlighted(false);
218 emit beforeWidgetActivated(theWidget);
219 theWidget->activate();
220 theWidget->setHighlighted(true);
222 myActiveWidget = theWidget;
224 emit widgetActivated(theWidget);
225 else if (!isEditingMode())
226 emit noMoreWidgets();
229 void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)
231 QPushButton* anCancelBtn = findChild<QPushButton*>(PROP_PANEL_CANCEL);
232 anCancelBtn->setEnabled(theEnabled);
235 bool XGUI_PropertyPanel::isCancelEnabled() const
237 QPushButton* anCancelBtn = findChild<QPushButton*>(PROP_PANEL_CANCEL);
238 return anCancelBtn->isEnabled();
241 void XGUI_PropertyPanel::setEditingMode(bool isEditing)
243 ModuleBase_IPropertyPanel::setEditingMode(isEditing);
244 foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
245 aWgt->setEditingMode(isEditing);