Salome HOME
[Bug PAL7444] display mesh takes a lot of more memory in 2.1.0 than in 2.0.0.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Preferences_SelectionDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_Preferences_SelectionDlg.cxx
25 //  Author : Natalia KOPNOVA
26 //  Module : SMESH
27 //  $Header$
28
29 #include "SMESHGUI_Preferences_SelectionDlg.h"
30 #include "SMESHGUI.h"
31
32 #include <qgroupbox.h>
33 #include <qlayout.h>
34 #include <qlabel.h>
35 #include <qlineedit.h>
36 #include <qvalidator.h>
37 #include <qspinbox.h>
38 #include <qpushbutton.h>
39 #include <qpalette.h>
40 #include <qcolordialog.h>
41
42 using namespace std;
43
44 //=================================================================================
45 // class    : SMESHGUI_LineEdit
46 // purpose  : 
47 //=================================================================================
48 SMESHGUI_LineEdit::SMESHGUI_LineEdit(QWidget* parent, const char *name)
49   : QLineEdit(parent, name)
50 {
51 }
52
53 SMESHGUI_LineEdit::SMESHGUI_LineEdit(const QString& text, QWidget* parent, const char *name)
54   : QLineEdit(text, parent, name)
55 {
56 }
57
58 void SMESHGUI_LineEdit::focusOutEvent(QFocusEvent* e)
59 {
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;
65     aVal->fixup(aValid);
66     if (aText != aValid) {
67       setText(aValid);
68       update();
69       return;
70     }
71   }
72   QLineEdit::focusOutEvent(e);
73 }
74
75
76 //=================================================================================
77 // class    : SMESHGUI_DoubleValidator
78 // purpose  : 
79 //=================================================================================
80 SMESHGUI_DoubleValidator::SMESHGUI_DoubleValidator(QObject * parent, const char *name)
81   : QDoubleValidator(parent, name)
82 {
83 }
84
85 SMESHGUI_DoubleValidator::SMESHGUI_DoubleValidator(double bottom, double top, int decimals,
86                                                  QObject * parent, const char *name)
87   : QDoubleValidator(bottom, top, decimals, parent, name)
88 {
89 }
90
91 void SMESHGUI_DoubleValidator::fixup(QString& theText) const
92 {
93   bool ok;
94   double aValue = theText.toDouble(&ok);
95   if (ok) {
96     if (aValue < bottom())
97       theText = QString::number(bottom(), 'g', decimals());
98     if (aValue > top())
99       theText = QString::number(top(), 'g', decimals());
100   }
101 }
102
103
104 //=================================================================================
105 // class    : SMESHGUI_Preferences_SelectionDlg()
106 // purpose  : 
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 )
110 {
111   if ( !name ) setName( "SMESHGUI_Preferences_SelectionDlg" );
112   setCaption( tr( "SMESH_PREF_SELECTION"  ) );
113
114   QVBoxLayout* aMainLayout = new QVBoxLayout(this, 11, 6);
115   QLabel* aLabel;
116   
117   /***************************************************************/
118   QGroupBox* aSelectBox = new QGroupBox(4, Qt::Horizontal, this, "selection");
119   aSelectBox->setTitle(tr("SMESH_SELECTION"));
120
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));
125
126   aSelectBox->addSpace(0);
127   aSelectBox->addSpace(0);
128
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));
133
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);
140   
141   /***************************************************************/
142   QGroupBox* aPreSelectBox = new QGroupBox(1, Qt::Vertical, this, "preselection");
143   aPreSelectBox->setTitle(tr("SMESH_PRESELECTION"));
144
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));
149
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);
156   
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);
163
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);
168
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);
173
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);
179
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);
187
188   aBtnLayout->addWidget(aOKBtn);
189   aBtnLayout->addStretch();
190   aBtnLayout->addWidget(aCloseBtn);
191
192   /***************************************************************/
193   aMainLayout->addWidget(aSelectBox);
194   aMainLayout->addWidget(aPreSelectBox);
195   aMainLayout->addWidget(aPrecisionBox);
196   aMainLayout->addWidget(aButtons);
197
198   for (int i = 0; i < 3; i++)
199     connect(myColor[i], SIGNAL(clicked()), this, SLOT(onSelectColor()));
200
201   connect(aOKBtn, SIGNAL(clicked()), this, SLOT(accept()));
202   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
203
204   /* Move widget on the botton right corner of main widget */
205   int x, y ;
206   SMESHGUI::GetSMESHGUI()->DefineDlgPosition(this, x, y);
207   this->move(x, y);
208 }
209
210 //=================================================================================
211 // function : ~SMESHGUI_Preferences_SelectionDlg()
212 // purpose  : Destroys the object and frees any allocated resources
213 //=================================================================================
214 SMESHGUI_Preferences_SelectionDlg::~SMESHGUI_Preferences_SelectionDlg()
215 {
216     // no need to delete child widgets, Qt does it all for us
217 }
218
219 //=================================================================================
220 // function : closeEvent()
221 // purpose  :
222 //=================================================================================
223 void SMESHGUI_Preferences_SelectionDlg::closeEvent( QCloseEvent* e )
224 {
225   reject();
226 }
227
228 //=================================================================================
229 // function : onSelectColor()
230 // purpose  :
231 //=================================================================================
232 void SMESHGUI_Preferences_SelectionDlg::onSelectColor()
233 {
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);
241   }
242 }
243
244 //=================================================================================
245 // function : SetColor()
246 // purpose  :
247 //=================================================================================
248 void SMESHGUI_Preferences_SelectionDlg::SetColor(int type, QColor color)
249 {
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);
254  }
255 }
256
257 //=================================================================================
258 // function : GetColor()
259 // purpose  :
260 //=================================================================================
261 QColor SMESHGUI_Preferences_SelectionDlg::GetColor(int type)
262 {
263   QColor aColor;
264   if (type > 0 && type <= 3)
265     aColor = myColor[type-1]->palette().active().button();
266   return aColor;
267 }
268
269 //=================================================================================
270 // function : SetWidth()
271 // purpose  :
272 //=================================================================================
273 void SMESHGUI_Preferences_SelectionDlg::SetWidth(int type, int value)
274 {
275   if (type > 0 && type <= 2)
276     myWidth[type-1]->setValue(value);
277 }
278
279 //=================================================================================
280 // function : GetWidth()
281 // purpose  :
282 //=================================================================================
283 int SMESHGUI_Preferences_SelectionDlg::GetWidth(int type)
284 {
285   if (type > 0 && type <= 2)
286     return myWidth[type-1]->value();
287   return 0;
288 }
289
290 //=================================================================================
291 // function : SetPrecision()
292 // purpose  :
293 //=================================================================================
294 void SMESHGUI_Preferences_SelectionDlg::SetPrecision(int type, double value)
295 {
296   if (type > 0 && type <= 2)
297     myPrecision[type-1]->setText(QString::number(value));
298 }
299
300 //=================================================================================
301 // function : GetPrecision()
302 // purpose  :
303 //=================================================================================
304 double SMESHGUI_Preferences_SelectionDlg::GetPrecision(int type)
305 {
306   if (type > 0 && type <= 2)
307     return myPrecision[type-1]->text().toDouble();
308   return 0;
309 }