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 myPanelPage->clearPage();
88 myActiveWidget = NULL;
89 setWindowTitle(tr("Property Panel"));
92 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
94 myWidgets = theWidgets;
95 if (theWidgets.empty()) return;
96 foreach (ModuleBase_ModelWidget* aWidget, theWidgets) {
97 connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
98 this, SLOT(activateWidget(ModuleBase_ModelWidget*)));
99 connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
100 this, SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
101 connect(aWidget, SIGNAL(keyReleased(QKeyEvent*)),
102 this, SIGNAL(keyReleased(QKeyEvent*)));
104 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
106 QList<QWidget*> aControls = aLastWidget->getControls();
107 if (!aControls.empty()) {
108 QWidget* aLastControl = aControls.last();
110 QToolButton* anOkBtn = findChild<QToolButton*>(PROP_PANEL_OK);
111 QToolButton* aCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
113 setTabOrder(aLastControl, anOkBtn);
114 setTabOrder(anOkBtn, aCancelBtn);
119 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
124 ModuleBase_PageBase* XGUI_PropertyPanel::contentWidget()
127 return static_cast<ModuleBase_PageBase*>(myPanelPage);
130 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
132 // Invalid feature case on abort of the operation
133 if (theFeature.get() == NULL)
135 if (theFeature->isAction() || !theFeature->data())
137 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
138 if (!eachWidget->feature().get())
139 eachWidget->setFeature(theFeature);
140 eachWidget->restoreValue();
142 // the repaint is used here to immediately react in GUI to the values change.
146 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
148 // TO CHECK: Editing operation does not have automatical activation of widgets
149 if (isEditingMode()) {
150 activateWidget(NULL);
153 ModuleBase_ModelWidget* aNextWidget = 0;
154 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
155 bool isFoundWidget = false;
156 for (; anIt != aLast && !aNextWidget; anIt++) {
157 if (isFoundWidget || !theWidget) {
158 if ((*anIt)->focusTo()) {
162 isFoundWidget = (*anIt) == theWidget;
164 // Normaly focusTo is enough to activate widget
165 // here is a special case on mouse click in the viewer
166 if(aNextWidget == NULL) {
167 activateWidget(aNextWidget);
171 void XGUI_PropertyPanel::activateNextWidget()
173 activateNextWidget(myActiveWidget);
176 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
178 // Avoid activation of already actve widget. It could happen on focusIn event many times
179 if (theWidget == myActiveWidget) {
183 myActiveWidget->deactivate();
184 myActiveWidget->setHighlighted(false);
187 emit beforeWidgetActivated(theWidget);
188 theWidget->setHighlighted(true);
189 theWidget->activate();
191 myActiveWidget = theWidget;
192 if (myActiveWidget) {
193 emit widgetActivated(theWidget);
194 } else if (!isEditingMode()) {
195 emit noMoreWidgets();
199 void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)
201 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
202 anCancelBtn->setEnabled(theEnabled);
205 bool XGUI_PropertyPanel::isCancelEnabled() const
207 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
208 return anCancelBtn->isEnabled();
211 void XGUI_PropertyPanel::setEditingMode(bool isEditing)
213 ModuleBase_IPropertyPanel::setEditingMode(isEditing);
214 foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
215 aWgt->setEditingMode(isEditing);
219 void XGUI_PropertyPanel::setupActions(XGUI_ActionsMgr* theMgr)
221 QStringList aButtonNames;
222 aButtonNames << PROP_PANEL_OK << PROP_PANEL_CANCEL << PROP_PANEL_HELP;
223 QList<XGUI_ActionsMgr::OperationStateActionId> aActionIds;
224 aActionIds << XGUI_ActionsMgr::Accept << XGUI_ActionsMgr::Abort << XGUI_ActionsMgr::Help;
225 for (int i = 0; i < aButtonNames.size(); ++i) {
226 QToolButton* aBtn = findChild<QToolButton*>(aButtonNames.at(i));
227 QAction* anAct = theMgr->operationStateAction(aActionIds.at(i));
228 aBtn->setDefaultAction(anAct);
232 ModuleBase_ModelWidget* XGUI_PropertyPanel::preselectionWidget() const
234 return myPreselectionWidget;
237 void XGUI_PropertyPanel::setPreselectionWidget(ModuleBase_ModelWidget* theWidget)
239 myPreselectionWidget = theWidget;