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 eachWidget->setFeature(theFeature);
136 eachWidget->restoreValue();
138 // the repaint is used here to immediately react in GUI to the values change.
142 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
144 // TO CHECK: Editing operation does not have automatical activation of widgets
145 if (isEditingMode()) {
146 activateWidget(NULL);
149 ModuleBase_ModelWidget* aNextWidget = 0;
150 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
151 bool isFoundWidget = false;
152 for (; anIt != aLast && !aNextWidget; anIt++) {
153 if (isFoundWidget || !theWidget) {
154 if ((*anIt)->focusTo()) {
158 isFoundWidget = (*anIt) == theWidget;
160 // Normaly focusTo is enough to activate widget
161 // here is a special case on mouse click in the viewer
162 if(aNextWidget == NULL) {
163 activateWidget(aNextWidget);
167 void XGUI_PropertyPanel::activateNextWidget()
169 activateNextWidget(myActiveWidget);
172 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
174 // Avoid activation of already actve widget. It could happen on focusIn event many times
175 if (theWidget == myActiveWidget) {
179 myActiveWidget->deactivate();
180 myActiveWidget->setHighlighted(false);
183 emit beforeWidgetActivated(theWidget);
184 theWidget->setHighlighted(true);
185 theWidget->activate();
187 myActiveWidget = theWidget;
188 if (myActiveWidget) {
189 emit widgetActivated(theWidget);
190 } else if (!isEditingMode()) {
191 emit noMoreWidgets();
195 void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)
197 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
198 anCancelBtn->setEnabled(theEnabled);
201 bool XGUI_PropertyPanel::isCancelEnabled() const
203 QToolButton* anCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
204 return anCancelBtn->isEnabled();
207 void XGUI_PropertyPanel::setEditingMode(bool isEditing)
209 ModuleBase_IPropertyPanel::setEditingMode(isEditing);
210 foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
211 aWgt->setEditingMode(isEditing);
215 void XGUI_PropertyPanel::setupActions(XGUI_ActionsMgr* theMgr)
217 QStringList aButtonNames;
218 aButtonNames << PROP_PANEL_OK << PROP_PANEL_CANCEL << PROP_PANEL_HELP;
219 QList<XGUI_ActionsMgr::OperationStateActionId> aActionIds;
220 aActionIds << XGUI_ActionsMgr::Accept << XGUI_ActionsMgr::Abort << XGUI_ActionsMgr::Help;
221 for (int i = 0; i < aButtonNames.size(); ++i) {
222 QToolButton* aBtn = findChild<QToolButton*>(aButtonNames.at(i));
223 QAction* anAct = theMgr->operationStateAction(aActionIds.at(i));
224 aBtn->setDefaultAction(anAct);