2 // File : SMESHGUI_Preferences_ColorDlg.cxx
3 // Created : Mon Jun 17 19:11:27 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
11 #include "SMESHGUI_Preferences_ColorDlg.h"
14 #include "utilities.h"
16 #include <qbuttongroup.h>
17 #include <qcheckbox.h>
18 #include <qcombobox.h>
22 #include <qpushbutton.h>
24 #include <qcolordialog.h>
29 * Constructs a SMESHGUI_Preferences_ColorDlg which is a child of 'parent', with the
30 * name 'name' and widget flags set to 'f'
32 * The dialog will by default be modeless, unless you set 'modal' to
33 * TRUE to construct a modal dialog.
35 SMESHGUI_Preferences_ColorDlg::SMESHGUI_Preferences_ColorDlg( QWidget* parent, const char* name )
36 : QDialog( parent, name, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
39 setName( "SMESHGUI_Preferences_ColorDlg" );
40 setCaption( tr( "Preferences - Set Color" ) );
41 setSizeGripEnabled( TRUE );
42 QGridLayout* SMESHGUI_Preferences_ColorDlgLayout = new QGridLayout( this );
43 SMESHGUI_Preferences_ColorDlgLayout->setSpacing( 6 );
44 SMESHGUI_Preferences_ColorDlgLayout->setMargin( 11 );
46 ButtonGroup1 = new QButtonGroup( tr( "Elements" ), this, "ButtonGroup1" );
47 ButtonGroup1->setColumnLayout(0, Qt::Vertical );
48 ButtonGroup1->layout()->setSpacing( 0 );
49 ButtonGroup1->layout()->setMargin( 0 );
50 QGridLayout* ButtonGroup1Layout = new QGridLayout( ButtonGroup1->layout() );
51 ButtonGroup1Layout->setAlignment( Qt::AlignTop );
52 ButtonGroup1Layout->setSpacing( 6 );
53 ButtonGroup1Layout->setMargin( 11 );
55 TextLabel_Fill = new QLabel( tr( "Fill" ), ButtonGroup1, "TextLabel_2D_Fill" );
56 ButtonGroup1Layout->addWidget( TextLabel_Fill, 0, 0 );
58 btnFillColor = new QPushButton( ButtonGroup1, "btnFillColor" );
59 btnFillColor->setFixedSize( QSize( 25, 25 ) );
60 ButtonGroup1Layout->addWidget( btnFillColor, 0, 1 );
62 TextLabel_Outine = new QLabel( tr( "Outline" ), ButtonGroup1, "TextLabel_2D_Outine" );
63 ButtonGroup1Layout->addWidget( TextLabel_Outine, 0, 2 );
65 btnOutlineColor = new QPushButton( ButtonGroup1, "btnOutlineColor" );
66 btnOutlineColor->setFixedSize( QSize( 25, 25 ) );
67 ButtonGroup1Layout->addWidget( btnOutlineColor, 0, 3 );
69 TextLabel_Width = new QLabel( tr( "Width" ), ButtonGroup1, "TextLabel_2D_Width" );
70 ButtonGroup1Layout->addWidget( TextLabel_Width, 0, 4 );
72 SpinBox_Width = new QSpinBox( 0, 5, 1, ButtonGroup1, "SpinBox_Width" );
73 SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
74 SpinBox_Width->setWrapping( FALSE );
75 SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
76 ButtonGroup1Layout->addWidget( SpinBox_Width, 0, 5 );
78 TextLabel_BackFace = new QLabel( tr( "Back Face" ), ButtonGroup1, "TextLabel_BackFace" );
79 ButtonGroup1Layout->addWidget( TextLabel_BackFace, 1, 0 );
81 btnBackFaceColor = new QPushButton( ButtonGroup1, "btnBackFaceColor" );
82 btnBackFaceColor->setFixedSize( QSize( 25, 25 ) );
83 ButtonGroup1Layout->addWidget( btnBackFaceColor, 1, 1 );
85 TextLabel_ShrinkCoeff = new QLabel( tr( "Shrink coef." ), ButtonGroup1, "TextLabel_ShrinkCoeff" );
86 ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff, 2, 0 );
88 SpinBox_Shrink = new QSpinBox( 20, 100, 1, ButtonGroup1, "SpinBox_Shrink" );
89 SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
90 SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
91 ButtonGroup1Layout->addMultiCellWidget( SpinBox_Shrink, 2, 2, 1, 5);
93 SMESHGUI_Preferences_ColorDlgLayout->addWidget( ButtonGroup1, 0, 0 );
95 ButtonGroup2 = new QButtonGroup( tr( "Nodes" ), this, "ButtonGroup2" );
96 ButtonGroup2->setColumnLayout(0, Qt::Vertical );
97 ButtonGroup2->layout()->setSpacing( 0 );
98 ButtonGroup2->layout()->setMargin( 0 );
99 QGridLayout* ButtonGroup2Layout = new QGridLayout( ButtonGroup2->layout() );
100 ButtonGroup2Layout->setAlignment( Qt::AlignTop );
101 ButtonGroup2Layout->setSpacing( 6 );
102 ButtonGroup2Layout->setMargin( 11 );
104 TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2, "TextLabel_Nodes_Color" );
105 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color, 0, 0 );
107 btnNodeColor = new QPushButton( ButtonGroup2, "btnNodeColor" );
108 btnNodeColor->setFixedSize( QSize( 25, 25 ) );
109 ButtonGroup2Layout->addWidget( btnNodeColor, 0, 1 );
111 TextLabel_Nodes_Size = new QLabel( tr( "Size" ), ButtonGroup2, "TextLabel_Nodes_Size" );
112 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Size, 0, 2 );
114 SpinBox_Nodes_Size = new QSpinBox( 0, 5, 1, ButtonGroup2, "SpinBox_Nodes_Size" );
115 SpinBox_Nodes_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
116 SpinBox_Nodes_Size->setWrapping( FALSE );
117 SpinBox_Nodes_Size->setButtonSymbols( QSpinBox::PlusMinus );
118 ButtonGroup2Layout->addWidget( SpinBox_Nodes_Size, 0, 3 );
120 SMESHGUI_Preferences_ColorDlgLayout->addWidget( ButtonGroup2, 1, 0 );
122 GroupButtons = new QButtonGroup( this, "GroupButtons" );
123 GroupButtons->setColumnLayout(0, Qt::Vertical );
124 GroupButtons->layout()->setSpacing( 0 );
125 GroupButtons->layout()->setMargin( 0 );
126 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
127 GroupButtonsLayout->setAlignment( Qt::AlignTop );
128 GroupButtonsLayout->setSpacing( 6 );
129 GroupButtonsLayout->setMargin( 11 );
131 buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
132 buttonOk->setAutoDefault( TRUE );
133 buttonOk->setDefault( TRUE );
134 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
136 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
138 buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons, "buttonCancel" );
139 buttonCancel->setAutoDefault( TRUE );
140 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
142 SMESHGUI_Preferences_ColorDlgLayout->addWidget( GroupButtons, 2, 0 );
148 * Destroys the object and frees any allocated resources
150 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
152 // no need to delete child widgets, Qt does it all for us
155 //=================================================================================
158 //=================================================================================
159 void SMESHGUI_Preferences_ColorDlg::Init()
161 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
162 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
164 /* signals and slots connections */
165 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
166 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
168 connect( btnFillColor, SIGNAL( clicked() ), this, SLOT( SelectFillColor() ) ) ;
169 connect( btnOutlineColor, SIGNAL( clicked() ), this, SLOT( SelectOutlineColor() ) ) ;
170 connect( btnNodeColor, SIGNAL( clicked() ), this, SLOT( SelectNodeColor() ) ) ;
171 connect( btnBackFaceColor, SIGNAL( clicked() ), this, SLOT( SelectBackFaceColor() ) ) ;
173 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
174 /* to close dialog if study change */
175 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
177 /* Move widget on the botton right corner of main widget */
179 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
183 //=================================================================================
184 // function : SelectFillColor()
186 //=================================================================================
187 void SMESHGUI_Preferences_ColorDlg::SelectFillColor()
189 QColor color = btnFillColor->palette().active().button();
190 color = QColorDialog::getColor( color );
191 if ( color.isValid() ) {
192 QPalette pal = btnFillColor->palette();
193 pal.setColor(QColorGroup::Button, color);
194 btnFillColor->setPalette(pal);
198 //=================================================================================
199 // function : SelectBackFaceColor()
201 //=================================================================================
202 void SMESHGUI_Preferences_ColorDlg::SelectBackFaceColor()
204 QColor color = btnBackFaceColor->palette().active().button();
205 color = QColorDialog::getColor( color );
206 if ( color.isValid() ) {
207 QPalette pal = btnBackFaceColor->palette();
208 pal.setColor(QColorGroup::Button, color);
209 btnBackFaceColor->setPalette(pal);
213 //=================================================================================
214 // function : SelectOutlineColor()
216 //=================================================================================
217 void SMESHGUI_Preferences_ColorDlg::SelectOutlineColor()
219 QColor color = btnOutlineColor->palette().active().button();
220 color = QColorDialog::getColor( color );
221 if ( color.isValid() ) {
222 QPalette pal = btnOutlineColor->palette();
223 pal.setColor(QColorGroup::Button, color);
224 btnOutlineColor->setPalette(pal);
228 //=================================================================================
229 // function : SelectNodeColor()
231 //=================================================================================
232 void SMESHGUI_Preferences_ColorDlg::SelectNodeColor()
234 QColor color = btnNodeColor->palette().active().button();
235 color = QColorDialog::getColor( color );
236 if ( color.isValid() ) {
237 QPalette pal = btnNodeColor->palette();
238 pal.setColor(QColorGroup::Button, color);
239 btnNodeColor->setPalette(pal);
243 //=================================================================================
244 // function : ClickOnOk()
246 //=================================================================================
247 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
249 mySMESHGUI->ResetState();
253 //=================================================================================
254 // function : ClickOnCancel()
256 //=================================================================================
257 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
259 mySMESHGUI->ResetState();
263 //=================================================================================
264 // function : DeactivateActiveDialog()
266 //=================================================================================
267 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
274 //=================================================================================
275 // function : closeEvent()
277 //=================================================================================
278 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* e )
280 this->ClickOnCancel() ; /* same than click on cancel button */
283 //=================================================================================
284 // function : ActivateThisDialog()
286 //=================================================================================
287 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
289 /* Emit a signal to deactivate any active dialog */
290 mySMESHGUI->EmitSignalDeactivateDialog() ;
295 //=================================================================================
296 // function : SetColor()
298 //=================================================================================
299 void SMESHGUI_Preferences_ColorDlg::SetColor(int type, QColor color)
304 QPalette pal = btnFillColor->palette();
305 pal.setColor(QColorGroup::Button, color);
306 btnFillColor->setPalette(pal);
311 QPalette pal = btnOutlineColor->palette();
312 pal.setColor(QColorGroup::Button, color);
313 btnOutlineColor->setPalette(pal);
318 QPalette pal = btnNodeColor->palette();
319 pal.setColor(QColorGroup::Button, color);
320 btnNodeColor->setPalette(pal);
323 case 4 : // back face
325 QPalette pal = btnBackFaceColor->palette();
326 pal.setColor(QColorGroup::Button, color);
327 btnBackFaceColor->setPalette(pal);
333 //=================================================================================
334 // function : GetColor()
336 //=================================================================================
337 QColor SMESHGUI_Preferences_ColorDlg::GetColor(int type)
341 case 1 : color = btnFillColor->palette().active().button(); break; // fill
342 case 2 : color = btnOutlineColor->palette().active().button(); break; // outline
343 case 3 : color = btnNodeColor->palette().active().button(); break; // node
344 case 4 : color = btnBackFaceColor->palette().active().button(); break; // back face
349 //=================================================================================
350 // function : SetIntValue()
352 //=================================================================================
353 void SMESHGUI_Preferences_ColorDlg::SetIntValue(int type, int value)
356 case 1 : SpinBox_Width->setValue(value); break; // width
357 case 2 : SpinBox_Nodes_Size->setValue(value); break; // nodes size = value; break;
358 case 3 : SpinBox_Shrink->setValue(value); break; // shrink coeff
362 //=================================================================================
363 // function : GetIntValue()
365 //=================================================================================
366 int SMESHGUI_Preferences_ColorDlg::GetIntValue(int type)
370 case 1 : res = SpinBox_Width->value(); break; // width
371 case 2 : res = SpinBox_Nodes_Size->value(); break; // nodes size
372 case 3 : res = SpinBox_Shrink->value(); break; // shrink coeff