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 aBtn->setShortcut(QKeySequence(Qt::Key_Escape));
61 aBtnLay->addWidget(aBtn);
63 myCustomWidget = new QWidget(aContent);
64 myMainLayout->addWidget(myCustomWidget);
65 myMainLayout->addStretch(1);
68 XGUI_PropertyPanel::~XGUI_PropertyPanel()
72 void XGUI_PropertyPanel::cleanContent()
75 qDeleteAll(myCustomWidget->children());
76 myActiveWidget = NULL;
79 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
81 myWidgets = theWidgets;
82 int aS = myWidgets.size();
83 if (theWidgets.empty()) return;
85 QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast =
87 for (; anIt != aLast; anIt++) {
88 connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*)));
90 connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), this,
91 SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
92 connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
93 this, SLOT(activateWidget(ModuleBase_ModelWidget*)));
95 ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
97 connect(aPointWidget, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
98 SIGNAL(storedPoint2D(ObjectPtr, const std::string&)));
100 ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
102 QList<QWidget*> aControls = aLastWidget->getControls();
103 if (!aControls.empty()) {
104 QWidget* aLastControl = aControls.last();
106 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
107 QPushButton* aCancelBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
109 setTabOrder(aLastControl, anOkBtn);
110 setTabOrder(anOkBtn, aCancelBtn);
115 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
120 QWidget* XGUI_PropertyPanel::contentWidget()
122 return myCustomWidget;
125 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
127 // Invalid feature case on abort of the operation
128 if(!theFeature->data())
130 foreach(ModuleBase_ModelWidget* eachWidget, myWidgets)
132 eachWidget->setFeature(theFeature);
133 eachWidget->restoreValue();
135 // the repaint is used here to immediately react in GUI to the values change.
139 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
141 ModuleBase_ModelWidget* aNextWidget = 0;
142 QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
143 bool isFoundWidget = false;
144 for (; anIt != aLast && !aNextWidget; anIt++) {
145 if (isFoundWidget || !theWidget) {
146 if ((*anIt)->focusTo()) {
150 isFoundWidget = (*anIt) == theWidget;
152 // Normaly focusTo is enough to activate widget
153 // here is a special case on mouse click in the viewer
154 if(aNextWidget == NULL) {
155 activateWidget(NULL);
159 void XGUI_PropertyPanel::activateNextWidget()
161 activateNextWidget(myActiveWidget);
164 void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
166 QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
167 anOkBtn->setEnabled(isEnabled);
170 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
173 myActiveWidget->setHighlighted(false);
176 theWidget->setHighlighted(true);
178 myActiveWidget = theWidget;
179 emit widgetActivated(theWidget);