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
24 // File : SMESHGUI_Preferences_ColorDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_Preferences_ColorDlg.h"
31 #include "SMESHGUI_Utils.h"
33 #include "utilities.h"
36 #include <qbuttongroup.h>
37 #include <qcheckbox.h>
38 #include <qcombobox.h>
42 #include <qpushbutton.h>
44 #include <qcolordialog.h>
48 #include "SUIT_Desktop.h"
52 //=================================================================================
53 // function : SMESHGUI_Preferences_ColorDlg()
54 // purpose : Constructs a SMESHGUI_Preferences_ColorDlg which is a child
55 // of 'parent', with the name 'name' and widget flags set to 'f'
56 // The dialog will by default be modeless, unless you
57 // set'modal' to TRUE to construct a modal dialog.
58 //=================================================================================
59 SMESHGUI_Preferences_ColorDlg::SMESHGUI_Preferences_ColorDlg( SMESHGUI* theModule, const char* name)
60 : QDialog( SMESH::GetDesktop( theModule ), name, true, WStyle_Customize |
61 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
62 mySMESHGUI( theModule )
65 setName("SMESHGUI_Preferences_ColorDlg");
66 setCaption(tr("Preferences - Set Color"));
67 setSizeGripEnabled(TRUE);
68 QGridLayout* SMESHGUI_Preferences_ColorDlgLayout = new QGridLayout(this);
69 SMESHGUI_Preferences_ColorDlgLayout->setSpacing(6);
70 SMESHGUI_Preferences_ColorDlgLayout->setMargin(11);
72 ButtonGroup1 = new QButtonGroup(tr("Elements"), this, "ButtonGroup1");
73 ButtonGroup1->setColumnLayout(0, Qt::Vertical);
74 ButtonGroup1->layout()->setSpacing(0);
75 ButtonGroup1->layout()->setMargin(0);
76 QGridLayout* ButtonGroup1Layout = new QGridLayout(ButtonGroup1->layout());
77 ButtonGroup1Layout->setAlignment(Qt::AlignTop);
78 ButtonGroup1Layout->setSpacing(6);
79 ButtonGroup1Layout->setMargin(11);
81 TextLabel_Fill = new QLabel(tr("Fill"), ButtonGroup1, "TextLabel_2D_Fill");
82 ButtonGroup1Layout->addWidget(TextLabel_Fill, 0, 0);
84 btnFillColor = new QPushButton(ButtonGroup1, "btnFillColor");
85 btnFillColor->setFixedSize(QSize(25, 25));
86 ButtonGroup1Layout->addWidget(btnFillColor, 0, 1);
88 TextLabel_Outine = new QLabel(tr("Outline"), ButtonGroup1, "TextLabel_2D_Outine");
89 ButtonGroup1Layout->addWidget(TextLabel_Outine, 0, 2);
91 btnOutlineColor = new QPushButton(ButtonGroup1, "btnOutlineColor");
92 btnOutlineColor->setFixedSize(QSize(25, 25));
93 ButtonGroup1Layout->addWidget(btnOutlineColor, 0, 3);
95 TextLabel_Width = new QLabel(tr("Width"), ButtonGroup1, "TextLabel_2D_Width");
96 ButtonGroup1Layout->addWidget(TextLabel_Width, 0, 4);
98 SpinBox_Width = new QSpinBox(0, 5, 1, ButtonGroup1, "SpinBox_Width");
99 SpinBox_Width->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
100 SpinBox_Width->setWrapping(FALSE);
101 SpinBox_Width->setButtonSymbols(QSpinBox::PlusMinus);
102 ButtonGroup1Layout->addWidget(SpinBox_Width, 0, 5);
104 TextLabel_BackFace = new QLabel(tr("Back Face"), ButtonGroup1, "TextLabel_BackFace");
105 ButtonGroup1Layout->addWidget(TextLabel_BackFace, 1, 0);
107 btnBackFaceColor = new QPushButton(ButtonGroup1, "btnBackFaceColor");
108 btnBackFaceColor->setFixedSize(QSize(25, 25));
109 ButtonGroup1Layout->addWidget(btnBackFaceColor, 1, 1);
111 TextLabel_ShrinkCoeff = new QLabel(tr("Shrink coef."), ButtonGroup1, "TextLabel_ShrinkCoeff");
112 ButtonGroup1Layout->addWidget(TextLabel_ShrinkCoeff, 2, 0);
114 SpinBox_Shrink = new QSpinBox(20, 100, 1, ButtonGroup1, "SpinBox_Shrink");
115 SpinBox_Shrink->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
116 SpinBox_Shrink->setButtonSymbols(QSpinBox::PlusMinus);
117 ButtonGroup1Layout->addMultiCellWidget(SpinBox_Shrink, 2, 2, 1, 5);
119 SMESHGUI_Preferences_ColorDlgLayout->addWidget(ButtonGroup1, 0, 0);
121 ButtonGroup2 = new QButtonGroup(tr("Nodes"), this, "ButtonGroup2");
122 ButtonGroup2->setColumnLayout(0, Qt::Vertical);
123 ButtonGroup2->layout()->setSpacing(0);
124 ButtonGroup2->layout()->setMargin(0);
125 QGridLayout* ButtonGroup2Layout = new QGridLayout(ButtonGroup2->layout());
126 ButtonGroup2Layout->setAlignment(Qt::AlignTop);
127 ButtonGroup2Layout->setSpacing(6);
128 ButtonGroup2Layout->setMargin(11);
130 TextLabel_Nodes_Color = new QLabel(tr("Color"), ButtonGroup2, "TextLabel_Nodes_Color");
131 ButtonGroup2Layout->addWidget(TextLabel_Nodes_Color, 0, 0);
133 btnNodeColor = new QPushButton(ButtonGroup2, "btnNodeColor");
134 btnNodeColor->setFixedSize(QSize(25, 25));
135 ButtonGroup2Layout->addWidget(btnNodeColor, 0, 1);
137 TextLabel_Nodes_Size = new QLabel(tr("Size"), ButtonGroup2, "TextLabel_Nodes_Size");
138 ButtonGroup2Layout->addWidget(TextLabel_Nodes_Size, 0, 2);
140 SpinBox_Nodes_Size = new QSpinBox(0, 5, 1, ButtonGroup2, "SpinBox_Nodes_Size");
141 SpinBox_Nodes_Size->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
142 SpinBox_Nodes_Size->setWrapping(FALSE);
143 SpinBox_Nodes_Size->setButtonSymbols(QSpinBox::PlusMinus);
144 ButtonGroup2Layout->addWidget(SpinBox_Nodes_Size, 0, 3);
146 SMESHGUI_Preferences_ColorDlgLayout->addWidget(ButtonGroup2, 1, 0);
148 GroupButtons = new QButtonGroup(this, "GroupButtons");
149 GroupButtons->setColumnLayout(0, Qt::Vertical);
150 GroupButtons->layout()->setSpacing(0);
151 GroupButtons->layout()->setMargin(0);
152 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
153 GroupButtonsLayout->setAlignment(Qt::AlignTop);
154 GroupButtonsLayout->setSpacing(6);
155 GroupButtonsLayout->setMargin(11);
157 buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk");
158 buttonOk->setAutoDefault(TRUE);
159 buttonOk->setDefault(TRUE);
160 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
162 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
164 buttonCancel = new QPushButton(tr("&Cancel"), GroupButtons, "buttonCancel");
165 buttonCancel->setAutoDefault(TRUE);
166 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
168 SMESHGUI_Preferences_ColorDlgLayout->addWidget(GroupButtons, 2, 0);
173 //=================================================================================
174 // function : ~SMESHGUI_Preferences_ColorDlg()
175 // purpose : Destructor
176 //=================================================================================
177 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
179 // no need to delete child widgets, Qt does it all for us
182 //=================================================================================
185 //=================================================================================
186 void SMESHGUI_Preferences_ColorDlg::Init()
188 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
190 /* signals and slots connections */
191 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
192 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
194 connect(btnFillColor, SIGNAL(clicked()), this, SLOT(SelectFillColor()));
195 connect(btnOutlineColor, SIGNAL(clicked()), this, SLOT(SelectOutlineColor()));
196 connect(btnNodeColor, SIGNAL(clicked()), this, SLOT(SelectNodeColor()));
197 connect(btnBackFaceColor, SIGNAL(clicked()), this, SLOT(SelectBackFaceColor()));
199 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
200 /* to close dialog if study change */
201 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
204 //=================================================================================
205 // function : SelectFillColor()
207 //=================================================================================
208 void SMESHGUI_Preferences_ColorDlg::SelectFillColor()
210 QColor color = btnFillColor->palette().active().button();
211 color = QColorDialog::getColor(color);
212 if (color.isValid()) {
213 QPalette pal = btnFillColor->palette();
214 pal.setColor(QColorGroup::Button, color);
215 btnFillColor->setPalette(pal);
219 //=================================================================================
220 // function : SelectBackFaceColor()
222 //=================================================================================
223 void SMESHGUI_Preferences_ColorDlg::SelectBackFaceColor()
225 QColor color = btnBackFaceColor->palette().active().button();
226 color = QColorDialog::getColor(color);
227 if (color.isValid()) {
228 QPalette pal = btnBackFaceColor->palette();
229 pal.setColor(QColorGroup::Button, color);
230 btnBackFaceColor->setPalette(pal);
234 //=================================================================================
235 // function : SelectOutlineColor()
237 //=================================================================================
238 void SMESHGUI_Preferences_ColorDlg::SelectOutlineColor()
240 QColor color = btnOutlineColor->palette().active().button();
241 color = QColorDialog::getColor(color);
242 if (color.isValid()) {
243 QPalette pal = btnOutlineColor->palette();
244 pal.setColor(QColorGroup::Button, color);
245 btnOutlineColor->setPalette(pal);
249 //=================================================================================
250 // function : SelectNodeColor()
252 //=================================================================================
253 void SMESHGUI_Preferences_ColorDlg::SelectNodeColor()
255 QColor color = btnNodeColor->palette().active().button();
256 color = QColorDialog::getColor(color);
257 if (color.isValid()) {
258 QPalette pal = btnNodeColor->palette();
259 pal.setColor(QColorGroup::Button, color);
260 btnNodeColor->setPalette(pal);
264 //=================================================================================
265 // function : ClickOnOk()
267 //=================================================================================
268 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
270 mySMESHGUI->ResetState();
274 //=================================================================================
275 // function : ClickOnCancel()
277 //=================================================================================
278 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
280 mySMESHGUI->ResetState();
284 //=================================================================================
285 // function : DeactivateActiveDialog()
287 //=================================================================================
288 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
292 //=================================================================================
293 // function : closeEvent()
295 //=================================================================================
296 void SMESHGUI_Preferences_ColorDlg::closeEvent (QCloseEvent*)
298 this->ClickOnCancel(); /* same than click on cancel button */
301 //=================================================================================
302 // function : ActivateThisDialog()
304 //=================================================================================
305 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
307 /* Emit a signal to deactivate any active dialog */
308 mySMESHGUI->EmitSignalDeactivateDialog();
311 //=================================================================================
312 // function : SetColor()
314 //=================================================================================
315 void SMESHGUI_Preferences_ColorDlg::SetColor (int type, QColor color)
320 QPalette pal = btnFillColor->palette();
321 pal.setColor(QColorGroup::Button, color);
322 btnFillColor->setPalette(pal);
327 QPalette pal = btnOutlineColor->palette();
328 pal.setColor(QColorGroup::Button, color);
329 btnOutlineColor->setPalette(pal);
334 QPalette pal = btnNodeColor->palette();
335 pal.setColor(QColorGroup::Button, color);
336 btnNodeColor->setPalette(pal);
339 case 4 : // back face
341 QPalette pal = btnBackFaceColor->palette();
342 pal.setColor(QColorGroup::Button, color);
343 btnBackFaceColor->setPalette(pal);
349 //=================================================================================
350 // function : GetColor()
352 //=================================================================================
353 QColor SMESHGUI_Preferences_ColorDlg::GetColor (int type)
357 case 1 : color = btnFillColor->palette().active().button(); break; // fill
358 case 2 : color = btnOutlineColor->palette().active().button(); break; // outline
359 case 3 : color = btnNodeColor->palette().active().button(); break; // node
360 case 4 : color = btnBackFaceColor->palette().active().button(); break; // back face
365 //=================================================================================
366 // function : SetIntValue()
368 //=================================================================================
369 void SMESHGUI_Preferences_ColorDlg::SetIntValue (int type, int value)
372 case 1 : SpinBox_Width->setValue(value); break; // width
373 case 2 : SpinBox_Nodes_Size->setValue(value); break; // nodes size = value; break;
374 case 3 : SpinBox_Shrink->setValue(value); break; // shrink coeff
378 //=================================================================================
379 // function : GetIntValue()
381 //=================================================================================
382 int SMESHGUI_Preferences_ColorDlg::GetIntValue (int type)
386 case 1 : res = SpinBox_Width->value(); break; // width
387 case 2 : res = SpinBox_Nodes_Size->value(); break; // nodes size
388 case 3 : res = SpinBox_Shrink->value(); break; // shrink coeff