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