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 "SMESHGUI_Utils.h"
34 #include "SUIT_Desktop.h"
36 #include <qgroupbox.h>
39 #include <qlineedit.h>
40 #include <qvalidator.h>
42 #include <qpushbutton.h>
44 #include <qcolordialog.h>
48 //=================================================================================
49 // class : SMESHGUI_LineEdit
51 //=================================================================================
52 SMESHGUI_LineEdit::SMESHGUI_LineEdit(QWidget* parent, const char *name)
53 : QLineEdit(parent, name)
57 SMESHGUI_LineEdit::SMESHGUI_LineEdit(const QString& text, QWidget* parent, const char *name)
58 : QLineEdit(text, parent, name)
62 void SMESHGUI_LineEdit::focusOutEvent(QFocusEvent* e)
64 const QValidator* aVal = validator();
65 QString aText = text();
66 int aCurPos = cursorPosition();
67 if (aVal && aVal->validate(aText, aCurPos) != QValidator::Acceptable) {
68 QString aValid = aText;
70 if (aText != aValid) {
76 QLineEdit::focusOutEvent(e);
80 //=================================================================================
81 // class : SMESHGUI_DoubleValidator
83 //=================================================================================
84 SMESHGUI_DoubleValidator::SMESHGUI_DoubleValidator(QObject * parent, const char *name)
85 : QDoubleValidator(parent, name)
89 SMESHGUI_DoubleValidator::SMESHGUI_DoubleValidator(double bottom, double top, int decimals,
90 QObject * parent, const char *name)
91 : QDoubleValidator(bottom, top, decimals, parent, name)
95 void SMESHGUI_DoubleValidator::fixup(QString& theText) const
98 double aValue = theText.toDouble(&ok);
100 if (aValue < bottom())
101 theText = QString::number(bottom(), 'g', decimals());
103 theText = QString::number(top(), 'g', decimals());
108 //=================================================================================
109 // class : SMESHGUI_Preferences_SelectionDlg()
111 //=================================================================================
112 SMESHGUI_Preferences_SelectionDlg::SMESHGUI_Preferences_SelectionDlg( SMESHGUI* theModule, const char* name )
113 : QDialog( SMESH::GetDesktop( theModule ), name, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
114 mySMESHGUI( theModule )
116 if ( !name ) setName( "SMESHGUI_Preferences_SelectionDlg" );
117 setCaption( tr( "SMESH_PREF_SELECTION" ) );
119 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 11, 6);
122 /***************************************************************/
123 QGroupBox* aSelectBox = new QGroupBox(4, Qt::Horizontal, this, "selection");
124 aSelectBox->setTitle(tr("SMESH_SELECTION"));
126 aLabel = new QLabel(aSelectBox, "selection color label");
127 aLabel->setText(tr("SMESH_OUTLINE_COLOR"));
128 myColor[2] = new QPushButton(aSelectBox, "outline color");
129 myColor[2]->setFixedSize(QSize(25, 25));
131 aSelectBox->addSpace(0);
132 aSelectBox->addSpace(0);
134 aLabel = new QLabel(aSelectBox, "selection color label");
135 aLabel->setText(tr("SMESH_ELEMENTS_COLOR"));
136 myColor[1] = new QPushButton(aSelectBox, "elements color");
137 myColor[1]->setFixedSize(QSize(25, 25));
139 aLabel = new QLabel(aSelectBox, "selection width label");
140 aLabel->setText(tr("SMESH_WIDTH"));
141 myWidth[1] = new QSpinBox(0, 5, 1, aSelectBox, "selection width");
142 myWidth[1]->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
143 myWidth[1]->setButtonSymbols(QSpinBox::PlusMinus);
144 myWidth[1]->setMinimumWidth(50);
146 /***************************************************************/
147 QGroupBox* aPreSelectBox = new QGroupBox(1, Qt::Vertical, this, "preselection");
148 aPreSelectBox->setTitle(tr("SMESH_PRESELECTION"));
150 aLabel = new QLabel(aPreSelectBox, "preselection color label");
151 aLabel->setText(tr("SMESH_HILIGHT_COLOR"));
152 myColor[0] = new QPushButton(aPreSelectBox, "preselection color");
153 myColor[0]->setFixedSize(QSize(25, 25));
155 aLabel = new QLabel(aPreSelectBox, "preselection width label");
156 aLabel->setText(tr("SMESH_WIDTH"));
157 myWidth[0] = new QSpinBox(0, 5, 1, aPreSelectBox, "preselection width");
158 myWidth[0]->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
159 myWidth[0]->setButtonSymbols(QSpinBox::PlusMinus);
160 myWidth[0]->setMinimumWidth(50);
162 /***************************************************************/
163 QGroupBox* aPrecisionBox = new QGroupBox(1, Qt::Vertical, this, "preselection");
164 aPrecisionBox->setTitle(tr("SMESH_PRECISION"));
165 QDoubleValidator* aValidator = new SMESHGUI_DoubleValidator(aPrecisionBox);
166 aValidator->setBottom(0.001);
167 aValidator->setDecimals(6);
169 aLabel = new QLabel(aPrecisionBox, "node tol label");
170 aLabel->setText(tr("SMESH_NODES"));
171 myPrecision[0] = new SMESHGUI_LineEdit(aPrecisionBox, "node precision");
172 myPrecision[0]->setValidator(aValidator);
174 aLabel = new QLabel(aPrecisionBox, "item tol label");
175 aLabel->setText(tr("SMESH_ELEMENTS"));
176 myPrecision[1] = new SMESHGUI_LineEdit(aPrecisionBox, "item precision");
177 myPrecision[1]->setValidator(aValidator);
179 /***************************************************************/
180 QFrame* aButtons = new QFrame(this, "button box");
181 aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
182 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
183 aBtnLayout->setAutoAdd(false);
185 QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
186 aOKBtn->setText(tr("SMESH_BUT_OK"));
187 aOKBtn->setAutoDefault(true);
188 aOKBtn->setDefault(true);
189 QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
190 aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
191 aCloseBtn->setAutoDefault(true);
193 aBtnLayout->addWidget(aOKBtn);
194 aBtnLayout->addStretch();
195 aBtnLayout->addWidget(aCloseBtn);
197 /***************************************************************/
198 aMainLayout->addWidget(aSelectBox);
199 aMainLayout->addWidget(aPreSelectBox);
200 aMainLayout->addWidget(aPrecisionBox);
201 aMainLayout->addWidget(aButtons);
203 for (int i = 0; i < 3; i++)
204 connect(myColor[i], SIGNAL(clicked()), this, SLOT(onSelectColor()));
206 connect(aOKBtn, SIGNAL(clicked()), this, SLOT(accept()));
207 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
209 /* Move widget on the botton right corner of main widget */
211 mySMESHGUI->DefineDlgPosition(this, x, y);
215 //=================================================================================
216 // function : ~SMESHGUI_Preferences_SelectionDlg()
217 // purpose : Destroys the object and frees any allocated resources
218 //=================================================================================
219 SMESHGUI_Preferences_SelectionDlg::~SMESHGUI_Preferences_SelectionDlg()
221 // no need to delete child widgets, Qt does it all for us
224 //=================================================================================
225 // function : closeEvent()
227 //=================================================================================
228 void SMESHGUI_Preferences_SelectionDlg::closeEvent( QCloseEvent* e )
233 //=================================================================================
234 // function : onSelectColor()
236 //=================================================================================
237 void SMESHGUI_Preferences_SelectionDlg::onSelectColor()
239 QPushButton* aSender = (QPushButton*)sender();
240 QColor aColor = aSender->palette().active().button();
241 aColor = QColorDialog::getColor(aColor, this);
242 if (aColor.isValid()) {
243 QPalette aPal = aSender->palette();
244 aPal.setColor(QColorGroup::Button, aColor);
245 aSender->setPalette(aPal);
249 //=================================================================================
250 // function : SetColor()
252 //=================================================================================
253 void SMESHGUI_Preferences_SelectionDlg::SetColor(int type, QColor color)
255 if (type > 0 && type <= 3) {
256 QPalette aPal = myColor[type-1]->palette();
257 aPal.setColor(QColorGroup::Button, color);
258 myColor[type-1]->setPalette(aPal);
262 //=================================================================================
263 // function : GetColor()
265 //=================================================================================
266 QColor SMESHGUI_Preferences_SelectionDlg::GetColor(int type)
269 if (type > 0 && type <= 3)
270 aColor = myColor[type-1]->palette().active().button();
274 //=================================================================================
275 // function : SetWidth()
277 //=================================================================================
278 void SMESHGUI_Preferences_SelectionDlg::SetWidth(int type, int value)
280 if (type > 0 && type <= 2)
281 myWidth[type-1]->setValue(value);
284 //=================================================================================
285 // function : GetWidth()
287 //=================================================================================
288 int SMESHGUI_Preferences_SelectionDlg::GetWidth(int type)
290 if (type > 0 && type <= 2)
291 return myWidth[type-1]->value();
295 //=================================================================================
296 // function : SetPrecision()
298 //=================================================================================
299 void SMESHGUI_Preferences_SelectionDlg::SetPrecision(int type, double value)
301 if (type > 0 && type <= 2)
302 myPrecision[type-1]->setText(QString::number(value));
305 //=================================================================================
306 // function : GetPrecision()
308 //=================================================================================
309 double SMESHGUI_Preferences_SelectionDlg::GetPrecision(int type)
311 if (type > 0 && type <= 2)
312 return myPrecision[type-1]->text().toDouble();