Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/visu.git] / src / VISUGUI / VisuGUI_ScalarBarDlg.cxx
1 //  VISU VISUGUI : GUI of VISU 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   : VisuGUI_ScalarBarDlg.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND
26 //  Module : VISU
27 //  $Header$
28
29 #include "VisuGUI_ScalarBarDlg.h"
30
31 #include "VisuGUI.h"
32 #include "VisuGUI_Tools.h"
33 #include "VisuGUI_ViewTools.h"
34
35 #include "SVTK_ViewWindow.h"
36 #include "SVTK_FontWidget.h"
37
38 #include "VISUConfig.hh"
39 #include "VISU_Convertor.hxx"
40
41 #include "VISU_ScalarMapPL.hxx"
42 #include "VISU_ScalarMap_i.hh"
43 #include "VISU_ScalarMapAct.h"
44
45 #include "LightApp_Application.h"
46
47 #include "SUIT_Session.h"
48 #include "SUIT_MessageBox.h"
49 #include "SUIT_ResourceMgr.h"
50
51 #include <limits.h>
52 #include <qlayout.h>
53 #include <qvalidator.h>
54 #include <qcolordialog.h>
55
56 #include <vtkTextProperty.h>
57
58 using namespace std;
59
60
61 VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref):
62   QVBox(parent), myPreviewActor(0)
63 {
64   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
65   QString propertyName;
66   propertyName = QString("scalar_bar_vertical_");
67   myVerX = aResourceMgr->doubleValue("VISU", propertyName + "x", 0.);
68   myVerY = aResourceMgr->doubleValue("VISU", propertyName + "y", 0.);
69   myVerW = aResourceMgr->doubleValue("VISU", propertyName + "width", 0.);
70   myVerH = aResourceMgr->doubleValue("VISU", propertyName + "height",0.);
71   
72   propertyName = QString("scalar_bar_horizontal_");
73   myHorX = aResourceMgr->doubleValue("VISU", propertyName + "x", 0.);
74   myHorY = aResourceMgr->doubleValue("VISU", propertyName + "y", 0.);
75   myHorW = aResourceMgr->doubleValue("VISU", propertyName + "width", 0.);
76   myHorH = aResourceMgr->doubleValue("VISU", propertyName + "height",0.);
77   
78   Imin = 0.0; Imax = 0.0; /*Fmin = 0.0; Fmax = 0.0;*/ Rmin = 0.0; Rmax = 0.0;
79   myRangeMode = -1;
80
81   setSpacing(6);
82   //setMargin(11);
83
84   // Range ============================================================
85   RangeGroup = new QButtonGroup (tr("SCALAR_RANGE_GRP"), this, "RangeGroup");
86   RangeGroup->setColumnLayout(0, Qt::Vertical );
87   RangeGroup->layout()->setSpacing( 0 );
88   RangeGroup->layout()->setMargin( 0 );
89   QGridLayout* RangeGroupLayout = new QGridLayout( RangeGroup->layout() );
90   RangeGroupLayout->setAlignment( Qt::AlignTop );
91   RangeGroupLayout->setSpacing( 6 );
92   RangeGroupLayout->setMargin( 11 );
93
94   myModeLbl = new QLabel("Scalar Mode", RangeGroup);
95
96   myModeCombo = new QComboBox(RangeGroup);
97
98   CBLog = new QCheckBox (tr("LOGARITHMIC_SCALING"), RangeGroup);
99   CBLog->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
100
101   RBFrange = new QRadioButton (tr("FIELD_RANGE_BTN"), RangeGroup, "RBFrange");
102   RBIrange = new QRadioButton (tr("IMPOSED_RANGE_BTN"), RangeGroup, "RBIrange");
103   RBFrange->setChecked( true );
104
105   MinEdit = new QLineEdit( RangeGroup, "MinEdit" );
106   MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
107   MinEdit->setMinimumWidth( 70 );
108   MinEdit->setValidator( new QDoubleValidator(this) );
109   MinEdit->setText( "0.0" );
110   QLabel* MinLabel = new QLabel (tr("LBL_MIN"), RangeGroup, "MinLabel");
111   MinLabel->setBuddy(MinEdit);
112
113   MaxEdit = new QLineEdit( RangeGroup, "MaxEdit" );
114   MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
115   MaxEdit->setMinimumWidth( 70 );
116   MaxEdit->setValidator( new QDoubleValidator(this) );
117   MaxEdit->setText( "0.0" );
118   QLabel* MaxLabel = new QLabel (tr("LBL_MAX"), RangeGroup, "MaxLabel");
119   MaxLabel->setBuddy(MaxEdit);
120
121   RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
122   RangeGroupLayout->addMultiCellWidget( myModeCombo, 0, 0, 1, 3);
123   RangeGroupLayout->addMultiCellWidget( CBLog, 1, 1, 0, 3);
124   RangeGroupLayout->addMultiCellWidget( RBFrange, 2, 2, 0, 1);
125   RangeGroupLayout->addMultiCellWidget( RBIrange, 2, 2, 2, 3);
126   RangeGroupLayout->addWidget( MinLabel, 3, 0 );
127   RangeGroupLayout->addWidget( MinEdit,  3, 1 );
128   RangeGroupLayout->addWidget( MaxLabel, 3, 2 );
129   RangeGroupLayout->addWidget( MaxEdit,  3, 3 );
130
131   //TopLayout->addWidget( RangeGroup );
132
133   // Colors and Labels ========================================================
134   QGroupBox* ColLabGroup = new QGroupBox (tr("COLORS_LABELS_GRP"), this, "ColLabGroup");
135   ColLabGroup->setColumnLayout(0, Qt::Vertical );
136   ColLabGroup->layout()->setSpacing( 0 );
137   ColLabGroup->layout()->setMargin( 0 );
138   QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup->layout() );
139   ColLabGroupLayout->setAlignment( Qt::AlignTop );
140   ColLabGroupLayout->setSpacing( 6 );
141   ColLabGroupLayout->setMargin( 11 );
142
143   QLabel* ColorLabel = new QLabel (tr("LBL_NB_COLORS"), ColLabGroup, "ColorLabel");
144   ColorSpin = new QSpinBox( 2, 256, 1, ColLabGroup );
145   ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
146   ColorSpin->setMinimumWidth( 70 );
147   ColorSpin->setValue( 64 );
148
149   QLabel* LabelLabel = new QLabel (tr("LBL_NB_LABELS"), ColLabGroup, "LabelLabel");
150   LabelSpin = new QSpinBox( 2, 65, 1, ColLabGroup );
151   LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
152   LabelSpin->setMinimumWidth( 70 );
153   LabelSpin->setValue( 5 );
154
155   ColLabGroupLayout->addWidget( ColorLabel, 0, 0);
156   ColLabGroupLayout->addWidget( ColorSpin,  0, 1);
157   ColLabGroupLayout->addWidget( LabelLabel, 0, 2);
158   ColLabGroupLayout->addWidget( LabelSpin,  0, 3);
159
160   //TopLayout->addWidget( ColLabGroup );
161
162   // Orientation ==========================================================
163   QButtonGroup* OrientGroup = new QButtonGroup (tr("ORIENTATION_GRP"), this, "OrientGroup");
164   OrientGroup->setColumnLayout(0, Qt::Vertical );
165   OrientGroup->layout()->setSpacing( 0 );
166   OrientGroup->layout()->setMargin( 0 );
167   QGridLayout* OrientGroupLayout = new QGridLayout( OrientGroup->layout() );
168   OrientGroupLayout->setAlignment( Qt::AlignTop );
169   OrientGroupLayout->setSpacing( 6 );
170   OrientGroupLayout->setMargin( 11 );
171
172   RBvert = new QRadioButton (tr("VERTICAL_BTN"), OrientGroup, "RBvert");
173   RBvert->setChecked( true );
174   RBhori = new QRadioButton (tr("HORIZONTAL_BTN"), OrientGroup, "RBhori");
175   OrientGroupLayout->addWidget( RBvert, 0, 0 );
176   OrientGroupLayout->addWidget( RBhori, 0, 1 );
177
178   //  TopLayout->addWidget( OrientGroup );
179
180   // Origin ===============================================================
181   QGroupBox* OriginGroup = new QGroupBox (tr("ORIGIN_GRP"), this, "OriginGroup");
182   OriginGroup->setColumnLayout(0, Qt::Vertical );
183   OriginGroup->layout()->setSpacing( 0 );
184   OriginGroup->layout()->setMargin( 0 );
185   QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup->layout() );
186   OriginGroupLayout->setAlignment( Qt::AlignTop );
187   OriginGroupLayout->setSpacing( 6 );
188   OriginGroupLayout->setMargin( 11 );
189
190   QLabel* XLabel = new QLabel (tr("LBL_X"), OriginGroup, "XLabel");
191   XSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
192   XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
193   XSpin->setMinimumWidth( 70 );
194   XSpin->setValue( 0.01 );
195
196   QLabel* YLabel = new QLabel (tr("LBL_Y"), OriginGroup, "YLabel");
197   YSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
198   YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
199   YSpin->setMinimumWidth( 70 );
200   YSpin->setValue( 0.01 );
201
202   OriginGroupLayout->addWidget( XLabel, 0, 0);
203   OriginGroupLayout->addWidget( XSpin,  0, 1);
204   OriginGroupLayout->addWidget( YLabel, 0, 2);
205   OriginGroupLayout->addWidget( YSpin,  0, 3);
206
207   //TopLayout->addWidget( OriginGroup );
208
209   // Dimensions =========================================================
210   QGroupBox* DimGroup = new QGroupBox (tr("DIMENSIONS_GRP"), this, "DimGroup");
211   DimGroup->setColumnLayout(0, Qt::Vertical );
212   DimGroup->layout()->setSpacing( 0 );
213   DimGroup->layout()->setMargin( 0 );
214   QGridLayout* DimGroupLayout = new QGridLayout( DimGroup->layout() );
215   DimGroupLayout->setAlignment( Qt::AlignTop );
216   DimGroupLayout->setSpacing( 6 );
217   DimGroupLayout->setMargin( 11 );
218
219   QLabel* WidthLabel = new QLabel (tr("LBL_WIDTH"), DimGroup, "WidthLabel");
220   WidthSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
221   WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
222   WidthSpin->setMinimumWidth( 70 );
223   WidthSpin->setValue( 0.1 );
224
225   QLabel* HeightLabel = new QLabel (tr("LBL_HEIGHT"), DimGroup, "HeightLabel");
226   HeightSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
227   HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
228   HeightSpin->setMinimumWidth( 70 );
229   HeightSpin->setValue( 0.8 );
230
231   DimGroupLayout->addWidget( WidthLabel, 0, 0);
232   DimGroupLayout->addWidget( WidthSpin,  0, 1);
233   DimGroupLayout->addWidget( HeightLabel, 0, 2);
234   DimGroupLayout->addWidget( HeightSpin,  0, 3);
235
236   //TopLayout->addWidget( DimGroup );
237
238   // Save check box ===========================================================
239   QHBox* aSaveBox = new QHBox(this);
240   if (!SetPref) {
241     CBSave = new QCheckBox (tr("SAVE_DEFAULT_CHK"), aSaveBox, "CBSave");
242     //TopLayout->addWidget(CBSave);
243   }
244   else {
245     CBSave = 0;
246   }
247   myTextBtn = new QPushButton("Text properties...", aSaveBox);
248   myTextDlg = new VisuGUI_TextPrefDlg(this);
249   myTextDlg->setTitleVisible(!SetPref);
250
251   QGroupBox* CheckGroup = new QGroupBox("", this, "CheckGroup");
252   CheckGroup->setColumnLayout(0, Qt::Vertical );
253   CheckGroup->layout()->setSpacing( 0 );
254   CheckGroup->layout()->setMargin( 0 );
255   QGridLayout* CheckGroupLayout = new QGridLayout( CheckGroup->layout() );
256   
257   myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), CheckGroup);
258   myPreviewCheck->setChecked(false);
259   CheckGroupLayout->addWidget(myPreviewCheck , 0, 0 );
260
261   // signals and slots connections ===========================================
262   connect( RangeGroup,   SIGNAL( clicked( int ) ), this, SLOT( changeRange( int ) ) );
263   connect( myModeCombo,   SIGNAL( activated( int ) ), this, SLOT( changeScalarMode( int ) ) );
264   connect( OrientGroup,  SIGNAL( clicked( int ) ), this, SLOT( changeDefaults( int ) ) );
265   connect( XSpin,        SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
266   connect( YSpin,        SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
267   connect( myTextBtn,    SIGNAL( clicked() ), this, SLOT( onTextPref() ) );
268   connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) );
269   connect( ColorSpin,    SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ));
270   connect( LabelSpin,    SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ));
271   connect( WidthSpin,    SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() ));
272   connect( HeightSpin,   SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() ));
273   connect( CBLog,        SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ));
274   changeRange( 0 );
275   changeDefaults( 0 );
276   myIsStoreTextProp = false;
277   myBusy = false;
278 }
279
280 /**
281  * Initializes dialog box values from resources
282  */
283 void VisuGUI_ScalarBarPane::initFromResources() {
284   int sbCol=64,sbLab=5,orient=0;
285   float sbX1=0.01,sbY1=0.1,sbW=0.1,sbH=0.8;
286   float sbVmin=0., sbVmax=0.;
287   bool sbRange=false;
288   QString aString;
289
290   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
291
292   bool anIsArrangeBar = aResourceMgr->booleanValue("VISU", "scalar_bars_default_position", 0);
293   int aPlace = 1;
294   if (anIsArrangeBar){
295     aPlace = aResourceMgr->integerValue("VISU", "scalar_bar_position_num",0);
296   }
297
298   int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0);
299   myModeCombo->setCurrentItem(aScalarMode);
300
301   orient = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", orient);
302   if(orient != 0){
303     orient=1;
304     sbX1=0.2;
305     sbY1=0.01;
306     sbW=0.6;
307     sbH=0.12;
308   }
309   
310   QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
311
312   sbX1 = aResourceMgr->doubleValue("VISU", propertyName + "x", sbX1);
313   sbY1 = aResourceMgr->doubleValue("VISU", propertyName + "y", sbY1);
314
315   sbW = aResourceMgr->doubleValue("VISU", propertyName + "width", sbW);
316   sbH = aResourceMgr->doubleValue("VISU", propertyName + "height",sbH);
317   
318   if(orient){
319     sbY1 += sbH*(aPlace-1);
320   } else {
321     sbX1 += sbW*(aPlace-1);
322   }
323   sbCol = aResourceMgr->integerValue("VISU" ,"scalar_bar_num_colors", sbCol);
324   sbLab = aResourceMgr->integerValue("VISU", "scalar_bar_num_labels", sbLab);
325
326   int rangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0);
327   if (rangeType == 1) sbRange = true;
328   sbVmin = aResourceMgr->doubleValue("VISU", "scalar_range_min", sbVmin);
329   sbVmax = aResourceMgr->doubleValue("VISU", "scalar_range_max", sbVmax);
330
331   bool isLog = aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false);
332   setLogarithmic(isLog);
333   
334   if((sbX1 < 0.) || (sbY1 < 0.) ||
335      ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
336     if(orient == 0) {
337       sbX1=0.01;
338       sbY1=0.1;
339       sbW=0.1;
340       sbH=0.8;
341     } else {
342       sbX1=0.2;
343       sbY1=0.01;
344       sbW=0.6;
345       sbH=0.12;
346     }
347   }
348   if(sbCol < 2) sbCol=2;
349   if(sbCol > 64) sbCol=64;
350   if(sbLab < 2) sbLab=2;
351   if(sbLab > 65) sbLab=65;
352
353   if(sbVmin > sbVmax) {
354     sbVmin=0.;
355     sbVmax=0.;
356   }
357
358   setRange( sbVmin, sbVmax, /*0.0, 0.0,*/ sbRange );
359   setPosAndSize( sbX1, sbY1, sbW, sbH, orient == 0);
360   setScalarBarData( sbCol, sbLab );
361
362   // "Title"
363   bool isBold = false, isItalic = false, isShadow = false;
364   int aFontFamily = VTK_ARIAL;
365
366   if ( aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" ) )
367     {
368       QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" );
369       
370       if ( f.family() == "Arial" )
371         aFontFamily = VTK_ARIAL;
372       else if ( f.family() == "Courier" )
373         aFontFamily = VTK_COURIER;
374       else if ( f.family() == "Times" )
375         aFontFamily = VTK_TIMES;
376       
377       isBold = f.bold();
378       isItalic = f.italic();
379       isShadow =  f.underline();
380     }
381   
382   QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
383   
384   myTextDlg->myTitleFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow);
385
386   // "Labels"
387   isBold = isItalic = isShadow = false;
388   aFontFamily = VTK_ARIAL;
389
390   if ( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" ) )
391     {
392       QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" );
393       
394       if ( f.family() == "Arial" )
395         aFontFamily = VTK_ARIAL;
396       else if ( f.family() == "Courier" )
397         aFontFamily = VTK_COURIER;
398       else if ( f.family() == "Times" )
399         aFontFamily = VTK_TIMES;
400       
401       isBold = f.bold();
402       isItalic = f.italic();
403       isShadow =  f.underline();
404     }
405   
406   aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
407   
408   myTextDlg->myLabelFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow);
409 }
410
411 /**
412  * Stores dialog values to resources
413  */
414 void VisuGUI_ScalarBarPane::storeToResources() {
415   int orient = (RBvert->isChecked())? 0 : 1;
416   float sbX1   = XSpin->value();
417   float sbY1   = YSpin->value();
418   float sbW    = WidthSpin->value();
419   float sbH    = HeightSpin->value();
420   int sbCol  = ColorSpin->value();
421   int sbLab  = LabelSpin->value();
422
423   if((sbX1 < 0.) || (sbY1 < 0.) || ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
424     if(orient == 0) {
425       sbX1=0.01;
426       sbY1=0.1;
427       sbW=0.17;
428       sbH=0.8;
429     } else {
430       sbX1=0.2;
431       sbY1=0.01;
432       sbW=0.6;
433       sbH=0.12;
434     }
435   }
436
437   bool sbRange = RBIrange->isChecked();
438   float sbVmin = (float)(MinEdit->text().toDouble());
439   float sbVmax = (float)(MaxEdit->text().toDouble());
440
441   if(sbVmin > sbVmax) {
442     sbVmin=0.;
443     sbVmax=0.;
444   }
445
446   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
447
448   aResourceMgr->setValue("VISU", "scalar_bar_orientation", orient);
449
450   QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
451
452   aResourceMgr->setValue("VISU", propertyName + "x", sbX1);
453   aResourceMgr->setValue("VISU", propertyName + "y", sbY1);
454   aResourceMgr->setValue("VISU", propertyName + "width", sbW);
455   aResourceMgr->setValue("VISU", propertyName + "height", sbH);
456
457   aResourceMgr->setValue("VISU", "scalar_bar_num_colors", sbCol);
458   aResourceMgr->setValue("VISU", "scalar_bar_num_labels", sbLab);
459
460   if(sbRange)
461     {
462       aResourceMgr->setValue("VISU", "scalar_range_type", 1);
463       aResourceMgr->setValue("VISU", "scalar_range_min" ,sbVmin);
464       aResourceMgr->setValue("VISU", "scalar_range_max" ,sbVmax);
465     }
466   else
467     aResourceMgr->setValue("VISU", "scalar_range_type", 0);
468   
469   aResourceMgr->setValue("VISU", "scalar_bar_logarithmic", isLogarithmic());
470  
471   ////
472
473   if (myIsStoreTextProp) {
474     // "Title"
475     QColor aTitleColor (255, 255, 255);
476     int aTitleFontFamily = VTK_ARIAL;
477     bool isTitleBold = false;
478     bool isTitleItalic = false;
479     bool isTitleShadow = false;
480
481     myTextDlg->myTitleFont->GetData(aTitleColor, aTitleFontFamily,
482                                     isTitleBold, isTitleItalic, isTitleShadow);
483
484     QFont aTitleFont;
485     
486     aTitleFont.setBold(isTitleBold);
487     aTitleFont.setItalic(isTitleItalic);
488     aTitleFont.setUnderline(isTitleShadow);
489     
490     QString titleFontFamily;
491     switch (aTitleFontFamily) {
492     case VTK_ARIAL:
493       titleFontFamily = "Arial";
494       break;
495     case VTK_COURIER:
496       titleFontFamily = "Courier";
497       break;
498     case VTK_TIMES:
499       titleFontFamily = "Times";
500       break;
501     }
502     aTitleFont.setFamily(titleFontFamily);
503     
504     aResourceMgr->setValue("VISU", "scalar_bar_title_font", aTitleFont);
505     
506     aResourceMgr->setValue("VISU", "scalar_bar_title_color", aTitleColor);
507     
508     // "Label"
509     QColor aLabelColor (255, 255, 255);
510     int aLabelFontFamily = VTK_ARIAL;
511     bool isLabelBold = false;
512     bool isLabelItalic = false;
513     bool isLabelShadow = false;
514
515     myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
516                                     isLabelBold, isLabelItalic, isLabelShadow);
517
518
519     QFont aLabelFont;
520     
521     aLabelFont.setBold(isLabelBold);
522     aLabelFont.setItalic(isLabelItalic);
523     aLabelFont.setUnderline(isLabelShadow);
524
525     QString labelFontFamily;
526     switch (aLabelFontFamily) {
527     case VTK_ARIAL:
528       labelFontFamily = "Arial";
529       break;
530     case VTK_COURIER:
531       labelFontFamily = "Courier";
532       break;
533     case VTK_TIMES:
534       labelFontFamily = "Times";
535       break;
536     }
537
538     aLabelFont.setFamily(labelFontFamily);
539     
540     aResourceMgr->setValue("VISU", "scalar_bar_label_font", aLabelFont);
541
542     aResourceMgr->setValue("VISU", "scalar_bar_label_color", aLabelColor);
543   }
544 }
545
546 /**
547  * Initialise dialog box from presentation object
548  */
549 void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
550   initFromResources();
551   myScalarMap = thePrs;
552   myTitle = thePrs->GetTitle();
553   setPosAndSize( thePrs->GetPosX(),
554                  thePrs->GetPosY(),
555                  thePrs->GetWidth(),
556                  thePrs->GetHeight(),
557                  thePrs->GetBarOrientation());
558   switch(thePrs->GetScaling()){
559   case VISU::LOGARITHMIC :
560     setLogarithmic(true);
561     break;
562   default:
563     setLogarithmic(false);
564   }
565   vtkFloatingPointType aRange[2];
566   thePrs->GetScalarMapPL()->GetSourceRange(aRange);
567   Rmin = aRange[0]; Rmax = aRange[1];
568   setRange( thePrs->GetMin(), thePrs->GetMax(),
569             /*0.0, 0.0,*/ thePrs->IsRangeFixed() );
570   setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
571
572   // Update myModeCombo
573   int aNbComp = thePrs->GetField()->myNbComp;
574   bool isScalarMode = (aNbComp > 1);
575   myModeCombo->clear();
576   myModeCombo->insertItem("<Modulus>");
577   const VISU::PField& aField = thePrs->GetField();
578   const VISU::TNames& aCompNames = aField->myCompNames;
579   const VISU::TNames& aUnitNames = aField->myUnitNames;
580   for(int i = 0; i < aNbComp; i++){
581     QString aComponent = QString(aCompNames[i].c_str()).simplifyWhiteSpace();
582     if(aComponent.isNull() || aComponent == "")
583       aComponent = "Component " + QString::number(i+1);
584     else
585       aComponent = "[" + QString::number(i+1) + "] " + aComponent;
586
587     QString anUnit = QString(aUnitNames[i].c_str()).simplifyWhiteSpace();
588     if(anUnit.isNull() || anUnit == "")
589       anUnit = "-";
590     
591     aComponent = aComponent + ", " + anUnit;
592
593     myModeCombo->insertItem(aComponent);
594   }
595   //
596   myModeCombo->setCurrentItem(thePrs->GetScalarMode());
597   if (aNbComp==1){
598     myModeCombo->setCurrentItem(1);
599   }
600   //
601   myModeLbl->setEnabled(isScalarMode);
602   myModeCombo->setEnabled(isScalarMode);
603
604   // "Title"
605   myTextDlg->setTitleText(QString(thePrs->GetTitle()));
606
607   vtkFloatingPointType R, G, B;
608   thePrs->GetTitleColor(&R, &G, &B);
609
610   myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
611                                   thePrs->GetTitFontType(),
612                                   thePrs->IsBoldTitle(),
613                                   thePrs->IsItalicTitle(),
614                                   thePrs->IsShadowTitle());
615
616   // "Labels"
617   thePrs->GetLabelColor(&R, &G, &B);
618
619   myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
620                                   thePrs->GetLblFontType(),
621                                   thePrs->IsBoldLabel(),
622                                   thePrs->IsItalicLabel(),
623                                   thePrs->IsShadowLabel());
624
625   // Draw Preview
626   if (myPreviewCheck->isChecked()) {
627     createScalarBar();
628     updatePreview();
629   }
630
631 }
632 /*! Slot update preview of scalar bar, if preview is checked
633  */
634 void VisuGUI_ScalarBarPane::updatePreview()
635 {
636   if (myPreviewCheck->isChecked()) {
637     if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
638       deleteScalarBar();
639       createScalarBar();
640       vf->Repaint();
641     }
642   }
643 }
644
645 /*! Creating preview scalar bar
646  */
647 void VisuGUI_ScalarBarPane::createScalarBar()
648 {
649   if (VISU::GetActiveViewWindow<SVTK_ViewWindow>() == NULL) return;
650   if (myPreviewActor != 0) return;
651   if (myScalarMap == NULL) return;
652
653   if (!check()) return;
654   myScalarMapPL = VISU_ScalarMapPL::New();
655   if(myScalarMap->GetScalarMapPL())
656     myScalarMapPL->ShallowCopy(myScalarMap->GetScalarMapPL());
657   
658   if ( myBusy ) return;
659
660   myBusy = true;
661
662   int sbCol,sbLab;
663   sbCol = getNbColors();
664   sbLab = getNbLabels();
665   if(sbCol < 2) sbCol=2;
666   if(sbCol > 64) sbCol=64;
667   if(sbLab < 2) sbLab=2;
668   if(sbLab > 65) sbLab=65;
669   myPreviewActor = VISU_ScalarMapAct::New();
670   VISU_ScalarBarActor* aScalarBarActor = myPreviewActor->GetScalarBar();
671   myPreviewActor->GetScalarBar()->VisibilityOn();
672   myPreviewActor->PickableOff();
673   
674   myScalarMapPL->SetScalarMode(myModeCombo->currentItem());
675   if(isLogarithmic())
676     myScalarMapPL->SetScaling(VISU::LOGARITHMIC);
677   else
678     myScalarMapPL->SetScaling(VISU::LINEAR);
679   vtkFloatingPointType theRange[2];
680   theRange[0] = (vtkFloatingPointType)MinEdit->text().toDouble();
681   theRange[1] = (vtkFloatingPointType)MaxEdit->text().toDouble();
682   myScalarMapPL->SetScalarRange(theRange);
683   myScalarMapPL->SetNbColors(sbCol);
684   
685   myScalarMapPL->Update();
686   
687   aScalarBarActor->SetLookupTable(myScalarMapPL->GetBarTable());
688   
689   if (myTextDlg->getTitleText().latin1() != "") 
690     aScalarBarActor->SetTitle(myTextDlg->getTitleText().latin1());
691   else
692     aScalarBarActor->SetTitle(myTitle.c_str());
693   aScalarBarActor->SetOrientation(getOrientation());
694   aScalarBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
695   aScalarBarActor->GetPositionCoordinate()->SetValue(getX(),getY());
696   aScalarBarActor->SetWidth(getWidth());
697   aScalarBarActor->SetHeight(getHeight());
698   aScalarBarActor->SetNumberOfLabels(sbLab);
699   aScalarBarActor->SetMaximumNumberOfColors(sbCol);
700
701   // title text property
702   QColor aTitleColor;
703   int aTitleFontFamily;
704   bool isTitleBold;
705   bool isTitleItalic;
706   bool isTitleShadow;
707   myTextDlg->myTitleFont->GetData(aTitleColor,aTitleFontFamily,
708                                   isTitleBold,isTitleItalic,isTitleShadow);
709   vtkTextProperty* aTitleProp = aScalarBarActor->GetTitleTextProperty();
710   aTitleProp->SetFontFamily(aTitleFontFamily);
711   aTitleProp->SetColor(vtkFloatingPointType(aTitleColor.red())/255.,
712                        vtkFloatingPointType(aTitleColor.green())/255.,
713                        vtkFloatingPointType(aTitleColor.blue())/255.);
714   (isTitleBold)? aTitleProp->BoldOn() : aTitleProp->BoldOff();
715   (isTitleItalic)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff();
716   (isTitleShadow)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff();
717   
718   // label text property
719   QColor aLabelColor;
720   int aLabelFontFamily;
721   bool isLabelBold;
722   bool isLabelItalic;
723   bool isLabelShadow;
724   myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
725                                   isLabelBold, isLabelItalic, isLabelShadow);
726   vtkTextProperty* aLabelProp = aScalarBarActor->GetLabelTextProperty();
727   aLabelProp->SetFontFamily(aLabelFontFamily);
728   aLabelProp->SetColor(vtkFloatingPointType(aLabelColor.red())/255.,
729                        vtkFloatingPointType(aLabelColor.green())/255.,
730                        vtkFloatingPointType(aLabelColor.blue())/255.);
731   (isLabelBold)? aLabelProp->BoldOn() : aLabelProp->BoldOff();
732   (isLabelItalic)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff();
733   (isLabelShadow)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff();
734
735   aScalarBarActor->Modified();
736
737   VISU::GetActiveViewWindow<SVTK_ViewWindow>()->AddActor(myPreviewActor);
738
739   myBusy = false;
740 }
741 /*! Deleting preview scalar bar
742  */
743 void VisuGUI_ScalarBarPane::deleteScalarBar()
744 {
745   if ( myBusy ) return;
746   
747   if (myPreviewActor == 0) return;
748   vtkRenderer* aRend       = myPreviewActor->GetRenderer();
749   if(aRend)
750     myPreviewActor->RemoveFromRender(aRend);
751   myPreviewActor->GetScalarBar()->VisibilityOff();
752   myPreviewActor->Delete();
753   myPreviewActor = 0;
754
755   if (myScalarMapPL){
756     myScalarMapPL->Delete();
757     myScalarMapPL = 0;
758   }
759 }
760 /*! public: Deleting preview scalar bar
761  */
762 void VisuGUI_ScalarBarPane::deletePreview()
763 {
764   deleteScalarBar();
765   if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
766     vf->Repaint();
767 }
768 /**
769  * Store values to presentation object
770  */
771 int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs) {
772   thePrs->SetScalarMode(myModeCombo->currentItem());
773   thePrs->SetPosition(XSpin->value(), YSpin->value());
774   thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
775   thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
776   if(isLogarithmic())
777     thePrs->SetScaling(VISU::LOGARITHMIC);
778   else
779     thePrs->SetScaling(VISU::LINEAR);
780
781   if (RBFrange->isChecked()) {
782     thePrs->SetSourceRange();
783   } else {
784     thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
785   }
786   thePrs->SetNbColors(ColorSpin->value());
787   thePrs->SetLabels(LabelSpin->value());
788
789   if (isToSave()) storeToResources();
790
791   if (myIsStoreTextProp) {
792     // "Title"
793     thePrs->SetTitle(myTextDlg->getTitleText().latin1());
794
795     QColor aTitColor (255, 255, 255);
796     int aTitleFontFamily = VTK_ARIAL;
797     bool isTitleBold = false;
798     bool isTitleItalic = false;
799     bool isTitleShadow = false;
800
801     myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
802                                     isTitleBold, isTitleItalic, isTitleShadow);
803
804     thePrs->SetBoldTitle(isTitleBold);
805     thePrs->SetItalicTitle(isTitleItalic);
806     thePrs->SetShadowTitle(isTitleShadow);
807     thePrs->SetTitFontType(aTitleFontFamily);
808     thePrs->SetTitleColor(aTitColor.red()/255.,
809                           aTitColor.green()/255.,
810                           aTitColor.blue()/255.);
811
812     // "Label"
813     QColor aLblColor (255, 255, 255);
814     int aLabelFontFamily = VTK_ARIAL;
815     bool isLabelBold = false;
816     bool isLabelItalic = false;
817     bool isLabelShadow = false;
818
819     myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
820                                     isLabelBold, isLabelItalic, isLabelShadow);
821
822     thePrs->SetBoldLabel(isLabelBold);
823     thePrs->SetItalicLabel(isLabelItalic);
824     thePrs->SetShadowLabel(isLabelShadow);
825     thePrs->SetLblFontType(aLabelFontFamily);
826     thePrs->SetLabelColor(aLblColor.red()/255.,
827                           aLblColor.green()/255.,
828                           aLblColor.blue()/255.);
829     myIsStoreTextProp = false;
830   }
831
832   return 1;
833 }
834
835 /*!
836   Called when orientation is changed
837 */
838 void VisuGUI_ScalarBarPane::changeDefaults( int )
839 {
840   if ( RBvert->isChecked() ) {
841     XSpin->setValue( myVerX );
842     YSpin->setValue( myVerY );
843     WidthSpin->setValue( myVerW );
844     HeightSpin->setValue( myVerH );
845   }
846   else {
847     XSpin->setValue( myHorX );
848     YSpin->setValue( myHorY );
849     WidthSpin->setValue( myHorW );
850     HeightSpin->setValue( myHorH );
851   }
852   updatePreview();
853 }
854
855 /*!
856   Called when Range mode is changed
857 */
858 void VisuGUI_ScalarBarPane::changeRange( int )
859 {
860   int mode = -1;
861   if ( RBFrange->isChecked() )
862     mode = 0;
863   if ( RBIrange->isChecked() )
864     mode = 1;
865   if ( myRangeMode == mode )
866     return;
867   //MinSpin->setMaxValue( Fmin );
868   //MaxSpin->setMinValue( Fmax );
869   if ( RBFrange->isChecked() ) {
870     //MinLabel->setEnabled( false );
871     MinEdit->setEnabled( false );
872     //MaxLabel->setEnabled( false );
873     MaxEdit->setEnabled( false );
874     if ( mode != -1 ) {
875       Imin = MinEdit->text().toDouble();
876       Imax = MaxEdit->text().toDouble();
877     }
878     MinEdit->setText( QString::number( Rmin ) );
879     MaxEdit->setText( QString::number( Rmax ) );
880   }
881   else {
882     //MinLabel->setEnabled( true );
883     MinEdit->setEnabled( true );
884     //MaxLabel->setEnabled( true );
885     MaxEdit->setEnabled( true );
886     MinEdit->setText( QString::number( Imin ) );
887     MaxEdit->setText( QString::number( Imax ) );
888   }
889   myRangeMode = mode;
890   updatePreview();
891 }
892
893 /*!
894   Called when X,Y position is changed
895 */
896 void VisuGUI_ScalarBarPane::XYChanged( double )
897 {
898   QtxDblSpinBox* snd = (QtxDblSpinBox*)sender();
899   if ( snd == XSpin ) {
900     WidthSpin->setMaxValue( 1.0 - XSpin->value() );
901   }
902   if ( snd == YSpin ) {
903     HeightSpin->setMaxValue( 1.0 - YSpin->value() );
904   }
905   updatePreview();
906 }
907
908 /*!
909   Called when scalar mode is changed
910 */
911 void VisuGUI_ScalarBarPane::changeScalarMode( int theMode )
912 {
913   if ( myScalarMap ) {
914     if ( RBFrange->isChecked() ) {
915       vtkFloatingPointType aRange[2];
916       int aMode = myScalarMap->GetScalarMode();
917       myScalarMap->SetScalarMode(theMode);
918       myScalarMap->GetScalarMapPL()->GetSourceRange(aRange);
919       MinEdit->setText( QString::number( aRange[0] ) );
920       MaxEdit->setText( QString::number( aRange[1] ) );
921       myScalarMap->SetScalarMode(aMode);
922     }
923   }
924   updatePreview();
925 }
926
927 /*!
928   Sets default values and range mode
929 */
930 void VisuGUI_ScalarBarPane::setRange( double imin, double imax/*, double fmin, double fmax*/, bool sbRange )
931 {
932   Imin = imin; Imax = imax;// Fmin = fmin; Fmax = fmax;
933   if ( RBIrange->isChecked() ) {
934     MinEdit->setText( QString::number( Imin ) );
935     MaxEdit->setText( QString::number( Imax ) );
936   }
937   else {
938     MinEdit->setText( QString::number( Rmin ) );
939     MaxEdit->setText( QString::number( Rmax ) );
940   }
941   myRangeMode = -1;
942   if( sbRange )
943     RBIrange->setChecked( true );
944   else
945     RBFrange->setChecked( true );
946   changeRange( 0 );
947 }
948
949 /*!
950   Sets default values and range mode
951 */
952 void VisuGUI_ScalarBarPane::setDefaultRange(double imin, double imax){
953   Rmin = imin;
954   Rmax = imax;
955 }
956
957 /*!
958   Sets size and position
959 */
960 void VisuGUI_ScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
961 {
962   if ( vert ) {
963     myVerX = x;
964     myVerY = y;
965     myVerW = w;
966     myVerH = h;
967     RBvert->setChecked( true );
968   }
969   else {
970     myHorX = x;
971     myHorY = y;
972     myHorW = w;
973     myHorH = h;
974     RBhori->setChecked( true );
975   }
976   changeDefaults( 0 );
977 }
978
979 /*!
980   Sets colors and labels number
981 */
982 void VisuGUI_ScalarBarPane::setScalarBarData( int colors, int labels )
983 {
984   ColorSpin->setValue( colors );
985   LabelSpin->setValue( labels );
986 }
987
988 /*!
989   Gets orientation
990 */
991 int  VisuGUI_ScalarBarPane::getOrientation()
992 {
993   if (RBvert->isChecked() )
994     return  1;
995   else
996     return 0;
997 }
998
999 /*!
1000   Called when <OK> button is clicked, validates data and closes dialog
1001 */
1002 bool VisuGUI_ScalarBarPane::check()
1003 {
1004   double minVal = MinEdit->text().toDouble();
1005   double maxVal = MaxEdit->text().toDouble();
1006   if ( RBIrange->isChecked() ) {
1007     if (minVal >= maxVal) {
1008       SUIT_MessageBox::warn1( this,tr("WRN_VISU"),
1009                              tr("MSG_MINMAX_VALUES"),
1010                              tr("BUT_OK"));
1011       return false;
1012     }
1013   }
1014   // check if logarithmic mode is on and check imposed range to not contain negative values
1015   if ( CBLog->isChecked() ) {
1016     if ( RBIrange->isChecked() ) {
1017       if ( (minVal > 0) && (maxVal > 0) ) {
1018         // nothing to do
1019       }
1020       else {
1021         SUIT_MessageBox::warn1( this,
1022                                 tr("WRN_VISU"),
1023                                 tr("WRN_LOGARITHMIC_RANGE"),
1024                                 tr("BUT_OK"));
1025         return false;
1026       }
1027     }
1028     else {
1029       if ( Rmin > 0 && Rmax > 0 ) {
1030         // nothing to do
1031       }
1032       else {
1033         SUIT_MessageBox::warn1( this,
1034                                 tr("WRN_VISU"),
1035                                 tr("WRN_LOGARITHMIC_FIELD_RANGE"),
1036                                 tr("BUT_OK"));
1037         RBIrange->setChecked(1);
1038         changeRange(1);
1039         //MinEdit->setText( QString::number( Rmin ) );
1040         //MaxEdit->setText( QString::number( Rmax ) );
1041         return false;
1042       }
1043     }
1044   }
1045   return true;
1046 }
1047
1048 void VisuGUI_ScalarBarPane::onTextPref()
1049 {
1050   myTextDlg->storeBeginValues();
1051   myIsStoreTextProp = myTextDlg->exec() || myIsStoreTextProp;
1052   updatePreview();
1053 }
1054
1055 void VisuGUI_ScalarBarPane::onPreviewCheck (bool thePreview)
1056 {
1057   if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
1058     if (thePreview) {
1059       createScalarBar();
1060     } else {
1061       deleteScalarBar();
1062     }
1063     vf->Repaint();
1064   }
1065 }
1066
1067 //#######################################################################################
1068
1069 /*!
1070   Constructor
1071 */
1072 VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg (SalomeApp_Module* theModule, bool SetPref)
1073     : QDialog(VISU::GetDesktop(theModule), 0, true,
1074               WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
1075 {
1076   setName("VisuGUI_ScalarBarDlg");
1077   setCaption(SetPref ? tr("DLG_PREF_TITLE") : tr("DLG_PROP_TITLE"));
1078   setSizeGripEnabled(TRUE);
1079
1080   QVBoxLayout* TopLayout = new QVBoxLayout(this);
1081   TopLayout->setSpacing(6);
1082   TopLayout->setMargin(11);
1083
1084   myScalarPane = new VisuGUI_ScalarBarPane(this, SetPref);
1085   TopLayout->addWidget(myScalarPane);
1086
1087   // Common buttons ===========================================================
1088   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1089   GroupButtons->setColumnLayout(0, Qt::Vertical );
1090   GroupButtons->layout()->setSpacing( 0 );
1091   GroupButtons->layout()->setMargin( 0 );
1092   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1093   GroupButtonsLayout->setAlignment( Qt::AlignTop );
1094   GroupButtonsLayout->setSpacing( 6 );
1095   GroupButtonsLayout->setMargin( 11 );
1096
1097   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
1098   buttonOk->setAutoDefault( TRUE );
1099   buttonOk->setDefault( TRUE );
1100   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
1101   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1102
1103   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
1104   buttonCancel->setAutoDefault( TRUE );
1105   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
1106
1107   QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
1108   buttonHelp->setAutoDefault( TRUE );
1109   GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
1110
1111   TopLayout->addWidget( GroupButtons );
1112
1113   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
1114   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
1115   connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( onHelp() ) );
1116 }
1117
1118 /*!
1119   Called when <OK> button is clicked, validates data and closes dialog
1120 */
1121 void VisuGUI_ScalarBarDlg::accept()
1122 {
1123   if (myScalarPane->check()) 
1124     {
1125       myScalarPane->deletePreview(); 
1126       QDialog::accept();
1127     }
1128 }
1129
1130 /*!
1131   Called when <Cancel> button is clicked, remove preview and closes dialog
1132 */
1133 void VisuGUI_ScalarBarDlg::reject()
1134 {
1135   myScalarPane->deletePreview();
1136   QDialog::reject();
1137 }
1138
1139 /*!
1140   Called when <Help> button is clicked, shows the corresponding help page in defined browser
1141 */
1142 void VisuGUI_ScalarBarDlg::onHelp()
1143 {
1144   QString aHelpFileName = "/files/scalar_map_presentation.htm";
1145   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1146   if (app) {
1147     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
1148     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
1149   }
1150   else {
1151     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1152                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1153                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
1154                            QObject::tr("BUT_OK"));
1155   }
1156 }
1157
1158
1159 //#######################################################################################
1160 VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent)
1161   : QDialog(parent, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
1162 {
1163   setName("VisuGUI_TextPrefDlg");
1164   setCaption(tr("TIT_TEXT_PREF"));
1165   setSizeGripEnabled(TRUE);
1166
1167   QVBoxLayout* TopLayout = new QVBoxLayout(this);
1168   TopLayout->setSpacing(6);
1169   TopLayout->setMargin(11);
1170
1171   // "Title" grp
1172   QGroupBox* aTitleGrp = new QGroupBox (2, Qt::Vertical, tr("LBL_TITLE"), this);
1173
1174   //   edit line
1175   myTitleEdt = new QLineEdit (aTitleGrp);
1176
1177   //   font
1178   QHBox* aHBox = new QHBox (aTitleGrp);
1179   aHBox->setSpacing(5);
1180   myTitleFont = new SVTK_FontWidget (aHBox);
1181
1182   TopLayout->addWidget(aTitleGrp);
1183
1184   // "Labels" grp
1185   QGroupBox* aLabelsGrp = new QGroupBox (1, Qt::Vertical, tr("LBL_LABELS"), this);
1186
1187   //   font
1188   aHBox = new QHBox (aLabelsGrp);
1189   aHBox->setSpacing(5);
1190   myLabelFont = new SVTK_FontWidget (aHBox);
1191
1192   TopLayout->addWidget(aLabelsGrp);
1193
1194   // Common buttons ===========================================================
1195   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1196   GroupButtons->setColumnLayout(0, Qt::Vertical );
1197   GroupButtons->layout()->setSpacing( 0 );
1198   GroupButtons->layout()->setMargin( 0 );
1199   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1200   GroupButtonsLayout->setAlignment( Qt::AlignTop );
1201   GroupButtonsLayout->setSpacing( 6 );
1202   GroupButtonsLayout->setMargin( 11 );
1203
1204   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
1205   buttonOk->setAutoDefault( TRUE );
1206   buttonOk->setDefault( TRUE );
1207   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
1208   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1209
1210   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
1211   buttonCancel->setAutoDefault( TRUE );
1212   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
1213
1214   QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
1215   buttonHelp->setAutoDefault( TRUE );
1216   GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
1217
1218   TopLayout->addWidget( GroupButtons );
1219
1220   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(accept()));
1221   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
1222   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(onHelp()));
1223 }
1224
1225 void VisuGUI_TextPrefDlg::onHelp()
1226 {
1227   QString aHelpFileName = "/files/scalar_map_presentation.htm";
1228   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1229   if (app) {
1230     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
1231     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
1232   }
1233   else {
1234     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1235                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1236                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
1237                            QObject::tr("BUT_OK"));
1238   }
1239 }
1240
1241 void VisuGUI_TextPrefDlg::storeBeginValues()
1242 {
1243   myTitle = myTitleEdt->text();
1244   myTitleFont->GetData(myColors[0], myComboVals[0], myCheckVals[0], myCheckVals[1], myCheckVals[2]);
1245   myLabelFont->GetData(myColors[1], myComboVals[1], myCheckVals[3], myCheckVals[4], myCheckVals[5]);
1246 }
1247
1248 /*!
1249   Called when <Cancel> button is clicked, restore begin values
1250 */
1251 void VisuGUI_TextPrefDlg::reject()
1252 {
1253   myTitleEdt->setText(myTitle);
1254   myTitleFont->SetData(myColors[0], myComboVals[0], myCheckVals[0], myCheckVals[1], myCheckVals[2]);
1255   myLabelFont->SetData(myColors[1], myComboVals[1], myCheckVals[3], myCheckVals[4], myCheckVals[5]);
1256
1257   QDialog::reject();
1258 }
1259 /*!
1260   Called when <Ok> button is clicked, store begin values
1261 */
1262 void VisuGUI_TextPrefDlg::accept()
1263 {
1264   storeBeginValues();
1265
1266   QDialog::accept();
1267 }