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),
39 this->setWindowTitle(tr("Property Panel"));
40 QAction* aViewAct = this->toggleViewAction();
41 this->setObjectName(PROP_PANEL);
42 setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
44 QWidget* aContent = new QWidget(this);
45 QGridLayout* aMainLayout = new QGridLayout(aContent);
46 const int kPanelColumn = 0;
48 aMainLayout->setContentsMargins(3, 3, 3, 3);
49 this->setWidget(aContent);
51 QFrame* aFrm = new QFrame(aContent);
52 aFrm->setFrameStyle(QFrame::Raised);
53 aFrm->setFrameShape(QFrame::Panel);
54 QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
55 ModuleBase_Tools::zeroMargins(aBtnLay);
56 aMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn);
58 QStringList aBtnNames;
59 aBtnNames << QString(PROP_PANEL_HELP)
60 << QString(PROP_PANEL_OK)
61 << QString(PROP_PANEL_CANCEL);
62 foreach(QString eachBtnName, aBtnNames) {
63 QToolButton* aBtn = new QToolButton(aFrm);
64 aBtn->setObjectName(eachBtnName);
65 aBtn->setAutoRaise(true);
66 aBtnLay->addWidget(aBtn);
68 aBtnLay->insertStretch(1, 1);
70 myPanelPage = new ModuleBase_PageWidget(aContent);
71 myPanelPage->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
72 aMainLayout->addWidget(myPanelPage, aPanelRow, kPanelColumn);
75 XGUI_PropertyPanel::~XGUI_PropertyPanel()
79 void XGUI_PropertyPanel::cleanContent()
82 myActiveWidget->deactivate();
84 myPanelPage->clearPage();
85 myActiveWidget = NULL;
86 setWindowTitle(tr("Property Panel"));
89 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
91 myWidgets = theWidgets;
92 if (theWidgets.empty()) return;
93 foreach (ModuleBase_ModelWidget* aWidget, theWidgets) {
94 connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
95 this, SLOT(activateWidget(ModuleBase_ModelWidget*)));
96 connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
97 this, SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
98 connect(aWidget, SIGNAL(keyReleased(QKeyEvent*)),
99 this, SIGNAL(keyReleased(QKeyEvent*)));
101 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
103 QList<QWidget*> aControls = aLastWidget->getControls();
104 if (!aControls.empty()) {
105 QWidget* aLastControl = aControls.last();
107 QToolButton* anOkBtn = findChild<QToolButton*>(PROP_PANEL_OK);
108 QToolButton* aCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
110 setTabOrder(aLastControl, anOkBtn);
111 setTabOrder(anOkBtn, aCancelBtn);
116 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
121 ModuleBase_PageBase* XGUI_PropertyPanel::contentWidget()
124 return static_cast<ModuleBase_PageBase*>(myPanelPage);
127 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
129 // Invalid feature case on abort of the operation
130 if (theFeature.get() == NULL)
132 if (theFeature->isAction() || !theFeature->data())
134 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
135 if (!eachWidget->feature().get())
136 eachWidget->setFeature(theFeature);
137 eachWidget->restoreValue();
139 // the repaint is used here to immediately react in GUI to the values change.
143 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
145 // TO CHECK: Editing operation does not have automatical activation of widgets
146 if (isEditingMode()) {
147 activateWidget(NULL);
150 ModuleBase_ModelWidget* aNextWidget = 0;
151 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
152 bool isFoundWidget = false;
153 for (; anIt != aLast && !aNextWidget; anIt++) {
154 if (isFoundWidget || !theWidget) {
155 if ((*anIt)->focusTo()) {
159 isFoundWidget = (*anIt) == theWidget;
161 // Normaly focusTo is enough to activate widget
162 // here is a special case on mouse click in the viewer
163 if(aNextWidget == NULL) {
164 activateWidget(aNextWidget);
168 void XGUI_PropertyPanel::activateNextWidget()
170 activateNextWidget(myActiveWidget);
173 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
175 // Avoid activation of already actve widget. It could happen on focusIn event many times
176 if (theWidget == myActiveWidget) {
180 myActiveWidget->deactivate();
181 myActiveWidget->setHighlighted(false);
184 emit beforeWidgetActivated(theWidget);
185 theWidget->setHighlighted(true);
186 theWidget->activate();
188 myActiveWidget = theWidget;
189 if (myActiveWidget) {
190 emit widgetActivated(theWidget);
191 } else if (!isEditingMode()) {
192 emit noMoreWidgets();
196 void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)
198 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
199 anCancelBtn->setEnabled(theEnabled);
202 bool XGUI_PropertyPanel::isCancelEnabled() const
204 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
205 return anCancelBtn->isEnabled();
208 void XGUI_PropertyPanel::setEditingMode(bool isEditing)
210 ModuleBase_IPropertyPanel::setEditingMode(isEditing);
211 foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
212 aWgt->setEditingMode(isEditing);
216 void XGUI_PropertyPanel::setupActions(XGUI_ActionsMgr* theMgr)
218 QStringList aButtonNames;
219 aButtonNames << PROP_PANEL_OK << PROP_PANEL_CANCEL << PROP_PANEL_HELP;
220 QList<XGUI_ActionsMgr::OperationStateActionId> aActionIds;
221 aActionIds << XGUI_ActionsMgr::Accept << XGUI_ActionsMgr::Abort << XGUI_ActionsMgr::Help;
222 for (int i = 0; i < aButtonNames.size(); ++i) {
223 QToolButton* aBtn = findChild<QToolButton*>(aButtonNames.at(i));
224 QAction* anAct = theMgr->operationStateAction(aActionIds.at(i));
225 aBtn->setDefaultAction(anAct);