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;
84 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
86 myWidgets = theWidgets;
87 if (theWidgets.empty()) return;
88 bool isEnableStretch = true;
89 QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast =
91 for (; anIt != aLast; anIt++) {
92 connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*)));
93 connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
94 this, SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
95 connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
96 this, SLOT(activateWidget(ModuleBase_ModelWidget*)));
98 //ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
100 // connect(aPointWidget, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
101 // SIGNAL(storedPoint2D(ObjectPtr, const std::string&)))
104 if (!isEnableStretch) continue;
105 foreach(QWidget* eachWidget, (*anIt)->getControls()) {
106 QSizePolicy::Policy aVPolicy = eachWidget->sizePolicy().verticalPolicy();
107 if(aVPolicy == QSizePolicy::Expanding ||
108 aVPolicy == QSizePolicy::MinimumExpanding) {
109 isEnableStretch = false;
113 setStretchEnabled(isEnableStretch);
114 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
116 QList<QWidget*> aControls = aLastWidget->getControls();
117 if (!aControls.empty()) {
118 QWidget* aLastControl = aControls.last();
120 QPushButton* anOkBtn = findChild<QPushButton*>(PROP_PANEL_OK);
121 QPushButton* aCancelBtn = findChild<QPushButton*>(PROP_PANEL_CANCEL);
123 setTabOrder(aLastControl, anOkBtn);
124 setTabOrder(anOkBtn, aCancelBtn);
129 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
134 QWidget* XGUI_PropertyPanel::contentWidget()
136 return myCustomWidget;
139 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
141 // Invalid feature case on abort of the operation
142 if(!theFeature->data())
144 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets)
146 eachWidget->setFeature(theFeature);
147 eachWidget->restoreValue();
149 // the repaint is used here to immediately react in GUI to the values change.
153 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
155 // TO CHECK: Editing operation does not have automatical activation of widgets
156 if (isEditingMode()) {
157 activateWidget(NULL);
160 ModuleBase_ModelWidget* aNextWidget = 0;
161 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
162 bool isFoundWidget = false;
163 for (; anIt != aLast && !aNextWidget; anIt++) {
164 if (isFoundWidget || !theWidget) {
165 if ((*anIt)->focusTo()) {
169 isFoundWidget = (*anIt) == theWidget;
171 // Normaly focusTo is enough to activate widget
172 // here is a special case on mouse click in the viewer
173 //if(aNextWidget == NULL) {
174 activateWidget(aNextWidget);
178 void XGUI_PropertyPanel::setStretchEnabled(bool isEnabled)
180 if (myMainLayout->count() == 0)
182 int aStretchIdx = myMainLayout->count() - 1;
183 bool hasStretch = myMainLayout->itemAt(aStretchIdx)->spacerItem() != NULL;
186 if (!hasStretch) myMainLayout->addStretch(1);
187 } else if (hasStretch) {
188 aChild = myMainLayout->takeAt(aStretchIdx);
193 void XGUI_PropertyPanel::activateNextWidget()
195 activateNextWidget(myActiveWidget);
198 void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
200 QPushButton* anOkBtn = findChild<QPushButton*>(PROP_PANEL_OK);
201 anOkBtn->setEnabled(isEnabled);
204 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
206 // Avoid activation of already actve widget. It could happen on focusIn event many times
207 if (theWidget == myActiveWidget)
210 myActiveWidget->deactivate();
211 myActiveWidget->setHighlighted(false);
214 theWidget->activate();
215 theWidget->setHighlighted(true);
217 myActiveWidget = theWidget;
219 emit widgetActivated(theWidget);
220 else if (!isEditingMode())
221 emit noMoreWidgets();