+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onOk
+ *
+ * OK button slot
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onOk()
+{
+ if ( onApply() )
+ onCancel();
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onApply
+ *
+ * Apply button slot
+ */
+//=================================================================================================
+bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
+{
+ if ( mySelection ) {
+ // Scalar Bar properties
+ if ( !myActor )
+ return false;
+ vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
+
+ vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
+ QColor aTColor = myTitleColorBtn->paletteBackgroundColor();
+ aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
+ if ( myTitleFontCombo->currentItem() == 0 )
+ aTitleTextPrp->SetFontFamilyToArial();
+ else if ( myTitleFontCombo->currentItem() == 1 )
+ aTitleTextPrp->SetFontFamilyToCourier();
+ else
+ aTitleTextPrp->SetFontFamilyToTimes();
+ aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
+ aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
+ aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
+ myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
+
+ vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
+ QColor aLColor = myLabelsColorBtn->paletteBackgroundColor();
+ aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
+ if ( myLabelsFontCombo->currentItem() == 0 )
+ aLabelsTextPrp->SetFontFamilyToArial();
+ else if ( myLabelsFontCombo->currentItem() == 1 )
+ aLabelsTextPrp->SetFontFamilyToCourier();
+ else
+ aLabelsTextPrp->SetFontFamilyToTimes();
+ aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
+ aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
+ aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
+ myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
+
+ myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
+ myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
+
+ if ( myHorizRadioBtn->isChecked() )
+ myScalarBarActor->SetOrientationToHorizontal();
+ else
+ myScalarBarActor->SetOrientationToVertical();
+
+ myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
+ myScalarBarActor->SetWidth( myWidthSpin->value() );
+ myScalarBarActor->SetHeight( myHeightSpin->value() );
+
+ double aMin = myMinEdit->text().toDouble();
+ double aMax = myMaxEdit->text().toDouble();
+ myScalarBarActor->GetLookupTable()->SetRange( aMin, aMax );
+ SMESH::RepaintCurrentView();
+ }
+ else {
+ // Scalar Bar preferences
+ QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleColor", QString().sprintf( "%d:%d:%d", titleColor.red(), titleColor.green(), titleColor.blue() ) );
+ if ( myTitleFontCombo->currentItem() == 0 )
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleFont", "Arial" );
+ else if ( myTitleFontCombo->currentItem() == 1 )
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleFont", "Courier" );
+ else
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleFont", "Times" );
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleBold", myTitleBoldCheck->isChecked() ? "true" : "false" );
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleItalic", myTitleItalicCheck->isChecked() ? "true" : "false" );
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleShadow", myTitleShadowCheck->isChecked() ? "true" : "false" );
+
+ QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelColor", QString().sprintf( "%d:%d:%d", labelColor.red(), labelColor.green(),labelColor. blue() ) );
+ if ( myLabelsFontCombo->currentItem() == 0 )
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelFont", "Arial" );
+ else if ( myLabelsFontCombo->currentItem() == 1 )
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelFont", "Courier" );
+ else
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelFont", "Times" );
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelBold", myLabelsBoldCheck->isChecked() ? "true" : "false" );
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelItalic", myLabelsItalicCheck->isChecked() ? "true" : "false" );
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelShadow", myLabelsShadowCheck->isChecked() ? "true" : "false" );
+
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarNbOfColors", myColorsSpin->value() );
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarNbOfLabels", myLabelsSpin->value() );
+
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarOrientation", myHorizRadioBtn->isChecked() ? "Horizontal" : "Vertical" );
+
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarXPosition", myXSpin->value() );
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarYPosition", myYSpin->value() );
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarWidth", myWidthSpin->value() );
+ QAD_CONFIG->addSetting( "SMESH:ScalarBarHeight", myHeightSpin->value() );
+ }
+ return true;
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onCancel
+ *
+ * Cancel button slot
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
+{
+ close();
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
+ *
+ * Change Title color button slot
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
+{
+ QColor aColor = myTitleColorBtn->paletteBackgroundColor();
+ aColor = QColorDialog::getColor( aColor, this );
+ if ( aColor.isValid() )
+ myTitleColorBtn->setPaletteBackgroundColor( aColor );
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
+ *
+ * Change Labels color button slot
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
+{
+ QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
+ aColor = QColorDialog::getColor( aColor, this );
+ if ( aColor.isValid() )
+ myLabelsColorBtn->setPaletteBackgroundColor( aColor );
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
+ *
+ * Called when selection changed
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
+{
+ if( mySelection ) {
+ if ( mySelection->IObjectCount() == 1 ) {
+ Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
+ if( anIO->hasEntry() ) {
+ SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
+ if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
+ myActor = anActor;
+ vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
+
+ if ( myScalarBarActor->GetLookupTable() ) {
+ float *range = myScalarBarActor->GetLookupTable()->GetRange();
+ myMinEdit->setText( QString::number( range[0] ) );
+ myMaxEdit->setText( QString::number( range[1] ) );
+ }
+
+ vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
+ float aTColor[3];
+ aTitleTextPrp->GetColor( aTColor );
+ myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
+ myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
+ myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
+ myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
+ myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
+
+ vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
+ float aLColor[3];
+ aLabelsTextPrp->GetColor( aLColor );
+ myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
+ myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
+ myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
+ myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
+ myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
+
+ myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
+ myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
+
+ if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
+ myVertRadioBtn->setChecked( true );
+ else
+ myHorizRadioBtn->setChecked( true );
+ myIniOrientation = myVertRadioBtn->isChecked();
+
+ myIniX = myScalarBarActor->GetPosition()[0];
+ myIniY = myScalarBarActor->GetPosition()[1];
+ myIniW = myScalarBarActor->GetWidth();
+ myIniH = myScalarBarActor->GetHeight();
+ setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
+
+ myRangeGrp->setEnabled( true );
+ myFontGrp->setEnabled( true );
+ myLabColorGrp->setEnabled( true );
+ myOrientationGrp->setEnabled( true );
+ myOriginDimGrp->setEnabled( true );
+ myOkBtn->setEnabled( true );
+ myApplyBtn->setEnabled( true );
+ return;
+ }
+ }
+ }
+ myActor = 0;
+ myRangeGrp->setEnabled( false );
+ myFontGrp->setEnabled( false );
+ myLabColorGrp->setEnabled( false );
+ myOrientationGrp->setEnabled( false );
+ myOriginDimGrp->setEnabled( false );
+ myOkBtn->setEnabled( false );
+ myApplyBtn->setEnabled( false );
+ }
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::closeEvent
+ *
+ * Close event handler
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
+{
+ if ( mySelection ) // "Properties" dialog box
+ myDlg = 0;
+ QDialog::closeEvent( e );
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
+ *
+ * Called when X, Y values are changed
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
+{
+ myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
+ myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
+ *
+ * Called when X, Y values are changed
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
+ const double y,
+ const double w,
+ const double h )
+{
+ blockSignals( true );
+ myXSpin->setValue( x );
+ myYSpin->setValue( y );
+ myWidthSpin->setMaxValue( 1.0 );
+ myWidthSpin->setValue( w );
+ myHeightSpin->setMaxValue( 1.0 );
+ myHeightSpin->setValue( h );
+ blockSignals( false );
+ onXYChanged();
+}
+
+//=================================================================================================
+/*!
+ * SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
+ *
+ * Called when orientation is changed
+ */
+//=================================================================================================
+void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
+{
+ int aOrientation = myVertRadioBtn->isChecked();
+ if ( aOrientation == myIniOrientation )
+ setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
+ else
+ setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
+ aOrientation ? DEF_VER_Y : DEF_HOR_Y,
+ aOrientation ? DEF_VER_W : DEF_HOR_W,
+ aOrientation ? DEF_VER_H : DEF_HOR_H );
+}