]> SALOME platform Git repositories - modules/visu.git/blob - src/VVTK/VVTK_SizeBox.cxx
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/visu.git] / src / VVTK / VVTK_SizeBox.cxx
1 //  VISU VISUGUI : GUI of VISU 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.com
21 //
22 //
23 //
24 //  File   : VVTK_SizeBox.cxx
25 //  Author : Oleg UVAROV
26 //  Module : VISU
27
28 #include "VVTK_SizeBox.h"
29
30 #include "SUIT_ResourceMgr.h"
31 #include "SUIT_Session.h"
32
33 #include "QtxDblSpinBox.h"
34 #include "QtxIntSpinBox.h"
35
36 #include <qlayout.h>
37 #include <qlabel.h>
38 #include <qlineedit.h>
39 #include <qcheckbox.h>
40 #include <qgroupbox.h>
41 #include <qbuttongroup.h>
42 #include <qradiobutton.h>
43 #include <qpushbutton.h>
44 #include <qcolordialog.h>
45
46 using namespace std;
47
48 VVTK_SizeBox::VVTK_SizeBox( QWidget* parent ) :
49   QVBox( parent )
50 {
51   layout()->setSpacing( 0 );
52   layout()->setMargin( 0 );
53
54   // Size
55   QGroupBox* SizeGroup = new QGroupBox ( tr( "SIZE_TITLE" ), this, "SizeGroup" );
56   SizeGroup->setColumnLayout(0, Qt::Vertical );
57   SizeGroup->layout()->setSpacing( 0 );
58   SizeGroup->layout()->setMargin( 0 );
59
60   QGridLayout* SizeGroupLayout = new QGridLayout (SizeGroup->layout());
61   SizeGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
62   SizeGroupLayout->setSpacing(6);
63   SizeGroupLayout->setMargin(11);
64
65   // Outside Size
66   myOutsideSizeLabel = new QLabel( tr( "OUTSIDE_SIZE" ), SizeGroup );
67   myOutsideSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
68   myOutsideSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
69
70   SizeGroupLayout->addWidget( myOutsideSizeLabel, 0, 0 );
71   SizeGroupLayout->addWidget( myOutsideSizeSpinBox, 0, 1 );
72
73   // Geometry Size
74   myGeomSizeLabel = new QLabel( tr( "GEOM_SIZE" ), SizeGroup );
75   myGeomSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
76   myGeomSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
77
78   SizeGroupLayout->addWidget( myGeomSizeLabel, 0, 0 );
79   SizeGroupLayout->addWidget( myGeomSizeSpinBox, 0, 1 );
80
81   // Min Size
82   myMinSizeLabel = new QLabel( tr( "MIN_SIZE" ), SizeGroup );
83   myMinSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
84   myMinSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
85
86   SizeGroupLayout->addWidget( myMinSizeLabel, 1, 0 );
87   SizeGroupLayout->addWidget( myMinSizeSpinBox, 1, 1 );
88
89   // Max Size
90   myMaxSizeLabel = new QLabel( tr( "MAX_SIZE" ), SizeGroup );
91   myMaxSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
92   myMaxSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
93
94   SizeGroupLayout->addWidget( myMaxSizeLabel, 1, 2 );
95   SizeGroupLayout->addWidget( myMaxSizeSpinBox, 1, 3 );
96
97   // Magnification
98   myMagnificationLabel = new QLabel( tr( "MAGNIFICATION" ), SizeGroup );
99   myMagnificationSpinBox = new QtxIntSpinBox( 1, 10000, 10, SizeGroup );
100   myMagnificationSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
101
102   SizeGroupLayout->addWidget( myMagnificationLabel, 2, 0 );
103   SizeGroupLayout->addWidget( myMagnificationSpinBox, 2, 1 );
104
105   // Increment
106   myIncrementLabel = new QLabel( tr( "INCREMENT" ), SizeGroup );
107   myIncrementSpinBox = new QtxDblSpinBox( 0.01, 10, 0.1, SizeGroup );
108   myIncrementSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
109
110   SizeGroupLayout->addWidget( myIncrementLabel, 2, 2 );
111   SizeGroupLayout->addWidget( myIncrementSpinBox, 2, 3 );
112
113
114   // Color
115   myColorGroup = new QGroupBox ( tr( "COLOR_TITLE" ), this, "ColorGroup" );
116   myColorGroup->setColumnLayout(0, Qt::Vertical );
117   myColorGroup->layout()->setSpacing( 0 );
118   myColorGroup->layout()->setMargin( 0 );
119
120   QGridLayout* ColorGroupLayout = new QGridLayout (myColorGroup->layout());
121   ColorGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
122   ColorGroupLayout->setSpacing(6);
123   ColorGroupLayout->setMargin(11);
124
125   myUniformCheckBox = new QCheckBox( tr( "UNIFORM_COLOR" ), myColorGroup );
126
127   myColorLabel = new QLabel( tr( "COLOR" ), myColorGroup );
128   myColorButton = new QPushButton( myColorGroup );
129
130   ColorGroupLayout->addWidget( myUniformCheckBox, 0, 0 );
131   ColorGroupLayout->addWidget( myColorLabel, 0, 1 );
132   ColorGroupLayout->addWidget( myColorButton, 0, 2 );
133
134   connect( myUniformCheckBox, SIGNAL( toggled( bool ) ), myColorButton, SLOT( setEnabled( bool ) ) );
135   connect( myColorButton, SIGNAL( clicked() ), this, SLOT( onColorButtonPressed() ) );
136
137   setType( VVTK_SizeBox::Results );
138 }
139
140 void VVTK_SizeBox::onToggleResults()
141 {
142   myType = VVTK_SizeBox::Results;
143
144   myOutsideSizeLabel->hide();
145   myOutsideSizeSpinBox->hide();
146
147   myGeomSizeLabel->hide();
148   myGeomSizeSpinBox->hide();
149
150   myMinSizeLabel->show();
151   myMinSizeSpinBox->show();
152
153   myMaxSizeLabel->show();
154   myMaxSizeSpinBox->show();
155
156   myMagnificationLabel->show();
157   myMagnificationSpinBox->show();
158
159   myIncrementLabel->show();
160   myIncrementSpinBox->show();
161
162   myColorGroup->hide();
163
164   myUniformCheckBox->hide();
165 }
166
167 void VVTK_SizeBox::onToggleGeometry()
168 {
169   myType = VVTK_SizeBox::Geometry;
170
171   myOutsideSizeLabel->hide();
172   myOutsideSizeSpinBox->hide();
173
174   myGeomSizeLabel->show();
175   myGeomSizeSpinBox->show();
176
177   myMinSizeLabel->hide();
178   myMinSizeSpinBox->hide();
179
180   myMaxSizeLabel->hide();
181   myMaxSizeSpinBox->hide();
182
183   myMagnificationLabel->show();
184   myMagnificationSpinBox->show();
185
186   myIncrementLabel->show();
187   myIncrementSpinBox->show();
188
189   myColorGroup->show();
190
191   myUniformCheckBox->hide();
192 }
193
194 void VVTK_SizeBox::onToggleInside()
195 {
196   myType = VVTK_SizeBox::Inside;
197
198   myOutsideSizeLabel->hide();
199   myOutsideSizeSpinBox->hide();
200
201   myGeomSizeLabel->hide();
202   myGeomSizeSpinBox->hide();
203
204   myMinSizeLabel->show();
205   myMinSizeSpinBox->show();
206
207   myMaxSizeLabel->show();
208   myMaxSizeSpinBox->show();
209
210   myMagnificationLabel->hide();
211   myMagnificationSpinBox->hide();
212
213   myIncrementLabel->hide();
214   myIncrementSpinBox->hide();
215
216   myColorGroup->hide();
217
218   myUniformCheckBox->hide();
219 }
220
221 void VVTK_SizeBox::onToggleOutside()
222 {
223   myType = VVTK_SizeBox::Outside;
224
225   myOutsideSizeLabel->show();
226   myOutsideSizeSpinBox->show();
227
228   myGeomSizeLabel->hide();
229   myGeomSizeSpinBox->hide();
230
231   myMinSizeLabel->hide();
232   myMinSizeSpinBox->hide();
233
234   myMaxSizeLabel->hide();
235   myMaxSizeSpinBox->hide();
236
237   myMagnificationLabel->hide();
238   myMagnificationSpinBox->hide();
239
240   myIncrementLabel->hide();
241   myIncrementSpinBox->hide();
242
243   myColorGroup->show();
244
245   myUniformCheckBox->show();
246 }
247
248 void VVTK_SizeBox::setType( int theType )
249 {
250   myType = theType;
251
252   switch( myType )
253   {
254     case VVTK_SizeBox::Results  : onToggleResults(); break;
255     case VVTK_SizeBox::Geometry : onToggleGeometry(); break;
256     case VVTK_SizeBox::Inside   : onToggleInside();  break;
257     case VVTK_SizeBox::Outside  : onToggleOutside();  break;
258     default : break;
259   }
260 }
261
262 float VVTK_SizeBox::getOutsideSize() const
263 {
264   return myOutsideSizeSpinBox->value() / 100.0;
265 }
266
267 void VVTK_SizeBox::setOutsideSize( float theOutsideSize )
268 {
269   myOutsideSizeSpinBox->setValue( ( int )( theOutsideSize * 100 ) );
270 }
271
272 float VVTK_SizeBox::getGeomSize() const
273 {
274   return myGeomSizeSpinBox->value() / 100.0;
275 }
276
277 void VVTK_SizeBox::setGeomSize( float theGeomSize )
278 {
279   myGeomSizeSpinBox->setValue( ( int )( theGeomSize * 100 ) );
280 }
281
282 float VVTK_SizeBox::getMinSize() const
283 {
284   return myMinSizeSpinBox->value() / 100.0;
285 }
286
287 void VVTK_SizeBox::setMinSize( float theMinSize )
288 {
289   myMinSizeSpinBox->setValue( ( int )( theMinSize * 100 ) );
290 }
291
292 float VVTK_SizeBox::getMaxSize() const
293 {
294   return myMaxSizeSpinBox->value() / 100.0;
295 }
296
297 void VVTK_SizeBox::setMaxSize( float theMaxSize )
298 {
299   myMaxSizeSpinBox->setValue( ( int )( theMaxSize * 100 ) );
300 }
301
302 float VVTK_SizeBox::getMagnification() const
303 {
304   return myMagnificationSpinBox->value() / 100.0;
305 }
306
307 void VVTK_SizeBox::setMagnification( float theMagnification )
308 {
309   myMagnificationSpinBox->setValue( ( int )( theMagnification * 100 ) );
310 }
311
312 float VVTK_SizeBox::getIncrement() const
313 {
314   return myIncrementSpinBox->value();
315 }
316
317 void VVTK_SizeBox::setIncrement( float theIncrement )
318 {
319   myIncrementSpinBox->setValue( theIncrement );
320 }
321
322 bool VVTK_SizeBox::getUniform() const
323 {
324   return myUniformCheckBox->isChecked();
325 }
326
327 void VVTK_SizeBox::setUniform( bool theUniform )
328 {
329   myUniformCheckBox->setChecked( theUniform );
330   myColorButton->setEnabled( theUniform );
331 }
332
333 QColor VVTK_SizeBox::getColor() const
334 {
335   return myColorButton->paletteBackgroundColor();
336 }
337
338 void VVTK_SizeBox::setColor( const QColor& theColor )
339 {
340   myColorButton->setPaletteBackgroundColor( theColor );
341 }
342
343 void VVTK_SizeBox::onColorButtonPressed()
344 {
345   QColor aColor = QColorDialog::getColor( myColorButton->paletteBackgroundColor(), this );
346   if( aColor.isValid() )
347     myColorButton->setPaletteBackgroundColor( aColor );
348 }