1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_aParameterDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_aParameterDlg.h"
30 #include "SMESHGUI_aParameter.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_Utils.h"
35 #include "SUIT_Tools.h"
36 #include "SUIT_Desktop.h"
39 #include <qgroupbox.h>
41 #include <qpushbutton.h>
44 #include <qvalidator.h>
45 #include <qtextedit.h>
49 //======================================================================================
50 // function : SMESHGUI_aParameterDlg()
52 // The dialog will by default be modal, unless you set 'modal' to
53 // false when constructing dialog
55 //======================================================================================
56 SMESHGUI_aParameterDlg::SMESHGUI_aParameterDlg
57 ( SMESHGUI* theModule,
58 std::list<SMESHGUI_aParameterPtr> params,
61 : QDialog( SMESH::GetDesktop( theModule ), "MyParameterDialog", modal, WStyle_Customize |
62 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
66 /* creating widgets */
71 /* Move widget on the botton right corner of main widget */
72 SUIT_Tools::centerWidget(this, SMESH::GetDesktop( theModule ) );
75 //======================================================================================
76 // function : SMESHGUI_aParameterDlg::init()
77 // purpose : creates dialog's layout
78 //======================================================================================
79 void SMESHGUI_aParameterDlg::init()
81 setSizeGripEnabled(TRUE);
83 QGridLayout* topLayout = new QGridLayout(this);
84 topLayout->setMargin(11); topLayout->setSpacing(6);
86 /***************************************************************/
87 QGroupBox* GroupC1 = new QGroupBox(this, "GroupC1");
88 GroupC1->setColumnLayout(0, Qt::Vertical);
89 GroupC1->layout()->setSpacing(0);
90 GroupC1->layout()->setMargin(0);
91 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout());
92 GroupC1Layout->setAlignment(Qt::AlignTop);
93 GroupC1Layout->setSpacing(6);
94 GroupC1Layout->setMargin(11);
95 /* Spin boxes with labels */
96 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
97 for (int row = 0; paramIt != myParamList.end(); paramIt++ , row++)
99 SMESHGUI_aParameterPtr param = (*paramIt);
100 QLabel * label = new QLabel(GroupC1, "TextLabel");
101 GroupC1Layout->addWidget(label, row, 0);
102 label->setText(param->Label());
103 QWidget* aSpinWidget = 0;
104 switch (param->GetType()) {
105 case SMESHGUI_aParameter::DOUBLE: {
106 SMESHGUI_SpinBox* spin = new SMESHGUI_SpinBox(GroupC1);
108 spin->setPrecision(12);
111 case SMESHGUI_aParameter::INT: {
112 QSpinBox* spin = new QSpinBox(GroupC1);
116 case SMESHGUI_aParameter::TEXT: {
117 QTextEdit* edit = new QTextEdit(GroupC1);
118 edit->setWordWrap(QTextEdit::NoWrap);
119 edit->setTextFormat(Qt::PlainText);
126 GroupC1Layout->addWidget(aSpinWidget, row, 1);
127 aSpinWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
128 aSpinWidget->setMinimumSize(150, 0);
129 param->InitializeWidget(aSpinWidget);
130 mySpinList.push_back(aSpinWidget);
134 /***************************************************************/
135 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
136 GroupButtons->setColumnLayout(0, Qt::Vertical);
137 GroupButtons->layout()->setSpacing(0);
138 GroupButtons->layout()->setMargin(0);
139 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
140 GroupButtonsLayout->setAlignment(Qt::AlignTop);
141 GroupButtonsLayout->setSpacing(6);
142 GroupButtonsLayout->setMargin(11);
144 myButtonOk = new QPushButton(GroupButtons, "buttonOk");
145 myButtonOk->setText(tr("SMESH_BUT_OK"));
146 myButtonOk->setAutoDefault(TRUE);
147 myButtonOk->setDefault(TRUE);
148 GroupButtonsLayout->addWidget(myButtonOk, 0, 0);
149 /* add spacer between buttons */
150 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
152 myButtonCancel = new QPushButton(GroupButtons, "buttonCancel");
153 myButtonCancel->setText(tr("SMESH_BUT_CANCEL"));
154 myButtonCancel->setAutoDefault(TRUE);
155 GroupButtonsLayout->addWidget(myButtonCancel, 0, 2);
157 /***************************************************************/
158 topLayout->addWidget(GroupC1, 0, 0);
159 topLayout->addWidget(GroupButtons, 1, 0);
161 /* signals and slots connections */
162 connect(myButtonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
163 connect(myButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
166 //======================================================================================
167 // function : ~SMESHGUI_aParameterDlg()
168 // purpose : Destructor
169 //======================================================================================
170 SMESHGUI_aParameterDlg::~SMESHGUI_aParameterDlg()
174 //=======================================================================
175 //function : ClickOnOk
177 //=======================================================================
178 void SMESHGUI_aParameterDlg::ClickOnOk()
180 if (!mySMESHGUI->isActiveStudyLocked()) {
181 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
182 list<QWidget*>::iterator widgetIt = mySpinList.begin();
184 paramIt != myParamList.end() && widgetIt != mySpinList.end();
185 paramIt++ , widgetIt++)
186 (*paramIt)->TakeValue(*widgetIt);
192 //=======================================================================
193 // function : Parameters()
194 // purpose : return a list of parameters from a dialog box
195 //=======================================================================
196 bool SMESHGUI_aParameterDlg::Parameters( SMESHGUI* theModule,
197 list<SMESHGUI_aParameterPtr> params,
200 if (!params.empty()) {
201 SMESHGUI_aParameterDlg *Dialog =
202 new SMESHGUI_aParameterDlg( theModule, params, aTitle, TRUE);
203 return (Dialog->exec() == QDialog::Accepted);