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>
13 #include <QVBoxLayout>
15 #include <QPushButton>
17 #include <QVBoxLayout>
25 XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
26 : ModuleBase_IPropertyPanel(theParent), myActiveWidget(0)
28 this->setWindowTitle(tr("Property Panel"));
29 QAction* aViewAct = this->toggleViewAction();
30 this->setObjectName(XGUI::PROP_PANEL);
31 setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
33 QWidget* aContent = new QWidget(this);
34 myMainLayout = new QVBoxLayout(aContent);
35 myMainLayout->setContentsMargins(3, 3, 3, 3);
36 this->setWidget(aContent);
38 QFrame* aFrm = new QFrame(aContent);
39 aFrm->setFrameStyle(QFrame::Sunken);
40 aFrm->setFrameShape(QFrame::Panel);
41 QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
42 aBtnLay->setContentsMargins(0, 0, 0, 0);
43 myMainLayout->addWidget(aFrm);
45 QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
47 aBtnLay->addWidget(aBtn);
48 aBtnLay->addStretch(1);
49 aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
50 aBtn->setObjectName(XGUI::PROP_PANEL_OK);
51 aBtn->setToolTip(tr("Ok"));
53 aBtnLay->addWidget(aBtn);
55 aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
56 aBtn->setToolTip(tr("Cancel"));
57 aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL);
59 aBtnLay->addWidget(aBtn);
61 myCustomWidget = new QWidget(aContent);
62 myMainLayout->addWidget(myCustomWidget);
63 myMainLayout->addStretch(1);
66 XGUI_PropertyPanel::~XGUI_PropertyPanel()
70 void XGUI_PropertyPanel::cleanContent()
73 qDeleteAll(myCustomWidget->children());
76 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
78 myWidgets = theWidgets;
79 int aS = myWidgets.size();
80 if (theWidgets.empty()) return;
82 QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast =
84 for (; anIt != aLast; anIt++) {
85 connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*)));
87 connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), this,
88 SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
89 connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
90 this, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)));
92 ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
94 connect(aPointWidget, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
95 SIGNAL(storedPoint2D(ObjectPtr, const std::string&)));
97 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
99 QList<QWidget*> aControls = aLastWidget->getControls();
100 if (!aControls.empty()) {
101 QWidget* aLastControl = aControls.last();
103 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
104 QPushButton* aCancelBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
106 setTabOrder(aLastControl, anOkBtn);
107 setTabOrder(anOkBtn, aCancelBtn);
112 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
117 QWidget* XGUI_PropertyPanel::contentWidget()
119 return myCustomWidget;
122 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
124 int aS = myWidgets.size();
125 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets)
127 eachWidget->setFeature(theFeature);
128 eachWidget->restoreValue();
130 // the repaint is used here to immediatelly react in GUI to the values change.
135 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
137 QObject* aSender = sender();
138 ModuleBase_ModelWidget* aNextWidget = 0;
139 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
140 bool isFoundWidget = false;
141 for (; anIt != aLast && !aNextWidget; anIt++) {
142 if (isFoundWidget || !theWidget) {
143 if ((*anIt)->focusTo()) {
147 isFoundWidget = (*anIt) == theWidget;
149 myActiveWidget = aNextWidget;
150 emit widgetActivated(myActiveWidget);
153 void XGUI_PropertyPanel::activateNextWidget()
155 activateNextWidget(myActiveWidget);
158 void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
160 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
161 anOkBtn->setEnabled(isEnabled);