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 ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
102 connect(aPointWidget, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)),
103 this, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)));
105 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
107 QList<QWidget*> aControls = aLastWidget->getControls();
108 if (!aControls.empty()) {
109 QWidget* aLastControl = aControls.last();
111 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
112 QPushButton* aCancelBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
114 setTabOrder(aLastControl, anOkBtn);
115 setTabOrder(anOkBtn, aCancelBtn);
118 ModuleBase_ModelWidget* aWidget = theWidgets.first();
120 activateWidget(aWidget);
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::onFocusActivated(const std::string& theAttributeName)
163 if (theAttributeName == XGUI::PROP_PANEL_OK) {
164 QPushButton* aBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
167 if (theAttributeName == XGUI::PROP_PANEL_CANCEL) {
168 QPushButton* aBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
172 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
173 if (eachWidget->canFocusTo(theAttributeName)) {
174 eachWidget->focusTo();
181 void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget)
183 ModuleBase_ModelWidget* aNextWidget = 0;
185 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(),
186 aLast = myWidgets.end();
187 for (;anIt != aLast; anIt++)
189 if ((*anIt) == theWidget) {
196 activateWidget(aNextWidget);
199 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
202 theWidget->focusTo();
203 emit widgetActivated(theWidget);