Salome HOME
Update copyright information
[modules/visu.git] / src / VISUGUI / VisuGUI_SizeBox.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  VISU VISUGUI : GUI of VISU component
21 //  File   : VisuGUI_SizeBox.cxx
22 //  Author : Oleg UVAROV
23 //  Module : VISU
24 //
25 #include "VisuGUI_SizeBox.h"
26
27 #include "VisuGUI_Tools.h"
28
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Session.h>
31
32 #include <SalomeApp_DoubleSpinBox.h>
33 #include <SalomeApp_IntSpinBox.h>
34 #include <QtxColorButton.h>
35
36 #include <QLayout>
37 #include <QLabel>
38 #include <QLineEdit>
39 #include <QCheckBox>
40 #include <QGroupBox>
41 #include <QButtonGroup>
42 #include <QRadioButton>
43 #include <QPushButton>
44 #include <QColorDialog>
45
46 using namespace std;
47
48 VisuGUI_SizeBox::VisuGUI_SizeBox( QWidget* parent ) :
49   QWidget( parent )
50 {
51   QVBoxLayout* aMainLayout = new QVBoxLayout( this );
52   aMainLayout->setSpacing( 0 );
53   aMainLayout->setMargin( 0 );
54
55   // Size
56   QGroupBox* SizeGroup = new QGroupBox ( tr( "SIZE_TITLE" ), this );
57   //SizeGroup->setColumnLayout(0, Qt::Vertical );
58   //SizeGroup->layout()->setSpacing( 0 );
59   //SizeGroup->layout()->setMargin( 0 );
60
61   QGridLayout* SizeGroupLayout = new QGridLayout (SizeGroup);
62   SizeGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
63   SizeGroupLayout->setSpacing(6);
64   SizeGroupLayout->setMargin(11);
65
66   // Outside Size
67   myOutsideSizeLabel = new QLabel( tr( "OUTSIDE_SIZE" ), SizeGroup );
68   myOutsideSizeSpinBox = new SalomeApp_IntSpinBox( SizeGroup );
69   VISU::initSpinBox( myOutsideSizeSpinBox, 0, 100, 1 );
70   myOutsideSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
71
72   SizeGroupLayout->addWidget( myOutsideSizeLabel, 0, 0 );
73   SizeGroupLayout->addWidget( myOutsideSizeSpinBox, 0, 1 );
74
75   // Geometry Size
76   myGeomSizeLabel = new QLabel( tr( "GEOM_SIZE" ), SizeGroup );
77   myGeomSizeSpinBox = new SalomeApp_IntSpinBox( SizeGroup );
78   VISU::initSpinBox( myGeomSizeSpinBox, 0, 100, 1 );  
79   myGeomSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
80
81   SizeGroupLayout->addWidget( myGeomSizeLabel, 0, 0 );
82   SizeGroupLayout->addWidget( myGeomSizeSpinBox, 0, 1 );
83
84   // Min Size
85   myMinSizeLabel = new QLabel( tr( "MIN_SIZE" ), SizeGroup );
86   myMinSizeSpinBox = new SalomeApp_IntSpinBox( SizeGroup );
87   VISU::initSpinBox( myMinSizeSpinBox, 0, 100, 1 );
88   myMinSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
89
90   SizeGroupLayout->addWidget( myMinSizeLabel, 1, 0 );
91   SizeGroupLayout->addWidget( myMinSizeSpinBox, 1, 1 );
92
93   // Max Size
94   myMaxSizeLabel = new QLabel( tr( "MAX_SIZE" ), SizeGroup );
95   myMaxSizeSpinBox = new SalomeApp_IntSpinBox( SizeGroup );
96   VISU::initSpinBox( myMaxSizeSpinBox, 0, 100, 1 );
97   myMaxSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
98
99   SizeGroupLayout->addWidget( myMaxSizeLabel, 1, 2 );
100   SizeGroupLayout->addWidget( myMaxSizeSpinBox, 1, 3 );
101
102   // Magnification
103   myMagnificationLabel = new QLabel( tr( "MAGNIFICATION" ), SizeGroup );
104   myMagnificationSpinBox = new SalomeApp_IntSpinBox( SizeGroup );
105   VISU::initSpinBox( myMagnificationSpinBox, 1, 10000, 10 );  
106   myMagnificationSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
107
108   SizeGroupLayout->addWidget( myMagnificationLabel, 2, 0 );
109   SizeGroupLayout->addWidget( myMagnificationSpinBox, 2, 1 );
110
111   // Increment
112   myIncrementLabel = new QLabel( tr( "INCREMENT" ), SizeGroup );
113   myIncrementSpinBox = new SalomeApp_DoubleSpinBox( SizeGroup );
114   VISU::initSpinBox( myIncrementSpinBox, 0.01, 10, 0.1, "parametric_precision" );
115   myIncrementSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
116
117   SizeGroupLayout->addWidget( myIncrementLabel, 2, 2 );
118   SizeGroupLayout->addWidget( myIncrementSpinBox, 2, 3 );
119
120   aMainLayout->addWidget( SizeGroup );
121
122   // Color
123   myColorGroup = new QGroupBox ( tr( "COLOR_TITLE" ), this );
124   //myColorGroup->setColumnLayout(0, Qt::Vertical );
125   //myColorGroup->layout()->setSpacing( 0 );
126   //myColorGroup->layout()->setMargin( 0 );
127
128   QGridLayout* ColorGroupLayout = new QGridLayout ( myColorGroup );
129   ColorGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
130   ColorGroupLayout->setSpacing(6);
131   ColorGroupLayout->setMargin(11);
132
133   myUniformCheckBox = new QCheckBox( tr( "UNIFORM_COLOR" ), myColorGroup );
134
135   myColorLabel = new QLabel( tr( "COLOR" ), myColorGroup );
136   myColorButton = new QtxColorButton( myColorGroup );
137
138   ColorGroupLayout->addWidget( myUniformCheckBox, 0, 0 );
139   ColorGroupLayout->addWidget( myColorLabel, 0, 1 );
140   ColorGroupLayout->addWidget( myColorButton, 0, 2 );
141
142   aMainLayout->addWidget( myColorGroup );
143
144   connect( myUniformCheckBox, SIGNAL( toggled( bool ) ), myColorButton, SLOT( setEnabled( bool ) ) );
145   //connect( myColorButton, SIGNAL( clicked() ), this, SLOT( onColorButtonPressed() ) );
146
147   setType( VisuGUI_SizeBox::Results );
148 }
149
150 void VisuGUI_SizeBox::onToggleResults()
151 {
152   myType = VisuGUI_SizeBox::Results;
153
154   myOutsideSizeLabel->hide();
155   myOutsideSizeSpinBox->hide();
156
157   myGeomSizeLabel->hide();
158   myGeomSizeSpinBox->hide();
159
160   myMinSizeLabel->show();
161   myMinSizeSpinBox->show();
162
163   myMaxSizeLabel->show();
164   myMaxSizeSpinBox->show();
165
166   myMagnificationLabel->show();
167   myMagnificationSpinBox->show();
168
169   myIncrementLabel->show();
170   myIncrementSpinBox->show();
171
172   myColorGroup->hide();
173
174   myUniformCheckBox->hide();
175 }
176
177 void VisuGUI_SizeBox::onToggleGeometry()
178 {
179   myType = VisuGUI_SizeBox::Geometry;
180
181   myOutsideSizeLabel->hide();
182   myOutsideSizeSpinBox->hide();
183
184   myGeomSizeLabel->show();
185   myGeomSizeSpinBox->show();
186
187   myMinSizeLabel->hide();
188   myMinSizeSpinBox->hide();
189
190   myMaxSizeLabel->hide();
191   myMaxSizeSpinBox->hide();
192
193   myMagnificationLabel->show();
194   myMagnificationSpinBox->show();
195
196   myIncrementLabel->show();
197   myIncrementSpinBox->show();
198
199   myColorGroup->show();
200
201   myUniformCheckBox->hide();
202 }
203
204 void VisuGUI_SizeBox::onToggleInside()
205 {
206   myType = VisuGUI_SizeBox::Inside;
207
208   myOutsideSizeLabel->hide();
209   myOutsideSizeSpinBox->hide();
210
211   myGeomSizeLabel->hide();
212   myGeomSizeSpinBox->hide();
213
214   myMinSizeLabel->show();
215   myMinSizeSpinBox->show();
216
217   myMaxSizeLabel->show();
218   myMaxSizeSpinBox->show();
219
220   myMagnificationLabel->hide();
221   myMagnificationSpinBox->hide();
222
223   myIncrementLabel->hide();
224   myIncrementSpinBox->hide();
225
226   myColorGroup->hide();
227
228   myUniformCheckBox->hide();
229 }
230
231 void VisuGUI_SizeBox::onToggleOutside()
232 {
233   myType = VisuGUI_SizeBox::Outside;
234
235   myOutsideSizeLabel->show();
236   myOutsideSizeSpinBox->show();
237
238   myGeomSizeLabel->hide();
239   myGeomSizeSpinBox->hide();
240
241   myMinSizeLabel->hide();
242   myMinSizeSpinBox->hide();
243
244   myMaxSizeLabel->hide();
245   myMaxSizeSpinBox->hide();
246
247   myMagnificationLabel->hide();
248   myMagnificationSpinBox->hide();
249
250   myIncrementLabel->hide();
251   myIncrementSpinBox->hide();
252
253   myColorGroup->show();
254
255   myUniformCheckBox->show();
256 }
257
258 void VisuGUI_SizeBox::setType( int theType )
259 {
260   myType = theType;
261
262   switch( myType )
263   {
264     case VisuGUI_SizeBox::Results  : onToggleResults(); break;
265     case VisuGUI_SizeBox::Geometry : onToggleGeometry(); break;
266     case VisuGUI_SizeBox::Inside   : onToggleInside();  break;
267     case VisuGUI_SizeBox::Outside  : onToggleOutside();  break;
268     default : break;
269   }
270 }
271
272 float VisuGUI_SizeBox::getOutsideSize() const
273 {
274   return myOutsideSizeSpinBox->value() / 100.0;
275 }
276
277 void VisuGUI_SizeBox::setOutsideSize( float theOutsideSize )
278 {
279   myOutsideSizeSpinBox->setValue( ( int ) ( theOutsideSize * 100. + 0.5 ) );
280 }
281
282 float VisuGUI_SizeBox::getGeomSize() const
283 {
284   return myGeomSizeSpinBox->value() / 100.0;
285 }
286
287 void VisuGUI_SizeBox::setGeomSize( float theGeomSize )
288 {
289   myGeomSizeSpinBox->setValue( ( int ) ( theGeomSize * 100. + 0.5 ) );
290 }
291
292 float VisuGUI_SizeBox::getMinSize() const
293 {
294   return myMinSizeSpinBox->value() / 100.0;
295 }
296
297 void VisuGUI_SizeBox::setMinSize( float theMinSize )
298 {
299   myMinSizeSpinBox->setValue( ( int ) ( theMinSize * 100. + 0.5 ) );
300 }
301
302 float VisuGUI_SizeBox::getMaxSize() const
303 {
304   return myMaxSizeSpinBox->value() / 100.0;
305 }
306
307 void VisuGUI_SizeBox::setMaxSize( float theMaxSize )
308 {
309   myMaxSizeSpinBox->setValue( (int) ( theMaxSize * 100. + 0.5 ) );
310 }
311
312 float VisuGUI_SizeBox::getMagnification() const
313 {
314   return myMagnificationSpinBox->value() / 100.0;
315 }
316
317 void VisuGUI_SizeBox::setMagnification( float theMagnification )
318 {
319   myMagnificationSpinBox->setValue( (int) ( theMagnification * 100. + 0.5 ) );
320 }
321
322 float VisuGUI_SizeBox::getIncrement() const
323 {
324   return myIncrementSpinBox->value();
325 }
326
327 void VisuGUI_SizeBox::setIncrement( float theIncrement )
328 {
329   myIncrementSpinBox->setValue( theIncrement );
330 }
331
332 bool VisuGUI_SizeBox::getUniform() const
333 {
334   return myUniformCheckBox->isChecked();
335 }
336
337 void VisuGUI_SizeBox::setUniform( bool theUniform )
338 {
339   myUniformCheckBox->setChecked( theUniform );
340   myColorButton->setEnabled( theUniform );
341 }
342
343 QColor VisuGUI_SizeBox::getColor() const
344 {
345   return myColorButton->color();//palette().color( myColorButton->backgroundRole() );
346   //return myColorButton->paletteBackgroundColor();
347 }
348
349 void VisuGUI_SizeBox::setColor( const QColor& theColor )
350 {
351   if ( theColor.isValid() )
352   {
353     //QPalette aPalette( myColorButton->palette() );
354     //aPalette.setColor( myColorButton->backgroundRole(), theColor );
355     myColorButton->setColor( theColor );
356   }
357   //myColorButton->setPaletteBackgroundColor( theColor );
358 }
359
360 void VisuGUI_SizeBox::enableSizeControls( bool enabled )
361 {
362   myMagnificationSpinBox->setEnabled( enabled );
363   myMaxSizeSpinBox->setEnabled( enabled );
364   myMinSizeSpinBox->setEnabled( enabled );
365   myIncrementSpinBox->setEnabled( enabled );
366   myGeomSizeSpinBox->setEnabled( enabled );
367 }
368
369 /*void VisuGUI_SizeBox::onColorButtonPressed()
370 {
371   QPalette aPalette( myColorButton->palette() );
372   QColor aColor = QColorDialog::
373     getColor( aPalette.color(myColorButton->backgroundRole() ), this );
374
375   if( aColor.isValid() )
376   {
377       aPalette.setColor( myColorButton->backgroundRole(), aColor );
378       myColorButton->setPalette( aPalette );
379   }
380 }*/