1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // VISU VISUGUI : GUI of VISU component
23 // File : VVTK_SizeBox.cxx
24 // Author : Oleg UVAROV
27 #include "VVTK_SizeBox.h"
29 #include "SUIT_ResourceMgr.h"
30 #include "SUIT_Session.h"
32 #include <QtxDoubleSpinBox.h>
33 #include <QtxIntSpinBox.h>
34 #include <QtxColorButton.h>
41 #include <QButtonGroup>
42 #include <QRadioButton>
43 #include <QPushButton>
44 #include <QColorDialog>
48 VVTK_SizeBox::VVTK_SizeBox( QWidget* parent ) :
51 QVBoxLayout* aMainLayout = new QVBoxLayout( this );
52 aMainLayout->setSpacing( 0 );
53 aMainLayout->setMargin( 0 );
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 );
61 QGridLayout* SizeGroupLayout = new QGridLayout (SizeGroup);
62 SizeGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
63 SizeGroupLayout->setSpacing(6);
64 SizeGroupLayout->setMargin(11);
67 myOutsideSizeLabel = new QLabel( tr( "OUTSIDE_SIZE" ), SizeGroup );
68 myOutsideSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
69 myOutsideSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
71 SizeGroupLayout->addWidget( myOutsideSizeLabel, 0, 0 );
72 SizeGroupLayout->addWidget( myOutsideSizeSpinBox, 0, 1 );
75 myGeomSizeLabel = new QLabel( tr( "GEOM_SIZE" ), SizeGroup );
76 myGeomSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
77 myGeomSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
79 SizeGroupLayout->addWidget( myGeomSizeLabel, 0, 0 );
80 SizeGroupLayout->addWidget( myGeomSizeSpinBox, 0, 1 );
83 myMinSizeLabel = new QLabel( tr( "MIN_SIZE" ), SizeGroup );
84 myMinSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
85 myMinSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
87 SizeGroupLayout->addWidget( myMinSizeLabel, 1, 0 );
88 SizeGroupLayout->addWidget( myMinSizeSpinBox, 1, 1 );
91 myMaxSizeLabel = new QLabel( tr( "MAX_SIZE" ), SizeGroup );
92 myMaxSizeSpinBox = new QtxIntSpinBox( 0, 100, 1, SizeGroup );
93 myMaxSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
95 SizeGroupLayout->addWidget( myMaxSizeLabel, 1, 2 );
96 SizeGroupLayout->addWidget( myMaxSizeSpinBox, 1, 3 );
99 myMagnificationLabel = new QLabel( tr( "MAGNIFICATION" ), SizeGroup );
100 myMagnificationSpinBox = new QtxIntSpinBox( 1, 10000, 10, SizeGroup );
101 myMagnificationSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
103 SizeGroupLayout->addWidget( myMagnificationLabel, 2, 0 );
104 SizeGroupLayout->addWidget( myMagnificationSpinBox, 2, 1 );
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 ) );
111 SizeGroupLayout->addWidget( myIncrementLabel, 2, 2 );
112 SizeGroupLayout->addWidget( myIncrementSpinBox, 2, 3 );
114 aMainLayout->addWidget( SizeGroup );
117 myColorGroup = new QGroupBox ( tr( "COLOR_TITLE" ), this );
118 //myColorGroup->setColumnLayout(0, Qt::Vertical );
119 //myColorGroup->layout()->setSpacing( 0 );
120 //myColorGroup->layout()->setMargin( 0 );
122 QGridLayout* ColorGroupLayout = new QGridLayout ( myColorGroup );
123 ColorGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
124 ColorGroupLayout->setSpacing(6);
125 ColorGroupLayout->setMargin(11);
127 myUniformCheckBox = new QCheckBox( tr( "UNIFORM_COLOR" ), myColorGroup );
129 myColorLabel = new QLabel( tr( "COLOR" ), myColorGroup );
130 myColorButton = new QtxColorButton( myColorGroup );
132 ColorGroupLayout->addWidget( myUniformCheckBox, 0, 0 );
133 ColorGroupLayout->addWidget( myColorLabel, 0, 1 );
134 ColorGroupLayout->addWidget( myColorButton, 0, 2 );
136 aMainLayout->addWidget( myColorGroup );
138 connect( myUniformCheckBox, SIGNAL( toggled( bool ) ), myColorButton, SLOT( setEnabled( bool ) ) );
139 //connect( myColorButton, SIGNAL( clicked() ), this, SLOT( onColorButtonPressed() ) );
141 setType( VVTK_SizeBox::Results );
144 void VVTK_SizeBox::onToggleResults()
146 myType = VVTK_SizeBox::Results;
148 myOutsideSizeLabel->hide();
149 myOutsideSizeSpinBox->hide();
151 myGeomSizeLabel->hide();
152 myGeomSizeSpinBox->hide();
154 myMinSizeLabel->show();
155 myMinSizeSpinBox->show();
157 myMaxSizeLabel->show();
158 myMaxSizeSpinBox->show();
160 myMagnificationLabel->show();
161 myMagnificationSpinBox->show();
163 myIncrementLabel->show();
164 myIncrementSpinBox->show();
166 myColorGroup->hide();
168 myUniformCheckBox->hide();
171 void VVTK_SizeBox::onToggleGeometry()
173 myType = VVTK_SizeBox::Geometry;
175 myOutsideSizeLabel->hide();
176 myOutsideSizeSpinBox->hide();
178 myGeomSizeLabel->show();
179 myGeomSizeSpinBox->show();
181 myMinSizeLabel->hide();
182 myMinSizeSpinBox->hide();
184 myMaxSizeLabel->hide();
185 myMaxSizeSpinBox->hide();
187 myMagnificationLabel->show();
188 myMagnificationSpinBox->show();
190 myIncrementLabel->show();
191 myIncrementSpinBox->show();
193 myColorGroup->show();
195 myUniformCheckBox->hide();
198 void VVTK_SizeBox::onToggleInside()
200 myType = VVTK_SizeBox::Inside;
202 myOutsideSizeLabel->hide();
203 myOutsideSizeSpinBox->hide();
205 myGeomSizeLabel->hide();
206 myGeomSizeSpinBox->hide();
208 myMinSizeLabel->show();
209 myMinSizeSpinBox->show();
211 myMaxSizeLabel->show();
212 myMaxSizeSpinBox->show();
214 myMagnificationLabel->hide();
215 myMagnificationSpinBox->hide();
217 myIncrementLabel->hide();
218 myIncrementSpinBox->hide();
220 myColorGroup->hide();
222 myUniformCheckBox->hide();
225 void VVTK_SizeBox::onToggleOutside()
227 myType = VVTK_SizeBox::Outside;
229 myOutsideSizeLabel->show();
230 myOutsideSizeSpinBox->show();
232 myGeomSizeLabel->hide();
233 myGeomSizeSpinBox->hide();
235 myMinSizeLabel->hide();
236 myMinSizeSpinBox->hide();
238 myMaxSizeLabel->hide();
239 myMaxSizeSpinBox->hide();
241 myMagnificationLabel->hide();
242 myMagnificationSpinBox->hide();
244 myIncrementLabel->hide();
245 myIncrementSpinBox->hide();
247 myColorGroup->show();
249 myUniformCheckBox->show();
252 void VVTK_SizeBox::setType( int theType )
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;
266 float VVTK_SizeBox::getOutsideSize() const
268 return myOutsideSizeSpinBox->value() / 100.0;
271 void VVTK_SizeBox::setOutsideSize( float theOutsideSize )
273 myOutsideSizeSpinBox->setValue( ( int )( theOutsideSize * 100 ) );
276 float VVTK_SizeBox::getGeomSize() const
278 return myGeomSizeSpinBox->value() / 100.0;
281 void VVTK_SizeBox::setGeomSize( float theGeomSize )
283 myGeomSizeSpinBox->setValue( ( int )( theGeomSize * 100 ) );
286 float VVTK_SizeBox::getMinSize() const
288 return myMinSizeSpinBox->value() / 100.0;
291 void VVTK_SizeBox::setMinSize( float theMinSize )
293 myMinSizeSpinBox->setValue( ( int )( theMinSize * 100 ) );
296 float VVTK_SizeBox::getMaxSize() const
298 return myMaxSizeSpinBox->value() / 100.0;
301 void VVTK_SizeBox::setMaxSize( float theMaxSize )
303 myMaxSizeSpinBox->setValue( ( int )( theMaxSize * 100 ) );
306 float VVTK_SizeBox::getMagnification() const
308 return myMagnificationSpinBox->value() / 100.0;
311 void VVTK_SizeBox::setMagnification( float theMagnification )
313 myMagnificationSpinBox->setValue( ( int )( theMagnification * 100 ) );
316 float VVTK_SizeBox::getIncrement() const
318 return myIncrementSpinBox->value();
321 void VVTK_SizeBox::setIncrement( float theIncrement )
323 myIncrementSpinBox->setValue( theIncrement );
326 bool VVTK_SizeBox::getUniform() const
328 return myUniformCheckBox->isChecked();
331 void VVTK_SizeBox::setUniform( bool theUniform )
333 myUniformCheckBox->setChecked( theUniform );
334 myColorButton->setEnabled( theUniform );
337 QColor VVTK_SizeBox::getColor() const
339 return myColorButton->color();//palette().color( myColorButton->backgroundRole() );
340 //return myColorButton->paletteBackgroundColor();
343 void VVTK_SizeBox::setColor( const QColor& theColor )
345 if ( theColor.isValid() )
347 //QPalette aPalette( myColorButton->palette() );
348 //aPalette.setColor( myColorButton->backgroundRole(), theColor );
349 myColorButton->setColor( theColor );
351 //myColorButton->setPaletteBackgroundColor( theColor );
354 void VVTK_SizeBox::enableSizeControls( bool enabled )
356 myMagnificationSpinBox->setEnabled( enabled );
357 myMaxSizeSpinBox->setEnabled( enabled );
358 myMinSizeSpinBox->setEnabled( enabled );
359 myIncrementSpinBox->setEnabled( enabled );
360 myGeomSizeSpinBox->setEnabled( enabled );
363 /*void VVTK_SizeBox::onColorButtonPressed()
365 QPalette aPalette( myColorButton->palette() );
366 QColor aColor = QColorDialog::
367 getColor( aPalette.color(myColorButton->backgroundRole() ), this );
369 if( aColor.isValid() )
371 aPalette.setColor( myColorButton->backgroundRole(), aColor );
372 myColorButton->setPalette( aPalette );