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->data())
145 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets)
147 eachWidget->setFeature(theFeature);
148 eachWidget->restoreValue();
150 // the repaint is used here to immediately react in GUI to the values change.
154 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
156 // TO CHECK: Editing operation does not have automatical activation of widgets
157 if (isEditingMode()) {
158 activateWidget(NULL);
161 ModuleBase_ModelWidget* aNextWidget = 0;
162 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
163 bool isFoundWidget = false;
164 for (; anIt != aLast && !aNextWidget; anIt++) {
165 if (isFoundWidget || !theWidget) {
166 if ((*anIt)->focusTo()) {
170 isFoundWidget = (*anIt) == theWidget;
172 // Normaly focusTo is enough to activate widget
173 // here is a special case on mouse click in the viewer
174 //if(aNextWidget == NULL) {
175 activateWidget(aNextWidget);
179 void XGUI_PropertyPanel::setStretchEnabled(bool isEnabled)
181 if (myMainLayout->count() == 0)
183 int aStretchIdx = myMainLayout->count() - 1;
184 bool hasStretch = myMainLayout->itemAt(aStretchIdx)->spacerItem() != NULL;
187 if (!hasStretch) myMainLayout->addStretch(1);
188 } else if (hasStretch) {
189 aChild = myMainLayout->takeAt(aStretchIdx);
194 void XGUI_PropertyPanel::activateNextWidget()
196 activateNextWidget(myActiveWidget);
199 void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
201 QPushButton* anOkBtn = findChild<QPushButton*>(PROP_PANEL_OK);
202 anOkBtn->setEnabled(true);//isEnabled);
205 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
207 // Avoid activation of already actve widget. It could happen on focusIn event many times
208 if (theWidget == myActiveWidget)
211 myActiveWidget->deactivate();
212 myActiveWidget->setHighlighted(false);
215 theWidget->activate();
216 theWidget->setHighlighted(true);
218 myActiveWidget = theWidget;
220 emit widgetActivated(theWidget);
221 else if (!isEditingMode())
222 emit noMoreWidgets();
225 void XGUI_PropertyPanel::setOkEnabled(bool theEnabled)
227 QPushButton* anOkBtn = findChild<QPushButton*>(PROP_PANEL_OK);
228 anOkBtn->setEnabled(true);//theEnabled);
231 bool XGUI_PropertyPanel::isOkEnabled() const
233 QPushButton* anOkBtn = findChild<QPushButton*>(PROP_PANEL_OK);
234 return anOkBtn->isEnabled();
237 void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)
239 QPushButton* anCancelBtn = findChild<QPushButton*>(PROP_PANEL_CANCEL);
240 anCancelBtn->setEnabled(theEnabled);
243 bool XGUI_PropertyPanel::isCancelEnabled() const
245 QPushButton* anCancelBtn = findChild<QPushButton*>(PROP_PANEL_CANCEL);
246 return anCancelBtn->isEnabled();