Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Preferences_ColorDlg.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 // SMESH SMESHGUI : GUI for SMESH component
23 // File   : SMESHGUI_Preferences_ColorDlg.cxx
24 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
25 // SMESH includes
26 //
27 #include "SMESHGUI_Preferences_ColorDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_Utils.h"
31
32 // SALOME GUI includes
33 #include <SUIT_Desktop.h>
34 #include <QtxColorButton.h>
35 #include <QtxIntSpinBox.h>
36
37 // Qt includes
38 #include <QGroupBox>
39 #include <QLabel>
40 #include <QPushButton>
41 #include <QVBoxLayout>
42 #include <QHBoxLayout>
43 #include <QGridLayout>
44 #include <QSpinBox>
45
46 #define SPACING 6
47 #define MARGIN  11
48
49 //=================================================================================
50 // function : SMESHGUI_Preferences_ColorDlg()
51 // purpose  : Constructs a SMESHGUI_Preferences_ColorDlg which is a child
52 //            of 'parent', with the name 'name' and widget flags set to 'f'
53 //            The dialog will by default be modeless, unless you
54 //            set'modal' to true to construct a modal dialog.
55 //=================================================================================
56 SMESHGUI_Preferences_ColorDlg::SMESHGUI_Preferences_ColorDlg( SMESHGUI* theModule )
57   : QDialog( SMESH::GetDesktop( theModule ) ),
58     mySMESHGUI( theModule )
59 {
60   setModal( true );
61   setWindowTitle( tr( "Preferences - Set Color" ) );
62   setSizeGripEnabled( true );
63
64   // -------------------------------
65   QVBoxLayout* topLayout = new QVBoxLayout( this );
66   topLayout->setSpacing( SPACING );
67   topLayout->setMargin( MARGIN );
68
69   // -------------------------------
70   QGroupBox* ButtonGroup1 = new QGroupBox( tr( "Elements" ), this );
71   QGridLayout* ButtonGroup1Layout = new QGridLayout( ButtonGroup1 );
72   ButtonGroup1Layout->setSpacing( SPACING );
73   ButtonGroup1Layout->setMargin( MARGIN );
74
75   QLabel* TextLabel_Fill = new QLabel( tr( "Fill" ), ButtonGroup1 );
76   btnFillColor = new QtxColorButton( ButtonGroup1 );
77
78   QLabel* TextLabel_BackFace = new QLabel( tr( "Back Face" ), ButtonGroup1 );
79   btnBackFaceColor = new QtxColorButton( ButtonGroup1 );
80
81   QLabel* TextLabel_Outine = new QLabel( tr( "Outline" ), ButtonGroup1 );
82   btnOutlineColor = new QtxColorButton( ButtonGroup1 );
83
84   QLabel* TextLabel_Width = new QLabel( tr( "Width" ), ButtonGroup1 );
85   SpinBox_Width = new QSpinBox( ButtonGroup1 );
86   SpinBox_Width->setRange( 0, 5 );
87   SpinBox_Width->setSingleStep( 1 );
88   SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
89   SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
90
91   QLabel* TextLabel_ShrinkCoeff = new QLabel( tr( "Shrink coef." ), ButtonGroup1 );
92   SpinBox_Shrink = new QtxIntSpinBox( ButtonGroup1 );
93   SpinBox_Shrink->setRange( 20, 100 );
94   SpinBox_Shrink->setSingleStep( 1 );
95   SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
96   SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
97
98   ButtonGroup1Layout->addWidget( TextLabel_Fill,        0, 0 );
99   ButtonGroup1Layout->addWidget( btnFillColor,          0, 1 );
100   ButtonGroup1Layout->addWidget( TextLabel_BackFace,    0, 2 );
101   ButtonGroup1Layout->addWidget( btnBackFaceColor,      0, 3 );
102   ButtonGroup1Layout->addWidget( TextLabel_Outine,      1, 0 );
103   ButtonGroup1Layout->addWidget( btnOutlineColor,       1, 1 );
104   ButtonGroup1Layout->addWidget( TextLabel_Width,       1, 2 );
105   ButtonGroup1Layout->addWidget( SpinBox_Width,         1, 3 );
106   ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff, 2, 0 );
107   ButtonGroup1Layout->addWidget( SpinBox_Shrink,        2, 1, 1, 3 );
108
109   // -------------------------------
110   QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
111   QHBoxLayout* ButtonGroup2Layout = new QHBoxLayout( ButtonGroup2 );
112   ButtonGroup2Layout->setSpacing( SPACING );
113   ButtonGroup2Layout->setMargin( MARGIN );
114
115   QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
116   btnNodeColor = new QtxColorButton( ButtonGroup2 );
117
118   QLabel* TextLabel_Nodes_Size = new QLabel( tr( "Size" ), ButtonGroup2 );
119   SpinBox_Nodes_Size = new QSpinBox( ButtonGroup2 );
120   SpinBox_Nodes_Size->setRange( 0, 5 );
121   SpinBox_Nodes_Size->setSingleStep( 1 );
122   SpinBox_Nodes_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
123   SpinBox_Nodes_Size->setButtonSymbols( QSpinBox::PlusMinus );
124
125   ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color );
126   ButtonGroup2Layout->addWidget( btnNodeColor );
127   ButtonGroup2Layout->addWidget( TextLabel_Nodes_Size );
128   ButtonGroup2Layout->addWidget( SpinBox_Nodes_Size );
129
130   // -------------------------------
131   QGroupBox* GroupButtons = new QGroupBox( this );
132   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
133   GroupButtonsLayout->setSpacing( SPACING );
134   GroupButtonsLayout->setMargin( MARGIN );
135
136   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
137   buttonOk->setAutoDefault( true );
138   buttonOk->setDefault( true );
139
140   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
141   buttonCancel->setAutoDefault( true );
142
143   GroupButtonsLayout->addWidget( buttonOk );
144   GroupButtonsLayout->addSpacing( 10 );
145   GroupButtonsLayout->addStretch();
146   GroupButtonsLayout->addWidget( buttonCancel );
147
148   // -------------------------------
149   topLayout->addWidget( ButtonGroup1 );
150   topLayout->addWidget( ButtonGroup2 );
151   topLayout->addWidget( GroupButtons );
152
153   // -------------------------------
154   mySMESHGUI->SetActiveDialogBox( this );
155
156   /* signals and slots connections */
157   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
158   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
159
160   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ),
161            this,       SLOT( DeactivateActiveDialog() ) );
162   /* to close dialog if study change */
163   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ),
164            this,       SLOT( ClickOnCancel() ) );
165 }
166
167 //=================================================================================
168 // function : ~SMESHGUI_Preferences_ColorDlg()
169 // purpose  : Destructor
170 //=================================================================================
171 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
172 {
173 }
174
175 //=================================================================================
176 // function : ClickOnOk()
177 // purpose  :
178 //=================================================================================
179 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
180 {
181   mySMESHGUI->ResetState();
182   accept();
183 }
184
185 //=================================================================================
186 // function : ClickOnCancel()
187 // purpose  :
188 //=================================================================================
189 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
190 {
191   mySMESHGUI->ResetState();
192   reject();
193 }
194
195 //=================================================================================
196 // function : DeactivateActiveDialog()
197 // purpose  :
198 //=================================================================================
199 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
200 {
201 }
202
203 //=================================================================================
204 // function : closeEvent()
205 // purpose  :
206 //=================================================================================
207 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
208 {
209   ClickOnCancel(); /* same than click on cancel button */
210 }
211
212 //=================================================================================
213 // function : ActivateThisDialog()
214 // purpose  :
215 //=================================================================================
216 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
217 {
218   /* Emit a signal to deactivate any active dialog */
219   mySMESHGUI->EmitSignalDeactivateDialog();
220 }
221
222 //=================================================================================
223 // function : SetColor()
224 // purpose  :
225 //=================================================================================
226 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
227 {
228   switch ( type ) {
229   case 1 : btnFillColor->setColor( color );     break; // fill
230   case 2 : btnOutlineColor->setColor( color );  break; // outline
231   case 3 : btnNodeColor->setColor( color );     break; // node
232   case 4 : btnBackFaceColor->setColor( color ); break; // back face
233   default: break;
234   }
235 }
236
237 //=================================================================================
238 // function : GetColor()
239 // purpose  :
240 //=================================================================================
241 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int type )
242 {
243   QColor color;
244   switch ( type ) {
245   case 1 : color = btnFillColor->color();     break; // fill
246   case 2 : color = btnOutlineColor->color();  break; // outline
247   case 3 : color = btnNodeColor->color();     break; // node
248   case 4 : color = btnBackFaceColor->color(); break; // back face
249   default: break;
250   }
251   return color;
252 }
253
254 //=================================================================================
255 // function : SetIntValue()
256 // purpose  :
257 //=================================================================================
258 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
259 {
260   switch ( type ) {
261   case 1 : SpinBox_Width->setValue( value );      break; // width
262   case 2 : SpinBox_Nodes_Size->setValue( value ); break; // nodes size = value; break;
263   case 3 : SpinBox_Shrink->setValue( value );     break; // shrink coeff
264   default: break;
265   }
266 }
267
268 //=================================================================================
269 // function : GetIntValue()
270 // purpose  :
271 //=================================================================================
272 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int type )
273 {
274   int res = 0;
275   switch ( type ) {
276   case 1 : res = SpinBox_Width->value();      break; // width
277   case 2 : res = SpinBox_Nodes_Size->value(); break; // nodes size
278   case 3 : res = SpinBox_Shrink->value();     break; // shrink coeff
279   default: break;
280   }
281   return res;
282 }