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 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_Preferences_ColorDlg.cxx
24 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
27 #include "SMESHGUI_Preferences_ColorDlg.h"
30 #include "SMESHGUI_Utils.h"
32 // SALOME GUI includes
33 #include <SUIT_Desktop.h>
34 #include <QtxColorButton.h>
35 #include <QtxDoubleSpinBox.h>
36 #include <QtxIntSpinBox.h>
41 #include <QPushButton>
42 #include <QVBoxLayout>
43 #include <QHBoxLayout>
44 #include <QGridLayout>
51 //=================================================================================
52 // function : SMESHGUI_Preferences_ColorDlg()
53 // purpose : Constructs a SMESHGUI_Preferences_ColorDlg which is a child
54 // of 'parent', with the name 'name' and widget flags set to 'f'
55 // The dialog will by default be modeless, unless you
56 // set'modal' to true to construct a modal dialog.
57 //=================================================================================
58 SMESHGUI_Preferences_ColorDlg::SMESHGUI_Preferences_ColorDlg( SMESHGUI* theModule )
59 : QDialog( SMESH::GetDesktop( theModule ) ),
60 mySMESHGUI( theModule )
63 setWindowTitle( tr( "Preferences - Set Color" ) );
64 setSizeGripEnabled( true );
66 // -------------------------------
67 QVBoxLayout* topLayout = new QVBoxLayout( this );
68 topLayout->setSpacing( SPACING );
69 topLayout->setMargin( MARGIN );
71 // -------------------------------
72 QGroupBox* ButtonGroup1 = new QGroupBox( tr( "Elements" ), this );
73 QGridLayout* ButtonGroup1Layout = new QGridLayout( ButtonGroup1 );
74 ButtonGroup1Layout->setSpacing( SPACING );
75 ButtonGroup1Layout->setMargin( MARGIN );
77 QLabel* TextLabel_Fill = new QLabel( tr( "Fill" ), ButtonGroup1 );
78 btnFillColor = new QtxColorButton( ButtonGroup1 );
80 QLabel* TextLabel_BackFace = new QLabel( tr( "Back Face" ), ButtonGroup1 );
81 btnBackFaceColor = new QtxColorButton( ButtonGroup1 );
83 QLabel* TextLabel_Outine = new QLabel( tr( "Outline" ), ButtonGroup1 );
84 btnOutlineColor = new QtxColorButton( ButtonGroup1 );
86 QLabel* TextLabel_0DElements_Color = new QLabel( tr( "0D elements" ), ButtonGroup1 );
87 btn0DElementsColor = new QtxColorButton( ButtonGroup1 );
89 QLabel* TextLabel_0DElements_Size = new QLabel( tr( "Size of 0D elements" ), ButtonGroup1 );
90 SpinBox_0DElements_Size = new QSpinBox( ButtonGroup1 );
91 SpinBox_0DElements_Size->setRange( 1, 10 );
92 SpinBox_0DElements_Size->setSingleStep( 1 );
93 SpinBox_0DElements_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
94 SpinBox_0DElements_Size->setButtonSymbols( QSpinBox::PlusMinus );
96 QLabel* TextLabel_Width = new QLabel( tr( "Width" ), ButtonGroup1 );
97 SpinBox_Width = new QSpinBox( ButtonGroup1 );
98 SpinBox_Width->setRange( 0, 5 );
99 SpinBox_Width->setSingleStep( 1 );
100 SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
101 SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
103 QLabel* TextLabel_ShrinkCoeff = new QLabel( tr( "Shrink coef." ), ButtonGroup1 );
104 SpinBox_Shrink = new QtxIntSpinBox( ButtonGroup1 );
105 SpinBox_Shrink->setRange( 20, 100 );
106 SpinBox_Shrink->setSingleStep( 1 );
107 SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
108 SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
110 ButtonGroup1Layout->addWidget( TextLabel_Fill, 0, 0 );
111 ButtonGroup1Layout->addWidget( btnFillColor, 0, 1 );
112 ButtonGroup1Layout->addWidget( TextLabel_BackFace, 0, 2 );
113 ButtonGroup1Layout->addWidget( btnBackFaceColor, 0, 3 );
114 ButtonGroup1Layout->addWidget( TextLabel_Outine, 1, 0 );
115 ButtonGroup1Layout->addWidget( btnOutlineColor, 1, 1 );
116 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Color, 1, 2 );
117 ButtonGroup1Layout->addWidget( btn0DElementsColor, 1, 3 );
118 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Size, 2, 0 );
119 ButtonGroup1Layout->addWidget( SpinBox_0DElements_Size, 2, 1 );
120 ButtonGroup1Layout->addWidget( TextLabel_Width, 3, 0 );
121 ButtonGroup1Layout->addWidget( SpinBox_Width, 3, 1 );
122 ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff, 3, 2 );
123 ButtonGroup1Layout->addWidget( SpinBox_Shrink, 3, 3 );
125 // -------------------------------
126 QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
127 QHBoxLayout* ButtonGroup2Layout = new QHBoxLayout( ButtonGroup2 );
128 ButtonGroup2Layout->setSpacing( SPACING );
129 ButtonGroup2Layout->setMargin( MARGIN );
131 QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
132 btnNodeColor = new QtxColorButton( ButtonGroup2 );
134 QLabel* TextLabel_Nodes_Size = new QLabel( tr( "Size" ), ButtonGroup2 );
135 SpinBox_Nodes_Size = new QSpinBox( ButtonGroup2 );
136 SpinBox_Nodes_Size->setRange( 0, 5 );
137 SpinBox_Nodes_Size->setSingleStep( 1 );
138 SpinBox_Nodes_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
139 SpinBox_Nodes_Size->setButtonSymbols( QSpinBox::PlusMinus );
141 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color );
142 ButtonGroup2Layout->addWidget( btnNodeColor );
143 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Size );
144 ButtonGroup2Layout->addWidget( SpinBox_Nodes_Size );
146 // -------------------------------
147 QGroupBox* ButtonGroup3 = new QGroupBox( tr( "Orientation of faces" ), this );
148 QGridLayout* ButtonGroup3Layout = new QGridLayout( ButtonGroup3 );
149 ButtonGroup3Layout->setSpacing( SPACING );
150 ButtonGroup3Layout->setMargin( MARGIN );
152 QLabel* TextLabel_Orientation_Color = new QLabel( tr( "Color" ), ButtonGroup3 );
153 btnOrientationColor = new QtxColorButton( ButtonGroup3 );
155 QLabel* TextLabel_Orientation_Scale = new QLabel( tr( "Scale" ), ButtonGroup3 );
156 SpinBox_Orientation_Scale = new QtxDoubleSpinBox( ButtonGroup3 );
157 SpinBox_Orientation_Scale->setRange( 0.05, 0.5 );
158 SpinBox_Orientation_Scale->setSingleStep( 0.05 );
159 SpinBox_Orientation_Scale->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
160 SpinBox_Orientation_Scale->setButtonSymbols( QSpinBox::PlusMinus );
162 CheckBox_Orientation_3DVectors = new QCheckBox( tr( "3D vectors" ), ButtonGroup3 );
164 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Color, 0, 0 );
165 ButtonGroup3Layout->addWidget( btnOrientationColor, 0, 1 );
166 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Scale, 0, 2 );
167 ButtonGroup3Layout->addWidget( SpinBox_Orientation_Scale, 0, 3 );
168 ButtonGroup3Layout->addWidget( CheckBox_Orientation_3DVectors, 1, 0, 1, 4 );
170 // -------------------------------
171 QGroupBox* GroupButtons = new QGroupBox( this );
172 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
173 GroupButtonsLayout->setSpacing( SPACING );
174 GroupButtonsLayout->setMargin( MARGIN );
176 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
177 buttonOk->setAutoDefault( true );
178 buttonOk->setDefault( true );
180 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
181 buttonCancel->setAutoDefault( true );
183 GroupButtonsLayout->addWidget( buttonOk );
184 GroupButtonsLayout->addSpacing( 10 );
185 GroupButtonsLayout->addStretch();
186 GroupButtonsLayout->addWidget( buttonCancel );
188 // -------------------------------
189 topLayout->addWidget( ButtonGroup1 );
190 topLayout->addWidget( ButtonGroup2 );
191 topLayout->addWidget( ButtonGroup3 );
192 topLayout->addWidget( GroupButtons );
194 // -------------------------------
195 mySMESHGUI->SetActiveDialogBox( this );
197 /* signals and slots connections */
198 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
199 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
201 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ),
202 this, SLOT( DeactivateActiveDialog() ) );
203 /* to close dialog if study change */
204 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ),
205 this, SLOT( ClickOnCancel() ) );
208 //=================================================================================
209 // function : ~SMESHGUI_Preferences_ColorDlg()
210 // purpose : Destructor
211 //=================================================================================
212 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
216 //=================================================================================
217 // function : ClickOnOk()
219 //=================================================================================
220 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
222 mySMESHGUI->ResetState();
226 //=================================================================================
227 // function : ClickOnCancel()
229 //=================================================================================
230 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
232 mySMESHGUI->ResetState();
236 //=================================================================================
237 // function : DeactivateActiveDialog()
239 //=================================================================================
240 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
244 //=================================================================================
245 // function : closeEvent()
247 //=================================================================================
248 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
250 ClickOnCancel(); /* same than click on cancel button */
253 //=================================================================================
254 // function : ActivateThisDialog()
256 //=================================================================================
257 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
259 /* Emit a signal to deactivate any active dialog */
260 mySMESHGUI->EmitSignalDeactivateDialog();
263 //=================================================================================
264 // function : SetColor()
266 //=================================================================================
267 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
270 case 1 : btnFillColor->setColor( color ); break; // fill
271 case 2 : btnOutlineColor->setColor( color ); break; // outline
272 case 3 : btnNodeColor->setColor( color ); break; // node
273 case 4 : btnBackFaceColor->setColor( color ); break; // back face
274 case 5 : btn0DElementsColor->setColor( color ); break; // 0d elements
275 case 6 : btnOrientationColor->setColor( color ); break; // orientation of faces
280 //=================================================================================
281 // function : GetColor()
283 //=================================================================================
284 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int type )
288 case 1 : color = btnFillColor->color(); break; // fill
289 case 2 : color = btnOutlineColor->color(); break; // outline
290 case 3 : color = btnNodeColor->color(); break; // node
291 case 4 : color = btnBackFaceColor->color(); break; // back face
292 case 5 : color = btn0DElementsColor->color(); break; // 0d elements
293 case 6 : color = btnOrientationColor->color(); break; // orientation of faces
299 //=================================================================================
300 // function : SetIntValue()
302 //=================================================================================
303 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
306 case 1 : SpinBox_Width->setValue( value ); break; // width
307 case 2 : SpinBox_Nodes_Size->setValue( value ); break; // nodes size = value; break;
308 case 3 : SpinBox_Shrink->setValue( value ); break; // shrink coeff
309 case 4 : SpinBox_0DElements_Size->setValue( value ); break; // 0d elements
314 //=================================================================================
315 // function : GetIntValue()
317 //=================================================================================
318 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int type )
322 case 1 : res = SpinBox_Width->value(); break; // width
323 case 2 : res = SpinBox_Nodes_Size->value(); break; // nodes size
324 case 3 : res = SpinBox_Shrink->value(); break; // shrink coeff
325 case 4 : res = SpinBox_0DElements_Size->value(); break; // 0d elements
331 //=================================================================================
332 // function : SetDoubleValue()
334 //=================================================================================
335 void SMESHGUI_Preferences_ColorDlg::SetDoubleValue( int type, double value )
338 case 1 : SpinBox_Orientation_Scale->setValue( value ); break; // orientation scale
343 //=================================================================================
344 // function : GetDoubleValue()
346 //=================================================================================
347 double SMESHGUI_Preferences_ColorDlg::GetDoubleValue( int type )
351 case 1 : res = SpinBox_Orientation_Scale->value(); break; // orientation scale
357 //=================================================================================
358 // function : SetBooleanValue()
360 //=================================================================================
361 void SMESHGUI_Preferences_ColorDlg::SetBooleanValue( int type, bool value )
364 case 1 : CheckBox_Orientation_3DVectors->setChecked( value ); break; // 3D vectors
369 //=================================================================================
370 // function : GetBooleanValue()
372 //=================================================================================
373 bool SMESHGUI_Preferences_ColorDlg::GetBooleanValue( int type )
377 case 1 : res = CheckBox_Orientation_3DVectors->isChecked(); break; // 3D vectors