1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : VVTK_SizeBox.cxx
25 // Author : Oleg UVAROV
28 #include "VVTK_SizeBox.h"
30 #include "SUIT_ResourceMgr.h"
31 #include "SUIT_Session.h"
33 #include "QtxDblSpinBox.h"
34 #include "QtxIntSpinBox.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>
48 VVTK_SizeBox::VVTK_SizeBox( QWidget* parent ) :
51 layout()->setSpacing( 0 );
52 layout()->setMargin( 0 );
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 );
60 QGridLayout* SizeGroupLayout = new QGridLayout (SizeGroup->layout());
61 SizeGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
62 SizeGroupLayout->setSpacing(6);
63 SizeGroupLayout->setMargin(11);
66 myOutsideSizeLabel = new QLabel( tr( "OUTSIDE_SIZE" ), SizeGroup );
67 myOutsideSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
68 myOutsideSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
70 SizeGroupLayout->addWidget( myOutsideSizeLabel, 0, 0 );
71 SizeGroupLayout->addWidget( myOutsideSizeSpinBox, 0, 1 );
74 myGeomSizeLabel = new QLabel( tr( "GEOM_SIZE" ), SizeGroup );
75 myGeomSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
76 myGeomSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
78 SizeGroupLayout->addWidget( myGeomSizeLabel, 0, 0 );
79 SizeGroupLayout->addWidget( myGeomSizeSpinBox, 0, 1 );
82 myMinSizeLabel = new QLabel( tr( "MIN_SIZE" ), SizeGroup );
83 myMinSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
84 myMinSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
86 SizeGroupLayout->addWidget( myMinSizeLabel, 1, 0 );
87 SizeGroupLayout->addWidget( myMinSizeSpinBox, 1, 1 );
90 myMaxSizeLabel = new QLabel( tr( "MAX_SIZE" ), SizeGroup );
91 myMaxSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
92 myMaxSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
94 SizeGroupLayout->addWidget( myMaxSizeLabel, 1, 2 );
95 SizeGroupLayout->addWidget( myMaxSizeSpinBox, 1, 3 );
98 myMagnificationLabel = new QLabel( tr( "MAGNIFICATION" ), SizeGroup );
99 myMagnificationSpinBox = new QtxIntSpinBox( 1, 10000, 10, SizeGroup );
100 myMagnificationSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
102 SizeGroupLayout->addWidget( myMagnificationLabel, 2, 0 );
103 SizeGroupLayout->addWidget( myMagnificationSpinBox, 2, 1 );
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 ) );
110 SizeGroupLayout->addWidget( myIncrementLabel, 2, 2 );
111 SizeGroupLayout->addWidget( myIncrementSpinBox, 2, 3 );
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 );
120 QGridLayout* ColorGroupLayout = new QGridLayout (myColorGroup->layout());
121 ColorGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
122 ColorGroupLayout->setSpacing(6);
123 ColorGroupLayout->setMargin(11);
125 myUniformCheckBox = new QCheckBox( tr( "UNIFORM_COLOR" ), myColorGroup );
127 myColorLabel = new QLabel( tr( "COLOR" ), myColorGroup );
128 myColorButton = new QPushButton( myColorGroup );
130 ColorGroupLayout->addWidget( myUniformCheckBox, 0, 0 );
131 ColorGroupLayout->addWidget( myColorLabel, 0, 1 );
132 ColorGroupLayout->addWidget( myColorButton, 0, 2 );
134 connect( myUniformCheckBox, SIGNAL( toggled( bool ) ), myColorButton, SLOT( setEnabled( bool ) ) );
135 connect( myColorButton, SIGNAL( clicked() ), this, SLOT( onColorButtonPressed() ) );
137 setType( VVTK_SizeBox::Results );
140 void VVTK_SizeBox::onToggleResults()
142 myType = VVTK_SizeBox::Results;
144 myOutsideSizeLabel->hide();
145 myOutsideSizeSpinBox->hide();
147 myGeomSizeLabel->hide();
148 myGeomSizeSpinBox->hide();
150 myMinSizeLabel->show();
151 myMinSizeSpinBox->show();
153 myMaxSizeLabel->show();
154 myMaxSizeSpinBox->show();
156 myMagnificationLabel->show();
157 myMagnificationSpinBox->show();
159 myIncrementLabel->show();
160 myIncrementSpinBox->show();
162 myColorGroup->hide();
164 myUniformCheckBox->hide();
167 void VVTK_SizeBox::onToggleGeometry()
169 myType = VVTK_SizeBox::Geometry;
171 myOutsideSizeLabel->hide();
172 myOutsideSizeSpinBox->hide();
174 myGeomSizeLabel->show();
175 myGeomSizeSpinBox->show();
177 myMinSizeLabel->hide();
178 myMinSizeSpinBox->hide();
180 myMaxSizeLabel->hide();
181 myMaxSizeSpinBox->hide();
183 myMagnificationLabel->show();
184 myMagnificationSpinBox->show();
186 myIncrementLabel->show();
187 myIncrementSpinBox->show();
189 myColorGroup->show();
191 myUniformCheckBox->hide();
194 void VVTK_SizeBox::onToggleInside()
196 myType = VVTK_SizeBox::Inside;
198 myOutsideSizeLabel->hide();
199 myOutsideSizeSpinBox->hide();
201 myGeomSizeLabel->hide();
202 myGeomSizeSpinBox->hide();
204 myMinSizeLabel->show();
205 myMinSizeSpinBox->show();
207 myMaxSizeLabel->show();
208 myMaxSizeSpinBox->show();
210 myMagnificationLabel->hide();
211 myMagnificationSpinBox->hide();
213 myIncrementLabel->hide();
214 myIncrementSpinBox->hide();
216 myColorGroup->hide();
218 myUniformCheckBox->hide();
221 void VVTK_SizeBox::onToggleOutside()
223 myType = VVTK_SizeBox::Outside;
225 myOutsideSizeLabel->show();
226 myOutsideSizeSpinBox->show();
228 myGeomSizeLabel->hide();
229 myGeomSizeSpinBox->hide();
231 myMinSizeLabel->hide();
232 myMinSizeSpinBox->hide();
234 myMaxSizeLabel->hide();
235 myMaxSizeSpinBox->hide();
237 myMagnificationLabel->hide();
238 myMagnificationSpinBox->hide();
240 myIncrementLabel->hide();
241 myIncrementSpinBox->hide();
243 myColorGroup->show();
245 myUniformCheckBox->show();
248 void VVTK_SizeBox::setType( int theType )
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;
262 float VVTK_SizeBox::getOutsideSize() const
264 return myOutsideSizeSpinBox->value() / 100.0;
267 void VVTK_SizeBox::setOutsideSize( float theOutsideSize )
269 myOutsideSizeSpinBox->setValue( ( int )( theOutsideSize * 100 ) );
272 float VVTK_SizeBox::getGeomSize() const
274 return myGeomSizeSpinBox->value() / 100.0;
277 void VVTK_SizeBox::setGeomSize( float theGeomSize )
279 myGeomSizeSpinBox->setValue( ( int )( theGeomSize * 100 ) );
282 float VVTK_SizeBox::getMinSize() const
284 return myMinSizeSpinBox->value() / 100.0;
287 void VVTK_SizeBox::setMinSize( float theMinSize )
289 myMinSizeSpinBox->setValue( ( int )( theMinSize * 100 ) );
292 float VVTK_SizeBox::getMaxSize() const
294 return myMaxSizeSpinBox->value() / 100.0;
297 void VVTK_SizeBox::setMaxSize( float theMaxSize )
299 myMaxSizeSpinBox->setValue( ( int )( theMaxSize * 100 ) );
302 float VVTK_SizeBox::getMagnification() const
304 return myMagnificationSpinBox->value() / 100.0;
307 void VVTK_SizeBox::setMagnification( float theMagnification )
309 myMagnificationSpinBox->setValue( ( int )( theMagnification * 100 ) );
312 float VVTK_SizeBox::getIncrement() const
314 return myIncrementSpinBox->value();
317 void VVTK_SizeBox::setIncrement( float theIncrement )
319 myIncrementSpinBox->setValue( theIncrement );
322 bool VVTK_SizeBox::getUniform() const
324 return myUniformCheckBox->isChecked();
327 void VVTK_SizeBox::setUniform( bool theUniform )
329 myUniformCheckBox->setChecked( theUniform );
330 myColorButton->setEnabled( theUniform );
333 QColor VVTK_SizeBox::getColor() const
335 return myColorButton->paletteBackgroundColor();
338 void VVTK_SizeBox::setColor( const QColor& theColor )
340 myColorButton->setPaletteBackgroundColor( theColor );
343 void VVTK_SizeBox::onColorButtonPressed()
345 QColor aColor = QColorDialog::getColor( myColorButton->paletteBackgroundColor(), this );
346 if( aColor.isValid() )
347 myColorButton->setPaletteBackgroundColor( aColor );