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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_Preferences_ColorDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESHGUI_Preferences_ColorDlg.h"
33 #include "utilities.h"
35 #include <qbuttongroup.h>
36 #include <qcheckbox.h>
37 #include <qcombobox.h>
41 #include <qpushbutton.h>
43 #include <qcolordialog.h>
48 * Constructs a SMESHGUI_Preferences_ColorDlg which is a child of 'parent', with the
49 * name 'name' and widget flags set to 'f'
51 * The dialog will by default be modeless, unless you set 'modal' to
52 * TRUE to construct a modal dialog.
54 SMESHGUI_Preferences_ColorDlg::SMESHGUI_Preferences_ColorDlg( QWidget* parent, const char* name )
55 : QDialog( parent, name, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
58 setName( "SMESHGUI_Preferences_ColorDlg" );
59 setCaption( tr( "Preferences - Set Color" ) );
60 setSizeGripEnabled( TRUE );
61 QGridLayout* SMESHGUI_Preferences_ColorDlgLayout = new QGridLayout( this );
62 SMESHGUI_Preferences_ColorDlgLayout->setSpacing( 6 );
63 SMESHGUI_Preferences_ColorDlgLayout->setMargin( 11 );
65 ButtonGroup1 = new QButtonGroup( tr( "Elements" ), this, "ButtonGroup1" );
66 ButtonGroup1->setColumnLayout(0, Qt::Vertical );
67 ButtonGroup1->layout()->setSpacing( 0 );
68 ButtonGroup1->layout()->setMargin( 0 );
69 QGridLayout* ButtonGroup1Layout = new QGridLayout( ButtonGroup1->layout() );
70 ButtonGroup1Layout->setAlignment( Qt::AlignTop );
71 ButtonGroup1Layout->setSpacing( 6 );
72 ButtonGroup1Layout->setMargin( 11 );
74 TextLabel_Fill = new QLabel( tr( "Fill" ), ButtonGroup1, "TextLabel_2D_Fill" );
75 ButtonGroup1Layout->addWidget( TextLabel_Fill, 0, 0 );
77 btnFillColor = new QPushButton( ButtonGroup1, "btnFillColor" );
78 btnFillColor->setFixedSize( QSize( 25, 25 ) );
79 ButtonGroup1Layout->addWidget( btnFillColor, 0, 1 );
81 TextLabel_Outine = new QLabel( tr( "Outline" ), ButtonGroup1, "TextLabel_2D_Outine" );
82 ButtonGroup1Layout->addWidget( TextLabel_Outine, 0, 2 );
84 btnOutlineColor = new QPushButton( ButtonGroup1, "btnOutlineColor" );
85 btnOutlineColor->setFixedSize( QSize( 25, 25 ) );
86 ButtonGroup1Layout->addWidget( btnOutlineColor, 0, 3 );
88 TextLabel_Width = new QLabel( tr( "Width" ), ButtonGroup1, "TextLabel_2D_Width" );
89 ButtonGroup1Layout->addWidget( TextLabel_Width, 0, 4 );
91 SpinBox_Width = new QSpinBox( 0, 5, 1, ButtonGroup1, "SpinBox_Width" );
92 SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
93 SpinBox_Width->setWrapping( FALSE );
94 SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
95 ButtonGroup1Layout->addWidget( SpinBox_Width, 0, 5 );
97 TextLabel_BackFace = new QLabel( tr( "Back Face" ), ButtonGroup1, "TextLabel_BackFace" );
98 ButtonGroup1Layout->addWidget( TextLabel_BackFace, 1, 0 );
100 btnBackFaceColor = new QPushButton( ButtonGroup1, "btnBackFaceColor" );
101 btnBackFaceColor->setFixedSize( QSize( 25, 25 ) );
102 ButtonGroup1Layout->addWidget( btnBackFaceColor, 1, 1 );
104 TextLabel_ShrinkCoeff = new QLabel( tr( "Shrink coef." ), ButtonGroup1, "TextLabel_ShrinkCoeff" );
105 ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff, 2, 0 );
107 SpinBox_Shrink = new QSpinBox( 20, 100, 1, ButtonGroup1, "SpinBox_Shrink" );
108 SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
109 SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
110 ButtonGroup1Layout->addMultiCellWidget( SpinBox_Shrink, 2, 2, 1, 5);
112 SMESHGUI_Preferences_ColorDlgLayout->addWidget( ButtonGroup1, 0, 0 );
114 ButtonGroup2 = new QButtonGroup( tr( "Nodes" ), this, "ButtonGroup2" );
115 ButtonGroup2->setColumnLayout(0, Qt::Vertical );
116 ButtonGroup2->layout()->setSpacing( 0 );
117 ButtonGroup2->layout()->setMargin( 0 );
118 QGridLayout* ButtonGroup2Layout = new QGridLayout( ButtonGroup2->layout() );
119 ButtonGroup2Layout->setAlignment( Qt::AlignTop );
120 ButtonGroup2Layout->setSpacing( 6 );
121 ButtonGroup2Layout->setMargin( 11 );
123 TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2, "TextLabel_Nodes_Color" );
124 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color, 0, 0 );
126 btnNodeColor = new QPushButton( ButtonGroup2, "btnNodeColor" );
127 btnNodeColor->setFixedSize( QSize( 25, 25 ) );
128 ButtonGroup2Layout->addWidget( btnNodeColor, 0, 1 );
130 TextLabel_Nodes_Size = new QLabel( tr( "Size" ), ButtonGroup2, "TextLabel_Nodes_Size" );
131 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Size, 0, 2 );
133 SpinBox_Nodes_Size = new QSpinBox( 0, 5, 1, ButtonGroup2, "SpinBox_Nodes_Size" );
134 SpinBox_Nodes_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
135 SpinBox_Nodes_Size->setWrapping( FALSE );
136 SpinBox_Nodes_Size->setButtonSymbols( QSpinBox::PlusMinus );
137 ButtonGroup2Layout->addWidget( SpinBox_Nodes_Size, 0, 3 );
139 SMESHGUI_Preferences_ColorDlgLayout->addWidget( ButtonGroup2, 1, 0 );
141 GroupButtons = new QButtonGroup( this, "GroupButtons" );
142 GroupButtons->setColumnLayout(0, Qt::Vertical );
143 GroupButtons->layout()->setSpacing( 0 );
144 GroupButtons->layout()->setMargin( 0 );
145 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
146 GroupButtonsLayout->setAlignment( Qt::AlignTop );
147 GroupButtonsLayout->setSpacing( 6 );
148 GroupButtonsLayout->setMargin( 11 );
150 buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
151 buttonOk->setAutoDefault( TRUE );
152 buttonOk->setDefault( TRUE );
153 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
155 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
157 buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons, "buttonCancel" );
158 buttonCancel->setAutoDefault( TRUE );
159 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
161 SMESHGUI_Preferences_ColorDlgLayout->addWidget( GroupButtons, 2, 0 );
167 * Destroys the object and frees any allocated resources
169 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
171 // no need to delete child widgets, Qt does it all for us
174 //=================================================================================
177 //=================================================================================
178 void SMESHGUI_Preferences_ColorDlg::Init()
180 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
181 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
183 /* signals and slots connections */
184 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
185 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
187 connect( btnFillColor, SIGNAL( clicked() ), this, SLOT( SelectFillColor() ) ) ;
188 connect( btnOutlineColor, SIGNAL( clicked() ), this, SLOT( SelectOutlineColor() ) ) ;
189 connect( btnNodeColor, SIGNAL( clicked() ), this, SLOT( SelectNodeColor() ) ) ;
190 connect( btnBackFaceColor, SIGNAL( clicked() ), this, SLOT( SelectBackFaceColor() ) ) ;
192 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
193 /* to close dialog if study change */
194 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
196 /* Move widget on the botton right corner of main widget */
198 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
202 //=================================================================================
203 // function : SelectFillColor()
205 //=================================================================================
206 void SMESHGUI_Preferences_ColorDlg::SelectFillColor()
208 QColor color = btnFillColor->palette().active().button();
209 color = QColorDialog::getColor( color );
210 if ( color.isValid() ) {
211 QPalette pal = btnFillColor->palette();
212 pal.setColor(QColorGroup::Button, color);
213 btnFillColor->setPalette(pal);
217 //=================================================================================
218 // function : SelectBackFaceColor()
220 //=================================================================================
221 void SMESHGUI_Preferences_ColorDlg::SelectBackFaceColor()
223 QColor color = btnBackFaceColor->palette().active().button();
224 color = QColorDialog::getColor( color );
225 if ( color.isValid() ) {
226 QPalette pal = btnBackFaceColor->palette();
227 pal.setColor(QColorGroup::Button, color);
228 btnBackFaceColor->setPalette(pal);
232 //=================================================================================
233 // function : SelectOutlineColor()
235 //=================================================================================
236 void SMESHGUI_Preferences_ColorDlg::SelectOutlineColor()
238 QColor color = btnOutlineColor->palette().active().button();
239 color = QColorDialog::getColor( color );
240 if ( color.isValid() ) {
241 QPalette pal = btnOutlineColor->palette();
242 pal.setColor(QColorGroup::Button, color);
243 btnOutlineColor->setPalette(pal);
247 //=================================================================================
248 // function : SelectNodeColor()
250 //=================================================================================
251 void SMESHGUI_Preferences_ColorDlg::SelectNodeColor()
253 QColor color = btnNodeColor->palette().active().button();
254 color = QColorDialog::getColor( color );
255 if ( color.isValid() ) {
256 QPalette pal = btnNodeColor->palette();
257 pal.setColor(QColorGroup::Button, color);
258 btnNodeColor->setPalette(pal);
262 //=================================================================================
263 // function : ClickOnOk()
265 //=================================================================================
266 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
268 mySMESHGUI->ResetState();
272 //=================================================================================
273 // function : ClickOnCancel()
275 //=================================================================================
276 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
278 mySMESHGUI->ResetState();
282 //=================================================================================
283 // function : DeactivateActiveDialog()
285 //=================================================================================
286 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
293 //=================================================================================
294 // function : closeEvent()
296 //=================================================================================
297 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* e )
299 this->ClickOnCancel() ; /* same than click on cancel button */
302 //=================================================================================
303 // function : ActivateThisDialog()
305 //=================================================================================
306 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
308 /* Emit a signal to deactivate any active dialog */
309 mySMESHGUI->EmitSignalDeactivateDialog() ;
314 //=================================================================================
315 // function : SetColor()
317 //=================================================================================
318 void SMESHGUI_Preferences_ColorDlg::SetColor(int type, QColor color)
323 QPalette pal = btnFillColor->palette();
324 pal.setColor(QColorGroup::Button, color);
325 btnFillColor->setPalette(pal);
330 QPalette pal = btnOutlineColor->palette();
331 pal.setColor(QColorGroup::Button, color);
332 btnOutlineColor->setPalette(pal);
337 QPalette pal = btnNodeColor->palette();
338 pal.setColor(QColorGroup::Button, color);
339 btnNodeColor->setPalette(pal);
342 case 4 : // back face
344 QPalette pal = btnBackFaceColor->palette();
345 pal.setColor(QColorGroup::Button, color);
346 btnBackFaceColor->setPalette(pal);
352 //=================================================================================
353 // function : GetColor()
355 //=================================================================================
356 QColor SMESHGUI_Preferences_ColorDlg::GetColor(int type)
360 case 1 : color = btnFillColor->palette().active().button(); break; // fill
361 case 2 : color = btnOutlineColor->palette().active().button(); break; // outline
362 case 3 : color = btnNodeColor->palette().active().button(); break; // node
363 case 4 : color = btnBackFaceColor->palette().active().button(); break; // back face
368 //=================================================================================
369 // function : SetIntValue()
371 //=================================================================================
372 void SMESHGUI_Preferences_ColorDlg::SetIntValue(int type, int value)
375 case 1 : SpinBox_Width->setValue(value); break; // width
376 case 2 : SpinBox_Nodes_Size->setValue(value); break; // nodes size = value; break;
377 case 3 : SpinBox_Shrink->setValue(value); break; // shrink coeff
381 //=================================================================================
382 // function : GetIntValue()
384 //=================================================================================
385 int SMESHGUI_Preferences_ColorDlg::GetIntValue(int type)
389 case 1 : res = SpinBox_Width->value(); break; // width
390 case 2 : res = SpinBox_Nodes_Size->value(); break; // nodes size
391 case 3 : res = SpinBox_Shrink->value(); break; // shrink coeff