2 * XGUI_PropertyPanel.cpp
4 * Created on: Apr 29, 2014
8 #include <XGUI_Constants.h>
9 #include <XGUI_PropertyPanel.h>
12 #include <QVBoxLayout>
14 #include <QPushButton>
16 #include <QVBoxLayout>
24 XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
26 this->setWindowTitle(tr("Property Panel"));
27 QAction* aViewAct = this->toggleViewAction();
28 this->setObjectName(XGUI::PROP_PANEL);
29 setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
31 QWidget* aContent = new QWidget(this);
32 myMainLayout = new QVBoxLayout(aContent);
33 myMainLayout->setContentsMargins(3, 3, 3, 3);
34 this->setWidget(aContent);
36 QFrame* aFrm = new QFrame(aContent);
37 aFrm->setFrameStyle(QFrame::Sunken);
38 aFrm->setFrameShape(QFrame::Panel);
39 QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
40 aBtnLay->setContentsMargins(0, 0, 0, 0);
41 myMainLayout->addWidget(aFrm);
43 QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
45 aBtnLay->addWidget(aBtn);
46 aBtnLay->addStretch(1);
47 aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
48 aBtn->setObjectName(XGUI::PROP_PANEL_OK);
49 aBtn->setToolTip(tr("Ok"));
51 aBtnLay->addWidget(aBtn);
52 aBtn->installEventFilter(this);
54 aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
55 aBtn->setToolTip(tr("Cancel"));
56 aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL);
58 aBtnLay->addWidget(aBtn);
60 myCustomWidget = new QWidget(aContent);
61 myMainLayout->addWidget(myCustomWidget);
62 myMainLayout->addStretch(1);
64 aBtn->installEventFilter(this);
67 XGUI_PropertyPanel::~XGUI_PropertyPanel()
71 void XGUI_PropertyPanel::cleanContent()
75 QLayoutItem* aItem = myMainLayout->takeAt(myMainLayout->count() - 1);
78 myMainLayout->removeWidget(myCustomWidget);
79 delete myCustomWidget;
81 myCustomWidget = new QWidget(widget());
82 myMainLayout->addWidget(myCustomWidget);
83 myMainLayout->addStretch(1);
86 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
88 myWidgets = theWidgets;
90 if (!theWidgets.empty()) {
91 QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast = theWidgets.end();
92 for (; anIt != aLast; anIt++) {
93 connect(*anIt, SIGNAL(keyReleased(const std::string&, QKeyEvent*)),
94 this, SIGNAL(keyReleased(const std::string&, QKeyEvent*)));
96 connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
97 this, SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
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);
112 ModuleBase_ModelWidget* aWidget = theWidgets.first();
114 activateWidget(aWidget);
119 bool XGUI_PropertyPanel::eventFilter(QObject *theObject, QEvent *theEvent)
121 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
122 QPushButton* aCancelBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
123 if (theObject == anOkBtn || theObject == aCancelBtn) {
124 if (theEvent->type() == QEvent::KeyRelease) {
125 QKeyEvent* aKeyEvent = (QKeyEvent*)theEvent;
126 if (aKeyEvent && aKeyEvent->key() == Qt::Key_Return) {
127 // TODO: this is enter button processing when the focus is on "Apply" or "Cancel" buttons
128 emit keyReleased("", (QKeyEvent*) theEvent);
133 return QDockWidget::eventFilter(theObject, theEvent);
136 QWidget* XGUI_PropertyPanel::contentWidget()
138 return myCustomWidget;
141 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
143 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
144 eachWidget->restoreValue(theFeature);
146 // the repaint is used here to immediatelly react in GUI to the values change.
150 void XGUI_PropertyPanel::onFocusActivated(const std::string& theAttributeName)
152 if (theAttributeName == XGUI::PROP_PANEL_OK) {
153 QPushButton* aBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
156 if (theAttributeName == XGUI::PROP_PANEL_CANCEL) {
157 QPushButton* aBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
161 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
162 if (eachWidget->canFocusTo(theAttributeName)) {
163 eachWidget->focusTo();
170 void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget)
172 ModuleBase_ModelWidget* aNextWidget = 0;
174 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(),
175 aLast = myWidgets.end();
176 for (;anIt != aLast; anIt++)
178 if ((*anIt) == theWidget) {
185 activateWidget(aNextWidget);
188 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
191 theWidget->focusTo();
192 emit widgetActivated(theWidget);