2 * XGUI_PropertyPanel.cpp
4 * Created on: Apr 29, 2014
8 #include <XGUI_PropertyPanel.h>
9 #include <XGUI_Constants.h>
10 #include <ModuleBase_WidgetPoint2D.h>
11 #include <ModuleBase_WidgetMultiSelector.h>
14 #include <QVBoxLayout>
16 #include <QPushButton>
18 #include <QVBoxLayout>
21 #include <QLayoutItem>
27 XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
28 : ModuleBase_IPropertyPanel(theParent),
31 this->setWindowTitle(tr("Property Panel"));
32 QAction* aViewAct = this->toggleViewAction();
33 this->setObjectName(XGUI::PROP_PANEL);
34 setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
36 QWidget* aContent = new QWidget(this);
37 myMainLayout = new QVBoxLayout(aContent);
38 myMainLayout->setContentsMargins(3, 3, 3, 3);
39 this->setWidget(aContent);
41 QFrame* aFrm = new QFrame(aContent);
42 aFrm->setFrameStyle(QFrame::Sunken);
43 aFrm->setFrameShape(QFrame::Panel);
44 QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
45 aBtnLay->setContentsMargins(0, 0, 0, 0);
46 myMainLayout->addWidget(aFrm);
48 QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
50 aBtnLay->addWidget(aBtn);
51 aBtnLay->addStretch(1);
52 aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
53 aBtn->setObjectName(XGUI::PROP_PANEL_OK);
54 aBtn->setToolTip(tr("Ok"));
56 aBtnLay->addWidget(aBtn);
58 aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
59 aBtn->setToolTip(tr("Cancel"));
60 aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL);
62 aBtn->setShortcut(QKeySequence(Qt::Key_Escape));
63 aBtnLay->addWidget(aBtn);
65 myCustomWidget = new QWidget(aContent);
66 myMainLayout->addWidget(myCustomWidget);
67 setStretchEnabled(true);
70 XGUI_PropertyPanel::~XGUI_PropertyPanel()
74 void XGUI_PropertyPanel::cleanContent()
77 qDeleteAll(myCustomWidget->children());
78 myActiveWidget = NULL;
81 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
83 myWidgets = theWidgets;
84 int aS = myWidgets.size();
85 if (theWidgets.empty()) return;
86 bool isEnableStretch = true;
87 QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast =
89 for (; anIt != aLast; anIt++) {
90 connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*)));
91 connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
92 this, SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
93 connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
94 this, SLOT(activateWidget(ModuleBase_ModelWidget*)));
96 ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
98 connect(aPointWidget, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)),
99 this, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)));
102 if (!isEnableStretch) continue;
103 foreach(QWidget* eachWidget, (*anIt)->getControls()) {
104 QSizePolicy::Policy aVPolicy = eachWidget->sizePolicy().verticalPolicy();
105 if(aVPolicy == QSizePolicy::Expanding ||
106 aVPolicy == QSizePolicy::MinimumExpanding) {
107 isEnableStretch = false;
111 setStretchEnabled(isEnableStretch);
112 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
114 QList<QWidget*> aControls = aLastWidget->getControls();
115 if (!aControls.empty()) {
116 QWidget* aLastControl = aControls.last();
118 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
119 QPushButton* aCancelBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
121 setTabOrder(aLastControl, anOkBtn);
122 setTabOrder(anOkBtn, aCancelBtn);
127 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
132 QWidget* XGUI_PropertyPanel::contentWidget()
134 return myCustomWidget;
137 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
139 // Invalid feature case on abort of the operation
140 if(!theFeature->data())
142 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets)
144 eachWidget->setFeature(theFeature);
145 eachWidget->restoreValue();
147 // the repaint is used here to immediately react in GUI to the values change.
151 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
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::setStretchEnabled(bool isEnabled)
173 if (myMainLayout->count() == 0)
175 int aStretchIdx = myMainLayout->count() - 1;
176 bool hasStretch = myMainLayout->itemAt(aStretchIdx)->spacerItem() != NULL;
179 if (!hasStretch) myMainLayout->addStretch(1);
180 } else if (hasStretch) {
181 aChild = myMainLayout->takeAt(aStretchIdx);
186 void XGUI_PropertyPanel::activateNextWidget()
188 activateNextWidget(myActiveWidget);
191 void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
193 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
194 anOkBtn->setEnabled(isEnabled);
197 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
199 // Avoid activation of already actve widget. It could happen on focusIn event many times
200 if (theWidget == myActiveWidget)
203 myActiveWidget->deactivate();
204 myActiveWidget->setHighlighted(false);
207 theWidget->activate();
208 theWidget->setHighlighted(true);
210 myActiveWidget = theWidget;
211 emit widgetActivated(theWidget);