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 <qbuttongroup.h>
35 #include <qcheckbox.h>
36 #include <qcombobox.h>
37 #include <qgroupbox.h>
39 #include <qlineedit.h>
40 #include <qpushbutton.h>
41 #include <qtoolbutton.h>
42 #include <qradiobutton.h>
45 #include <qvalidator.h>
46 #include <qcolordialog.h>
48 #include <vtkTextProperty.h>
49 #include <vtkScalarBarActor.h>
50 #include <vtkScalarsToColors.h>
52 #include "QAD_SpinBoxDbl.h"
53 #include "QAD_Config.h"
54 #include "SALOME_Selection.h"
56 #include "SMESH_Actor.h"
58 #define MINIMUM_WIDTH 70
59 #define MARGIN_SIZE 11
60 #define SPACING_SIZE 6
62 #define DEF_VER_X 0.01
63 #define DEF_VER_Y 0.10
64 #define DEF_VER_H 0.80
65 #define DEF_VER_W 0.10
66 #define DEF_HOR_X 0.20
67 #define DEF_HOR_Y 0.01
68 #define DEF_HOR_H 0.12
69 #define DEF_HOR_W 0.60
73 // Only one instance is allowed
74 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
76 //=================================================================================================
78 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
80 * Gets the only instance of "Scalar Bar Properties" dialog box
82 //=================================================================================================
83 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties(QWidget* parent,
84 SALOME_Selection* Sel)
87 myDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, Sel, false );
92 myDlg->setActiveWindow();
98 //=================================================================================================
100 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences
102 * Opens "Scalar Bar Preferences" dialog box
104 //=================================================================================================
105 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( QWidget* parent )
107 SMESHGUI_Preferences_ScalarBarDlg* aDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, 0, true );
111 //=================================================================================================
113 * SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
117 //=================================================================================================
118 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg(QWidget* parent,
119 SALOME_Selection* Sel,
121 : QDialog( parent, 0, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
123 setName( "SMESHGUI_Preferences_ScalarBarDlg" );
124 setCaption( Sel ? tr( "SMESH_PROPERTIES_SCALARBAR" ) : tr( "SMESH_PREFERENCES_SCALARBAR" ) );
125 setSizeGripEnabled( TRUE );
130 /******************************************************************************/
132 QGridLayout* aTopLayout = new QGridLayout( this );
133 aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
136 /******************************************************************************/
139 myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this, "myRangeGrp" );
140 myRangeGrp->setColumnLayout( 0, Qt::Vertical );
141 myRangeGrp->layout()->setSpacing( 0 ); myRangeGrp->layout()->setMargin( 0 );
142 QGridLayout* myRangeGrpLayout = new QGridLayout( myRangeGrp->layout() );
143 myRangeGrpLayout->setAlignment( Qt::AlignTop );
144 myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
146 myMinEdit = new QLineEdit( myRangeGrp, "myMinEdit" );
147 myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
148 myMinEdit->setValidator( new QDoubleValidator( this ) );
150 myMaxEdit = new QLineEdit( myRangeGrp, "myMaxEdit" );
151 myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
152 myMaxEdit->setValidator( new QDoubleValidator( this ) );
154 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp, "myMinLab" ), 0, 0 );
155 myRangeGrpLayout->addWidget( myMinEdit, 0, 1 );
156 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp, "myMaxLab" ), 0, 2 );
157 myRangeGrpLayout->addWidget( myMaxEdit, 0, 3 );
159 aTopLayout->addWidget( myRangeGrp, aRow, 0 );
163 /******************************************************************************/
165 myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this, "myFontGrp" );
166 myFontGrp->setColumnLayout( 0, Qt::Vertical );
167 myFontGrp->layout()->setSpacing( 0 ); myFontGrp->layout()->setMargin( 0 );
168 QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp->layout() );
169 myFontGrpLayout->setAlignment( Qt::AlignTop );
170 myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
172 myTitleColorBtn = new QToolButton( myFontGrp, "myTitleColorBtn" );
174 myTitleFontCombo = new QComboBox( false, myFontGrp, "myTitleFontCombo" );
175 myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
176 myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
177 myTitleFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
178 myTitleFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
179 myTitleFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
181 myTitleBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myTitleBoldCheck" );
182 myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myTitleItalicCheck" );
183 myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myTitleShadowCheck" );
185 myLabelsColorBtn = new QToolButton( myFontGrp, "myLabelsColorBtn" );
187 myLabelsFontCombo = new QComboBox( false, myFontGrp, "myLabelsFontCombo" );
188 myLabelsFontCombo->setMinimumWidth( MINIMUM_WIDTH );
189 myLabelsFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
190 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
191 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
192 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
194 myLabelsBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myLabelsBoldCheck" );
195 myLabelsItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myLabelsItalicCheck" );
196 myLabelsShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myLabelsShadowCheck" );
198 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_TITLE" ), myFontGrp, "myFontTitleLab" ), 0, 0 );
199 myFontGrpLayout->addWidget( myTitleColorBtn, 0, 1 );
200 myFontGrpLayout->addWidget( myTitleFontCombo, 0, 2 );
201 myFontGrpLayout->addWidget( myTitleBoldCheck, 0, 3 );
202 myFontGrpLayout->addWidget( myTitleItalicCheck, 0, 4 );
203 myFontGrpLayout->addWidget( myTitleShadowCheck, 0, 5 );
205 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_LABELS" ), myFontGrp, "myFontLabelsLab" ), 1, 0 );
206 myFontGrpLayout->addWidget( myLabelsColorBtn, 1, 1 );
207 myFontGrpLayout->addWidget( myLabelsFontCombo, 1, 2 );
208 myFontGrpLayout->addWidget( myLabelsBoldCheck, 1, 3 );
209 myFontGrpLayout->addWidget( myLabelsItalicCheck, 1, 4 );
210 myFontGrpLayout->addWidget( myLabelsShadowCheck, 1, 5 );
212 aTopLayout->addWidget( myFontGrp, aRow, 0 );
215 /******************************************************************************/
217 myLabColorGrp = new QGroupBox ( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), this, "myLabColorGrp" );
218 myLabColorGrp->setColumnLayout( 0, Qt::Vertical );
219 myLabColorGrp->layout()->setSpacing( 0 ); myLabColorGrp->layout()->setMargin( 0 );
220 QGridLayout* myLabColorGrpLayout = new QGridLayout( myLabColorGrp->layout() );
221 myLabColorGrpLayout->setAlignment( Qt::AlignTop );
222 myLabColorGrpLayout->setSpacing( SPACING_SIZE ); myLabColorGrpLayout->setMargin( MARGIN_SIZE );
224 myColorsSpin = new QSpinBox( 2, 256, 1, myLabColorGrp, "myColorsSpin" );
225 myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
226 myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
228 myLabelsSpin = new QSpinBox( 2, 65, 1, myLabColorGrp, "myLabelsSpin" );
229 myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
230 myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
232 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp, "myNbColorLab" ), 0, 0 );
233 myLabColorGrpLayout->addWidget( myColorsSpin, 0, 1 );
234 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp, "myNbLabsLab" ), 0, 2 );
235 myLabColorGrpLayout->addWidget( myLabelsSpin, 0, 3 );
237 aTopLayout->addWidget( myLabColorGrp, aRow, 0 );
240 /******************************************************************************/
242 myOrientationGrp = new QButtonGroup ( tr( "SMESH_ORIENTATION" ), this, "myOrientationGrp" );
243 myOrientationGrp->setColumnLayout( 0, Qt::Vertical );
244 myOrientationGrp->layout()->setSpacing( 0 ); myOrientationGrp->layout()->setMargin( 0 );
245 QGridLayout* myOrientationGrpLayout = new QGridLayout( myOrientationGrp->layout() );
246 myOrientationGrpLayout->setAlignment( Qt::AlignTop );
247 myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
249 myVertRadioBtn = new QRadioButton( tr( "SMESH_VERTICAL" ), myOrientationGrp, "myVertRadioBtn" );
250 myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp, "myHorizRadioBtn" );
251 myVertRadioBtn->setChecked( true );
253 myOrientationGrpLayout->addWidget( myVertRadioBtn, 0, 0 );
254 myOrientationGrpLayout->addWidget( myHorizRadioBtn, 0, 1 );
256 aTopLayout->addWidget( myOrientationGrp, aRow, 0 );
259 /******************************************************************************/
261 myOriginDimGrp = new QGroupBox ( tr( "SMESH_POSITION_SIZE_SCALARBAR" ), this, "myOriginDimGrp" );
262 myOriginDimGrp->setColumnLayout( 0, Qt::Vertical );
263 myOriginDimGrp->layout()->setSpacing( 0 ); myOriginDimGrp->layout()->setMargin( 0 );
264 QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp->layout() );
265 myOriginDimGrpLayout->setAlignment( Qt::AlignTop );
266 myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
268 myXSpin = new QAD_SpinBoxDbl( myOriginDimGrp, 0.0, 1.0, 0.1 );
269 myXSpin->setMinimumWidth( MINIMUM_WIDTH );
270 myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
272 myYSpin = new QAD_SpinBoxDbl( myOriginDimGrp, 0.0, 1.0, 0.1 );
273 myYSpin->setMinimumWidth( MINIMUM_WIDTH );
274 myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
276 myWidthSpin = new QAD_SpinBoxDbl( myOriginDimGrp, 0.0, 1.0, 0.1 );
277 myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
278 myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
280 myHeightSpin = new QAD_SpinBoxDbl( myOriginDimGrp, 0.0, 1.0, 0.1 );
281 myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
282 myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
284 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp, "myXLab" ), 0, 0 );
285 myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
286 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp, "myYLab" ), 0, 2 );
287 myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
288 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ), myOriginDimGrp, "myWidthLab" ), 1, 0 );
289 myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
290 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp, "myHeightLab" ), 1, 2 );
291 myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
293 aTopLayout->addWidget( myOriginDimGrp, aRow, 0 );
296 /***************************************************************/
298 myButtonGrp = new QGroupBox( this, "myButtonGrp" );
299 myButtonGrp->setColumnLayout(0, Qt::Vertical );
300 myButtonGrp->layout()->setSpacing( 0 ); myButtonGrp->layout()->setMargin( 0 );
301 QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp->layout() );
302 myButtonGrpLayout->setAlignment( Qt::AlignTop );
303 myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
305 myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), myButtonGrp, "myOkBtn" );
306 myOkBtn->setAutoDefault( TRUE ); myOkBtn->setDefault( TRUE );
307 myButtonGrpLayout->addWidget( myOkBtn );
309 myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp, "myApplyBtn" );
310 myApplyBtn->setAutoDefault( TRUE );
311 myButtonGrpLayout->addWidget( myApplyBtn );
313 myButtonGrpLayout->addStretch();
314 myCancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), myButtonGrp, "myCancelBtn" );
316 myCancelBtn->setText( tr( "SMESH_BUT_CLOSE" ) );
317 myCancelBtn->setAutoDefault( TRUE );
318 myButtonGrpLayout->addWidget( myCancelBtn );
320 aTopLayout->addWidget( myButtonGrp, aRow, 0 );
322 /***************************************************************/
324 // --> first init from preferences
325 QColor titleColor( 255, 255, 255 );
326 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarTitleColor" ) ) {
327 QStringList aTColor = QStringList::split( ":", QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleColor" ), false );
328 titleColor = QColor( ( aTColor.count() > 0 ? aTColor[0].toInt() : 255 ),
329 ( aTColor.count() > 1 ? aTColor[1].toInt() : 255 ),
330 ( aTColor.count() > 2 ? aTColor[2].toInt() : 255 ) );
332 myTitleColorBtn->setPaletteBackgroundColor( titleColor );
333 myTitleFontCombo->setCurrentItem( 0 );
334 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarTitleFont" ) ) {
335 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Arial" )
336 myTitleFontCombo->setCurrentItem( 0 );
337 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Courier" )
338 myTitleFontCombo->setCurrentItem( 1 );
339 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Times" )
340 myTitleFontCombo->setCurrentItem( 2 );
342 myTitleBoldCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleBold" ) == "true" );
343 myTitleItalicCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleItalic" ) == "true" );
344 myTitleShadowCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleShadow" ) == "true" );
346 QColor labelColor( 255, 255, 255 );
347 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarLabelColor" ) ) {
348 QStringList aLColor = QStringList::split( ":", QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelColor" ), false );
349 labelColor = QColor( ( aLColor.count() > 0 ? aLColor[0].toInt() : 255 ),
350 ( aLColor.count() > 1 ? aLColor[1].toInt() : 255 ),
351 ( aLColor.count() > 2 ? aLColor[2].toInt() : 255 ) );
353 myLabelsColorBtn->setPaletteBackgroundColor( labelColor );
354 myLabelsFontCombo->setCurrentItem( 0 );
355 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarLabelFont" ) ) {
356 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Arial" )
357 myLabelsFontCombo->setCurrentItem( 0 );
358 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Courier" )
359 myLabelsFontCombo->setCurrentItem( 1 );
360 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Times" )
361 myLabelsFontCombo->setCurrentItem( 2 );
363 myLabelsBoldCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelBold" ) == "true" );
364 myLabelsItalicCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelItalic" ) == "true" );
365 myLabelsShadowCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelShadow" ) == "true" );
368 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfColors" ) )
369 aNbColors = QAD_CONFIG->getSetting( "SMESH:ScalarBarNbOfColors" ).toInt();
370 myColorsSpin->setValue( aNbColors );
372 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfLabels" ) )
373 aNbLabels = QAD_CONFIG->getSetting( "SMESH:ScalarBarNbOfLabels" ).toInt();
374 myLabelsSpin->setValue( aNbLabels );
376 QString aOrientation = QAD_CONFIG->getSetting( "SMESH:ScalarBarOrientation" );
377 if ( aOrientation == "Horizontal" )
378 myHorizRadioBtn->setChecked( true );
380 myVertRadioBtn->setChecked( true );
381 myIniOrientation = myVertRadioBtn->isChecked();
383 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarXPosition" ) )
384 myIniX = QAD_CONFIG->getSetting( "SMESH:ScalarBarXPosition" ).toDouble();
386 myIniX = myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X;
387 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarYPosition" ) )
388 myIniY = QAD_CONFIG->getSetting( "SMESH:ScalarBarYPosition" ).toDouble();
390 myIniY = myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y;
391 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarWidth" ) )
392 myIniW = QAD_CONFIG->getSetting( "SMESH:ScalarBarWidth" ).toDouble();
394 myIniW = myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W;
395 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarHeight" ) )
396 myIniH = QAD_CONFIG->getSetting( "SMESH:ScalarBarHeight" ).toDouble();
398 myIniH = myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H;
399 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
402 // --> then init from selection if necessary
403 onSelectionChanged();
406 /***************************************************************/
408 connect( myTitleColorBtn, SIGNAL( clicked() ), this, SLOT( onTitleColor() ) );
409 connect( myLabelsColorBtn, SIGNAL( clicked() ), this, SLOT( onLabelsColor() ) );
410 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) );
411 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
412 connect( myXSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
413 connect( myYSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
414 connect( myOrientationGrp, SIGNAL( clicked( int ) ), this, SLOT( onOrientationChanged() ) );
416 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
417 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
419 connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalCloseAllDialogs() ), this, SLOT( onCancel() ) ) ;
422 //=================================================================================================
424 * SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
428 //=================================================================================================
429 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
433 //=================================================================================================
435 * SMESHGUI_Preferences_ScalarBarDlg::onOk
439 //=================================================================================================
440 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
446 //=================================================================================================
448 * SMESHGUI_Preferences_ScalarBarDlg::onApply
452 //=================================================================================================
453 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
456 // Scalar Bar properties
459 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
461 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
462 QColor aTColor = myTitleColorBtn->paletteBackgroundColor();
463 aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
464 if ( myTitleFontCombo->currentItem() == 0 )
465 aTitleTextPrp->SetFontFamilyToArial();
466 else if ( myTitleFontCombo->currentItem() == 1 )
467 aTitleTextPrp->SetFontFamilyToCourier();
469 aTitleTextPrp->SetFontFamilyToTimes();
470 aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
471 aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
472 aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
473 myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
475 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
476 QColor aLColor = myLabelsColorBtn->paletteBackgroundColor();
477 aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
478 if ( myLabelsFontCombo->currentItem() == 0 )
479 aLabelsTextPrp->SetFontFamilyToArial();
480 else if ( myLabelsFontCombo->currentItem() == 1 )
481 aLabelsTextPrp->SetFontFamilyToCourier();
483 aLabelsTextPrp->SetFontFamilyToTimes();
484 aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
485 aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
486 aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
487 myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
489 myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
490 myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
492 if ( myHorizRadioBtn->isChecked() )
493 myScalarBarActor->SetOrientationToHorizontal();
495 myScalarBarActor->SetOrientationToVertical();
497 myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
498 myScalarBarActor->SetWidth( myWidthSpin->value() );
499 myScalarBarActor->SetHeight( myHeightSpin->value() );
501 double aMin = myMinEdit->text().toDouble();
502 double aMax = myMaxEdit->text().toDouble();
503 myScalarBarActor->GetLookupTable()->SetRange( aMin, aMax );
504 SMESH::RepaintCurrentView();
507 // Scalar Bar preferences
508 QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
509 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleColor", QString().sprintf( "%d:%d:%d", titleColor.red(), titleColor.green(), titleColor.blue() ) );
510 if ( myTitleFontCombo->currentItem() == 0 )
511 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleFont", "Arial" );
512 else if ( myTitleFontCombo->currentItem() == 1 )
513 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleFont", "Courier" );
515 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleFont", "Times" );
516 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleBold", myTitleBoldCheck->isChecked() ? "true" : "false" );
517 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleItalic", myTitleItalicCheck->isChecked() ? "true" : "false" );
518 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleShadow", myTitleShadowCheck->isChecked() ? "true" : "false" );
520 QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
521 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelColor", QString().sprintf( "%d:%d:%d", labelColor.red(), labelColor.green(),labelColor. blue() ) );
522 if ( myLabelsFontCombo->currentItem() == 0 )
523 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelFont", "Arial" );
524 else if ( myLabelsFontCombo->currentItem() == 1 )
525 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelFont", "Courier" );
527 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelFont", "Times" );
528 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelBold", myLabelsBoldCheck->isChecked() ? "true" : "false" );
529 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelItalic", myLabelsItalicCheck->isChecked() ? "true" : "false" );
530 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelShadow", myLabelsShadowCheck->isChecked() ? "true" : "false" );
532 QAD_CONFIG->addSetting( "SMESH:ScalarBarNbOfColors", myColorsSpin->value() );
533 QAD_CONFIG->addSetting( "SMESH:ScalarBarNbOfLabels", myLabelsSpin->value() );
535 QAD_CONFIG->addSetting( "SMESH:ScalarBarOrientation", myHorizRadioBtn->isChecked() ? "Horizontal" : "Vertical" );
537 QAD_CONFIG->addSetting( "SMESH:ScalarBarXPosition", myXSpin->value() );
538 QAD_CONFIG->addSetting( "SMESH:ScalarBarYPosition", myYSpin->value() );
539 QAD_CONFIG->addSetting( "SMESH:ScalarBarWidth", myWidthSpin->value() );
540 QAD_CONFIG->addSetting( "SMESH:ScalarBarHeight", myHeightSpin->value() );
545 //=================================================================================================
547 * SMESHGUI_Preferences_ScalarBarDlg::onCancel
551 //=================================================================================================
552 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
557 //=================================================================================================
559 * SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
561 * Change Title color button slot
563 //=================================================================================================
564 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
566 QColor aColor = myTitleColorBtn->paletteBackgroundColor();
567 aColor = QColorDialog::getColor( aColor, this );
568 if ( aColor.isValid() )
569 myTitleColorBtn->setPaletteBackgroundColor( aColor );
572 //=================================================================================================
574 * SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
576 * Change Labels color button slot
578 //=================================================================================================
579 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
581 QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
582 aColor = QColorDialog::getColor( aColor, this );
583 if ( aColor.isValid() )
584 myLabelsColorBtn->setPaletteBackgroundColor( aColor );
587 //=================================================================================================
589 * SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
591 * Called when selection changed
593 //=================================================================================================
594 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
597 if ( mySelection->IObjectCount() == 1 ) {
598 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
599 if( anIO->hasEntry() ) {
600 SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
601 if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
603 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
605 if ( myScalarBarActor->GetLookupTable() ) {
606 float *range = myScalarBarActor->GetLookupTable()->GetRange();
607 myMinEdit->setText( QString::number( range[0] ) );
608 myMaxEdit->setText( QString::number( range[1] ) );
611 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
613 aTitleTextPrp->GetColor( aTColor );
614 myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
615 myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
616 myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
617 myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
618 myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
620 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
622 aLabelsTextPrp->GetColor( aLColor );
623 myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
624 myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
625 myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
626 myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
627 myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
629 myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
630 myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
632 if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
633 myVertRadioBtn->setChecked( true );
635 myHorizRadioBtn->setChecked( true );
636 myIniOrientation = myVertRadioBtn->isChecked();
638 myIniX = myScalarBarActor->GetPosition()[0];
639 myIniY = myScalarBarActor->GetPosition()[1];
640 myIniW = myScalarBarActor->GetWidth();
641 myIniH = myScalarBarActor->GetHeight();
642 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
644 myRangeGrp->setEnabled( true );
645 myFontGrp->setEnabled( true );
646 myLabColorGrp->setEnabled( true );
647 myOrientationGrp->setEnabled( true );
648 myOriginDimGrp->setEnabled( true );
649 myOkBtn->setEnabled( true );
650 myApplyBtn->setEnabled( true );
656 myRangeGrp->setEnabled( false );
657 myFontGrp->setEnabled( false );
658 myLabColorGrp->setEnabled( false );
659 myOrientationGrp->setEnabled( false );
660 myOriginDimGrp->setEnabled( false );
661 myOkBtn->setEnabled( false );
662 myApplyBtn->setEnabled( false );
666 //=================================================================================================
668 * SMESHGUI_Preferences_ScalarBarDlg::closeEvent
670 * Close event handler
672 //=================================================================================================
673 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
675 if ( mySelection ) // "Properties" dialog box
677 QDialog::closeEvent( e );
680 //=================================================================================================
682 * SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
684 * Called when X, Y values are changed
686 //=================================================================================================
687 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
689 myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
690 myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
693 //=================================================================================================
695 * SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
697 * Called when X, Y values are changed
699 //=================================================================================================
700 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
705 blockSignals( true );
706 myXSpin->setValue( x );
707 myYSpin->setValue( y );
708 myWidthSpin->setMaxValue( 1.0 );
709 myWidthSpin->setValue( w );
710 myHeightSpin->setMaxValue( 1.0 );
711 myHeightSpin->setValue( h );
712 blockSignals( false );
716 //=================================================================================================
718 * SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
720 * Called when orientation is changed
722 //=================================================================================================
723 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
725 int aOrientation = myVertRadioBtn->isChecked();
726 if ( aOrientation == myIniOrientation )
727 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
729 setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
730 aOrientation ? DEF_VER_Y : DEF_HOR_Y,
731 aOrientation ? DEF_VER_W : DEF_HOR_W,
732 aOrientation ? DEF_VER_H : DEF_HOR_H );