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),
29 this->setWindowTitle(tr("Property Panel"));
30 QAction* aViewAct = this->toggleViewAction();
31 this->setObjectName(XGUI::PROP_PANEL);
32 setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
34 QWidget* aContent = new QWidget(this);
35 myMainLayout = new QVBoxLayout(aContent);
36 myMainLayout->setContentsMargins(3, 3, 3, 3);
37 this->setWidget(aContent);
39 QFrame* aFrm = new QFrame(aContent);
40 aFrm->setFrameStyle(QFrame::Sunken);
41 aFrm->setFrameShape(QFrame::Panel);
42 QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
43 aBtnLay->setContentsMargins(0, 0, 0, 0);
44 myMainLayout->addWidget(aFrm);
46 QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
48 aBtnLay->addWidget(aBtn);
49 aBtnLay->addStretch(1);
50 aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
51 aBtn->setObjectName(XGUI::PROP_PANEL_OK);
52 aBtn->setToolTip(tr("Ok"));
54 aBtnLay->addWidget(aBtn);
56 aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
57 aBtn->setToolTip(tr("Cancel"));
58 aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL);
60 aBtnLay->addWidget(aBtn);
62 myCustomWidget = new QWidget(aContent);
63 myMainLayout->addWidget(myCustomWidget);
64 myMainLayout->addStretch(1);
67 XGUI_PropertyPanel::~XGUI_PropertyPanel()
71 void XGUI_PropertyPanel::cleanContent()
74 qDeleteAll(myCustomWidget->children());
75 myActiveWidget = NULL;
78 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
80 myWidgets = theWidgets;
81 int aS = myWidgets.size();
82 if (theWidgets.empty()) return;
84 QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast =
86 for (; anIt != aLast; anIt++) {
87 connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*)));
89 connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), this,
90 SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
91 connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
92 this, SLOT(activateWidget(ModuleBase_ModelWidget*)));
94 ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
96 connect(aPointWidget, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
97 SIGNAL(storedPoint2D(ObjectPtr, const std::string&)));
99 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
101 QList<QWidget*> aControls = aLastWidget->getControls();
102 if (!aControls.empty()) {
103 QWidget* aLastControl = aControls.last();
105 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
106 QPushButton* aCancelBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
108 setTabOrder(aLastControl, anOkBtn);
109 setTabOrder(anOkBtn, aCancelBtn);
114 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
119 QWidget* XGUI_PropertyPanel::contentWidget()
121 return myCustomWidget;
124 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
126 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets)
128 eachWidget->setFeature(theFeature);
129 eachWidget->restoreValue();
131 // the repaint is used here to immediately react in GUI to the values change.
135 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
137 ModuleBase_ModelWidget* aNextWidget = 0;
138 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
139 bool isFoundWidget = false;
140 for (; anIt != aLast && !aNextWidget; anIt++) {
141 if (isFoundWidget || !theWidget) {
142 if ((*anIt)->focusTo()) {
146 isFoundWidget = (*anIt) == theWidget;
148 // Normaly focusTo is enough to activate widget
149 // here is a special case on mouse click in the viewer
150 if(aNextWidget == NULL) {
151 activateWidget(NULL);
155 void XGUI_PropertyPanel::activateNextWidget()
157 activateNextWidget(myActiveWidget);
160 void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
162 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
163 anOkBtn->setEnabled(isEnabled);
166 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
169 myActiveWidget->setHighlighted(false);
172 theWidget->setHighlighted(true);
174 myActiveWidget = theWidget;
175 emit widgetActivated(theWidget);