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
30 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
33 #include <qbuttongroup.h>
34 #include <qcheckbox.h>
35 #include <qcombobox.h>
36 #include <qgroupbox.h>
38 #include <qlineedit.h>
39 #include <qpushbutton.h>
40 #include <qtoolbutton.h>
41 #include <qradiobutton.h>
44 #include <qvalidator.h>
45 #include <qcolordialog.h>
47 #include <vtkTextProperty.h>
48 #include <vtkScalarBarActor.h>
50 #include "QAD_SpinBoxDbl.h"
51 #include "QAD_Config.h"
52 #include "SALOME_Selection.h"
54 #include "SMESH_Actor.h"
56 #define MINIMUM_WIDTH 70
57 #define MARGIN_SIZE 11
58 #define SPACING_SIZE 6
60 #define DEF_VER_X 0.01
61 #define DEF_VER_Y 0.10
62 #define DEF_VER_H 0.80
63 #define DEF_VER_W 0.10
64 #define DEF_HOR_X 0.20
65 #define DEF_HOR_Y 0.01
66 #define DEF_HOR_H 0.12
67 #define DEF_HOR_W 0.60
69 // Only one instance is allowed
70 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
72 //=================================================================================================
74 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
76 * Gets the only instance of "Scalar Bar Properties" dialog box
78 //=================================================================================================
79 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties(QWidget* parent,
80 SALOME_Selection* Sel)
83 myDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, Sel, false );
88 myDlg->setActiveWindow();
94 //=================================================================================================
96 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences
98 * Opens "Scalar Bar Preferences" dialog box
100 //=================================================================================================
101 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( QWidget* parent )
103 SMESHGUI_Preferences_ScalarBarDlg* aDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, 0, true );
107 //=================================================================================================
109 * SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
113 //=================================================================================================
114 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg(QWidget* parent,
115 SALOME_Selection* Sel,
117 : QDialog( parent, 0, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
119 setName( "SMESHGUI_Preferences_ScalarBarDlg" );
120 setCaption( Sel ? tr( "SMESH_PROPERTIES_SCALARBAR" ) : tr( "SMESH_PREFERENCES_SCALARBAR" ) );
121 setSizeGripEnabled( TRUE );
126 /******************************************************************************/
128 QGridLayout* aTopLayout = new QGridLayout( this );
129 aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
132 /******************************************************************************/
135 myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this, "myRangeGrp" );
136 myRangeGrp->setColumnLayout( 0, Qt::Vertical );
137 myRangeGrp->layout()->setSpacing( 0 ); myRangeGrp->layout()->setMargin( 0 );
138 QGridLayout* myRangeGrpLayout = new QGridLayout( myRangeGrp->layout() );
139 myRangeGrpLayout->setAlignment( Qt::AlignTop );
140 myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
142 myMinEdit = new QLineEdit( myRangeGrp, "myMinEdit" );
143 myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
144 myMinEdit->setValidator( new QDoubleValidator( this ) );
146 myMaxEdit = new QLineEdit( myRangeGrp, "myMaxEdit" );
147 myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
148 myMaxEdit->setValidator( new QDoubleValidator( this ) );
150 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp, "myMinLab" ), 0, 0 );
151 myRangeGrpLayout->addWidget( myMinEdit, 0, 1 );
152 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp, "myMaxLab" ), 0, 2 );
153 myRangeGrpLayout->addWidget( myMaxEdit, 0, 3 );
155 aTopLayout->addWidget( myRangeGrp, aRow, 0 );
159 /******************************************************************************/
161 myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this, "myFontGrp" );
162 myFontGrp->setColumnLayout( 0, Qt::Vertical );
163 myFontGrp->layout()->setSpacing( 0 ); myFontGrp->layout()->setMargin( 0 );
164 QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp->layout() );
165 myFontGrpLayout->setAlignment( Qt::AlignTop );
166 myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
168 myTitleColorBtn = new QToolButton( myFontGrp, "myTitleColorBtn" );
170 myTitleFontCombo = new QComboBox( false, myFontGrp, "myTitleFontCombo" );
171 myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
172 myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
173 myTitleFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
174 myTitleFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
175 myTitleFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
177 myTitleBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myTitleBoldCheck" );
178 myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myTitleItalicCheck" );
179 myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myTitleShadowCheck" );
181 myLabelsColorBtn = new QToolButton( myFontGrp, "myLabelsColorBtn" );
183 myLabelsFontCombo = new QComboBox( false, myFontGrp, "myLabelsFontCombo" );
184 myLabelsFontCombo->setMinimumWidth( MINIMUM_WIDTH );
185 myLabelsFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
186 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
187 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
188 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
190 myLabelsBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myLabelsBoldCheck" );
191 myLabelsItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myLabelsItalicCheck" );
192 myLabelsShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myLabelsShadowCheck" );
194 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_TITLE" ), myFontGrp, "myFontTitleLab" ), 0, 0 );
195 myFontGrpLayout->addWidget( myTitleColorBtn, 0, 1 );
196 myFontGrpLayout->addWidget( myTitleFontCombo, 0, 2 );
197 myFontGrpLayout->addWidget( myTitleBoldCheck, 0, 3 );
198 myFontGrpLayout->addWidget( myTitleItalicCheck, 0, 4 );
199 myFontGrpLayout->addWidget( myTitleShadowCheck, 0, 5 );
201 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_LABELS" ), myFontGrp, "myFontLabelsLab" ), 1, 0 );
202 myFontGrpLayout->addWidget( myLabelsColorBtn, 1, 1 );
203 myFontGrpLayout->addWidget( myLabelsFontCombo, 1, 2 );
204 myFontGrpLayout->addWidget( myLabelsBoldCheck, 1, 3 );
205 myFontGrpLayout->addWidget( myLabelsItalicCheck, 1, 4 );
206 myFontGrpLayout->addWidget( myLabelsShadowCheck, 1, 5 );
208 aTopLayout->addWidget( myFontGrp, aRow, 0 );
211 /******************************************************************************/
213 myLabColorGrp = new QGroupBox ( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), this, "myLabColorGrp" );
214 myLabColorGrp->setColumnLayout( 0, Qt::Vertical );
215 myLabColorGrp->layout()->setSpacing( 0 ); myLabColorGrp->layout()->setMargin( 0 );
216 QGridLayout* myLabColorGrpLayout = new QGridLayout( myLabColorGrp->layout() );
217 myLabColorGrpLayout->setAlignment( Qt::AlignTop );
218 myLabColorGrpLayout->setSpacing( SPACING_SIZE ); myLabColorGrpLayout->setMargin( MARGIN_SIZE );
220 myColorsSpin = new QSpinBox( 2, 256, 1, myLabColorGrp, "myColorsSpin" );
221 myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
222 myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
224 myLabelsSpin = new QSpinBox( 2, 65, 1, myLabColorGrp, "myLabelsSpin" );
225 myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
226 myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
228 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp, "myNbColorLab" ), 0, 0 );
229 myLabColorGrpLayout->addWidget( myColorsSpin, 0, 1 );
230 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp, "myNbLabsLab" ), 0, 2 );
231 myLabColorGrpLayout->addWidget( myLabelsSpin, 0, 3 );
233 aTopLayout->addWidget( myLabColorGrp, aRow, 0 );
236 /******************************************************************************/
238 myOrientationGrp = new QButtonGroup ( tr( "SMESH_ORIENTATION" ), this, "myOrientationGrp" );
239 myOrientationGrp->setColumnLayout( 0, Qt::Vertical );
240 myOrientationGrp->layout()->setSpacing( 0 ); myOrientationGrp->layout()->setMargin( 0 );
241 QGridLayout* myOrientationGrpLayout = new QGridLayout( myOrientationGrp->layout() );
242 myOrientationGrpLayout->setAlignment( Qt::AlignTop );
243 myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
245 myVertRadioBtn = new QRadioButton( tr( "SMESH_VERTICAL" ), myOrientationGrp, "myVertRadioBtn" );
246 myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp, "myHorizRadioBtn" );
247 myVertRadioBtn->setChecked( true );
249 myOrientationGrpLayout->addWidget( myVertRadioBtn, 0, 0 );
250 myOrientationGrpLayout->addWidget( myHorizRadioBtn, 0, 1 );
252 aTopLayout->addWidget( myOrientationGrp, aRow, 0 );
255 /******************************************************************************/
257 myOriginDimGrp = new QGroupBox ( tr( "SMESH_POSITION_SIZE_SCALARBAR" ), this, "myOriginDimGrp" );
258 myOriginDimGrp->setColumnLayout( 0, Qt::Vertical );
259 myOriginDimGrp->layout()->setSpacing( 0 ); myOriginDimGrp->layout()->setMargin( 0 );
260 QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp->layout() );
261 myOriginDimGrpLayout->setAlignment( Qt::AlignTop );
262 myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
264 myXSpin = new QAD_SpinBoxDbl( myOriginDimGrp, 0.0, 1.0, 0.1 );
265 myXSpin->setMinimumWidth( MINIMUM_WIDTH );
266 myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
268 myYSpin = new QAD_SpinBoxDbl( myOriginDimGrp, 0.0, 1.0, 0.1 );
269 myYSpin->setMinimumWidth( MINIMUM_WIDTH );
270 myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
272 myWidthSpin = new QAD_SpinBoxDbl( myOriginDimGrp, 0.0, 1.0, 0.1 );
273 myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
274 myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
276 myHeightSpin = new QAD_SpinBoxDbl( myOriginDimGrp, 0.0, 1.0, 0.1 );
277 myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
278 myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
280 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp, "myXLab" ), 0, 0 );
281 myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
282 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp, "myYLab" ), 0, 2 );
283 myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
284 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ), myOriginDimGrp, "myWidthLab" ), 1, 0 );
285 myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
286 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp, "myHeightLab" ), 1, 2 );
287 myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
289 aTopLayout->addWidget( myOriginDimGrp, aRow, 0 );
292 /***************************************************************/
294 myButtonGrp = new QGroupBox( this, "myButtonGrp" );
295 myButtonGrp->setColumnLayout(0, Qt::Vertical );
296 myButtonGrp->layout()->setSpacing( 0 ); myButtonGrp->layout()->setMargin( 0 );
297 QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp->layout() );
298 myButtonGrpLayout->setAlignment( Qt::AlignTop );
299 myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
301 myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), myButtonGrp, "myOkBtn" );
302 myOkBtn->setAutoDefault( TRUE ); myOkBtn->setDefault( TRUE );
303 myButtonGrpLayout->addWidget( myOkBtn );
305 myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp, "myApplyBtn" );
306 myApplyBtn->setAutoDefault( TRUE );
307 myButtonGrpLayout->addWidget( myApplyBtn );
309 myButtonGrpLayout->addStretch();
310 myCancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), myButtonGrp, "myCancelBtn" );
312 myCancelBtn->setText( tr( "SMESH_BUT_CLOSE" ) );
313 myCancelBtn->setAutoDefault( TRUE );
314 myButtonGrpLayout->addWidget( myCancelBtn );
316 aTopLayout->addWidget( myButtonGrp, aRow, 0 );
318 /***************************************************************/
320 // --> first init from preferences
321 QColor titleColor( 255, 255, 255 );
322 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarTitleColor" ) ) {
323 QStringList aTColor = QStringList::split( ":", QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleColor" ), false );
324 titleColor = QColor( ( aTColor.count() > 0 ? aTColor[0].toInt() : 255 ),
325 ( aTColor.count() > 1 ? aTColor[1].toInt() : 255 ),
326 ( aTColor.count() > 2 ? aTColor[2].toInt() : 255 ) );
328 myTitleColorBtn->setPaletteBackgroundColor( titleColor );
329 myTitleFontCombo->setCurrentItem( 0 );
330 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarTitleFont" ) ) {
331 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Arial" )
332 myTitleFontCombo->setCurrentItem( 0 );
333 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Courier" )
334 myTitleFontCombo->setCurrentItem( 1 );
335 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Times" )
336 myTitleFontCombo->setCurrentItem( 2 );
338 myTitleBoldCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleBold" ) == "true" );
339 myTitleItalicCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleItalic" ) == "true" );
340 myTitleShadowCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleShadow" ) == "true" );
342 QColor labelColor( 255, 255, 255 );
343 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarLabelColor" ) ) {
344 QStringList aLColor = QStringList::split( ":", QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelColor" ), false );
345 labelColor = QColor( ( aLColor.count() > 0 ? aLColor[0].toInt() : 255 ),
346 ( aLColor.count() > 1 ? aLColor[1].toInt() : 255 ),
347 ( aLColor.count() > 2 ? aLColor[2].toInt() : 255 ) );
349 myLabelsColorBtn->setPaletteBackgroundColor( labelColor );
350 myLabelsFontCombo->setCurrentItem( 0 );
351 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarLabelFont" ) ) {
352 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Arial" )
353 myLabelsFontCombo->setCurrentItem( 0 );
354 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Courier" )
355 myLabelsFontCombo->setCurrentItem( 1 );
356 if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Times" )
357 myLabelsFontCombo->setCurrentItem( 2 );
359 myLabelsBoldCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelBold" ) == "true" );
360 myLabelsItalicCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelItalic" ) == "true" );
361 myLabelsShadowCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelShadow" ) == "true" );
364 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfColors" ) )
365 aNbColors = QAD_CONFIG->getSetting( "SMESH:ScalarBarNbOfColors" ).toInt();
366 myColorsSpin->setValue( aNbColors );
368 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfLabels" ) )
369 aNbLabels = QAD_CONFIG->getSetting( "SMESH:ScalarBarNbOfLabels" ).toInt();
370 myLabelsSpin->setValue( aNbLabels );
372 QString aOrientation = QAD_CONFIG->getSetting( "SMESH:ScalarBarOrientation" );
373 if ( aOrientation == "Horizontal" )
374 myHorizRadioBtn->setChecked( true );
376 myVertRadioBtn->setChecked( true );
377 myIniOrientation = myVertRadioBtn->isChecked();
379 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarXPosition" ) )
380 myIniX = QAD_CONFIG->getSetting( "SMESH:ScalarBarXPosition" ).toDouble();
382 myIniX = myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X;
383 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarYPosition" ) )
384 myIniY = QAD_CONFIG->getSetting( "SMESH:ScalarBarYPosition" ).toDouble();
386 myIniY = myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y;
387 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarWidth" ) )
388 myIniW = QAD_CONFIG->getSetting( "SMESH:ScalarBarWidth" ).toDouble();
390 myIniW = myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W;
391 if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarHeight" ) )
392 myIniH = QAD_CONFIG->getSetting( "SMESH:ScalarBarHeight" ).toDouble();
394 myIniH = myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H;
395 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
398 // --> then init from selection if necessary
399 onSelectionChanged();
402 /***************************************************************/
404 connect( myTitleColorBtn, SIGNAL( clicked() ), this, SLOT( onTitleColor() ) );
405 connect( myLabelsColorBtn, SIGNAL( clicked() ), this, SLOT( onLabelsColor() ) );
406 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) );
407 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
408 connect( myXSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
409 connect( myYSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
410 connect( myOrientationGrp, SIGNAL( clicked( int ) ), this, SLOT( onOrientationChanged() ) );
412 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
413 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
415 connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalCloseAllDialogs() ), this, SLOT( onCancel() ) ) ;
418 //=================================================================================================
420 * SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
424 //=================================================================================================
425 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
429 //=================================================================================================
431 * SMESHGUI_Preferences_ScalarBarDlg::onOk
435 //=================================================================================================
436 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
442 //=================================================================================================
444 * SMESHGUI_Preferences_ScalarBarDlg::onApply
448 //=================================================================================================
449 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
452 // Scalar Bar properties
455 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
457 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
458 QColor aTColor = myTitleColorBtn->paletteBackgroundColor();
459 aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
460 if ( myTitleFontCombo->currentItem() == 0 )
461 aTitleTextPrp->SetFontFamilyToArial();
462 else if ( myTitleFontCombo->currentItem() == 1 )
463 aTitleTextPrp->SetFontFamilyToCourier();
465 aTitleTextPrp->SetFontFamilyToTimes();
466 aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
467 aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
468 aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
469 myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
471 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
472 QColor aLColor = myLabelsColorBtn->paletteBackgroundColor();
473 aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
474 if ( myLabelsFontCombo->currentItem() == 0 )
475 aLabelsTextPrp->SetFontFamilyToArial();
476 else if ( myLabelsFontCombo->currentItem() == 1 )
477 aLabelsTextPrp->SetFontFamilyToCourier();
479 aLabelsTextPrp->SetFontFamilyToTimes();
480 aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
481 aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
482 aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
483 myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
485 myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
486 myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
488 if ( myHorizRadioBtn->isChecked() )
489 myScalarBarActor->SetOrientationToHorizontal();
491 myScalarBarActor->SetOrientationToVertical();
493 myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
494 myScalarBarActor->SetWidth( myWidthSpin->value() );
495 myScalarBarActor->SetHeight( myHeightSpin->value() );
497 double aMin = myMinEdit->text().toDouble();
498 double aMax = myMaxEdit->text().toDouble();
499 myScalarBarActor->GetLookupTable()->SetRange( aMin, aMax );
500 SMESHGUI::GetSMESHGUI()->UpdateView();
503 // Scalar Bar preferences
504 QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
505 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleColor", QString().sprintf( "%d:%d:%d", titleColor.red(), titleColor.green(), titleColor.blue() ) );
506 if ( myTitleFontCombo->currentItem() == 0 )
507 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleFont", "Arial" );
508 else if ( myTitleFontCombo->currentItem() == 1 )
509 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleFont", "Courier" );
511 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleFont", "Times" );
512 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleBold", myTitleBoldCheck->isChecked() ? "true" : "false" );
513 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleItalic", myTitleItalicCheck->isChecked() ? "true" : "false" );
514 QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleShadow", myTitleShadowCheck->isChecked() ? "true" : "false" );
516 QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
517 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelColor", QString().sprintf( "%d:%d:%d", labelColor.red(), labelColor.green(),labelColor. blue() ) );
518 if ( myLabelsFontCombo->currentItem() == 0 )
519 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelFont", "Arial" );
520 else if ( myLabelsFontCombo->currentItem() == 1 )
521 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelFont", "Courier" );
523 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelFont", "Times" );
524 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelBold", myLabelsBoldCheck->isChecked() ? "true" : "false" );
525 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelItalic", myLabelsItalicCheck->isChecked() ? "true" : "false" );
526 QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelShadow", myLabelsShadowCheck->isChecked() ? "true" : "false" );
528 QAD_CONFIG->addSetting( "SMESH:ScalarBarNbOfColors", myColorsSpin->value() );
529 QAD_CONFIG->addSetting( "SMESH:ScalarBarNbOfLabels", myLabelsSpin->value() );
531 QAD_CONFIG->addSetting( "SMESH:ScalarBarOrientation", myHorizRadioBtn->isChecked() ? "Horizontal" : "Vertical" );
533 QAD_CONFIG->addSetting( "SMESH:ScalarBarXPosition", myXSpin->value() );
534 QAD_CONFIG->addSetting( "SMESH:ScalarBarYPosition", myYSpin->value() );
535 QAD_CONFIG->addSetting( "SMESH:ScalarBarWidth", myWidthSpin->value() );
536 QAD_CONFIG->addSetting( "SMESH:ScalarBarHeight", myHeightSpin->value() );
541 //=================================================================================================
543 * SMESHGUI_Preferences_ScalarBarDlg::onCancel
547 //=================================================================================================
548 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
553 //=================================================================================================
555 * SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
557 * Change Title color button slot
559 //=================================================================================================
560 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
562 QColor aColor = myTitleColorBtn->paletteBackgroundColor();
563 aColor = QColorDialog::getColor( aColor, this );
564 if ( aColor.isValid() )
565 myTitleColorBtn->setPaletteBackgroundColor( aColor );
568 //=================================================================================================
570 * SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
572 * Change Labels color button slot
574 //=================================================================================================
575 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
577 QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
578 aColor = QColorDialog::getColor( aColor, this );
579 if ( aColor.isValid() )
580 myLabelsColorBtn->setPaletteBackgroundColor( aColor );
583 //=================================================================================================
585 * SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
587 * Called when selection changed
589 //=================================================================================================
590 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
593 if ( mySelection->IObjectCount() == 1 ) {
594 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
595 if( anIO->hasEntry() ) {
596 Standard_Boolean isOk;
597 SMESH_Actor* anActor = SMESHGUI::GetSMESHGUI()->FindActorByEntry( anIO->getEntry(), isOk, true );
598 if ( isOk && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
600 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
602 double aMin = 0.0, aMax = 0.0;
603 if ( myScalarBarActor->GetLookupTable() ) {
604 float *range = myScalarBarActor->GetLookupTable()->GetRange();
605 myMinEdit->setText( QString::number( range[0] ) );
606 myMaxEdit->setText( QString::number( range[1] ) );
609 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
611 aTitleTextPrp->GetColor( aTColor );
612 myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
613 myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
614 myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
615 myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
616 myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
618 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
620 aLabelsTextPrp->GetColor( aLColor );
621 myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
622 myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
623 myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
624 myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
625 myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
627 myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
628 myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
630 if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
631 myVertRadioBtn->setChecked( true );
633 myHorizRadioBtn->setChecked( true );
634 myIniOrientation = myVertRadioBtn->isChecked();
636 myIniX = myScalarBarActor->GetPosition()[0];
637 myIniY = myScalarBarActor->GetPosition()[1];
638 myIniW = myScalarBarActor->GetWidth();
639 myIniH = myScalarBarActor->GetHeight();
640 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
642 myRangeGrp->setEnabled( true );
643 myFontGrp->setEnabled( true );
644 myLabColorGrp->setEnabled( true );
645 myOrientationGrp->setEnabled( true );
646 myOriginDimGrp->setEnabled( true );
647 myOkBtn->setEnabled( true );
648 myApplyBtn->setEnabled( true );
654 myRangeGrp->setEnabled( false );
655 myFontGrp->setEnabled( false );
656 myLabColorGrp->setEnabled( false );
657 myOrientationGrp->setEnabled( false );
658 myOriginDimGrp->setEnabled( false );
659 myOkBtn->setEnabled( false );
660 myApplyBtn->setEnabled( false );
664 //=================================================================================================
666 * SMESHGUI_Preferences_ScalarBarDlg::closeEvent
668 * Close event handler
670 //=================================================================================================
671 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
673 if ( mySelection ) // "Properties" dialog box
675 QDialog::closeEvent( e );
678 //=================================================================================================
680 * SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
682 * Called when X, Y values are changed
684 //=================================================================================================
685 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
687 myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
688 myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
691 //=================================================================================================
693 * SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
695 * Called when X, Y values are changed
697 //=================================================================================================
698 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
703 blockSignals( true );
704 myXSpin->setValue( x );
705 myYSpin->setValue( y );
706 myWidthSpin->setMaxValue( 1.0 );
707 myWidthSpin->setValue( w );
708 myHeightSpin->setMaxValue( 1.0 );
709 myHeightSpin->setValue( h );
710 blockSignals( false );
714 //=================================================================================================
716 * SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
718 * Called when orientation is changed
720 //=================================================================================================
721 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
723 int aOrientation = myVertRadioBtn->isChecked();
724 if ( aOrientation == myIniOrientation )
725 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
727 setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
728 aOrientation ? DEF_VER_Y : DEF_HOR_Y,
729 aOrientation ? DEF_VER_W : DEF_HOR_W,
730 aOrientation ? DEF_VER_H : DEF_HOR_H );