1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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 // File : SMESHGUI_Preferences_ColorDlg.cxx
23 // 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 <QtxIntSpinBox.h>
40 #include <QPushButton>
41 #include <QVBoxLayout>
42 #include <QHBoxLayout>
43 #include <QGridLayout>
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 )
61 setWindowTitle( tr( "Preferences - Set Color" ) );
62 setSizeGripEnabled( true );
64 // -------------------------------
65 QVBoxLayout* topLayout = new QVBoxLayout( this );
66 topLayout->setSpacing( SPACING );
67 topLayout->setMargin( MARGIN );
69 // -------------------------------
70 QGroupBox* ButtonGroup1 = new QGroupBox( tr( "Elements" ), this );
71 QGridLayout* ButtonGroup1Layout = new QGridLayout( ButtonGroup1 );
72 ButtonGroup1Layout->setSpacing( SPACING );
73 ButtonGroup1Layout->setMargin( MARGIN );
75 QLabel* TextLabel_Fill = new QLabel( tr( "Fill" ), ButtonGroup1 );
76 btnFillColor = new QtxColorButton( ButtonGroup1 );
78 QLabel* TextLabel_BackFace = new QLabel( tr( "Back Face" ), ButtonGroup1 );
79 btnBackFaceColor = new QtxColorButton( ButtonGroup1 );
81 QLabel* TextLabel_Outine = new QLabel( tr( "Outline" ), ButtonGroup1 );
82 btnOutlineColor = new QtxColorButton( ButtonGroup1 );
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 );
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 );
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 );
109 // -------------------------------
110 QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
111 QHBoxLayout* ButtonGroup2Layout = new QHBoxLayout( ButtonGroup2 );
112 ButtonGroup2Layout->setSpacing( SPACING );
113 ButtonGroup2Layout->setMargin( MARGIN );
115 QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
116 btnNodeColor = new QtxColorButton( ButtonGroup2 );
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 );
125 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color );
126 ButtonGroup2Layout->addWidget( btnNodeColor );
127 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Size );
128 ButtonGroup2Layout->addWidget( SpinBox_Nodes_Size );
130 // -------------------------------
131 QGroupBox* GroupButtons = new QGroupBox( this );
132 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
133 GroupButtonsLayout->setSpacing( SPACING );
134 GroupButtonsLayout->setMargin( MARGIN );
136 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
137 buttonOk->setAutoDefault( true );
138 buttonOk->setDefault( true );
140 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
141 buttonCancel->setAutoDefault( true );
143 GroupButtonsLayout->addWidget( buttonOk );
144 GroupButtonsLayout->addSpacing( 10 );
145 GroupButtonsLayout->addStretch();
146 GroupButtonsLayout->addWidget( buttonCancel );
148 // -------------------------------
149 topLayout->addWidget( ButtonGroup1 );
150 topLayout->addWidget( ButtonGroup2 );
151 topLayout->addWidget( GroupButtons );
153 // -------------------------------
154 mySMESHGUI->SetActiveDialogBox( this );
156 /* signals and slots connections */
157 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
158 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
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() ) );
167 //=================================================================================
168 // function : ~SMESHGUI_Preferences_ColorDlg()
169 // purpose : Destructor
170 //=================================================================================
171 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
175 //=================================================================================
176 // function : ClickOnOk()
178 //=================================================================================
179 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
181 mySMESHGUI->ResetState();
185 //=================================================================================
186 // function : ClickOnCancel()
188 //=================================================================================
189 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
191 mySMESHGUI->ResetState();
195 //=================================================================================
196 // function : DeactivateActiveDialog()
198 //=================================================================================
199 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
203 //=================================================================================
204 // function : closeEvent()
206 //=================================================================================
207 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
209 ClickOnCancel(); /* same than click on cancel button */
212 //=================================================================================
213 // function : ActivateThisDialog()
215 //=================================================================================
216 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
218 /* Emit a signal to deactivate any active dialog */
219 mySMESHGUI->EmitSignalDeactivateDialog();
222 //=================================================================================
223 // function : SetColor()
225 //=================================================================================
226 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
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
237 //=================================================================================
238 // function : GetColor()
240 //=================================================================================
241 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int 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
254 //=================================================================================
255 // function : SetIntValue()
257 //=================================================================================
258 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
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
268 //=================================================================================
269 // function : GetIntValue()
271 //=================================================================================
272 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int 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