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>
39 #include <QPushButton>
40 #include <QVBoxLayout>
41 #include <QHBoxLayout>
42 #include <QGridLayout>
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 )
60 setWindowTitle( tr( "Preferences - Set Color" ) );
61 setSizeGripEnabled( true );
63 // -------------------------------
64 QVBoxLayout* topLayout = new QVBoxLayout( this );
65 topLayout->setSpacing( SPACING );
66 topLayout->setMargin( MARGIN );
68 // -------------------------------
69 QGroupBox* ButtonGroup1 = new QGroupBox( tr( "Elements" ), this );
70 QGridLayout* ButtonGroup1Layout = new QGridLayout( ButtonGroup1 );
71 ButtonGroup1Layout->setSpacing( SPACING );
72 ButtonGroup1Layout->setMargin( MARGIN );
74 QLabel* TextLabel_Fill = new QLabel( tr( "Fill" ), ButtonGroup1 );
75 btnFillColor = new QtxColorButton( ButtonGroup1 );
77 QLabel* TextLabel_BackFace = new QLabel( tr( "Back Face" ), ButtonGroup1 );
78 btnBackFaceColor = new QtxColorButton( ButtonGroup1 );
80 QLabel* TextLabel_Outine = new QLabel( tr( "Outline" ), ButtonGroup1 );
81 btnOutlineColor = new QtxColorButton( ButtonGroup1 );
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 );
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 );
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 );
108 // -------------------------------
109 QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
110 QHBoxLayout* ButtonGroup2Layout = new QHBoxLayout( ButtonGroup2 );
111 ButtonGroup2Layout->setSpacing( SPACING );
112 ButtonGroup2Layout->setMargin( MARGIN );
114 QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
115 btnNodeColor = new QtxColorButton( ButtonGroup2 );
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 );
124 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color );
125 ButtonGroup2Layout->addWidget( btnNodeColor );
126 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Size );
127 ButtonGroup2Layout->addWidget( SpinBox_Nodes_Size );
129 // -------------------------------
130 QGroupBox* GroupButtons = new QGroupBox( this );
131 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
132 GroupButtonsLayout->setSpacing( SPACING );
133 GroupButtonsLayout->setMargin( MARGIN );
135 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
136 buttonOk->setAutoDefault( true );
137 buttonOk->setDefault( true );
139 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
140 buttonCancel->setAutoDefault( true );
142 GroupButtonsLayout->addWidget( buttonOk );
143 GroupButtonsLayout->addSpacing( 10 );
144 GroupButtonsLayout->addStretch();
145 GroupButtonsLayout->addWidget( buttonCancel );
147 // -------------------------------
148 topLayout->addWidget( ButtonGroup1 );
149 topLayout->addWidget( ButtonGroup2 );
150 topLayout->addWidget( GroupButtons );
152 // -------------------------------
153 mySMESHGUI->SetActiveDialogBox( this );
155 /* signals and slots connections */
156 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
157 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
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() ) );
166 //=================================================================================
167 // function : ~SMESHGUI_Preferences_ColorDlg()
168 // purpose : Destructor
169 //=================================================================================
170 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
174 //=================================================================================
175 // function : ClickOnOk()
177 //=================================================================================
178 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
180 mySMESHGUI->ResetState();
184 //=================================================================================
185 // function : ClickOnCancel()
187 //=================================================================================
188 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
190 mySMESHGUI->ResetState();
194 //=================================================================================
195 // function : DeactivateActiveDialog()
197 //=================================================================================
198 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
202 //=================================================================================
203 // function : closeEvent()
205 //=================================================================================
206 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
208 ClickOnCancel(); /* same than click on cancel button */
211 //=================================================================================
212 // function : ActivateThisDialog()
214 //=================================================================================
215 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
217 /* Emit a signal to deactivate any active dialog */
218 mySMESHGUI->EmitSignalDeactivateDialog();
221 //=================================================================================
222 // function : SetColor()
224 //=================================================================================
225 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
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
236 //=================================================================================
237 // function : GetColor()
239 //=================================================================================
240 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int 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
253 //=================================================================================
254 // function : SetIntValue()
256 //=================================================================================
257 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
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
267 //=================================================================================
268 // function : GetIntValue()
270 //=================================================================================
271 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int 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