1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VisuGUI_ScalarBarDlg.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
29 #include "VisuGUI_ScalarBarDlg.h"
30 #include "VISU_ScalarMap_i.hh"
31 #include "VISU_ScalarMapPL.hxx"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Config.h"
36 #include "QAD_MessageBox.h"
37 #include "VISU_Convertor.hxx"
41 #include <qvalidator.h>
42 #include <qcolordialog.h>
48 VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane(QWidget * parent, bool SetPref):
51 myVerX = 0.01; myVerY = 0.10; myVerW = 0.10; myVerH = 0.80;
52 myHorX = 0.20; myHorY = 0.01; myHorW = 0.60; myHorH = 0.12;
53 Imin = 0.0; Imax = 0.0; /*Fmin = 0.0; Fmax = 0.0;*/ Rmin = 0.0; Rmax = 0.0;
59 // Range ============================================================
60 RangeGroup = new QButtonGroup( tr( "Scalar range" ), this, "RangeGroup" );
61 RangeGroup->setColumnLayout(0, Qt::Vertical );
62 RangeGroup->layout()->setSpacing( 0 );
63 RangeGroup->layout()->setMargin( 0 );
64 QGridLayout* RangeGroupLayout = new QGridLayout( RangeGroup->layout() );
65 RangeGroupLayout->setAlignment( Qt::AlignTop );
66 RangeGroupLayout->setSpacing( 6 );
67 RangeGroupLayout->setMargin( 11 );
69 myModeLbl = new QLabel("Scalar Mode", RangeGroup);
71 myModeCombo = new QComboBox(RangeGroup);
72 myModeCombo->insertItem("Modulus");
73 myModeCombo->insertItem("Component 1");
74 myModeCombo->insertItem("Component 2");
75 myModeCombo->insertItem("Component 3");
77 CBLog = new QCheckBox( tr( "Logarithmic scaling" ), RangeGroup );
78 CBLog->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
80 RBFrange = new QRadioButton( tr( "Use field range" ), RangeGroup, "RBFrange" );
81 RBIrange = new QRadioButton( tr( "Use imposed range" ), RangeGroup, "RBIrange" );
82 RBFrange->setChecked( true );
84 MinEdit = new QLineEdit( RangeGroup, "MinEdit" );
85 MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
86 MinEdit->setMinimumWidth( 70 );
87 MinEdit->setValidator( new QDoubleValidator(this) );
88 MinEdit->setText( "0.0" );
89 QLabel* MinLabel = new QLabel( tr( "Min:" ), RangeGroup, "MinLabel" );
90 MinLabel->setBuddy(MinEdit);
92 MaxEdit = new QLineEdit( RangeGroup, "MaxEdit" );
93 MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
94 MaxEdit->setMinimumWidth( 70 );
95 MaxEdit->setValidator( new QDoubleValidator(this) );
96 MaxEdit->setText( "0.0" );
97 QLabel* MaxLabel = new QLabel( tr( "Max:" ), RangeGroup, "MaxLabel" );
98 MaxLabel->setBuddy(MaxEdit);
100 RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
101 RangeGroupLayout->addMultiCellWidget( myModeCombo, 0, 0, 1, 3);
102 RangeGroupLayout->addMultiCellWidget( CBLog, 1, 1, 0, 3);
103 RangeGroupLayout->addMultiCellWidget( RBFrange, 2, 2, 0, 1);
104 RangeGroupLayout->addMultiCellWidget( RBIrange, 2, 2, 2, 3);
105 RangeGroupLayout->addWidget( MinLabel, 3, 0 );
106 RangeGroupLayout->addWidget( MinEdit, 3, 1 );
107 RangeGroupLayout->addWidget( MaxLabel, 3, 2 );
108 RangeGroupLayout->addWidget( MaxEdit, 3, 3 );
110 //TopLayout->addWidget( RangeGroup );
112 // Colors and Labels ========================================================
113 QGroupBox* ColLabGroup = new QGroupBox( tr( "Colors and labels" ), this, "ColLabGroup" );
114 ColLabGroup->setColumnLayout(0, Qt::Vertical );
115 ColLabGroup->layout()->setSpacing( 0 );
116 ColLabGroup->layout()->setMargin( 0 );
117 QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup->layout() );
118 ColLabGroupLayout->setAlignment( Qt::AlignTop );
119 ColLabGroupLayout->setSpacing( 6 );
120 ColLabGroupLayout->setMargin( 11 );
122 QLabel* ColorLabel = new QLabel( tr( "Nb. of colors:" ), ColLabGroup, "ColorLabel" );
123 ColorSpin = new QSpinBox( 2, 256, 1, ColLabGroup );
124 ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
125 ColorSpin->setMinimumWidth( 70 );
126 ColorSpin->setValue( 64 );
128 QLabel* LabelLabel = new QLabel( tr( "Nb. of labels:" ), ColLabGroup, "LabelLabel" );
129 LabelSpin = new QSpinBox( 2, 65, 1, ColLabGroup );
130 LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
131 LabelSpin->setMinimumWidth( 70 );
132 LabelSpin->setValue( 5 );
134 ColLabGroupLayout->addWidget( ColorLabel, 0, 0);
135 ColLabGroupLayout->addWidget( ColorSpin, 0, 1);
136 ColLabGroupLayout->addWidget( LabelLabel, 0, 2);
137 ColLabGroupLayout->addWidget( LabelSpin, 0, 3);
139 //TopLayout->addWidget( ColLabGroup );
141 // Orientation ==========================================================
142 QButtonGroup* OrientGroup = new QButtonGroup( tr( "Orientation" ), this, "OrientGroup" );
143 OrientGroup->setColumnLayout(0, Qt::Vertical );
144 OrientGroup->layout()->setSpacing( 0 );
145 OrientGroup->layout()->setMargin( 0 );
146 QGridLayout* OrientGroupLayout = new QGridLayout( OrientGroup->layout() );
147 OrientGroupLayout->setAlignment( Qt::AlignTop );
148 OrientGroupLayout->setSpacing( 6 );
149 OrientGroupLayout->setMargin( 11 );
151 RBvert = new QRadioButton( tr( "Vertical" ), OrientGroup, "RBvert" );
152 RBvert->setChecked( true );
153 RBhori = new QRadioButton( tr( "Horizontal" ), OrientGroup, "RBhori" );
154 OrientGroupLayout->addWidget( RBvert, 0, 0 );
155 OrientGroupLayout->addWidget( RBhori, 0, 1 );
157 // TopLayout->addWidget( OrientGroup );
159 // Origin ===============================================================
160 QGroupBox* OriginGroup = new QGroupBox( tr( "Origin" ), this, "OriginGroup" );
161 OriginGroup->setColumnLayout(0, Qt::Vertical );
162 OriginGroup->layout()->setSpacing( 0 );
163 OriginGroup->layout()->setMargin( 0 );
164 QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup->layout() );
165 OriginGroupLayout->setAlignment( Qt::AlignTop );
166 OriginGroupLayout->setSpacing( 6 );
167 OriginGroupLayout->setMargin( 11 );
169 QLabel* XLabel = new QLabel( tr( "X:" ), OriginGroup, "XLabel" );
170 XSpin = new QAD_SpinBoxDbl( OriginGroup, 0.0, 1.0, 0.1 );
171 XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
172 XSpin->setMinimumWidth( 70 );
173 XSpin->setValue( 0.01 );
175 QLabel* YLabel = new QLabel( tr( "Y:" ), OriginGroup, "YLabel" );
176 YSpin = new QAD_SpinBoxDbl( OriginGroup, 0.0, 1.0, 0.1 );
177 YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
178 YSpin->setMinimumWidth( 70 );
179 YSpin->setValue( 0.01 );
181 OriginGroupLayout->addWidget( XLabel, 0, 0);
182 OriginGroupLayout->addWidget( XSpin, 0, 1);
183 OriginGroupLayout->addWidget( YLabel, 0, 2);
184 OriginGroupLayout->addWidget( YSpin, 0, 3);
186 //TopLayout->addWidget( OriginGroup );
188 // Dimensions =========================================================
189 QGroupBox* DimGroup = new QGroupBox( tr( "Dimensions" ), this, "DimGroup" );
190 DimGroup->setColumnLayout(0, Qt::Vertical );
191 DimGroup->layout()->setSpacing( 0 );
192 DimGroup->layout()->setMargin( 0 );
193 QGridLayout* DimGroupLayout = new QGridLayout( DimGroup->layout() );
194 DimGroupLayout->setAlignment( Qt::AlignTop );
195 DimGroupLayout->setSpacing( 6 );
196 DimGroupLayout->setMargin( 11 );
198 QLabel* WidthLabel = new QLabel( tr( "Width:" ), DimGroup, "WidthLabel" );
199 WidthSpin = new QAD_SpinBoxDbl( DimGroup, 0.0, 1.0, 0.1 );
200 WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
201 WidthSpin->setMinimumWidth( 70 );
202 WidthSpin->setValue( 0.1 );
204 QLabel* HeightLabel = new QLabel( tr( "Height:" ), DimGroup, "HeightLabel" );
205 HeightSpin = new QAD_SpinBoxDbl( DimGroup, 0.0, 1.0, 0.1 );
206 HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
207 HeightSpin->setMinimumWidth( 70 );
208 HeightSpin->setValue( 0.8 );
210 DimGroupLayout->addWidget( WidthLabel, 0, 0);
211 DimGroupLayout->addWidget( WidthSpin, 0, 1);
212 DimGroupLayout->addWidget( HeightLabel, 0, 2);
213 DimGroupLayout->addWidget( HeightSpin, 0, 3);
215 //TopLayout->addWidget( DimGroup );
217 // Save check box ===========================================================
218 QHBox* aSaveBox = new QHBox(this);
220 CBSave = new QCheckBox( tr( "Save as default values" ), aSaveBox, "CBSave" );
221 //TopLayout->addWidget( CBSave );
226 myTextBtn = new QPushButton("Text properties...", aSaveBox);
227 myTextDlg = new VisuGUI_TextPrefDlg(this);
228 myTextDlg->setTitleVisible(!SetPref);
230 // signals and slots connections ===========================================
231 connect( RangeGroup, SIGNAL( clicked( int ) ), this, SLOT( changeRange( int ) ) );
232 connect( OrientGroup, SIGNAL( clicked( int ) ), this, SLOT( changeDefaults( int ) ) );
233 connect( XSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
234 connect( YSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
235 connect( myTextBtn, SIGNAL( clicked() ), this, SLOT( onTextPref() ) );
239 myIsStoreTextProp = false;
244 * Initializes dialog box values from resources
246 void VisuGUI_ScalarBarPane::initFromResources() {
247 int sbCol=64,sbLab=5,orient=1;
248 float sbX1=0.01,sbY1=0.1,sbW=0.1,sbH=0.8;
249 float sbVmin=0., sbVmax=0.;
252 QString Orientation = QAD_CONFIG->getSetting("Visu:SBOrientation");
253 if ( !Orientation.isEmpty() ) {
254 orient = Orientation.toInt();
264 QString SBXorigin = QAD_CONFIG->getSetting("Visu:SBXorigin");
265 if ( !SBXorigin.isEmpty() )
266 sbX1 = SBXorigin.toFloat();
268 QString SBYorigin = QAD_CONFIG->getSetting("Visu:SBYorigin");
269 if ( !SBYorigin.isEmpty() )
270 sbY1 = SBYorigin.toFloat();
272 QString SBWidth = QAD_CONFIG->getSetting("Visu:SBWidth");
273 if ( !SBWidth.isEmpty() )
274 sbW = SBWidth.toFloat();
276 QString SBHeight = QAD_CONFIG->getSetting("Visu:SBHeight");
277 if ( !SBHeight.isEmpty() )
278 sbH = SBHeight.toFloat();
280 QString SBColors = QAD_CONFIG->getSetting("Visu:SBNumberOfColors");
281 if ( !SBColors.isEmpty() )
282 sbCol = SBColors.toInt();
284 QString SBLabels = QAD_CONFIG->getSetting("Visu:SBNumberOfLabels");
285 if ( !SBLabels.isEmpty() )
286 sbLab = SBLabels.toInt();
288 QString ImpRange = QAD_CONFIG->getSetting("Visu:SBImposeRange");
289 if ( ImpRange.compare("true") == 0 )
292 QString SBVmin = QAD_CONFIG->getSetting("Visu:SBMinimumValue");
293 if ( !SBVmin.isEmpty() )
294 sbVmin = SBVmin.toFloat();
296 QString SBVmax = QAD_CONFIG->getSetting("Visu:SBMaximumValue");
297 if ( !SBVmax.isEmpty() )
298 sbVmax = SBVmax.toFloat();
300 QString aScaling = QAD_CONFIG->getSetting("Visu:SBScaling");
301 if(aScaling.compare("LOGARITHMIC") == 0)
302 setLogarithmic(true);
304 setLogarithmic(false);
306 if((sbX1 < 0.) || (sbY1 < 0.) ||
307 ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
320 if(sbCol < 2) sbCol=2;
321 if(sbCol > 64) sbCol=64;
322 if(sbLab < 2) sbLab=2;
323 if(sbLab > 65) sbLab=65;
325 if(sbVmin > sbVmax) {
330 setRange( sbVmin, sbVmax, /*0.0, 0.0,*/ sbRange );
331 setPosAndSize( sbX1, sbY1, sbW, sbH, orient == 1);
332 setScalarBarData( sbCol, sbLab );
334 QString aIsBoldTitle = QAD_CONFIG->getSetting("Visu:IsBoldTitle");
335 if (aIsBoldTitle.isEmpty())
336 myTextDlg->setBoldTitle(true);
338 myTextDlg->setBoldTitle(aIsBoldTitle.compare("true") == 0);
340 QString aIsItalicTitle = QAD_CONFIG->getSetting("Visu:IsItalicTitle");
341 if (aIsItalicTitle.isEmpty())
342 myTextDlg->setItalicTitle(true);
344 myTextDlg->setItalicTitle(aIsItalicTitle.compare("true") == 0);
346 QString aIsShadowTitle = QAD_CONFIG->getSetting("Visu:IsShadowTitle");
347 if (aIsShadowTitle.isEmpty())
348 myTextDlg->setShadowTitle(true);
350 myTextDlg->setShadowTitle(aIsShadowTitle.compare("true") == 0);
352 QString aTitFontType = QAD_CONFIG->getSetting("Visu:TitFontType");
353 if (!aTitFontType.isEmpty()) {
354 switch (aTitFontType.toInt()) {
355 case 0: myTextDlg->setTitleFont(VTK_ARIAL); break;
356 case 1: myTextDlg->setTitleFont(VTK_COURIER); break;
357 case 2: myTextDlg->setTitleFont(VTK_TIMES); break;
360 myTextDlg->setTitleFont(VTK_ARIAL);
363 QString aRTitColor = QAD_CONFIG->getSetting("Visu:TitleColorR");
364 R = (aRTitColor.isEmpty())? 1 : aRTitColor.toFloat();
368 QString aGTitColor = QAD_CONFIG->getSetting("Visu:TitleColorG");
369 G = (aGTitColor.isEmpty())? 1 : aGTitColor.toFloat();
373 QString aBTitColor = QAD_CONFIG->getSetting("Visu:TitleColorB");
374 B = (aBTitColor.isEmpty())? 1 : aBTitColor.toFloat();
378 myTextDlg->setTitleColor(QColor((int)(R*255.),
383 QString aIsBoldLabel = QAD_CONFIG->getSetting("Visu:IsBoldLabel");
384 if (aIsBoldLabel.isEmpty())
385 myTextDlg->setBoldLabel(true);
387 myTextDlg->setBoldLabel(aIsBoldLabel.compare("true") == 0);
389 QString aIsItalicLabel = QAD_CONFIG->getSetting("Visu:IsItalicLabel");
390 if (aIsItalicLabel.isEmpty())
391 myTextDlg->setItalicLabel(true);
393 myTextDlg->setItalicLabel(aIsItalicLabel.compare("true") == 0);
395 QString aIsShadowLabel = QAD_CONFIG->getSetting("Visu:IsShadowLabel");
396 if (aIsShadowLabel.isEmpty())
397 myTextDlg->setShadowLabel(true);
399 myTextDlg->setShadowLabel(aIsShadowLabel.compare("true") == 0);
401 QString aLblFontType = QAD_CONFIG->getSetting("Visu:LblFontType");
402 if (!aLblFontType.isEmpty()) {
403 switch (aLblFontType.toInt()) {
404 case 0: myTextDlg->setLabelFont(VTK_ARIAL); break;
405 case 1: myTextDlg->setLabelFont(VTK_COURIER); break;
406 case 2: myTextDlg->setLabelFont(VTK_TIMES); break;
409 myTextDlg->setLabelFont(VTK_ARIAL);
411 QString aRLblColor = QAD_CONFIG->getSetting("Visu:LabelColorR");
412 R = (aRLblColor.isEmpty())? 1 : aRLblColor.toFloat();
416 QString aGLblColor = QAD_CONFIG->getSetting("Visu:LabelColorG");
417 G = (aGLblColor.isEmpty())? 1 : aGLblColor.toFloat();
421 QString aBLblColor = QAD_CONFIG->getSetting("Visu:LabelColorB");
422 B = (aBLblColor.isEmpty())? 1 : aBLblColor.toFloat();
426 myTextDlg->setLabelColor(QColor((int)(R*255.),
434 * Stores dialog values to resources
436 void VisuGUI_ScalarBarPane::storeToResources() {
437 int orient = (RBvert->isChecked())? 1 : 0;
438 float sbX1 = XSpin->value();
439 float sbY1 = YSpin->value();
440 float sbW = WidthSpin->value();
441 float sbH = HeightSpin->value();
442 int sbCol = ColorSpin->value();
443 int sbLab = LabelSpin->value();
445 if((sbX1 < 0.) || (sbY1 < 0.) || ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
459 bool sbRange = RBIrange->isChecked();
460 float sbVmin = (float)(MinEdit->text().toDouble());
461 float sbVmax = (float)(MaxEdit->text().toDouble());
463 if(sbVmin > sbVmax) {
468 QAD_CONFIG->addSetting("Visu:SBOrientation",orient);
469 QAD_CONFIG->addSetting("Visu:SBXorigin",sbX1);
470 QAD_CONFIG->addSetting("Visu:SBYorigin",sbY1);
471 QAD_CONFIG->addSetting("Visu:SBWidth",sbW);
472 QAD_CONFIG->addSetting("Visu:SBHeight",sbH);
473 QAD_CONFIG->addSetting("Visu:SBNumberOfColors",sbCol);
474 QAD_CONFIG->addSetting("Visu:SBNumberOfLabels",sbLab);
476 QAD_CONFIG->addSetting("Visu:SBImposeRange", "true");
478 QAD_CONFIG->addSetting("Visu:SBImposeRange", "false");
479 QAD_CONFIG->addSetting("Visu:SBMinimumValue",sbVmin);
480 QAD_CONFIG->addSetting("Visu:SBMaximumValue",sbVmax);
482 QAD_CONFIG->addSetting("Visu:SBScaling", "LOGARITHMIC");
484 QAD_CONFIG->addSetting("Visu:SBScaling", "LINEAR");
488 if (myIsStoreTextProp) {
489 if (myTextDlg->isBoldTitle())
490 QAD_CONFIG->addSetting("Visu:IsBoldTitle","true");
492 QAD_CONFIG->addSetting("Visu:IsBoldTitle","false");
494 if (myTextDlg->isItalicTitle())
495 QAD_CONFIG->addSetting("Visu:IsItalicTitle","true");
497 QAD_CONFIG->addSetting("Visu:IsItalicTitle","false");
499 if (myTextDlg->isShadowTitle())
500 QAD_CONFIG->addSetting("Visu:IsShadowTitle","true");
502 QAD_CONFIG->addSetting("Visu:IsShadowTitle","false");
504 switch (myTextDlg->getTitleFont()) {
505 case VTK_ARIAL: QAD_CONFIG->addSetting("Visu:TitFontType",0); break;
506 case VTK_COURIER: QAD_CONFIG->addSetting("Visu:TitFontType",1); break;
507 case VTK_TIMES: QAD_CONFIG->addSetting("Visu:TitFontType",2); break;
509 QColor aColor = myTextDlg->getTitleColor();
510 QAD_CONFIG->addSetting("Visu:TitleColorR", aColor.red()/255.);
511 QAD_CONFIG->addSetting("Visu:TitleColorG", aColor.green()/255.);
512 QAD_CONFIG->addSetting("Visu:TitleColorB", aColor.blue()/255.);
515 if (myTextDlg->isBoldLabel())
516 QAD_CONFIG->addSetting("Visu:IsBoldLabel","true");
518 QAD_CONFIG->addSetting("Visu:IsBoldLabel","false");
520 if (myTextDlg->isItalicLabel())
521 QAD_CONFIG->addSetting("Visu:IsItalicLabel","true");
523 QAD_CONFIG->addSetting("Visu:IsItalicLabel","false");
525 if (myTextDlg->isShadowLabel())
526 QAD_CONFIG->addSetting("Visu:IsShadowLabel","true");
528 QAD_CONFIG->addSetting("Visu:IsShadowLabel","false");
530 switch (myTextDlg->getLabelFont()) {
531 case VTK_ARIAL: QAD_CONFIG->addSetting("Visu:LblFontType",0); break;
532 case VTK_COURIER: QAD_CONFIG->addSetting("Visu:LblFontType",1); break;
533 case VTK_TIMES: QAD_CONFIG->addSetting("Visu:LblFontType",2); break;
535 aColor = myTextDlg->getLabelColor();
536 QAD_CONFIG->addSetting("Visu:LabelColorR", aColor.red()/255.);
537 QAD_CONFIG->addSetting("Visu:LabelColorG", aColor.green()/255.);
538 QAD_CONFIG->addSetting("Visu:LabelColorB", aColor.blue()/255.);
544 * Initialise dialog box from presentation object
546 void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
548 myModeCombo->setCurrentItem(thePrs->GetScalarMode());
549 setPosAndSize( thePrs->GetPosX(),
553 thePrs->GetBarOrientation());
554 switch(thePrs->GetScaling()){
555 case VISU::LOGARITHMIC :
556 setLogarithmic(true);
559 setLogarithmic(false);
562 thePrs->GetScalarMapPL()->GetSourceRange(aRange);
563 Rmin = aRange[0]; Rmax = aRange[1];
564 setRange( thePrs->GetMin(), thePrs->GetMax(),
565 /*0.0, 0.0,*/ thePrs->IsRangeFixed() );
566 setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
567 bool isScalarMode = (thePrs->GetField()->myNbComp > 1);
568 myModeLbl->setEnabled(isScalarMode);
569 myModeCombo->setEnabled(isScalarMode);
571 myTextDlg->setTitleText(QString(thePrs->GetTitle()));
573 myTextDlg->setBoldTitle(thePrs->IsBoldTitle());
574 myTextDlg->setItalicTitle(thePrs->IsItalicTitle());
575 myTextDlg->setShadowTitle(thePrs->IsShadowTitle());
576 myTextDlg->setTitleFont(thePrs->GetTitFontType());
578 thePrs->GetTitleColor(&R, &G, &B);
579 myTextDlg->setTitleColor(QColor((int)(R*255.),
583 myTextDlg->setBoldLabel(thePrs->IsBoldLabel());
584 myTextDlg->setItalicLabel(thePrs->IsItalicLabel());
585 myTextDlg->setShadowLabel(thePrs->IsShadowLabel());
586 myTextDlg->setLabelFont(thePrs->GetLblFontType());
587 thePrs->GetLabelColor(&R, &G, &B);
588 myTextDlg->setLabelColor(QColor((int)(R*255.),
595 * Store values to presentation object
597 int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs) {
598 thePrs->SetScalarMode(myModeCombo->currentItem());
599 thePrs->SetPosition(XSpin->value(), YSpin->value());
600 thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
601 thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
603 thePrs->SetScaling(VISU::LOGARITHMIC);
605 thePrs->SetScaling(VISU::LINEAR);
607 if (RBFrange->isChecked()) {
608 thePrs->SetSourceRange();
610 thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
612 thePrs->SetNbColors(ColorSpin->value());
613 thePrs->SetLabels(LabelSpin->value());
615 if (isToSave()) storeToResources();
617 if (myIsStoreTextProp) {
618 thePrs->SetTitle(myTextDlg->getTitleText().latin1());
620 thePrs->SetBoldTitle(myTextDlg->isBoldTitle());
621 thePrs->SetItalicTitle(myTextDlg->isItalicTitle());
622 thePrs->SetShadowTitle(myTextDlg->isShadowTitle());
623 thePrs->SetTitFontType(myTextDlg->getTitleFont());
624 QColor aTitColor = myTextDlg->getTitleColor();
625 thePrs->SetTitleColor(aTitColor.red()/255.,
626 aTitColor.green()/255.,
627 aTitColor.blue()/255.);
629 thePrs->SetBoldLabel(myTextDlg->isBoldLabel());
630 thePrs->SetItalicLabel(myTextDlg->isItalicLabel());
631 thePrs->SetShadowLabel(myTextDlg->isShadowLabel());
632 thePrs->SetLblFontType(myTextDlg->getLabelFont());
633 QColor aLblColor = myTextDlg->getLabelColor();
634 thePrs->SetLabelColor(aLblColor.red()/255.,
635 aLblColor.green()/255.,
636 aLblColor.blue()/255.);
645 Called when orientation is changed
647 void VisuGUI_ScalarBarPane::changeDefaults( int )
649 if ( RBvert->isChecked() ) {
650 XSpin->setValue( myVerX );
651 YSpin->setValue( myVerY );
652 WidthSpin->setValue( myVerW );
653 HeightSpin->setValue( myVerH );
656 XSpin->setValue( myHorX );
657 YSpin->setValue( myHorY );
658 WidthSpin->setValue( myHorW );
659 HeightSpin->setValue( myHorH );
664 Called when Range mode is changed
666 void VisuGUI_ScalarBarPane::changeRange( int )
669 if ( RBFrange->isChecked() )
671 if ( RBIrange->isChecked() )
673 if ( myRangeMode == mode )
675 //MinSpin->setMaxValue( Fmin );
676 //MaxSpin->setMinValue( Fmax );
677 if ( RBFrange->isChecked() ) {
678 //MinLabel->setEnabled( false );
679 MinEdit->setEnabled( false );
680 //MaxLabel->setEnabled( false );
681 MaxEdit->setEnabled( false );
683 Imin = MinEdit->text().toDouble();
684 Imax = MaxEdit->text().toDouble();
686 MinEdit->setText( QString::number( Rmin ) );
687 MaxEdit->setText( QString::number( Rmax ) );
690 //MinLabel->setEnabled( true );
691 MinEdit->setEnabled( true );
692 //MaxLabel->setEnabled( true );
693 MaxEdit->setEnabled( true );
694 MinEdit->setText( QString::number( Imin ) );
695 MaxEdit->setText( QString::number( Imax ) );
701 Called when X,Y position is changed
703 void VisuGUI_ScalarBarPane::XYChanged( double )
705 QAD_SpinBoxDbl* snd = (QAD_SpinBoxDbl*)sender();
706 if ( snd == XSpin ) {
707 WidthSpin->setMaxValue( 1.0 - XSpin->value() );
709 if ( snd == YSpin ) {
710 HeightSpin->setMaxValue( 1.0 - YSpin->value() );
715 Sets default values and range mode
717 void VisuGUI_ScalarBarPane::setRange( double imin, double imax/*, double fmin, double fmax*/, bool sbRange )
719 Imin = imin; Imax = imax;// Fmin = fmin; Fmax = fmax;
720 if ( RBIrange->isChecked() ) {
721 MinEdit->setText( QString::number( Imin ) );
722 MaxEdit->setText( QString::number( Imax ) );
725 MinEdit->setText( QString::number( Rmin ) );
726 MaxEdit->setText( QString::number( Rmax ) );
730 RBIrange->setChecked( true );
732 RBFrange->setChecked( true );
737 Sets size and position
739 void VisuGUI_ScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
746 RBvert->setChecked( true );
753 RBhori->setChecked( true );
759 Sets colors and labels number
761 void VisuGUI_ScalarBarPane::setScalarBarData( int colors, int labels )
763 ColorSpin->setValue( colors );
764 LabelSpin->setValue( labels );
770 int VisuGUI_ScalarBarPane::getOrientation()
772 if (RBvert->isChecked() )
781 Called when <OK> button is clicked, validates data and closes dialog
783 bool VisuGUI_ScalarBarPane::check()
785 double minVal = MinEdit->text().toDouble();
786 double maxVal = MaxEdit->text().toDouble();
787 if ( RBIrange->isChecked() ) {
788 if (minVal >= maxVal) {
789 QAD_MessageBox::warn1( this,tr("VISU_WARNING"),
790 tr("MSG_MINMAX_VALUES"),
795 // check if logarithmic mode is on and check imposed range to not contain negative values
796 if ( CBLog->isChecked() ) {
797 if ( RBIrange->isChecked() ) {
798 if ( (minVal > 0) && (maxVal > 0) ) {
802 QAD_MessageBox::warn1( this,
804 tr("WRN_LOGARITHMIC_RANGE"),
810 if ( Rmin > 0 && Rmax > 0 ) {
814 QAD_MessageBox::warn1( this,
816 tr("WRN_LOGARITHMIC_FIELD_RANGE"),
818 RBIrange->setChecked(1);
820 //MinEdit->setText( QString::number( Rmin ) );
821 //MaxEdit->setText( QString::number( Rmax ) );
830 void VisuGUI_ScalarBarPane::onTextPref() {
831 myIsStoreTextProp = myTextDlg->exec();
838 //#######################################################################################
844 VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg(bool SetPref)
845 : QDialog( QAD_Application::getDesktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
847 setName( "VisuGUI_ScalarBarDlg" );
848 setCaption( SetPref ? tr( "Scalar Bar Preferences" ) : tr( "Scalar Bar Properties" ) );
849 setSizeGripEnabled( TRUE );
851 QVBoxLayout* TopLayout = new QVBoxLayout(this);
852 TopLayout->setSpacing(6);
853 TopLayout->setMargin(11);
855 myScalarPane = new VisuGUI_ScalarBarPane(this, SetPref);
856 TopLayout->addWidget(myScalarPane);
858 // Common buttons ===========================================================
859 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
860 GroupButtons->setColumnLayout(0, Qt::Vertical );
861 GroupButtons->layout()->setSpacing( 0 );
862 GroupButtons->layout()->setMargin( 0 );
863 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
864 GroupButtonsLayout->setAlignment( Qt::AlignTop );
865 GroupButtonsLayout->setSpacing( 6 );
866 GroupButtonsLayout->setMargin( 11 );
868 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
869 buttonOk->setAutoDefault( TRUE );
870 buttonOk->setDefault( TRUE );
871 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
872 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
874 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
875 buttonCancel->setAutoDefault( TRUE );
876 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
878 TopLayout->addWidget( GroupButtons );
880 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
881 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
888 Called when <OK> button is clicked, validates data and closes dialog
890 void VisuGUI_ScalarBarDlg::accept()
892 if (myScalarPane->check()) QDialog::accept();
899 //#######################################################################################
905 VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg(QWidget* parent) :
906 QDialog(parent, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
908 setName( "VisuGUI_TextPrefDlg" );
909 setCaption( tr("TIT_TEXT_PREF") );
910 setSizeGripEnabled( TRUE );
912 QVBoxLayout* TopLayout = new QVBoxLayout(this);
913 TopLayout->setSpacing(6);
914 TopLayout->setMargin(11);
916 QGroupBox* aTitleGrp = new QGroupBox( this );
917 aTitleGrp->setTitle(tr("LBL_TITLE"));
918 aTitleGrp->setColumnLayout(0, Qt::Vertical );
919 QGridLayout* aTitleLayout = new QGridLayout( aTitleGrp->layout() );
920 aTitleLayout->setSpacing( 6 );
921 aTitleLayout->setMargin( 3 );
923 myTitleEdt = new QLineEdit(aTitleGrp);
924 aTitleLayout->addMultiCellWidget(myTitleEdt, 0, 0, 0, 4);
927 aFontsLst.append("Arial");
928 aFontsLst.append("Courier");
929 aFontsLst.append("Times");
931 myTitColor = new QToolButton(aTitleGrp);
932 connect( myTitColor, SIGNAL(clicked()), this, SLOT(setTitleColor()) );
933 aTitleLayout->addWidget(myTitColor, 1, 0);
935 myTitFontCombo = new QComboBox(aTitleGrp);
936 myTitFontCombo->insertStrList(aFontsLst);
937 aTitleLayout->addWidget(myTitFontCombo, 1, 1);
939 myTitBoldChk = new QCheckBox(tr("LBL_BOLD"), aTitleGrp);
940 aTitleLayout->addWidget(myTitBoldChk, 1, 2);
942 myTitItalicChk = new QCheckBox(tr("LBL_ITALIC"), aTitleGrp);
943 aTitleLayout->addWidget(myTitItalicChk, 1, 3);
945 myTitShadowChk = new QCheckBox(tr("LBL_SHADOW"), aTitleGrp);
946 aTitleLayout->addWidget(myTitShadowChk, 1, 4);
948 TopLayout->addWidget( aTitleGrp );
950 QGroupBox* aLabelsGrp = new QGroupBox( this );
951 aLabelsGrp->setTitle(tr("LBL_LABELS"));
952 aLabelsGrp->setColumnLayout(0, Qt::Vertical );
953 QGridLayout* aLabelLayout = new QGridLayout( aLabelsGrp->layout() );
954 aLabelLayout->setSpacing( 6 );
955 aLabelLayout->setMargin( 3 );
957 myLblColor = new QToolButton(aLabelsGrp);
958 connect( myLblColor, SIGNAL(clicked()), this, SLOT(setLabelColor()) );
959 aLabelLayout->addWidget(myLblColor, 0, 0);
961 myLblFontCombo = new QComboBox(aLabelsGrp);
962 myLblFontCombo->insertStrList(aFontsLst);
963 aLabelLayout->addWidget(myLblFontCombo, 0, 1);
965 myLblBoldChk = new QCheckBox(tr("LBL_BOLD"), aLabelsGrp);
966 aLabelLayout->addWidget(myLblBoldChk, 0, 2);
968 myLblItalicChk = new QCheckBox(tr("LBL_ITALIC"), aLabelsGrp);
969 aLabelLayout->addWidget(myLblItalicChk, 0, 3);
971 myLblShadowChk = new QCheckBox(tr("LBL_SHADOW"), aLabelsGrp);
972 aLabelLayout->addWidget(myLblShadowChk, 0, 4);
974 TopLayout->addWidget( aLabelsGrp );
976 // Common buttons ===========================================================
977 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
978 GroupButtons->setColumnLayout(0, Qt::Vertical );
979 GroupButtons->layout()->setSpacing( 0 );
980 GroupButtons->layout()->setMargin( 0 );
981 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
982 GroupButtonsLayout->setAlignment( Qt::AlignTop );
983 GroupButtonsLayout->setSpacing( 6 );
984 GroupButtonsLayout->setMargin( 11 );
986 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
987 buttonOk->setAutoDefault( TRUE );
988 buttonOk->setDefault( TRUE );
989 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
990 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
992 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
993 buttonCancel->setAutoDefault( TRUE );
994 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
996 TopLayout->addWidget( GroupButtons );
998 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
999 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
1003 void VisuGUI_TextPrefDlg::setTitleColor() {
1004 QColor aColor = QColorDialog::getColor( getTitleColor(), this );
1005 if (aColor.isValid()) setTitleColor(aColor);
1008 void VisuGUI_TextPrefDlg::setLabelColor() {
1009 QColor aColor = QColorDialog::getColor( getLabelColor(), this );
1010 if (aColor.isValid()) setLabelColor(aColor);
1015 #define GETFONT(FuncName, Control) \
1016 int VisuGUI_TextPrefDlg::FuncName() \
1018 switch (Control->currentItem()) { \
1019 case 0: return VTK_ARIAL; \
1020 case 1: return VTK_COURIER; \
1021 case 2: return VTK_TIMES; \
1025 #define SETFONT(FuncName, Control) \
1026 void VisuGUI_TextPrefDlg::FuncName(int theFont) \
1028 switch (theFont) { \
1029 case VTK_ARIAL: Control->setCurrentItem(0); break; \
1030 case VTK_COURIER: Control->setCurrentItem(1); break; \
1031 case VTK_TIMES: Control->setCurrentItem(2); break; \
1035 GETFONT(getTitleFont, myTitFontCombo);
1036 SETFONT(setTitleFont, myTitFontCombo);
1038 GETFONT(getLabelFont, myLblFontCombo);
1039 SETFONT(setLabelFont, myLblFontCombo);