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
29 #include "SMESHGUI_Preferences_SelectionDlg.h"
32 #include <qgroupbox.h>
35 #include <qlineedit.h>
36 #include <qvalidator.h>
38 #include <qpushbutton.h>
40 #include <qcolordialog.h>
44 //=================================================================================
45 // class : SMESHGUI_LineEdit
47 //=================================================================================
48 SMESHGUI_LineEdit::SMESHGUI_LineEdit(QWidget* parent, const char *name)
49 : QLineEdit(parent, name)
53 SMESHGUI_LineEdit::SMESHGUI_LineEdit(const QString& text, QWidget* parent, const char *name)
54 : QLineEdit(text, parent, name)
58 void SMESHGUI_LineEdit::focusOutEvent(QFocusEvent* e)
60 const QValidator* aVal = validator();
61 QString aText = text();
62 int aCurPos = cursorPosition();
63 if (aVal && aVal->validate(aText, aCurPos) != QValidator::Acceptable) {
64 QString aValid = aText;
66 if (aText != aValid) {
72 QLineEdit::focusOutEvent(e);
76 //=================================================================================
77 // class : SMESHGUI_DoubleValidator
79 //=================================================================================
80 SMESHGUI_DoubleValidator::SMESHGUI_DoubleValidator(QObject * parent, const char *name)
81 : QDoubleValidator(parent, name)
85 SMESHGUI_DoubleValidator::SMESHGUI_DoubleValidator(double bottom, double top, int decimals,
86 QObject * parent, const char *name)
87 : QDoubleValidator(bottom, top, decimals, parent, name)
91 void SMESHGUI_DoubleValidator::fixup(QString& theText) const
94 double aValue = theText.toDouble(&ok);
96 if (aValue < bottom())
97 theText = QString::number(bottom(), 'g', decimals());
99 theText = QString::number(top(), 'g', decimals());
104 //=================================================================================
105 // class : SMESHGUI_Preferences_SelectionDlg()
107 //=================================================================================
108 SMESHGUI_Preferences_SelectionDlg::SMESHGUI_Preferences_SelectionDlg( QWidget* parent, const char* name )
109 : QDialog( parent, name, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
111 if ( !name ) setName( "SMESHGUI_Preferences_SelectionDlg" );
112 setCaption( tr( "SMESH_PREF_SELECTION" ) );
114 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 11, 6);
117 /***************************************************************/
118 QGroupBox* aSelectBox = new QGroupBox(4, Qt::Horizontal, this, "selection");
119 aSelectBox->setTitle(tr("SMESH_SELECTION"));
121 aLabel = new QLabel(aSelectBox, "selection color label");
122 aLabel->setText(tr("SMESH_OUTLINE_COLOR"));
123 myColor[2] = new QPushButton(aSelectBox, "outline color");
124 myColor[2]->setFixedSize(QSize(25, 25));
126 aSelectBox->addSpace(0);
127 aSelectBox->addSpace(0);
129 aLabel = new QLabel(aSelectBox, "selection color label");
130 aLabel->setText(tr("SMESH_ELEMENTS_COLOR"));
131 myColor[1] = new QPushButton(aSelectBox, "elements color");
132 myColor[1]->setFixedSize(QSize(25, 25));
134 aLabel = new QLabel(aSelectBox, "selection width label");
135 aLabel->setText(tr("SMESH_WIDTH"));
136 myWidth[1] = new QSpinBox(0, 5, 1, aSelectBox, "selection width");
137 myWidth[1]->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
138 myWidth[1]->setButtonSymbols(QSpinBox::PlusMinus);
139 myWidth[1]->setMinimumWidth(50);
141 /***************************************************************/
142 QGroupBox* aPreSelectBox = new QGroupBox(1, Qt::Vertical, this, "preselection");
143 aPreSelectBox->setTitle(tr("SMESH_PRESELECTION"));
145 aLabel = new QLabel(aPreSelectBox, "preselection color label");
146 aLabel->setText(tr("SMESH_HILIGHT_COLOR"));
147 myColor[0] = new QPushButton(aPreSelectBox, "preselection color");
148 myColor[0]->setFixedSize(QSize(25, 25));
150 aLabel = new QLabel(aPreSelectBox, "preselection width label");
151 aLabel->setText(tr("SMESH_WIDTH"));
152 myWidth[0] = new QSpinBox(0, 5, 1, aPreSelectBox, "preselection width");
153 myWidth[0]->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
154 myWidth[0]->setButtonSymbols(QSpinBox::PlusMinus);
155 myWidth[0]->setMinimumWidth(50);
157 /***************************************************************/
158 QGroupBox* aPrecisionBox = new QGroupBox(1, Qt::Vertical, this, "preselection");
159 aPrecisionBox->setTitle(tr("SMESH_PRECISION"));
160 QDoubleValidator* aValidator = new SMESHGUI_DoubleValidator(aPrecisionBox);
161 aValidator->setBottom(0.001);
162 aValidator->setDecimals(6);
164 aLabel = new QLabel(aPrecisionBox, "node tol label");
165 aLabel->setText(tr("SMESH_NODES"));
166 myPrecision[0] = new SMESHGUI_LineEdit(aPrecisionBox, "node precision");
167 myPrecision[0]->setValidator(aValidator);
169 aLabel = new QLabel(aPrecisionBox, "item tol label");
170 aLabel->setText(tr("SMESH_ELEMENTS"));
171 myPrecision[1] = new SMESHGUI_LineEdit(aPrecisionBox, "item precision");
172 myPrecision[1]->setValidator(aValidator);
174 /***************************************************************/
175 QFrame* aButtons = new QFrame(this, "button box");
176 aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
177 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
178 aBtnLayout->setAutoAdd(false);
180 QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
181 aOKBtn->setText(tr("SMESH_BUT_OK"));
182 aOKBtn->setAutoDefault(true);
183 aOKBtn->setDefault(true);
184 QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
185 aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
186 aCloseBtn->setAutoDefault(true);
188 aBtnLayout->addWidget(aOKBtn);
189 aBtnLayout->addStretch();
190 aBtnLayout->addWidget(aCloseBtn);
192 /***************************************************************/
193 aMainLayout->addWidget(aSelectBox);
194 aMainLayout->addWidget(aPreSelectBox);
195 aMainLayout->addWidget(aPrecisionBox);
196 aMainLayout->addWidget(aButtons);
198 for (int i = 0; i < 3; i++)
199 connect(myColor[i], SIGNAL(clicked()), this, SLOT(onSelectColor()));
201 connect(aOKBtn, SIGNAL(clicked()), this, SLOT(accept()));
202 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
204 /* Move widget on the botton right corner of main widget */
206 SMESHGUI::GetSMESHGUI()->DefineDlgPosition(this, x, y);
210 //=================================================================================
211 // function : ~SMESHGUI_Preferences_SelectionDlg()
212 // purpose : Destroys the object and frees any allocated resources
213 //=================================================================================
214 SMESHGUI_Preferences_SelectionDlg::~SMESHGUI_Preferences_SelectionDlg()
216 // no need to delete child widgets, Qt does it all for us
219 //=================================================================================
220 // function : closeEvent()
222 //=================================================================================
223 void SMESHGUI_Preferences_SelectionDlg::closeEvent( QCloseEvent* e )
228 //=================================================================================
229 // function : onSelectColor()
231 //=================================================================================
232 void SMESHGUI_Preferences_SelectionDlg::onSelectColor()
234 QPushButton* aSender = (QPushButton*)sender();
235 QColor aColor = aSender->palette().active().button();
236 aColor = QColorDialog::getColor(aColor, this);
237 if (aColor.isValid()) {
238 QPalette aPal = aSender->palette();
239 aPal.setColor(QColorGroup::Button, aColor);
240 aSender->setPalette(aPal);
244 //=================================================================================
245 // function : SetColor()
247 //=================================================================================
248 void SMESHGUI_Preferences_SelectionDlg::SetColor(int type, QColor color)
250 if (type > 0 && type <= 3) {
251 QPalette aPal = myColor[type-1]->palette();
252 aPal.setColor(QColorGroup::Button, color);
253 myColor[type-1]->setPalette(aPal);
257 //=================================================================================
258 // function : GetColor()
260 //=================================================================================
261 QColor SMESHGUI_Preferences_SelectionDlg::GetColor(int type)
264 if (type > 0 && type <= 3)
265 aColor = myColor[type-1]->palette().active().button();
269 //=================================================================================
270 // function : SetWidth()
272 //=================================================================================
273 void SMESHGUI_Preferences_SelectionDlg::SetWidth(int type, int value)
275 if (type > 0 && type <= 2)
276 myWidth[type-1]->setValue(value);
279 //=================================================================================
280 // function : GetWidth()
282 //=================================================================================
283 int SMESHGUI_Preferences_SelectionDlg::GetWidth(int type)
285 if (type > 0 && type <= 2)
286 return myWidth[type-1]->value();
290 //=================================================================================
291 // function : SetPrecision()
293 //=================================================================================
294 void SMESHGUI_Preferences_SelectionDlg::SetPrecision(int type, double value)
296 if (type > 0 && type <= 2)
297 myPrecision[type-1]->setText(QString::number(value));
300 //=================================================================================
301 // function : GetPrecision()
303 //=================================================================================
304 double SMESHGUI_Preferences_SelectionDlg::GetPrecision(int type)
306 if (type > 0 && type <= 2)
307 return myPrecision[type-1]->text().toDouble();