1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // VISU VISUGUI : GUI of VISU component
21 // File : VisuGUI_SizeBox.cxx
22 // Author : Oleg UVAROV
25 #include "VisuGUI_SizeBox.h"
27 #include "VisuGUI_Tools.h"
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Session.h>
32 #include <SalomeApp_DoubleSpinBox.h>
33 #include <SalomeApp_IntSpinBox.h>
34 #include <QtxColorButton.h>
41 #include <QButtonGroup>
42 #include <QRadioButton>
43 #include <QPushButton>
44 #include <QColorDialog>
48 VisuGUI_SizeBox::VisuGUI_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 SalomeApp_IntSpinBox( SizeGroup );
69 VISU::initSpinBox( myOutsideSizeSpinBox, 0, 100, 1 );
70 myOutsideSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
72 SizeGroupLayout->addWidget( myOutsideSizeLabel, 0, 0 );
73 SizeGroupLayout->addWidget( myOutsideSizeSpinBox, 0, 1 );
76 myGeomSizeLabel = new QLabel( tr( "GEOM_SIZE" ), SizeGroup );
77 myGeomSizeSpinBox = new SalomeApp_IntSpinBox( SizeGroup );
78 VISU::initSpinBox( myGeomSizeSpinBox, 0, 100, 1 );
79 myGeomSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
81 SizeGroupLayout->addWidget( myGeomSizeLabel, 0, 0 );
82 SizeGroupLayout->addWidget( myGeomSizeSpinBox, 0, 1 );
85 myMinSizeLabel = new QLabel( tr( "MIN_SIZE" ), SizeGroup );
86 myMinSizeSpinBox = new SalomeApp_IntSpinBox( SizeGroup );
87 VISU::initSpinBox( myMinSizeSpinBox, 0, 100, 1 );
88 myMinSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
90 SizeGroupLayout->addWidget( myMinSizeLabel, 1, 0 );
91 SizeGroupLayout->addWidget( myMinSizeSpinBox, 1, 1 );
94 myMaxSizeLabel = new QLabel( tr( "MAX_SIZE" ), SizeGroup );
95 myMaxSizeSpinBox = new SalomeApp_IntSpinBox( SizeGroup );
96 VISU::initSpinBox( myMaxSizeSpinBox, 0, 100, 1 );
97 myMaxSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
99 SizeGroupLayout->addWidget( myMaxSizeLabel, 1, 2 );
100 SizeGroupLayout->addWidget( myMaxSizeSpinBox, 1, 3 );
103 myMagnificationLabel = new QLabel( tr( "MAGNIFICATION" ), SizeGroup );
104 myMagnificationSpinBox = new SalomeApp_IntSpinBox( SizeGroup );
105 VISU::initSpinBox( myMagnificationSpinBox, 1, 10000, 10 );
106 myMagnificationSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
108 SizeGroupLayout->addWidget( myMagnificationLabel, 2, 0 );
109 SizeGroupLayout->addWidget( myMagnificationSpinBox, 2, 1 );
112 myIncrementLabel = new QLabel( tr( "INCREMENT" ), SizeGroup );
113 myIncrementSpinBox = new SalomeApp_DoubleSpinBox( SizeGroup );
114 VISU::initSpinBox( myIncrementSpinBox, 0.01, 10, 0.1, "parametric_precision" );
115 myIncrementSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
117 SizeGroupLayout->addWidget( myIncrementLabel, 2, 2 );
118 SizeGroupLayout->addWidget( myIncrementSpinBox, 2, 3 );
120 aMainLayout->addWidget( SizeGroup );
123 myColorGroup = new QGroupBox ( tr( "COLOR_TITLE" ), this );
124 //myColorGroup->setColumnLayout(0, Qt::Vertical );
125 //myColorGroup->layout()->setSpacing( 0 );
126 //myColorGroup->layout()->setMargin( 0 );
128 QGridLayout* ColorGroupLayout = new QGridLayout ( myColorGroup );
129 ColorGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
130 ColorGroupLayout->setSpacing(6);
131 ColorGroupLayout->setMargin(11);
133 myUniformCheckBox = new QCheckBox( tr( "UNIFORM_COLOR" ), myColorGroup );
135 myColorLabel = new QLabel( tr( "COLOR" ), myColorGroup );
136 myColorButton = new QtxColorButton( myColorGroup );
138 ColorGroupLayout->addWidget( myUniformCheckBox, 0, 0 );
139 ColorGroupLayout->addWidget( myColorLabel, 0, 1 );
140 ColorGroupLayout->addWidget( myColorButton, 0, 2 );
142 aMainLayout->addWidget( myColorGroup );
144 connect( myUniformCheckBox, SIGNAL( toggled( bool ) ), myColorButton, SLOT( setEnabled( bool ) ) );
145 //connect( myColorButton, SIGNAL( clicked() ), this, SLOT( onColorButtonPressed() ) );
147 setType( VisuGUI_SizeBox::Results );
150 void VisuGUI_SizeBox::onToggleResults()
152 myType = VisuGUI_SizeBox::Results;
154 myOutsideSizeLabel->hide();
155 myOutsideSizeSpinBox->hide();
157 myGeomSizeLabel->hide();
158 myGeomSizeSpinBox->hide();
160 myMinSizeLabel->show();
161 myMinSizeSpinBox->show();
163 myMaxSizeLabel->show();
164 myMaxSizeSpinBox->show();
166 myMagnificationLabel->show();
167 myMagnificationSpinBox->show();
169 myIncrementLabel->show();
170 myIncrementSpinBox->show();
172 myColorGroup->hide();
174 myUniformCheckBox->hide();
177 void VisuGUI_SizeBox::onToggleGeometry()
179 myType = VisuGUI_SizeBox::Geometry;
181 myOutsideSizeLabel->hide();
182 myOutsideSizeSpinBox->hide();
184 myGeomSizeLabel->show();
185 myGeomSizeSpinBox->show();
187 myMinSizeLabel->hide();
188 myMinSizeSpinBox->hide();
190 myMaxSizeLabel->hide();
191 myMaxSizeSpinBox->hide();
193 myMagnificationLabel->show();
194 myMagnificationSpinBox->show();
196 myIncrementLabel->show();
197 myIncrementSpinBox->show();
199 myColorGroup->show();
201 myUniformCheckBox->hide();
204 void VisuGUI_SizeBox::onToggleInside()
206 myType = VisuGUI_SizeBox::Inside;
208 myOutsideSizeLabel->hide();
209 myOutsideSizeSpinBox->hide();
211 myGeomSizeLabel->hide();
212 myGeomSizeSpinBox->hide();
214 myMinSizeLabel->show();
215 myMinSizeSpinBox->show();
217 myMaxSizeLabel->show();
218 myMaxSizeSpinBox->show();
220 myMagnificationLabel->hide();
221 myMagnificationSpinBox->hide();
223 myIncrementLabel->hide();
224 myIncrementSpinBox->hide();
226 myColorGroup->hide();
228 myUniformCheckBox->hide();
231 void VisuGUI_SizeBox::onToggleOutside()
233 myType = VisuGUI_SizeBox::Outside;
235 myOutsideSizeLabel->show();
236 myOutsideSizeSpinBox->show();
238 myGeomSizeLabel->hide();
239 myGeomSizeSpinBox->hide();
241 myMinSizeLabel->hide();
242 myMinSizeSpinBox->hide();
244 myMaxSizeLabel->hide();
245 myMaxSizeSpinBox->hide();
247 myMagnificationLabel->hide();
248 myMagnificationSpinBox->hide();
250 myIncrementLabel->hide();
251 myIncrementSpinBox->hide();
253 myColorGroup->show();
255 myUniformCheckBox->show();
258 void VisuGUI_SizeBox::setType( int theType )
264 case VisuGUI_SizeBox::Results : onToggleResults(); break;
265 case VisuGUI_SizeBox::Geometry : onToggleGeometry(); break;
266 case VisuGUI_SizeBox::Inside : onToggleInside(); break;
267 case VisuGUI_SizeBox::Outside : onToggleOutside(); break;
272 float VisuGUI_SizeBox::getOutsideSize() const
274 return myOutsideSizeSpinBox->value() / 100.0;
277 void VisuGUI_SizeBox::setOutsideSize( float theOutsideSize )
279 myOutsideSizeSpinBox->setValue( ( int )( theOutsideSize * 100 ) );
282 float VisuGUI_SizeBox::getGeomSize() const
284 return myGeomSizeSpinBox->value() / 100.0;
287 void VisuGUI_SizeBox::setGeomSize( float theGeomSize )
289 myGeomSizeSpinBox->setValue( ( int )( theGeomSize * 100 ) );
292 float VisuGUI_SizeBox::getMinSize() const
294 return myMinSizeSpinBox->value() / 100.0;
297 void VisuGUI_SizeBox::setMinSize( float theMinSize )
299 myMinSizeSpinBox->setValue( ( int )( theMinSize * 100 ) );
302 float VisuGUI_SizeBox::getMaxSize() const
304 return myMaxSizeSpinBox->value() / 100.0;
307 void VisuGUI_SizeBox::setMaxSize( float theMaxSize )
309 myMaxSizeSpinBox->setValue( ( int )( theMaxSize * 100 ) );
312 float VisuGUI_SizeBox::getMagnification() const
314 return myMagnificationSpinBox->value() / 100.0;
317 void VisuGUI_SizeBox::setMagnification( float theMagnification )
319 myMagnificationSpinBox->setValue( ( int )( theMagnification * 100 ) );
322 float VisuGUI_SizeBox::getIncrement() const
324 return myIncrementSpinBox->value();
327 void VisuGUI_SizeBox::setIncrement( float theIncrement )
329 myIncrementSpinBox->setValue( theIncrement );
332 bool VisuGUI_SizeBox::getUniform() const
334 return myUniformCheckBox->isChecked();
337 void VisuGUI_SizeBox::setUniform( bool theUniform )
339 myUniformCheckBox->setChecked( theUniform );
340 myColorButton->setEnabled( theUniform );
343 QColor VisuGUI_SizeBox::getColor() const
345 return myColorButton->color();//palette().color( myColorButton->backgroundRole() );
346 //return myColorButton->paletteBackgroundColor();
349 void VisuGUI_SizeBox::setColor( const QColor& theColor )
351 if ( theColor.isValid() )
353 //QPalette aPalette( myColorButton->palette() );
354 //aPalette.setColor( myColorButton->backgroundRole(), theColor );
355 myColorButton->setColor( theColor );
357 //myColorButton->setPaletteBackgroundColor( theColor );
360 void VisuGUI_SizeBox::enableSizeControls( bool enabled )
362 myMagnificationSpinBox->setEnabled( enabled );
363 myMaxSizeSpinBox->setEnabled( enabled );
364 myMinSizeSpinBox->setEnabled( enabled );
365 myIncrementSpinBox->setEnabled( enabled );
366 myGeomSizeSpinBox->setEnabled( enabled );
369 /*void VisuGUI_SizeBox::onColorButtonPressed()
371 QPalette aPalette( myColorButton->palette() );
372 QColor aColor = QColorDialog::
373 getColor( aPalette.color(myColorButton->backgroundRole() ), this );
375 if( aColor.isValid() )
377 aPalette.setColor( myColorButton->backgroundRole(), aColor );
378 myColorButton->setPalette( aPalette );