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 QDockWidget(theParent)
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);
54 aBtn->installEventFilter(this);
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);
66 aBtn->installEventFilter(this);
69 XGUI_PropertyPanel::~XGUI_PropertyPanel()
73 void XGUI_PropertyPanel::cleanContent()
77 QLayoutItem* aItem = myMainLayout->takeAt(myMainLayout->count() - 1);
80 myMainLayout->removeWidget(myCustomWidget);
81 delete myCustomWidget;
83 myCustomWidget = new QWidget(widget());
84 myMainLayout->addWidget(myCustomWidget);
85 myMainLayout->addStretch(1);
88 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
90 myWidgets = theWidgets;
92 if (!theWidgets.empty()) {
93 QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast = theWidgets.end();
94 for (; anIt != aLast; anIt++) {
95 connect(*anIt, SIGNAL(keyReleased(const std::string&, QKeyEvent*)),
96 this, SIGNAL(keyReleased(const std::string&, QKeyEvent*)));
98 connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
99 this, SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
101 //connect(*anIt, SIGNAL(activated(ModuleBase_ModelWidget*)),
102 // this, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)));
104 ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
106 connect(aPointWidget, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)),
107 this, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)));
109 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
111 QList<QWidget*> aControls = aLastWidget->getControls();
112 if (!aControls.empty()) {
113 QWidget* aLastControl = aControls.last();
115 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
116 QPushButton* aCancelBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
118 setTabOrder(aLastControl, anOkBtn);
119 setTabOrder(anOkBtn, aCancelBtn);
122 onActivateNextWidget(0);
126 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
131 bool XGUI_PropertyPanel::eventFilter(QObject *theObject, QEvent *theEvent)
133 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
134 QPushButton* aCancelBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
135 if (theObject == anOkBtn || theObject == aCancelBtn) {
136 if (theEvent->type() == QEvent::KeyRelease) {
137 QKeyEvent* aKeyEvent = (QKeyEvent*)theEvent;
138 if (aKeyEvent && aKeyEvent->key() == Qt::Key_Return) {
139 // TODO: this is enter button processing when the focus is on "Apply" or "Cancel" buttons
140 emit keyReleased("", (QKeyEvent*) theEvent);
145 return QDockWidget::eventFilter(theObject, theEvent);
148 QWidget* XGUI_PropertyPanel::contentWidget()
150 return myCustomWidget;
153 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
155 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
156 eachWidget->restoreValue(theFeature);
158 // the repaint is used here to immediatelly react in GUI to the values change.
162 void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget)
164 ModuleBase_ModelWidget* aNextWidget = 0;
165 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(),
166 aLast = myWidgets.end();
167 bool isFoundWidget = false;
168 for (;anIt != aLast && !aNextWidget; anIt++)
170 if (isFoundWidget || !theWidget) {
171 if ((*anIt)->focusTo()) {
175 isFoundWidget = (*anIt) == theWidget;
177 emit widgetActivated(aNextWidget);