Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Preferences_ScalarBarDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_Preferences_ScalarBarDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
31 #include "SMESHGUI.h"
32
33 #include <qbuttongroup.h>
34 #include <qcheckbox.h>
35 #include <qcombobox.h>
36 #include <qgroupbox.h>
37 #include <qlabel.h>
38 #include <qlineedit.h>
39 #include <qpushbutton.h>
40 #include <qtoolbutton.h>
41 #include <qradiobutton.h>
42 #include <qspinbox.h>
43 #include <qlayout.h>
44 #include <qvalidator.h>
45 #include <qcolordialog.h>
46
47 #include <vtkTextProperty.h>
48 #include <vtkScalarBarActor.h>
49
50 #include "QAD_SpinBoxDbl.h"
51 #include "QAD_Config.h"
52 #include "SALOME_Selection.h"
53 #include "SMESHGUI.h"
54 #include "SMESH_Actor.h"
55
56 #define MINIMUM_WIDTH 70
57 #define MARGIN_SIZE   11
58 #define SPACING_SIZE   6
59
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
68
69 // Only one instance is allowed
70 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
71
72 //=================================================================================================
73 /*!
74  *  SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
75  *
76  *  Gets the only instance of "Scalar Bar Properties" dialog box
77  */
78 //=================================================================================================
79 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties(QWidget* parent, 
80                                                             SALOME_Selection* Sel)
81 {
82   if ( !myDlg ) {
83     myDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, Sel, false );
84     myDlg->show();
85   }
86   else {
87     myDlg->show();
88     myDlg->setActiveWindow();
89     myDlg->raise();
90     myDlg->setFocus();
91   }
92 }
93
94 //=================================================================================================
95 /*!
96  *  SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences
97  *
98  *  Opens "Scalar Bar Preferences" dialog box
99  */
100 //=================================================================================================
101 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( QWidget* parent )
102 {
103   SMESHGUI_Preferences_ScalarBarDlg* aDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, 0, true );
104   aDlg->exec();
105 }
106
107 //=================================================================================================
108 /*!
109  *  SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
110  *
111  *  Constructor
112  */
113 //=================================================================================================
114 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg(QWidget* parent, 
115                                                                      SALOME_Selection* Sel, 
116                                                                      bool modal)
117      : QDialog( parent, 0, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
118 {
119   setName( "SMESHGUI_Preferences_ScalarBarDlg" );
120   setCaption( Sel ? tr( "SMESH_PROPERTIES_SCALARBAR" ) : tr( "SMESH_PREFERENCES_SCALARBAR" ) );
121   setSizeGripEnabled( TRUE );
122
123   mySelection = Sel;
124   myActor = 0;
125
126   /******************************************************************************/
127   // Top layout
128   QGridLayout* aTopLayout = new QGridLayout( this );
129   aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
130   int aRow = 0;
131
132   /******************************************************************************/
133   // Scalar range
134   if ( mySelection ) {
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 );
141     
142     myMinEdit = new QLineEdit( myRangeGrp, "myMinEdit" );
143     myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
144     myMinEdit->setValidator( new QDoubleValidator( this ) );
145
146     myMaxEdit = new QLineEdit( myRangeGrp, "myMaxEdit" );
147     myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
148     myMaxEdit->setValidator( new QDoubleValidator( this ) );
149
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 );
154
155     aTopLayout->addWidget( myRangeGrp, aRow, 0 );
156     aRow++;
157   }
158
159   /******************************************************************************/
160   // Text properties
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 );
167     
168   myTitleColorBtn = new QToolButton( myFontGrp, "myTitleColorBtn" );
169   
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" ) );
176   
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" );
180
181   myLabelsColorBtn = new QToolButton( myFontGrp, "myLabelsColorBtn" );
182   
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" ) );
189   
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" );
193
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 );
200   
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 );
207
208   aTopLayout->addWidget( myFontGrp, aRow, 0 );
209   aRow++;
210
211   /******************************************************************************/
212   // Labels & Colors
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 );
219     
220   myColorsSpin = new QSpinBox( 2, 256, 1, myLabColorGrp, "myColorsSpin" );
221   myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
222   myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
223
224   myLabelsSpin = new QSpinBox( 2, 65, 1, myLabColorGrp, "myLabelsSpin" );
225   myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
226   myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
227
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 );
232
233   aTopLayout->addWidget( myLabColorGrp, aRow, 0 );
234   aRow++;
235
236   /******************************************************************************/
237   // Orientation
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 );
244     
245   myVertRadioBtn  = new QRadioButton( tr( "SMESH_VERTICAL" ),   myOrientationGrp, "myVertRadioBtn" );
246   myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp, "myHorizRadioBtn" );
247   myVertRadioBtn->setChecked( true );
248
249   myOrientationGrpLayout->addWidget( myVertRadioBtn,  0, 0 );
250   myOrientationGrpLayout->addWidget( myHorizRadioBtn, 0, 1 );
251
252   aTopLayout->addWidget( myOrientationGrp, aRow, 0 );
253   aRow++;
254
255   /******************************************************************************/
256   // Position & Size
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 );
263     
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 ) );
267
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 ) );
271
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 ) );
275
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 ) );
279
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 );
288
289   aTopLayout->addWidget( myOriginDimGrp, aRow, 0 );
290   aRow++;
291
292   /***************************************************************/
293   // Common buttons
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 );
300
301   myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), myButtonGrp, "myOkBtn" );
302   myOkBtn->setAutoDefault( TRUE ); myOkBtn->setDefault( TRUE );
303   myButtonGrpLayout->addWidget( myOkBtn );
304   if ( mySelection ) {
305     myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp, "myApplyBtn" );
306     myApplyBtn->setAutoDefault( TRUE );
307     myButtonGrpLayout->addWidget( myApplyBtn );
308   }
309   myButtonGrpLayout->addStretch();
310   myCancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), myButtonGrp, "myCancelBtn" );
311   if ( mySelection )
312     myCancelBtn->setText( tr( "SMESH_BUT_CLOSE" ) );
313   myCancelBtn->setAutoDefault( TRUE );
314   myButtonGrpLayout->addWidget( myCancelBtn );
315
316   aTopLayout->addWidget( myButtonGrp, aRow, 0 );
317
318   /***************************************************************/
319   // Init
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 ) );
327   }
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 );
337   }
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" );
341
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 ) );
348   }
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 );
358   }
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" );
362
363   int aNbColors = 64;
364   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfColors" ) )
365     aNbColors = QAD_CONFIG->getSetting( "SMESH:ScalarBarNbOfColors" ).toInt();
366   myColorsSpin->setValue( aNbColors );
367   int aNbLabels = 5;
368   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfLabels" ) )
369     aNbLabels = QAD_CONFIG->getSetting( "SMESH:ScalarBarNbOfLabels" ).toInt();
370   myLabelsSpin->setValue( aNbLabels );
371
372   QString aOrientation = QAD_CONFIG->getSetting( "SMESH:ScalarBarOrientation" );
373   if ( aOrientation == "Horizontal" )
374     myHorizRadioBtn->setChecked( true );
375   else
376     myVertRadioBtn->setChecked( true );
377   myIniOrientation = myVertRadioBtn->isChecked();
378
379   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarXPosition" ) )
380     myIniX = QAD_CONFIG->getSetting( "SMESH:ScalarBarXPosition" ).toDouble();
381   else
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();
385   else
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();
389   else
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();
393   else
394     myIniH = myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H;
395   setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
396
397   if ( mySelection ) {
398     // --> then init from selection if necessary
399     onSelectionChanged();
400   }
401   
402   /***************************************************************/
403   // Connect section
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() ) );
411   if ( mySelection ) {
412     connect( myApplyBtn,        SIGNAL( clicked() ), this, SLOT( onApply() ) );
413     connect( mySelection,       SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
414   }
415   connect( SMESHGUI::GetSMESHGUI(),  SIGNAL( SignalCloseAllDialogs() ), this, SLOT( onCancel() ) ) ;
416 }
417
418 //=================================================================================================
419 /*!
420  *  SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
421  *
422  *  Destructor
423  */
424 //=================================================================================================
425 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
426 {
427 }
428
429 //=================================================================================================
430 /*!
431  *  SMESHGUI_Preferences_ScalarBarDlg::onOk
432  *
433  *  OK button slot
434  */
435 //=================================================================================================
436 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
437 {
438   if ( onApply() )
439     onCancel();
440 }
441
442 //=================================================================================================
443 /*!
444  *  SMESHGUI_Preferences_ScalarBarDlg::onApply
445  *
446  *  Apply button slot
447  */
448 //=================================================================================================
449 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
450 {
451   if ( mySelection ) {
452     // Scalar Bar properties
453     if ( !myActor )
454       return false;
455     vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
456
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();
464     else
465       aTitleTextPrp->SetFontFamilyToTimes();
466     aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
467     aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
468     aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
469     myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
470
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();
478     else
479       aLabelsTextPrp->SetFontFamilyToTimes();
480     aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
481     aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
482     aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
483     myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
484
485     myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
486     myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
487
488     if ( myHorizRadioBtn->isChecked() )
489       myScalarBarActor->SetOrientationToHorizontal();
490     else
491       myScalarBarActor->SetOrientationToVertical();
492
493     myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
494     myScalarBarActor->SetWidth( myWidthSpin->value() );
495     myScalarBarActor->SetHeight( myHeightSpin->value() );
496
497     double aMin = myMinEdit->text().toDouble();
498     double aMax = myMaxEdit->text().toDouble();
499     myScalarBarActor->GetLookupTable()->SetRange( aMin, aMax );
500     SMESHGUI::GetSMESHGUI()->UpdateView();
501   }
502   else {
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" );
510     else
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" );
515
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" );
522     else
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" );
527
528     QAD_CONFIG->addSetting( "SMESH:ScalarBarNbOfColors", myColorsSpin->value() );
529     QAD_CONFIG->addSetting( "SMESH:ScalarBarNbOfLabels", myLabelsSpin->value() );
530
531     QAD_CONFIG->addSetting( "SMESH:ScalarBarOrientation", myHorizRadioBtn->isChecked() ? "Horizontal" : "Vertical" );
532     
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() );
537   }
538   return true;
539 }
540
541 //=================================================================================================
542 /*!
543  *  SMESHGUI_Preferences_ScalarBarDlg::onCancel
544  *
545  *  Cancel button slot
546  */
547 //=================================================================================================
548 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
549 {
550   close();
551 }
552
553 //=================================================================================================
554 /*!
555  *  SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
556  *
557  *  Change Title color button slot
558  */
559 //=================================================================================================
560 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
561 {
562   QColor aColor = myTitleColorBtn->paletteBackgroundColor();
563   aColor = QColorDialog::getColor( aColor, this );
564   if ( aColor.isValid() ) 
565     myTitleColorBtn->setPaletteBackgroundColor( aColor );
566 }
567
568 //=================================================================================================
569 /*!
570  *  SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
571  *
572  *  Change Labels color button slot
573  */
574 //=================================================================================================
575 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
576 {
577   QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
578   aColor = QColorDialog::getColor( aColor, this );
579   if ( aColor.isValid() ) 
580     myLabelsColorBtn->setPaletteBackgroundColor( aColor );
581 }
582
583 //=================================================================================================
584 /*!
585  *  SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
586  *
587  *  Called when selection changed
588  */
589 //=================================================================================================
590 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
591 {
592   if( mySelection ) {
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 ) {
599           myActor = anActor;
600           vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
601           
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] ) );
607           }
608
609           vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
610           float aTColor[3];
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() );
617
618           vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
619           float aLColor[3];
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() );
626
627           myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
628           myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
629
630           if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
631             myVertRadioBtn->setChecked( true );
632           else
633             myHorizRadioBtn->setChecked( true );
634           myIniOrientation = myVertRadioBtn->isChecked();
635           
636           myIniX = myScalarBarActor->GetPosition()[0];
637           myIniY = myScalarBarActor->GetPosition()[1];
638           myIniW = myScalarBarActor->GetWidth();
639           myIniH = myScalarBarActor->GetHeight();
640           setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
641
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 );
649           return;
650         }
651       }
652     }
653     myActor = 0;
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 );
661   }
662 }
663
664 //=================================================================================================
665 /*!
666  *  SMESHGUI_Preferences_ScalarBarDlg::closeEvent
667  *
668  *  Close event handler
669  */
670 //=================================================================================================
671 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
672 {
673   if ( mySelection ) // "Properties" dialog box
674     myDlg = 0;
675   QDialog::closeEvent( e );
676 }
677
678 //=================================================================================================
679 /*!
680  *  SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
681  *
682  *  Called when X, Y values are changed
683  */
684 //=================================================================================================
685 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
686 {
687   myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
688   myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
689 }
690
691 //=================================================================================================
692 /*!
693  *  SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
694  *
695  *  Called when X, Y values are changed
696  */
697 //=================================================================================================
698 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
699                                                           const double y,
700                                                           const double w,
701                                                           const double h )
702 {
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 );
711   onXYChanged();
712 }
713
714 //=================================================================================================
715 /*!
716  *  SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
717  *
718  *  Called when orientation is changed
719  */
720 //=================================================================================================
721 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged() 
722 {
723   int aOrientation = myVertRadioBtn->isChecked();
724   if ( aOrientation == myIniOrientation )
725     setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
726   else
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 );
731 }