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.salome-platform.org or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_Preferences_SelectionDlg.cxx
25 // Author : Natalia KOPNOVA
30 #include "SMESHGUI_Preferences_SelectionDlg.h"
33 #include <qgroupbox.h>
36 #include <qlineedit.h>
37 #include <qvalidator.h>
39 #include <qpushbutton.h>
41 #include <qcolordialog.h>
43 //=================================================================================
44 // class : SMESHGUI_LineEdit
46 //=================================================================================
47 SMESHGUI_LineEdit::SMESHGUI_LineEdit(QWidget* parent, const char *name)
48 : QLineEdit(parent, name)
52 SMESHGUI_LineEdit::SMESHGUI_LineEdit(const QString& text, QWidget* parent, const char *name)
53 : QLineEdit(text, parent, name)
57 void SMESHGUI_LineEdit::focusOutEvent(QFocusEvent* e)
59 const QValidator* aVal = validator();
60 QString aText = text();
61 int aCurPos = cursorPosition();
62 if (aVal && aVal->validate(aText, aCurPos) != QValidator::Acceptable) {
63 QString aValid = aText;
65 if (aText != aValid) {
71 QLineEdit::focusOutEvent(e);
75 //=================================================================================
76 // class : SMESHGUI_DoubleValidator
78 //=================================================================================
79 SMESHGUI_DoubleValidator::SMESHGUI_DoubleValidator(QObject * parent, const char *name)
80 : QDoubleValidator(parent, name)
84 SMESHGUI_DoubleValidator::SMESHGUI_DoubleValidator(double bottom, double top, int decimals,
85 QObject * parent, const char *name)
86 : QDoubleValidator(bottom, top, decimals, parent, name)
90 void SMESHGUI_DoubleValidator::fixup(QString& theText) const
93 double aValue = theText.toDouble(&ok);
95 if (aValue < bottom())
96 theText = QString::number(bottom(), 'g', decimals());
98 theText = QString::number(top(), 'g', decimals());
103 //=================================================================================
104 // class : SMESHGUI_Preferences_SelectionDlg()
106 //=================================================================================
107 SMESHGUI_Preferences_SelectionDlg::SMESHGUI_Preferences_SelectionDlg( QWidget* parent, const char* name )
108 : QDialog( parent, name, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
110 if ( !name ) setName( "SMESHGUI_Preferences_SelectionDlg" );
111 setCaption( tr( "SMESH_PREF_SELECTION" ) );
113 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 11, 6);
116 /***************************************************************/
117 QGroupBox* aSelectBox = new QGroupBox(4, Qt::Horizontal, this, "selection");
118 aSelectBox->setTitle(tr("SMESH_SELECTION"));
120 aLabel = new QLabel(aSelectBox, "selection color label");
121 aLabel->setText(tr("SMESH_OUTLINE_COLOR"));
122 myColor[2] = new QPushButton(aSelectBox, "outline color");
123 myColor[2]->setFixedSize(QSize(25, 25));
125 aSelectBox->addSpace(0);
126 aSelectBox->addSpace(0);
128 aLabel = new QLabel(aSelectBox, "selection color label");
129 aLabel->setText(tr("SMESH_ELEMENTS_COLOR"));
130 myColor[1] = new QPushButton(aSelectBox, "elements color");
131 myColor[1]->setFixedSize(QSize(25, 25));
133 aLabel = new QLabel(aSelectBox, "selection width label");
134 aLabel->setText(tr("SMESH_WIDTH"));
135 myWidth[1] = new QSpinBox(0, 5, 1, aSelectBox, "selection width");
136 myWidth[1]->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
137 myWidth[1]->setButtonSymbols(QSpinBox::PlusMinus);
138 myWidth[1]->setMinimumWidth(50);
140 /***************************************************************/
141 QGroupBox* aPreSelectBox = new QGroupBox(1, Qt::Vertical, this, "preselection");
142 aPreSelectBox->setTitle(tr("SMESH_PRESELECTION"));
144 aLabel = new QLabel(aPreSelectBox, "preselection color label");
145 aLabel->setText(tr("SMESH_HILIGHT_COLOR"));
146 myColor[0] = new QPushButton(aPreSelectBox, "preselection color");
147 myColor[0]->setFixedSize(QSize(25, 25));
149 aLabel = new QLabel(aPreSelectBox, "preselection width label");
150 aLabel->setText(tr("SMESH_WIDTH"));
151 myWidth[0] = new QSpinBox(0, 5, 1, aPreSelectBox, "preselection width");
152 myWidth[0]->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
153 myWidth[0]->setButtonSymbols(QSpinBox::PlusMinus);
154 myWidth[0]->setMinimumWidth(50);
156 /***************************************************************/
157 QGroupBox* aPrecisionBox = new QGroupBox(1, Qt::Vertical, this, "preselection");
158 aPrecisionBox->setTitle(tr("SMESH_PRECISION"));
159 QDoubleValidator* aValidator = new SMESHGUI_DoubleValidator(aPrecisionBox);
160 aValidator->setBottom(0.001);
161 aValidator->setDecimals(6);
163 aLabel = new QLabel(aPrecisionBox, "node tol label");
164 aLabel->setText(tr("SMESH_NODES"));
165 myPrecision[0] = new SMESHGUI_LineEdit(aPrecisionBox, "node precision");
166 myPrecision[0]->setValidator(aValidator);
168 aLabel = new QLabel(aPrecisionBox, "item tol label");
169 aLabel->setText(tr("SMESH_ELEMENTS"));
170 myPrecision[1] = new SMESHGUI_LineEdit(aPrecisionBox, "item precision");
171 myPrecision[1]->setValidator(aValidator);
173 /***************************************************************/
174 QFrame* aButtons = new QFrame(this, "button box");
175 aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
176 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
177 aBtnLayout->setAutoAdd(false);
179 QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
180 aOKBtn->setText(tr("SMESH_BUT_OK"));
181 aOKBtn->setAutoDefault(true);
182 aOKBtn->setDefault(true);
183 QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
184 aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
185 aCloseBtn->setAutoDefault(true);
187 aBtnLayout->addWidget(aOKBtn);
188 aBtnLayout->addStretch();
189 aBtnLayout->addWidget(aCloseBtn);
191 /***************************************************************/
192 aMainLayout->addWidget(aSelectBox);
193 aMainLayout->addWidget(aPreSelectBox);
194 aMainLayout->addWidget(aPrecisionBox);
195 aMainLayout->addWidget(aButtons);
197 for (int i = 0; i < 3; i++)
198 connect(myColor[i], SIGNAL(clicked()), this, SLOT(onSelectColor()));
200 connect(aOKBtn, SIGNAL(clicked()), this, SLOT(accept()));
201 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
203 /* Move widget on the botton right corner of main widget */
205 SMESHGUI::GetSMESHGUI()->DefineDlgPosition(this, x, y);
209 //=================================================================================
210 // function : ~SMESHGUI_Preferences_SelectionDlg()
211 // purpose : Destroys the object and frees any allocated resources
212 //=================================================================================
213 SMESHGUI_Preferences_SelectionDlg::~SMESHGUI_Preferences_SelectionDlg()
215 // no need to delete child widgets, Qt does it all for us
218 //=================================================================================
219 // function : closeEvent()
221 //=================================================================================
222 void SMESHGUI_Preferences_SelectionDlg::closeEvent( QCloseEvent* e )
227 //=================================================================================
228 // function : onSelectColor()
230 //=================================================================================
231 void SMESHGUI_Preferences_SelectionDlg::onSelectColor()
233 QPushButton* aSender = (QPushButton*)sender();
234 QColor aColor = aSender->palette().active().button();
235 aColor = QColorDialog::getColor(aColor, this);
236 if (aColor.isValid()) {
237 QPalette aPal = aSender->palette();
238 aPal.setColor(QColorGroup::Button, aColor);
239 aSender->setPalette(aPal);
243 //=================================================================================
244 // function : SetColor()
246 //=================================================================================
247 void SMESHGUI_Preferences_SelectionDlg::SetColor(int type, QColor color)
249 if (type > 0 && type <= 3) {
250 QPalette aPal = myColor[type-1]->palette();
251 aPal.setColor(QColorGroup::Button, color);
252 myColor[type-1]->setPalette(aPal);
256 //=================================================================================
257 // function : GetColor()
259 //=================================================================================
260 QColor SMESHGUI_Preferences_SelectionDlg::GetColor(int type)
263 if (type > 0 && type <= 3)
264 aColor = myColor[type-1]->palette().active().button();
268 //=================================================================================
269 // function : SetWidth()
271 //=================================================================================
272 void SMESHGUI_Preferences_SelectionDlg::SetWidth(int type, int value)
274 if (type > 0 && type <= 2)
275 myWidth[type-1]->setValue(value);
278 //=================================================================================
279 // function : GetWidth()
281 //=================================================================================
282 int SMESHGUI_Preferences_SelectionDlg::GetWidth(int type)
284 if (type > 0 && type <= 2)
285 return myWidth[type-1]->value();
289 //=================================================================================
290 // function : SetPrecision()
292 //=================================================================================
293 void SMESHGUI_Preferences_SelectionDlg::SetPrecision(int type, double value)
295 if (type > 0 && type <= 2)
296 myPrecision[type-1]->setText(QString::number(value));
299 //=================================================================================
300 // function : GetPrecision()
302 //=================================================================================
303 double SMESHGUI_Preferences_SelectionDlg::GetPrecision(int type)
305 if (type > 0 && type <= 2)
306 return myPrecision[type-1]->text().toDouble();