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_ScalarBarDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
32 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESH_Actor.h"
36 #include "SUIT_ResourceMgr.h"
38 #include "SalomeApp_SelectionMgr.h"
39 #include "SALOME_ListIO.hxx"
41 #include <QtxDblSpinBox.h>
43 #include <qbuttongroup.h>
44 #include <qcheckbox.h>
45 #include <qcombobox.h>
46 #include <qgroupbox.h>
48 #include <qlineedit.h>
49 #include <qpushbutton.h>
50 #include <qtoolbutton.h>
51 #include <qradiobutton.h>
54 #include <qvalidator.h>
55 #include <qcolordialog.h>
57 #include <vtkTextProperty.h>
58 #include <vtkScalarBarActor.h>
59 #include <vtkScalarsToColors.h>
61 #define MINIMUM_WIDTH 70
62 #define MARGIN_SIZE 11
63 #define SPACING_SIZE 6
65 #define DEF_VER_X 0.01
66 #define DEF_VER_Y 0.10
67 #define DEF_VER_H 0.80
68 #define DEF_VER_W 0.10
69 #define DEF_HOR_X 0.20
70 #define DEF_HOR_Y 0.01
71 #define DEF_HOR_H 0.12
72 #define DEF_HOR_W 0.60
76 // Only one instance is allowed
77 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
79 //=================================================================================================
81 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
83 * Gets the only instance of "Scalar Bar Properties" dialog box
85 //=================================================================================================
86 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties (QWidget* parent,
87 SalomeApp_SelectionMgr* Sel)
90 myDlg = new SMESHGUI_Preferences_ScalarBarDlg (parent, Sel, false);
94 myDlg->setActiveWindow();
100 //=================================================================================================
102 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences
104 * Opens "Scalar Bar Preferences" dialog box
106 //=================================================================================================
107 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences (QWidget* parent)
109 SMESHGUI_Preferences_ScalarBarDlg* aDlg =
110 new SMESHGUI_Preferences_ScalarBarDlg (parent, 0, true);
114 //=================================================================================================
116 * SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
120 //=================================================================================================
121 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg (QWidget* parent,
122 SalomeApp_SelectionMgr* Sel,
124 : QDialog(parent, 0, modal, WStyle_Customize | WStyle_NormalBorder |
125 WStyle_Title | WStyle_SysMenu | WDestructiveClose)
127 setName("SMESHGUI_Preferences_ScalarBarDlg");
128 setCaption(Sel ? tr("SMESH_PROPERTIES_SCALARBAR") : tr("SMESH_PREFERENCES_SCALARBAR"));
129 setSizeGripEnabled(TRUE);
131 mySelectionMgr = Sel;
134 /******************************************************************************/
136 QGridLayout* aTopLayout = new QGridLayout( this );
137 aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
140 /******************************************************************************/
142 if ( mySelectionMgr ) {
143 myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this, "myRangeGrp" );
144 myRangeGrp->setColumnLayout( 0, Qt::Vertical );
145 myRangeGrp->layout()->setSpacing( 0 ); myRangeGrp->layout()->setMargin( 0 );
146 QGridLayout* myRangeGrpLayout = new QGridLayout( myRangeGrp->layout() );
147 myRangeGrpLayout->setAlignment( Qt::AlignTop );
148 myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
150 myMinEdit = new QLineEdit( myRangeGrp, "myMinEdit" );
151 myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
152 myMinEdit->setValidator( new QDoubleValidator( this ) );
154 myMaxEdit = new QLineEdit( myRangeGrp, "myMaxEdit" );
155 myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
156 myMaxEdit->setValidator( new QDoubleValidator( this ) );
158 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp, "myMinLab" ), 0, 0 );
159 myRangeGrpLayout->addWidget( myMinEdit, 0, 1 );
160 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp, "myMaxLab" ), 0, 2 );
161 myRangeGrpLayout->addWidget( myMaxEdit, 0, 3 );
163 aTopLayout->addWidget( myRangeGrp, aRow, 0 );
167 /******************************************************************************/
169 myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this, "myFontGrp" );
170 myFontGrp->setColumnLayout( 0, Qt::Vertical );
171 myFontGrp->layout()->setSpacing( 0 ); myFontGrp->layout()->setMargin( 0 );
172 QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp->layout() );
173 myFontGrpLayout->setAlignment( Qt::AlignTop );
174 myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
176 myTitleColorBtn = new QToolButton( myFontGrp, "myTitleColorBtn" );
178 myTitleFontCombo = new QComboBox( false, myFontGrp, "myTitleFontCombo" );
179 myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
180 myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
181 myTitleFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
182 myTitleFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
183 myTitleFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
185 myTitleBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myTitleBoldCheck" );
186 myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myTitleItalicCheck" );
187 myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myTitleShadowCheck" );
189 myLabelsColorBtn = new QToolButton( myFontGrp, "myLabelsColorBtn" );
191 myLabelsFontCombo = new QComboBox( false, myFontGrp, "myLabelsFontCombo" );
192 myLabelsFontCombo->setMinimumWidth( MINIMUM_WIDTH );
193 myLabelsFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
194 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
195 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
196 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
198 myLabelsBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myLabelsBoldCheck" );
199 myLabelsItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myLabelsItalicCheck" );
200 myLabelsShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myLabelsShadowCheck" );
202 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_TITLE" ), myFontGrp, "myFontTitleLab" ), 0, 0 );
203 myFontGrpLayout->addWidget( myTitleColorBtn, 0, 1 );
204 myFontGrpLayout->addWidget( myTitleFontCombo, 0, 2 );
205 myFontGrpLayout->addWidget( myTitleBoldCheck, 0, 3 );
206 myFontGrpLayout->addWidget( myTitleItalicCheck, 0, 4 );
207 myFontGrpLayout->addWidget( myTitleShadowCheck, 0, 5 );
209 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_LABELS" ), myFontGrp, "myFontLabelsLab" ), 1, 0 );
210 myFontGrpLayout->addWidget( myLabelsColorBtn, 1, 1 );
211 myFontGrpLayout->addWidget( myLabelsFontCombo, 1, 2 );
212 myFontGrpLayout->addWidget( myLabelsBoldCheck, 1, 3 );
213 myFontGrpLayout->addWidget( myLabelsItalicCheck, 1, 4 );
214 myFontGrpLayout->addWidget( myLabelsShadowCheck, 1, 5 );
216 aTopLayout->addWidget( myFontGrp, aRow, 0 );
219 /******************************************************************************/
221 myLabColorGrp = new QGroupBox ( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), this, "myLabColorGrp" );
222 myLabColorGrp->setColumnLayout( 0, Qt::Vertical );
223 myLabColorGrp->layout()->setSpacing( 0 ); myLabColorGrp->layout()->setMargin( 0 );
224 QGridLayout* myLabColorGrpLayout = new QGridLayout( myLabColorGrp->layout() );
225 myLabColorGrpLayout->setAlignment( Qt::AlignTop );
226 myLabColorGrpLayout->setSpacing( SPACING_SIZE ); myLabColorGrpLayout->setMargin( MARGIN_SIZE );
228 myColorsSpin = new QSpinBox( 2, 256, 1, myLabColorGrp, "myColorsSpin" );
229 myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
230 myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
232 myLabelsSpin = new QSpinBox( 2, 65, 1, myLabColorGrp, "myLabelsSpin" );
233 myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
234 myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
236 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp, "myNbColorLab" ), 0, 0 );
237 myLabColorGrpLayout->addWidget( myColorsSpin, 0, 1 );
238 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp, "myNbLabsLab" ), 0, 2 );
239 myLabColorGrpLayout->addWidget( myLabelsSpin, 0, 3 );
241 aTopLayout->addWidget( myLabColorGrp, aRow, 0 );
244 /******************************************************************************/
246 myOrientationGrp = new QButtonGroup ( tr( "SMESH_ORIENTATION" ), this, "myOrientationGrp" );
247 myOrientationGrp->setColumnLayout( 0, Qt::Vertical );
248 myOrientationGrp->layout()->setSpacing( 0 ); myOrientationGrp->layout()->setMargin( 0 );
249 QGridLayout* myOrientationGrpLayout = new QGridLayout( myOrientationGrp->layout() );
250 myOrientationGrpLayout->setAlignment( Qt::AlignTop );
251 myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
253 myVertRadioBtn = new QRadioButton( tr( "SMESH_VERTICAL" ), myOrientationGrp, "myVertRadioBtn" );
254 myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp, "myHorizRadioBtn" );
255 myVertRadioBtn->setChecked( true );
257 myOrientationGrpLayout->addWidget( myVertRadioBtn, 0, 0 );
258 myOrientationGrpLayout->addWidget( myHorizRadioBtn, 0, 1 );
260 aTopLayout->addWidget( myOrientationGrp, aRow, 0 );
263 /******************************************************************************/
265 myOriginDimGrp = new QGroupBox (tr("SMESH_POSITION_SIZE_SCALARBAR"), this, "myOriginDimGrp");
266 myOriginDimGrp->setColumnLayout(0, Qt::Vertical);
267 myOriginDimGrp->layout()->setSpacing( 0 ); myOriginDimGrp->layout()->setMargin( 0 );
268 QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp->layout() );
269 myOriginDimGrpLayout->setAlignment( Qt::AlignTop );
270 myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
272 myXSpin = new QtxDblSpinBox (0.0, 1.0, 0.1, myOriginDimGrp);
273 myXSpin->setMinimumWidth( MINIMUM_WIDTH );
274 myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
276 myYSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
277 myYSpin->setMinimumWidth( MINIMUM_WIDTH );
278 myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
280 myWidthSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
281 myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
282 myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
284 myHeightSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
285 myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
286 myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
288 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp, "myXLab" ), 0, 0 );
289 myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
290 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp, "myYLab" ), 0, 2 );
291 myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
292 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ), myOriginDimGrp, "myWidthLab" ), 1, 0 );
293 myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
294 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp, "myHeightLab" ), 1, 2 );
295 myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
297 aTopLayout->addWidget( myOriginDimGrp, aRow, 0 );
300 /***************************************************************/
302 myButtonGrp = new QGroupBox( this, "myButtonGrp" );
303 myButtonGrp->setColumnLayout(0, Qt::Vertical );
304 myButtonGrp->layout()->setSpacing( 0 ); myButtonGrp->layout()->setMargin( 0 );
305 QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp->layout() );
306 myButtonGrpLayout->setAlignment( Qt::AlignTop );
307 myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
309 myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), myButtonGrp, "myOkBtn" );
310 myOkBtn->setAutoDefault( TRUE ); myOkBtn->setDefault( TRUE );
311 myButtonGrpLayout->addWidget( myOkBtn );
312 if ( mySelectionMgr ) {
313 myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp, "myApplyBtn" );
314 myApplyBtn->setAutoDefault( TRUE );
315 myButtonGrpLayout->addWidget( myApplyBtn );
317 myButtonGrpLayout->addStretch();
318 myCancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), myButtonGrp, "myCancelBtn" );
319 if ( mySelectionMgr )
320 myCancelBtn->setText( tr( "SMESH_BUT_CLOSE" ) );
321 myCancelBtn->setAutoDefault( TRUE );
322 myButtonGrpLayout->addWidget( myCancelBtn );
324 aTopLayout->addWidget( myButtonGrp, aRow, 0 );
326 /***************************************************************/
328 // --> first init from preferences
329 SUIT_ResourceMgr* mgr = SMESHGUI::resourceMgr();
331 QColor titleColor (255, 255, 255);
332 if (mgr && mgr->hasValue("SMESH", "ScalarBarTitleColor")) {
333 QStringList aTColor =
334 QStringList::split(":", mgr->stringValue("SMESH", "ScalarBarTitleColor"), false);
335 titleColor = QColor((aTColor.count() > 0 ? aTColor[0].toInt() : 255),
336 (aTColor.count() > 1 ? aTColor[1].toInt() : 255),
337 (aTColor.count() > 2 ? aTColor[2].toInt() : 255));
339 myTitleColorBtn->setPaletteBackgroundColor(titleColor);
340 myTitleFontCombo->setCurrentItem(0);
341 if (mgr && mgr->hasValue("SMESH", "ScalarBarTitleFont")) {
342 if (mgr->stringValue("SMESH", "ScalarBarTitleFont") == "Arial")
343 myTitleFontCombo->setCurrentItem(0);
344 if (mgr->stringValue("SMESH", "ScalarBarTitleFont") == "Courier")
345 myTitleFontCombo->setCurrentItem(1);
346 if (mgr->stringValue("SMESH", "ScalarBarTitleFont") == "Times")
347 myTitleFontCombo->setCurrentItem(2);
349 myTitleBoldCheck->setChecked (mgr && mgr->stringValue("SMESH", "ScalarBarTitleBold") == "true");
350 myTitleItalicCheck->setChecked(mgr && mgr->stringValue("SMESH", "ScalarBarTitleItalic") == "true");
351 myTitleShadowCheck->setChecked(mgr && mgr->stringValue("SMESH", "ScalarBarTitleShadow") == "true");
353 QColor labelColor (255, 255, 255);
354 if (mgr && mgr->hasValue("SMESH", "ScalarBarLabelColor")) {
355 QStringList aLColor =
356 QStringList::split(":", mgr->stringValue("SMESH", "ScalarBarLabelColor"), false);
357 labelColor = QColor((aLColor.count() > 0 ? aLColor[0].toInt() : 255),
358 (aLColor.count() > 1 ? aLColor[1].toInt() : 255),
359 (aLColor.count() > 2 ? aLColor[2].toInt() : 255));
361 myLabelsColorBtn->setPaletteBackgroundColor(labelColor);
362 myLabelsFontCombo->setCurrentItem(0);
363 if (mgr && mgr->hasValue("SMESH", "ScalarBarLabelFont")) {
364 if (mgr->stringValue("SMESH", "ScalarBarLabelFont") == "Arial")
365 myLabelsFontCombo->setCurrentItem(0);
366 if (mgr->stringValue("SMESH", "ScalarBarLabelFont") == "Courier")
367 myLabelsFontCombo->setCurrentItem(1);
368 if (mgr->stringValue("SMESH", "ScalarBarLabelFont") == "Times")
369 myLabelsFontCombo->setCurrentItem(2);
371 myLabelsBoldCheck ->setChecked(mgr && mgr->stringValue("SMESH", "ScalarBarLabelBold") == "true");
372 myLabelsItalicCheck->setChecked(mgr && mgr->stringValue("SMESH", "ScalarBarLabelItalic") == "true");
373 myLabelsShadowCheck->setChecked(mgr && mgr->stringValue("SMESH", "ScalarBarLabelShadow") == "true");
376 if (mgr && mgr->hasValue("SMESH", "ScalarBarNbOfColors"))
377 aNbColors = mgr->integerValue("SMESH", "ScalarBarNbOfColors");
378 myColorsSpin->setValue(aNbColors);
381 if (mgr && mgr->hasValue("SMESH", "ScalarBarNbOfLabels"))
382 aNbLabels = mgr->integerValue("SMESH", "ScalarBarNbOfLabels");
383 myLabelsSpin->setValue(aNbLabels);
385 QString aOrientation = (mgr ? mgr->stringValue("SMESH", "ScalarBarOrientation") : "");
386 if (aOrientation == "Horizontal")
387 myHorizRadioBtn->setChecked(true);
389 myVertRadioBtn->setChecked(true);
390 myIniOrientation = myVertRadioBtn->isChecked();
392 if (mgr && mgr->hasValue("SMESH", "ScalarBarXPosition"))
393 myIniX = mgr->doubleValue("SMESH", "ScalarBarXPosition");
395 myIniX = myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X;
397 if (mgr && mgr->hasValue("SMESH", "ScalarBarYPosition"))
398 myIniY = mgr->doubleValue("SMESH", "ScalarBarYPosition");
400 myIniY = myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y;
402 if (mgr && mgr->hasValue("SMESH", "ScalarBarWidth"))
403 myIniW = mgr->doubleValue("SMESH", "ScalarBarWidth");
405 myIniW = myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W;
407 if (mgr && mgr->hasValue("SMESH", "ScalarBarHeight"))
408 myIniH = mgr->doubleValue("SMESH", "ScalarBarHeight");
410 myIniH = myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H;
412 setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
414 if (mySelectionMgr) {
415 // --> then init from selection if necessary
416 onSelectionChanged();
419 /***************************************************************/
421 connect( myTitleColorBtn, SIGNAL( clicked() ), this, SLOT( onTitleColor() ) );
422 connect( myLabelsColorBtn, SIGNAL( clicked() ), this, SLOT( onLabelsColor() ) );
423 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) );
424 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
425 connect( myXSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
426 connect( myYSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
427 connect( myOrientationGrp, SIGNAL( clicked( int ) ), this, SLOT( onOrientationChanged() ) );
428 if ( mySelectionMgr ) {
429 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
430 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
432 connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalCloseAllDialogs() ), this, SLOT( onCancel() ) ) ;
435 //=================================================================================================
437 * SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
441 //=================================================================================================
442 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
446 //=================================================================================================
448 * SMESHGUI_Preferences_ScalarBarDlg::onOk
452 //=================================================================================================
453 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
459 //=================================================================================================
461 * SMESHGUI_Preferences_ScalarBarDlg::onApply
465 //=================================================================================================
466 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
468 if (mySelectionMgr) {
469 // Scalar Bar properties
472 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
474 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
475 QColor aTColor = myTitleColorBtn->paletteBackgroundColor();
476 aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
477 if ( myTitleFontCombo->currentItem() == 0 )
478 aTitleTextPrp->SetFontFamilyToArial();
479 else if ( myTitleFontCombo->currentItem() == 1 )
480 aTitleTextPrp->SetFontFamilyToCourier();
482 aTitleTextPrp->SetFontFamilyToTimes();
483 aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
484 aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
485 aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
486 myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
488 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
489 QColor aLColor = myLabelsColorBtn->paletteBackgroundColor();
490 aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
491 if ( myLabelsFontCombo->currentItem() == 0 )
492 aLabelsTextPrp->SetFontFamilyToArial();
493 else if ( myLabelsFontCombo->currentItem() == 1 )
494 aLabelsTextPrp->SetFontFamilyToCourier();
496 aLabelsTextPrp->SetFontFamilyToTimes();
497 aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
498 aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
499 aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
500 myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
502 myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
503 myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
505 if ( myHorizRadioBtn->isChecked() )
506 myScalarBarActor->SetOrientationToHorizontal();
508 myScalarBarActor->SetOrientationToVertical();
510 myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
511 myScalarBarActor->SetWidth( myWidthSpin->value() );
512 myScalarBarActor->SetHeight( myHeightSpin->value() );
514 double aMin = myMinEdit->text().toDouble();
515 double aMax = myMaxEdit->text().toDouble();
516 myScalarBarActor->GetLookupTable()->SetRange( aMin, aMax );
517 SMESH::RepaintCurrentView();
519 // Scalar Bar preferences
520 SUIT_ResourceMgr* mgr = SMESHGUI::resourceMgr();
521 if (!mgr) return false;
523 QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
524 mgr->setValue("SMESH", "ScalarBarTitleColor",
525 QString().sprintf("%d:%d:%d", titleColor.red(), titleColor.green(), titleColor.blue()));
526 if (myTitleFontCombo->currentItem() == 0)
527 mgr->setValue("SMESH", "ScalarBarTitleFont", "Arial");
528 else if (myTitleFontCombo->currentItem() == 1)
529 mgr->setValue("SMESH", "ScalarBarTitleFont", "Courier");
531 mgr->setValue("SMESH", "ScalarBarTitleFont", "Times");
533 mgr->setValue("SMESH", "ScalarBarTitleBold" , myTitleBoldCheck ->isChecked() ? "true" : "false");
534 mgr->setValue("SMESH", "ScalarBarTitleItalic", myTitleItalicCheck->isChecked() ? "true" : "false");
535 mgr->setValue("SMESH", "ScalarBarTitleShadow", myTitleShadowCheck->isChecked() ? "true" : "false");
537 QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
538 mgr->setValue("SMESH", "ScalarBarLabelColor",
539 QString().sprintf("%d:%d:%d", labelColor.red(), labelColor.green(),labelColor. blue()));
541 if (myLabelsFontCombo->currentItem() == 0)
542 mgr->setValue("SMESH", "ScalarBarLabelFont", "Arial");
543 else if ( myLabelsFontCombo->currentItem() == 1 )
544 mgr->setValue("SMESH", "ScalarBarLabelFont", "Courier");
546 mgr->setValue("SMESH", "ScalarBarLabelFont", "Times");
548 mgr->setValue("SMESH", "ScalarBarLabelBold", myLabelsBoldCheck->isChecked() ? "true" : "false");
549 mgr->setValue("SMESH", "ScalarBarLabelItalic", myLabelsItalicCheck->isChecked() ? "true" : "false");
550 mgr->setValue("SMESH", "ScalarBarLabelShadow", myLabelsShadowCheck->isChecked() ? "true" : "false");
552 mgr->setValue("SMESH", "ScalarBarNbOfColors", myColorsSpin->value());
553 mgr->setValue("SMESH", "ScalarBarNbOfLabels", myLabelsSpin->value());
555 mgr->setValue("SMESH", "ScalarBarOrientation", myHorizRadioBtn->isChecked() ? "Horizontal" : "Vertical");
557 mgr->setValue("SMESH", "ScalarBarXPosition", myXSpin->value());
558 mgr->setValue("SMESH", "ScalarBarYPosition", myYSpin->value());
559 mgr->setValue("SMESH", "ScalarBarWidth", myWidthSpin->value());
560 mgr->setValue("SMESH", "ScalarBarHeight", myHeightSpin->value());
565 //=================================================================================================
567 * SMESHGUI_Preferences_ScalarBarDlg::onCancel
571 //=================================================================================================
572 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
577 //=================================================================================================
579 * SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
581 * Change Title color button slot
583 //=================================================================================================
584 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
586 QColor aColor = myTitleColorBtn->paletteBackgroundColor();
587 aColor = QColorDialog::getColor( aColor, this );
588 if ( aColor.isValid() )
589 myTitleColorBtn->setPaletteBackgroundColor( aColor );
592 //=================================================================================================
594 * SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
596 * Change Labels color button slot
598 //=================================================================================================
599 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
601 QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
602 aColor = QColorDialog::getColor( aColor, this );
603 if ( aColor.isValid() )
604 myLabelsColorBtn->setPaletteBackgroundColor( aColor );
607 //=================================================================================================
609 * SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
611 * Called when selection changed
613 //=================================================================================================
614 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
616 if (mySelectionMgr) {
618 mySelectionMgr->selectedObjects(aList);
620 if (aList.Extent() == 1) {
621 Handle(SALOME_InteractiveObject) anIO = aList.First();
622 if( anIO->hasEntry() ) {
623 SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
624 if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
626 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
628 if ( myScalarBarActor->GetLookupTable() ) {
629 float *range = myScalarBarActor->GetLookupTable()->GetRange();
630 myMinEdit->setText( QString::number( range[0] ) );
631 myMaxEdit->setText( QString::number( range[1] ) );
634 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
636 aTitleTextPrp->GetColor( aTColor );
637 myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
638 myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
639 myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
640 myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
641 myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
643 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
645 aLabelsTextPrp->GetColor( aLColor );
646 myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
647 myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
648 myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
649 myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
650 myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
652 myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
653 myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
655 if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
656 myVertRadioBtn->setChecked( true );
658 myHorizRadioBtn->setChecked( true );
659 myIniOrientation = myVertRadioBtn->isChecked();
661 myIniX = myScalarBarActor->GetPosition()[0];
662 myIniY = myScalarBarActor->GetPosition()[1];
663 myIniW = myScalarBarActor->GetWidth();
664 myIniH = myScalarBarActor->GetHeight();
665 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
667 myRangeGrp->setEnabled( true );
668 myFontGrp->setEnabled( true );
669 myLabColorGrp->setEnabled( true );
670 myOrientationGrp->setEnabled( true );
671 myOriginDimGrp->setEnabled( true );
672 myOkBtn->setEnabled( true );
673 myApplyBtn->setEnabled( true );
679 myRangeGrp->setEnabled( false );
680 myFontGrp->setEnabled( false );
681 myLabColorGrp->setEnabled( false );
682 myOrientationGrp->setEnabled( false );
683 myOriginDimGrp->setEnabled( false );
684 myOkBtn->setEnabled( false );
685 myApplyBtn->setEnabled( false );
689 //=================================================================================================
691 * SMESHGUI_Preferences_ScalarBarDlg::closeEvent
693 * Close event handler
695 //=================================================================================================
696 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
698 if ( mySelectionMgr ) // "Properties" dialog box
700 QDialog::closeEvent( e );
703 //=================================================================================================
705 * SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
707 * Called when X, Y values are changed
709 //=================================================================================================
710 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
712 myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
713 myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
716 //=================================================================================================
718 * SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
720 * Called when X, Y values are changed
722 //=================================================================================================
723 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
728 blockSignals( true );
729 myXSpin->setValue( x );
730 myYSpin->setValue( y );
731 myWidthSpin->setMaxValue( 1.0 );
732 myWidthSpin->setValue( w );
733 myHeightSpin->setMaxValue( 1.0 );
734 myHeightSpin->setValue( h );
735 blockSignals( false );
739 //=================================================================================================
741 * SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
743 * Called when orientation is changed
745 //=================================================================================================
746 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
748 int aOrientation = myVertRadioBtn->isChecked();
749 if ( aOrientation == myIniOrientation )
750 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
752 setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
753 aOrientation ? DEF_VER_Y : DEF_HOR_Y,
754 aOrientation ? DEF_VER_W : DEF_HOR_W,
755 aOrientation ? DEF_VER_H : DEF_HOR_H );