Salome HOME
Fix for bug 9366: incorrect size of the 'Select color' buttons
[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 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_Utils.h"
34
35 #include "SMESH_Actor.h"
36
37 #include "SUIT_Desktop.h"
38 #include "SUIT_ResourceMgr.h"
39
40 #include "SalomeApp_SelectionMgr.h"
41 #include "SALOME_ListIO.hxx"
42
43 #include <QtxDblSpinBox.h>
44
45 #include <qbuttongroup.h>
46 #include <qcheckbox.h>
47 #include <qcombobox.h>
48 #include <qgroupbox.h>
49 #include <qlabel.h>
50 #include <qlineedit.h>
51 #include <qpushbutton.h>
52 #include <qtoolbutton.h>
53 #include <qradiobutton.h>
54 #include <qspinbox.h>
55 #include <qlayout.h>
56 #include <qvalidator.h>
57 #include <qcolordialog.h>
58
59 #include <vtkTextProperty.h>
60 #include <vtkScalarBarActor.h>
61 #include <vtkScalarsToColors.h>
62
63 #define MINIMUM_WIDTH 70
64 #define MARGIN_SIZE   11
65 #define SPACING_SIZE   6
66
67 #define DEF_VER_X  0.01
68 #define DEF_VER_Y  0.10
69 #define DEF_VER_H  0.80
70 #define DEF_VER_W  0.10
71 #define DEF_HOR_X  0.20
72 #define DEF_HOR_Y  0.01
73 #define DEF_HOR_H  0.12
74 #define DEF_HOR_W  0.60
75
76 using namespace std;
77
78 // Only one instance is allowed
79 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
80
81 //=================================================================================================
82 /*!
83  *  SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
84  *
85  *  Gets the only instance of "Scalar Bar Properties" dialog box
86  */
87 //=================================================================================================
88 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( SMESHGUI* theModule )
89 {
90   if (!myDlg) {
91     myDlg = new SMESHGUI_Preferences_ScalarBarDlg( theModule, true);
92     myDlg->show();
93   } else {
94     myDlg->show();
95     myDlg->setActiveWindow();
96     myDlg->raise();
97     myDlg->setFocus();
98   }
99 }
100
101 //=================================================================================================
102 /*!
103  *  SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences
104  *
105  *  Opens "Scalar Bar Preferences" dialog box
106  */
107 //=================================================================================================
108 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( SMESHGUI* theModule )
109 {
110   SMESHGUI_Preferences_ScalarBarDlg* aDlg =
111     new SMESHGUI_Preferences_ScalarBarDlg( theModule, false);
112   aDlg->exec();
113 }
114
115 //=================================================================================================
116 /*!
117  *  SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
118  *
119  *  Constructor
120  */
121 //=================================================================================================
122 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI* theModule, bool property, bool modal )
123      : QDialog( SMESH::GetDesktop( theModule ), 0, modal, WStyle_Customize | WStyle_NormalBorder |
124                 WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
125        mySMESHGUI( theModule ),
126        mySelectionMgr( property ? SMESH::GetSelectionMgr( theModule ) : 0 )
127 {
128   setName("SMESHGUI_Preferences_ScalarBarDlg");
129   setCaption( property ? tr("SMESH_PROPERTIES_SCALARBAR") : tr("SMESH_PREFERENCES_SCALARBAR"));
130   setSizeGripEnabled(TRUE);
131
132   myActor = 0;
133
134   /******************************************************************************/
135   // Top layout
136   QGridLayout* aTopLayout = new QGridLayout( this );
137   aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
138   int aRow = 0;
139
140   /******************************************************************************/
141   // Scalar range
142   if ( mySelectionMgr ) {
143     myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this, "myRangeGrp" );
144     myRangeGrp->setColumnLayout( 0, Qt::Vertical );
145     myRangeGrp->layout()->setSpacing( 0 ); myRangeGrp->layout()->setMargin( 0 );
146     QGridLayout* myRangeGrpLayout = new QGridLayout( myRangeGrp->layout() );
147     myRangeGrpLayout->setAlignment( Qt::AlignTop );
148     myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
149
150     myMinEdit = new QLineEdit( myRangeGrp, "myMinEdit" );
151     myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
152     myMinEdit->setValidator( new QDoubleValidator( this ) );
153
154     myMaxEdit = new QLineEdit( myRangeGrp, "myMaxEdit" );
155     myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
156     myMaxEdit->setValidator( new QDoubleValidator( this ) );
157
158     myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp, "myMinLab" ), 0, 0 );
159     myRangeGrpLayout->addWidget( myMinEdit, 0, 1 );
160     myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp, "myMaxLab" ), 0, 2 );
161     myRangeGrpLayout->addWidget( myMaxEdit, 0, 3 );
162
163     aTopLayout->addWidget( myRangeGrp, aRow, 0 );
164     aRow++;
165   }
166
167   /******************************************************************************/
168   // Text properties
169   myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this, "myFontGrp" );
170   myFontGrp->setColumnLayout( 0, Qt::Vertical );
171   myFontGrp->layout()->setSpacing( 0 ); myFontGrp->layout()->setMargin( 0 );
172   QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp->layout() );
173   myFontGrpLayout->setAlignment( Qt::AlignTop );
174   myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
175
176   myTitleColorBtn = new QToolButton( myFontGrp, "myTitleColorBtn" );
177   myTitleColorBtn->setMinimumWidth( 20 );
178
179   myTitleFontCombo = new QComboBox( false, myFontGrp, "myTitleFontCombo" );
180   myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
181   myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
182   myTitleFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
183   myTitleFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
184   myTitleFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
185
186   myTitleBoldCheck   = new QCheckBox( tr( "SMESH_FONT_BOLD" ),   myFontGrp, "myTitleBoldCheck" );
187   myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myTitleItalicCheck" );
188   myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myTitleShadowCheck" );
189
190   myLabelsColorBtn = new QToolButton( myFontGrp, "myLabelsColorBtn" );
191   myLabelsColorBtn->setMinimumWidth( 20 );
192
193   myLabelsFontCombo = new QComboBox( false, myFontGrp, "myLabelsFontCombo" );
194   myLabelsFontCombo->setMinimumWidth( MINIMUM_WIDTH );
195   myLabelsFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
196   myLabelsFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
197   myLabelsFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
198   myLabelsFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
199
200   myLabelsBoldCheck   = new QCheckBox( tr( "SMESH_FONT_BOLD" ),   myFontGrp, "myLabelsBoldCheck" );
201   myLabelsItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myLabelsItalicCheck" );
202   myLabelsShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myLabelsShadowCheck" );
203
204   myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_TITLE" ), myFontGrp, "myFontTitleLab" ), 0, 0 );
205   myFontGrpLayout->addWidget( myTitleColorBtn,    0, 1 );
206   myFontGrpLayout->addWidget( myTitleFontCombo,   0, 2 );
207   myFontGrpLayout->addWidget( myTitleBoldCheck,   0, 3 );
208   myFontGrpLayout->addWidget( myTitleItalicCheck, 0, 4 );
209   myFontGrpLayout->addWidget( myTitleShadowCheck, 0, 5 );
210
211   myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_LABELS" ), myFontGrp, "myFontLabelsLab" ), 1, 0 );
212   myFontGrpLayout->addWidget( myLabelsColorBtn,    1, 1 );
213   myFontGrpLayout->addWidget( myLabelsFontCombo,   1, 2 );
214   myFontGrpLayout->addWidget( myLabelsBoldCheck,   1, 3 );
215   myFontGrpLayout->addWidget( myLabelsItalicCheck, 1, 4 );
216   myFontGrpLayout->addWidget( myLabelsShadowCheck, 1, 5 );
217
218   aTopLayout->addWidget( myFontGrp, aRow, 0 );
219   aRow++;
220
221   /******************************************************************************/
222   // Labels & Colors
223   myLabColorGrp = new QGroupBox ( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), this, "myLabColorGrp" );
224   myLabColorGrp->setColumnLayout( 0, Qt::Vertical );
225   myLabColorGrp->layout()->setSpacing( 0 ); myLabColorGrp->layout()->setMargin( 0 );
226   QGridLayout* myLabColorGrpLayout = new QGridLayout( myLabColorGrp->layout() );
227   myLabColorGrpLayout->setAlignment( Qt::AlignTop );
228   myLabColorGrpLayout->setSpacing( SPACING_SIZE ); myLabColorGrpLayout->setMargin( MARGIN_SIZE );
229
230   myColorsSpin = new QSpinBox( 2, 256, 1, myLabColorGrp, "myColorsSpin" );
231   myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
232   myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
233
234   myLabelsSpin = new QSpinBox( 2, 65, 1, myLabColorGrp, "myLabelsSpin" );
235   myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
236   myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
237
238   myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp, "myNbColorLab" ), 0, 0 );
239   myLabColorGrpLayout->addWidget( myColorsSpin, 0, 1 );
240   myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp, "myNbLabsLab" ), 0, 2 );
241   myLabColorGrpLayout->addWidget( myLabelsSpin, 0, 3 );
242
243   aTopLayout->addWidget( myLabColorGrp, aRow, 0 );
244   aRow++;
245
246   /******************************************************************************/
247   // Orientation
248   myOrientationGrp = new QButtonGroup ( tr( "SMESH_ORIENTATION" ), this, "myOrientationGrp" );
249   myOrientationGrp->setColumnLayout( 0, Qt::Vertical );
250   myOrientationGrp->layout()->setSpacing( 0 ); myOrientationGrp->layout()->setMargin( 0 );
251   QGridLayout* myOrientationGrpLayout = new QGridLayout( myOrientationGrp->layout() );
252   myOrientationGrpLayout->setAlignment( Qt::AlignTop );
253   myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
254
255   myVertRadioBtn  = new QRadioButton( tr( "SMESH_VERTICAL" ),   myOrientationGrp, "myVertRadioBtn" );
256   myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp, "myHorizRadioBtn" );
257   myVertRadioBtn->setChecked( true );
258
259   myOrientationGrpLayout->addWidget( myVertRadioBtn,  0, 0 );
260   myOrientationGrpLayout->addWidget( myHorizRadioBtn, 0, 1 );
261
262   aTopLayout->addWidget( myOrientationGrp, aRow, 0 );
263   aRow++;
264
265   /******************************************************************************/
266   // Position & Size
267   myOriginDimGrp = new QGroupBox (tr("SMESH_POSITION_SIZE_SCALARBAR"), this, "myOriginDimGrp");
268   myOriginDimGrp->setColumnLayout(0, Qt::Vertical);
269   myOriginDimGrp->layout()->setSpacing( 0 ); myOriginDimGrp->layout()->setMargin( 0 );
270   QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp->layout() );
271   myOriginDimGrpLayout->setAlignment( Qt::AlignTop );
272   myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
273
274   myXSpin = new QtxDblSpinBox (0.0, 1.0, 0.1, myOriginDimGrp);
275   myXSpin->setMinimumWidth( MINIMUM_WIDTH );
276   myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
277
278   myYSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
279   myYSpin->setMinimumWidth( MINIMUM_WIDTH );
280   myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
281
282   myWidthSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
283   myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
284   myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
285
286   myHeightSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
287   myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
288   myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
289
290   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp, "myXLab" ), 0, 0 );
291   myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
292   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp, "myYLab" ), 0, 2 );
293   myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
294   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ),  myOriginDimGrp, "myWidthLab" ),  1, 0 );
295   myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
296   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp, "myHeightLab" ), 1, 2 );
297   myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
298
299   aTopLayout->addWidget( myOriginDimGrp, aRow, 0 );
300   aRow++;
301
302   /***************************************************************/
303   // Common buttons
304   myButtonGrp = new QGroupBox( this, "myButtonGrp" );
305   myButtonGrp->setColumnLayout(0, Qt::Vertical );
306   myButtonGrp->layout()->setSpacing( 0 ); myButtonGrp->layout()->setMargin( 0 );
307   QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp->layout() );
308   myButtonGrpLayout->setAlignment( Qt::AlignTop );
309   myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
310
311   myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), myButtonGrp, "myOkBtn" );
312   myOkBtn->setAutoDefault( TRUE ); myOkBtn->setDefault( TRUE );
313   myButtonGrpLayout->addWidget( myOkBtn );
314   if ( mySelectionMgr ) {
315     myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp, "myApplyBtn" );
316     myApplyBtn->setAutoDefault( TRUE );
317     myButtonGrpLayout->addWidget( myApplyBtn );
318   }
319   myButtonGrpLayout->addStretch();
320   myCancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), myButtonGrp, "myCancelBtn" );
321   if ( mySelectionMgr )
322     myCancelBtn->setText( tr( "SMESH_BUT_CLOSE" ) );
323   myCancelBtn->setAutoDefault( TRUE );
324   myButtonGrpLayout->addWidget( myCancelBtn );
325
326   aTopLayout->addWidget( myButtonGrp, aRow, 0 );
327
328   /***************************************************************/
329   // Init
330   // --> first init from preferences
331   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
332
333   QColor titleColor (255, 255, 255);
334   if (mgr && mgr->hasValue("SMESH", "scalar_bar_title_color")) {
335     QStringList aTColor =
336       QStringList::split(":", mgr->stringValue("SMESH", "scalar_bar_title_color"), false);
337     titleColor = QColor((aTColor.count() > 0 ? aTColor[0].toInt() : 255),
338                         (aTColor.count() > 1 ? aTColor[1].toInt() : 255),
339                         (aTColor.count() > 2 ? aTColor[2].toInt() : 255));
340   }
341   myTitleColorBtn->setPaletteBackgroundColor(titleColor);
342   myTitleFontCombo->setCurrentItem(0);
343   if (mgr && mgr->hasValue("SMESH", "scalar_bar_title_font")) {
344     QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
345     if( f.family()=="Arial" )
346       myTitleFontCombo->setCurrentItem(0);
347     if( f.family()=="Courier" )
348       myTitleFontCombo->setCurrentItem(1);
349     if( f.family()=="Times")
350       myTitleFontCombo->setCurrentItem(2);
351   
352     myTitleBoldCheck->setChecked  ( f.bold() );
353     myTitleItalicCheck->setChecked( f.italic() );
354     myTitleShadowCheck->setChecked( f.underline() );
355   }
356
357   QColor labelColor (255, 255, 255);
358   if (mgr && mgr->hasValue("SMESH", "scalar_bar_label_color")) {
359     QStringList aLColor =
360       QStringList::split(":", mgr->stringValue("SMESH", "scalar_bar_label_color"), false);
361     labelColor = QColor((aLColor.count() > 0 ? aLColor[0].toInt() : 255),
362                         (aLColor.count() > 1 ? aLColor[1].toInt() : 255),
363                         (aLColor.count() > 2 ? aLColor[2].toInt() : 255));
364   }
365   myLabelsColorBtn->setPaletteBackgroundColor(labelColor);
366   myLabelsFontCombo->setCurrentItem(0);
367   if (mgr && mgr->hasValue("SMESH", "scalar_bar_label_font")) {
368     QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
369     if (f.family() == "Arial")
370       myLabelsFontCombo->setCurrentItem(0);
371     if (f.family() == "Courier")
372       myLabelsFontCombo->setCurrentItem(1);
373     if (f.family() == "Times")
374       myLabelsFontCombo->setCurrentItem(2);
375       
376     myLabelsBoldCheck  ->setChecked( f.bold() );
377     myLabelsItalicCheck->setChecked( f.italic() );
378     myLabelsShadowCheck->setChecked( f.underline() );
379   }
380
381   int aNbColors = 64;
382   if (mgr && mgr->hasValue("SMESH", "scalar_bar_num_colors"))
383     aNbColors = mgr->integerValue("SMESH", "scalar_bar_num_colors");
384   myColorsSpin->setValue(aNbColors);
385
386   int aNbLabels = 5;
387   if (mgr && mgr->hasValue("SMESH", "scalar_bar_num_labels"))
388     aNbLabels = mgr->integerValue("SMESH", "scalar_bar_num_labels");
389   myLabelsSpin->setValue(aNbLabels);
390
391   int aOrientation = ( mgr ? mgr->integerValue( "SMESH", "scalar_bar_orientation", 1 ) : 1 );
392   bool isHoriz = ( aOrientation==1 );
393   if (aOrientation == 1)
394     myHorizRadioBtn->setChecked(true);
395   else
396     myVertRadioBtn->setChecked(true);
397   myIniOrientation = myVertRadioBtn->isChecked();
398
399   QString name = isHoriz ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
400   if (mgr && mgr->hasValue("SMESH", name.arg( "x" )))
401     myIniX = mgr->doubleValue("SMESH", name.arg( "x" ));
402   else
403     myIniX = myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X;
404
405   if (mgr && mgr->hasValue("SMESH", name.arg( "y" )))
406     myIniY = mgr->doubleValue("SMESH", name.arg( "y" ));
407   else
408     myIniY = myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y;
409
410   if (mgr && mgr->hasValue("SMESH", name.arg( "width" )))
411     myIniW = mgr->doubleValue("SMESH", name.arg( "width" ));
412   else
413     myIniW = myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W;
414
415   if (mgr && mgr->hasValue("SMESH", name.arg( "height" )))
416     myIniH = mgr->doubleValue("SMESH", name.arg( "height" ));
417   else
418     myIniH = myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H;
419
420   setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
421
422   if (mySelectionMgr) {
423     // --> then init from selection if necessary
424     onSelectionChanged();
425   }
426
427   /***************************************************************/
428   // Connect section
429   connect( myTitleColorBtn,     SIGNAL( clicked() ), this, SLOT( onTitleColor() ) );
430   connect( myLabelsColorBtn,    SIGNAL( clicked() ), this, SLOT( onLabelsColor() ) );
431   connect( myOkBtn,             SIGNAL( clicked() ), this, SLOT( onOk() ) );
432   connect( myCancelBtn,         SIGNAL( clicked() ), this, SLOT( onCancel() ) );
433   connect( myXSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
434   connect( myYSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
435   connect( myOrientationGrp,    SIGNAL( clicked( int ) ), this, SLOT( onOrientationChanged() ) );
436   if ( mySelectionMgr ) {
437     connect( myApplyBtn,        SIGNAL( clicked() ), this, SLOT( onApply() ) );
438     connect( mySelectionMgr,    SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
439   }
440   connect( mySMESHGUI,  SIGNAL( SignalCloseAllDialogs() ), this, SLOT( onCancel() ) ) ;
441 }
442
443 //=================================================================================================
444 /*!
445  *  SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
446  *
447  *  Destructor
448  */
449 //=================================================================================================
450 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
451 {
452 }
453
454 //=================================================================================================
455 /*!
456  *  SMESHGUI_Preferences_ScalarBarDlg::onOk
457  *
458  *  OK button slot
459  */
460 //=================================================================================================
461 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
462 {
463   if ( onApply() )
464     onCancel();
465 }
466
467 //=================================================================================================
468 /*!
469  *  SMESHGUI_Preferences_ScalarBarDlg::onApply
470  *
471  *  Apply button slot
472  */
473 //=================================================================================================
474 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
475 {
476   if (mySelectionMgr) {
477     // Scalar Bar properties
478     if (!myActor)
479       return false;
480     vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
481
482     vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
483     QColor aTColor = myTitleColorBtn->paletteBackgroundColor();
484     aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
485     if ( myTitleFontCombo->currentItem() == 0 )
486       aTitleTextPrp->SetFontFamilyToArial();
487     else if ( myTitleFontCombo->currentItem() == 1 )
488       aTitleTextPrp->SetFontFamilyToCourier();
489     else
490       aTitleTextPrp->SetFontFamilyToTimes();
491     aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
492     aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
493     aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
494     myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
495
496     vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
497     QColor aLColor = myLabelsColorBtn->paletteBackgroundColor();
498     aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
499     if ( myLabelsFontCombo->currentItem() == 0 )
500       aLabelsTextPrp->SetFontFamilyToArial();
501     else if ( myLabelsFontCombo->currentItem() == 1 )
502       aLabelsTextPrp->SetFontFamilyToCourier();
503     else
504       aLabelsTextPrp->SetFontFamilyToTimes();
505     aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
506     aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
507     aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
508     myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
509
510     myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
511     myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
512
513     if ( myHorizRadioBtn->isChecked() )
514       myScalarBarActor->SetOrientationToHorizontal();
515     else
516       myScalarBarActor->SetOrientationToVertical();
517
518     myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
519     myScalarBarActor->SetWidth( myWidthSpin->value() );
520     myScalarBarActor->SetHeight( myHeightSpin->value() );
521
522     double aMin = myMinEdit->text().toDouble();
523     double aMax = myMaxEdit->text().toDouble();
524     myScalarBarActor->GetLookupTable()->SetRange( aMin, aMax );
525     SMESH::RepaintCurrentView();
526   } else {
527     // Scalar Bar preferences
528     SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
529     if (!mgr) return false;
530
531     QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
532     mgr->setValue("SMESH", "scalar_bar_title_color", titleColor );
533
534     QFont f;
535     if (myTitleFontCombo->currentItem() == 0)
536       f.setFamily( "Arial" );
537     else if (myTitleFontCombo->currentItem() == 1)
538       f.setFamily( "Courier" );
539     else
540       f.setFamily( "Times");
541
542     f.setBold( myTitleBoldCheck  ->isChecked() );
543     f.setItalic( myTitleItalicCheck->isChecked() );
544     f.setUnderline( myTitleShadowCheck->isChecked() );
545     mgr->setValue( "SMESH", "scalar_bar_title_font", f );
546
547     QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
548     mgr->setValue("SMESH", "scalar_bar_label_color", labelColor );
549
550     if (myLabelsFontCombo->currentItem() == 0)
551       f.setFamily( "Arial" );
552     else if ( myLabelsFontCombo->currentItem() == 1 )
553       f.setFamily( "Courier");
554     else
555       f.setFamily( "Times");
556
557     f.setBold( myLabelsBoldCheck  ->isChecked() );
558     f.setItalic( myLabelsItalicCheck->isChecked() );
559     f.setUnderline( myLabelsShadowCheck->isChecked() );
560     mgr->setValue( "SMESH", "scalar_bar_label_font", f );
561
562     mgr->setValue("SMESH", "scalar_bar_num_colors", myColorsSpin->value());
563     mgr->setValue("SMESH", "scalar_bar_num_labels", myLabelsSpin->value());
564
565     mgr->setValue("SMESH", "scalar_bar_orientation", myHorizRadioBtn->isChecked() ? 1 : 0 );
566
567     QString name = myHorizRadioBtn->isChecked() ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
568     mgr->setValue("SMESH", name.arg( "x" ), myXSpin->value());
569     mgr->setValue("SMESH", name.arg( "y" ), myYSpin->value());
570     mgr->setValue("SMESH", name.arg( "width" ),     myWidthSpin->value());
571     mgr->setValue("SMESH", name.arg( "height" ),    myHeightSpin->value());
572   }
573   return true;
574 }
575
576 //=================================================================================================
577 /*!
578  *  SMESHGUI_Preferences_ScalarBarDlg::onCancel
579  *
580  *  Cancel button slot
581  */
582 //=================================================================================================
583 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
584 {
585   close();
586 }
587
588 //=================================================================================================
589 /*!
590  *  SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
591  *
592  *  Change Title color button slot
593  */
594 //=================================================================================================
595 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
596 {
597   QColor aColor = myTitleColorBtn->paletteBackgroundColor();
598   aColor = QColorDialog::getColor( aColor, this );
599   if ( aColor.isValid() )
600     myTitleColorBtn->setPaletteBackgroundColor( aColor );
601 }
602
603 //=================================================================================================
604 /*!
605  *  SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
606  *
607  *  Change Labels color button slot
608  */
609 //=================================================================================================
610 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
611 {
612   QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
613   aColor = QColorDialog::getColor( aColor, this );
614   if ( aColor.isValid() )
615     myLabelsColorBtn->setPaletteBackgroundColor( aColor );
616 }
617
618 //=================================================================================================
619 /*!
620  *  SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
621  *
622  *  Called when selection changed
623  */
624 //=================================================================================================
625 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
626 {
627   if (mySelectionMgr) {
628     SALOME_ListIO aList;
629     mySelectionMgr->selectedObjects(aList);
630
631     if (aList.Extent() == 1) {
632       Handle(SALOME_InteractiveObject) anIO = aList.First();
633       if( anIO->hasEntry() ) {
634         SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
635         if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
636           myActor = anActor;
637           vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
638
639           if ( myScalarBarActor->GetLookupTable() ) {
640             float *range = myScalarBarActor->GetLookupTable()->GetRange();
641             myMinEdit->setText( QString::number( range[0] ) );
642             myMaxEdit->setText( QString::number( range[1] ) );
643           }
644
645           vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
646           float aTColor[3];
647           aTitleTextPrp->GetColor( aTColor );
648           myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
649           myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
650           myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
651           myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
652           myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
653
654           vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
655           float aLColor[3];
656           aLabelsTextPrp->GetColor( aLColor );
657           myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
658           myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
659           myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
660           myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
661           myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
662
663           myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
664           myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
665
666           if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
667             myVertRadioBtn->setChecked( true );
668           else
669             myHorizRadioBtn->setChecked( true );
670           myIniOrientation = myVertRadioBtn->isChecked();
671
672           myIniX = myScalarBarActor->GetPosition()[0];
673           myIniY = myScalarBarActor->GetPosition()[1];
674           myIniW = myScalarBarActor->GetWidth();
675           myIniH = myScalarBarActor->GetHeight();
676           setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
677
678           myRangeGrp->setEnabled( true );
679           myFontGrp->setEnabled( true );
680           myLabColorGrp->setEnabled( true );
681           myOrientationGrp->setEnabled( true );
682           myOriginDimGrp->setEnabled( true );
683           myOkBtn->setEnabled( true );
684           myApplyBtn->setEnabled( true );
685           return;
686         }
687       }
688     }
689     myActor = 0;
690     myRangeGrp->setEnabled( false );
691     myFontGrp->setEnabled( false );
692     myLabColorGrp->setEnabled( false );
693     myOrientationGrp->setEnabled( false );
694     myOriginDimGrp->setEnabled( false );
695     myOkBtn->setEnabled( false );
696     myApplyBtn->setEnabled( false );
697   }
698 }
699
700 //=================================================================================================
701 /*!
702  *  SMESHGUI_Preferences_ScalarBarDlg::closeEvent
703  *
704  *  Close event handler
705  */
706 //=================================================================================================
707 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
708 {
709   if ( mySelectionMgr ) // "Properties" dialog box
710     myDlg = 0;
711   QDialog::closeEvent( e );
712 }
713
714 //=================================================================================================
715 /*!
716  *  SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
717  *
718  *  Called when X, Y values are changed
719  */
720 //=================================================================================================
721 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
722 {
723   myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
724   myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
725 }
726
727 //=================================================================================================
728 /*!
729  *  SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
730  *
731  *  Called when X, Y values are changed
732  */
733 //=================================================================================================
734 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
735                                                           const double y,
736                                                           const double w,
737                                                           const double h )
738 {
739   blockSignals( true );
740   myXSpin->setValue( x );
741   myYSpin->setValue( y );
742   myWidthSpin->setMaxValue( 1.0 );
743   myWidthSpin->setValue( w );
744   myHeightSpin->setMaxValue( 1.0 );
745   myHeightSpin->setValue( h );
746   blockSignals( false );
747   onXYChanged();
748 }
749
750 //=================================================================================================
751 /*!
752  *  SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
753  *
754  *  Called when orientation is changed
755  */
756 //=================================================================================================
757 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
758 {
759   int aOrientation = myVertRadioBtn->isChecked();
760   if ( aOrientation == myIniOrientation )
761     setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
762   else
763     setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
764                       aOrientation ? DEF_VER_Y : DEF_HOR_Y,
765                       aOrientation ? DEF_VER_W : DEF_HOR_W,
766                       aOrientation ? DEF_VER_H : DEF_HOR_H );
767 }