]> SALOME platform Git repositories - modules/visu.git/blob - src/VVTK/VVTK_SizeBox.cxx
Salome HOME
7d040131396351c969e42fa9f3c0e52b35978fc4
[modules/visu.git] / src / VVTK / VVTK_SizeBox.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 //  VISU VISUGUI : GUI of VISU component
23 //  File   : VVTK_SizeBox.cxx
24 //  Author : Oleg UVAROV
25 //  Module : VISU
26 //
27 #include "VVTK_SizeBox.h"
28
29 #include "SUIT_ResourceMgr.h"
30 #include "SUIT_Session.h"
31
32 #include <QtxDoubleSpinBox.h>
33 #include <QtxIntSpinBox.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 VVTK_SizeBox::VVTK_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 QtxIntSpinBox( 0, 100, 1, SizeGroup );
69   myOutsideSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
70
71   SizeGroupLayout->addWidget( myOutsideSizeLabel, 0, 0 );
72   SizeGroupLayout->addWidget( myOutsideSizeSpinBox, 0, 1 );
73
74   // Geometry Size
75   myGeomSizeLabel = new QLabel( tr( "GEOM_SIZE" ), SizeGroup );
76   myGeomSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
77   myGeomSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
78
79   SizeGroupLayout->addWidget( myGeomSizeLabel, 0, 0 );
80   SizeGroupLayout->addWidget( myGeomSizeSpinBox, 0, 1 );
81
82   // Min Size
83   myMinSizeLabel = new QLabel( tr( "MIN_SIZE" ), SizeGroup );
84   myMinSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
85   myMinSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
86
87   SizeGroupLayout->addWidget( myMinSizeLabel, 1, 0 );
88   SizeGroupLayout->addWidget( myMinSizeSpinBox, 1, 1 );
89
90   // Max Size
91   myMaxSizeLabel = new QLabel( tr( "MAX_SIZE" ), SizeGroup );
92   myMaxSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
93   myMaxSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
94
95   SizeGroupLayout->addWidget( myMaxSizeLabel, 1, 2 );
96   SizeGroupLayout->addWidget( myMaxSizeSpinBox, 1, 3 );
97
98   // Magnification
99   myMagnificationLabel = new QLabel( tr( "MAGNIFICATION" ), SizeGroup );
100   myMagnificationSpinBox = new QtxIntSpinBox( 1, 10000, 10, SizeGroup );
101   myMagnificationSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
102
103   SizeGroupLayout->addWidget( myMagnificationLabel, 2, 0 );
104   SizeGroupLayout->addWidget( myMagnificationSpinBox, 2, 1 );
105
106   // Increment
107   myIncrementLabel = new QLabel( tr( "INCREMENT" ), SizeGroup );
108   myIncrementSpinBox = new QtxDoubleSpinBox( 0.01, 10, 0.1, SizeGroup );
109   myIncrementSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
110
111   SizeGroupLayout->addWidget( myIncrementLabel, 2, 2 );
112   SizeGroupLayout->addWidget( myIncrementSpinBox, 2, 3 );
113
114   aMainLayout->addWidget( SizeGroup );
115
116   // Color
117   myColorGroup = new QGroupBox ( tr( "COLOR_TITLE" ), this );
118   //myColorGroup->setColumnLayout(0, Qt::Vertical );
119   //myColorGroup->layout()->setSpacing( 0 );
120   //myColorGroup->layout()->setMargin( 0 );
121
122   QGridLayout* ColorGroupLayout = new QGridLayout ( myColorGroup );
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 QtxColorButton( myColorGroup );
131
132   ColorGroupLayout->addWidget( myUniformCheckBox, 0, 0 );
133   ColorGroupLayout->addWidget( myColorLabel, 0, 1 );
134   ColorGroupLayout->addWidget( myColorButton, 0, 2 );
135
136   aMainLayout->addWidget( myColorGroup );
137
138   connect( myUniformCheckBox, SIGNAL( toggled( bool ) ), myColorButton, SLOT( setEnabled( bool ) ) );
139   //connect( myColorButton, SIGNAL( clicked() ), this, SLOT( onColorButtonPressed() ) );
140
141   setType( VVTK_SizeBox::Results );
142 }
143
144 void VVTK_SizeBox::onToggleResults()
145 {
146   myType = VVTK_SizeBox::Results;
147
148   myOutsideSizeLabel->hide();
149   myOutsideSizeSpinBox->hide();
150
151   myGeomSizeLabel->hide();
152   myGeomSizeSpinBox->hide();
153
154   myMinSizeLabel->show();
155   myMinSizeSpinBox->show();
156
157   myMaxSizeLabel->show();
158   myMaxSizeSpinBox->show();
159
160   myMagnificationLabel->show();
161   myMagnificationSpinBox->show();
162
163   myIncrementLabel->show();
164   myIncrementSpinBox->show();
165
166   myColorGroup->hide();
167
168   myUniformCheckBox->hide();
169 }
170
171 void VVTK_SizeBox::onToggleGeometry()
172 {
173   myType = VVTK_SizeBox::Geometry;
174
175   myOutsideSizeLabel->hide();
176   myOutsideSizeSpinBox->hide();
177
178   myGeomSizeLabel->show();
179   myGeomSizeSpinBox->show();
180
181   myMinSizeLabel->hide();
182   myMinSizeSpinBox->hide();
183
184   myMaxSizeLabel->hide();
185   myMaxSizeSpinBox->hide();
186
187   myMagnificationLabel->show();
188   myMagnificationSpinBox->show();
189
190   myIncrementLabel->show();
191   myIncrementSpinBox->show();
192
193   myColorGroup->show();
194
195   myUniformCheckBox->hide();
196 }
197
198 void VVTK_SizeBox::onToggleInside()
199 {
200   myType = VVTK_SizeBox::Inside;
201
202   myOutsideSizeLabel->hide();
203   myOutsideSizeSpinBox->hide();
204
205   myGeomSizeLabel->hide();
206   myGeomSizeSpinBox->hide();
207
208   myMinSizeLabel->show();
209   myMinSizeSpinBox->show();
210
211   myMaxSizeLabel->show();
212   myMaxSizeSpinBox->show();
213
214   myMagnificationLabel->hide();
215   myMagnificationSpinBox->hide();
216
217   myIncrementLabel->hide();
218   myIncrementSpinBox->hide();
219
220   myColorGroup->hide();
221
222   myUniformCheckBox->hide();
223 }
224
225 void VVTK_SizeBox::onToggleOutside()
226 {
227   myType = VVTK_SizeBox::Outside;
228
229   myOutsideSizeLabel->show();
230   myOutsideSizeSpinBox->show();
231
232   myGeomSizeLabel->hide();
233   myGeomSizeSpinBox->hide();
234
235   myMinSizeLabel->hide();
236   myMinSizeSpinBox->hide();
237
238   myMaxSizeLabel->hide();
239   myMaxSizeSpinBox->hide();
240
241   myMagnificationLabel->hide();
242   myMagnificationSpinBox->hide();
243
244   myIncrementLabel->hide();
245   myIncrementSpinBox->hide();
246
247   myColorGroup->show();
248
249   myUniformCheckBox->show();
250 }
251
252 void VVTK_SizeBox::setType( int theType )
253 {
254   myType = theType;
255
256   switch( myType )
257   {
258     case VVTK_SizeBox::Results  : onToggleResults(); break;
259     case VVTK_SizeBox::Geometry : onToggleGeometry(); break;
260     case VVTK_SizeBox::Inside   : onToggleInside();  break;
261     case VVTK_SizeBox::Outside  : onToggleOutside();  break;
262     default : break;
263   }
264 }
265
266 float VVTK_SizeBox::getOutsideSize() const
267 {
268   return myOutsideSizeSpinBox->value() / 100.0;
269 }
270
271 void VVTK_SizeBox::setOutsideSize( float theOutsideSize )
272 {
273   myOutsideSizeSpinBox->setValue( ( int )( theOutsideSize * 100 ) );
274 }
275
276 float VVTK_SizeBox::getGeomSize() const
277 {
278   return myGeomSizeSpinBox->value() / 100.0;
279 }
280
281 void VVTK_SizeBox::setGeomSize( float theGeomSize )
282 {
283   myGeomSizeSpinBox->setValue( ( int )( theGeomSize * 100 ) );
284 }
285
286 float VVTK_SizeBox::getMinSize() const
287 {
288   return myMinSizeSpinBox->value() / 100.0;
289 }
290
291 void VVTK_SizeBox::setMinSize( float theMinSize )
292 {
293   myMinSizeSpinBox->setValue( ( int )( theMinSize * 100 ) );
294 }
295
296 float VVTK_SizeBox::getMaxSize() const
297 {
298   return myMaxSizeSpinBox->value() / 100.0;
299 }
300
301 void VVTK_SizeBox::setMaxSize( float theMaxSize )
302 {
303   myMaxSizeSpinBox->setValue( ( int )( theMaxSize * 100 ) );
304 }
305
306 float VVTK_SizeBox::getMagnification() const
307 {
308   return myMagnificationSpinBox->value() / 100.0;
309 }
310
311 void VVTK_SizeBox::setMagnification( float theMagnification )
312 {
313   myMagnificationSpinBox->setValue( ( int )( theMagnification * 100 ) );
314 }
315
316 float VVTK_SizeBox::getIncrement() const
317 {
318   return myIncrementSpinBox->value();
319 }
320
321 void VVTK_SizeBox::setIncrement( float theIncrement )
322 {
323   myIncrementSpinBox->setValue( theIncrement );
324 }
325
326 bool VVTK_SizeBox::getUniform() const
327 {
328   return myUniformCheckBox->isChecked();
329 }
330
331 void VVTK_SizeBox::setUniform( bool theUniform )
332 {
333   myUniformCheckBox->setChecked( theUniform );
334   myColorButton->setEnabled( theUniform );
335 }
336
337 QColor VVTK_SizeBox::getColor() const
338 {
339   return myColorButton->color();//palette().color( myColorButton->backgroundRole() );
340   //return myColorButton->paletteBackgroundColor();
341 }
342
343 void VVTK_SizeBox::setColor( const QColor& theColor )
344 {
345   if ( theColor.isValid() )
346   {
347     //QPalette aPalette( myColorButton->palette() );
348     //aPalette.setColor( myColorButton->backgroundRole(), theColor );
349     myColorButton->setColor( theColor );
350   }
351   //myColorButton->setPaletteBackgroundColor( theColor );
352 }
353
354 void VVTK_SizeBox::enableSizeControls( bool enabled )
355 {
356   myMagnificationSpinBox->setEnabled( enabled );
357   myMaxSizeSpinBox->setEnabled( enabled );
358   myMinSizeSpinBox->setEnabled( enabled );
359   myIncrementSpinBox->setEnabled( enabled );
360   myGeomSizeSpinBox->setEnabled( enabled );
361 }
362
363 /*void VVTK_SizeBox::onColorButtonPressed()
364 {
365   QPalette aPalette( myColorButton->palette() );
366   QColor aColor = QColorDialog::
367     getColor( aPalette.color(myColorButton->backgroundRole() ), this );
368
369   if( aColor.isValid() )
370   {
371       aPalette.setColor( myColorButton->backgroundRole(), aColor );
372       myColorButton->setPalette( aPalette );
373   }
374 }*/