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