2 * XGUI_PropertyPanel.cpp
4 * Created on: Apr 29, 2014
8 #include <XGUI_Constants.h>
9 #include <XGUI_PropertyPanel.h>
10 #include <ModuleBase_WidgetPoint2D.h>
13 #include <QVBoxLayout>
15 #include <QPushButton>
17 #include <QVBoxLayout>
25 XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
27 this->setWindowTitle(tr("Property Panel"));
28 QAction* aViewAct = this->toggleViewAction();
29 this->setObjectName(XGUI::PROP_PANEL);
30 setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
32 QWidget* aContent = new QWidget(this);
33 myMainLayout = new QVBoxLayout(aContent);
34 myMainLayout->setContentsMargins(3, 3, 3, 3);
35 this->setWidget(aContent);
37 QFrame* aFrm = new QFrame(aContent);
38 aFrm->setFrameStyle(QFrame::Sunken);
39 aFrm->setFrameShape(QFrame::Panel);
40 QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
41 aBtnLay->setContentsMargins(0, 0, 0, 0);
42 myMainLayout->addWidget(aFrm);
44 QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
46 aBtnLay->addWidget(aBtn);
47 aBtnLay->addStretch(1);
48 aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
49 aBtn->setObjectName(XGUI::PROP_PANEL_OK);
50 aBtn->setToolTip(tr("Ok"));
52 aBtnLay->addWidget(aBtn);
53 aBtn->installEventFilter(this);
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);
65 aBtn->installEventFilter(this);
68 XGUI_PropertyPanel::~XGUI_PropertyPanel()
72 void XGUI_PropertyPanel::cleanContent()
76 QLayoutItem* aItem = myMainLayout->takeAt(myMainLayout->count() - 1);
79 myMainLayout->removeWidget(myCustomWidget);
80 delete myCustomWidget;
82 myCustomWidget = new QWidget(widget());
83 myMainLayout->addWidget(myCustomWidget);
84 myMainLayout->addStretch(1);
87 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
89 myWidgets = theWidgets;
91 if (!theWidgets.empty()) {
92 QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast = theWidgets.end();
93 for (; anIt != aLast; anIt++) {
94 connect(*anIt, SIGNAL(keyReleased(const std::string&, QKeyEvent*)),
95 this, SIGNAL(keyReleased(const std::string&, QKeyEvent*)));
97 connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
98 this, SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
100 connect(*anIt, SIGNAL(activated(ModuleBase_ModelWidget*)),
101 this, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)));
103 ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
105 connect(aPointWidget, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)),
106 this, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)));
108 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
110 QList<QWidget*> aControls = aLastWidget->getControls();
111 if (!aControls.empty()) {
112 QWidget* aLastControl = aControls.last();
114 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
115 QPushButton* aCancelBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
117 setTabOrder(aLastControl, anOkBtn);
118 setTabOrder(anOkBtn, aCancelBtn);
121 onActivateNextWidget(0);
125 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
130 bool XGUI_PropertyPanel::eventFilter(QObject *theObject, QEvent *theEvent)
132 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
133 QPushButton* aCancelBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
134 if (theObject == anOkBtn || theObject == aCancelBtn) {
135 if (theEvent->type() == QEvent::KeyRelease) {
136 QKeyEvent* aKeyEvent = (QKeyEvent*)theEvent;
137 if (aKeyEvent && aKeyEvent->key() == Qt::Key_Return) {
138 // TODO: this is enter button processing when the focus is on "Apply" or "Cancel" buttons
139 emit keyReleased("", (QKeyEvent*) theEvent);
144 return QDockWidget::eventFilter(theObject, theEvent);
147 QWidget* XGUI_PropertyPanel::contentWidget()
149 return myCustomWidget;
152 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
154 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
155 eachWidget->restoreValue(theFeature);
157 // the repaint is used here to immediatelly react in GUI to the values change.
161 void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget)
163 ModuleBase_ModelWidget* aNextWidget = 0;
164 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(),
165 aLast = myWidgets.end();
166 bool isFoundWidget = false;
167 for (;anIt != aLast && !aNextWidget; anIt++)
169 if (isFoundWidget || !theWidget) {
170 if ((*anIt)->focusTo()) {
174 isFoundWidget = (*anIt) == theWidget;
176 emit widgetActivated(aNextWidget);