1 // Copyright (C) 2007-2023 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : QtxDoubleSpinSlider.cxx
23 // Author : Maxim GLIBIN, OpenCASCADE S.A.S. (maxim.glibin@opencascade.com)
25 #include "QtxDoubleSpinSlider.h"
28 * CONSTRUCTOR of double spin box
30 QtxDoubleSpinSlider::QtxDoubleSpinSlider( QWidget* theParent ) : QtxSlider( theParent )
32 // Get default value of slider
33 double aMin = mySlider->minimum() / 100.;
34 double aMax = mySlider->maximum() / 100.;
35 double aStep = mySlider->singleStep() / 100.;
37 // Create double spin box
38 myDoubleSpinBox = new QtxDoubleSpinBox( aMin, aMax, aStep, theParent );
39 myDoubleSpinBox->setFixedWidth( 100 );
41 // Add widget in main layout
42 mainLayout->addWidget( myDoubleSpinBox );
44 // Signals and slots connections
45 connect( myDoubleSpinBox, SIGNAL(valueChanged( double )), this, SLOT(DoubleSpinHasChanged( double )) );
46 connect( this, SIGNAL(valueUpdated( int )), this, SLOT(setValue( int )) );
49 QtxDoubleSpinSlider::QtxDoubleSpinSlider( double theMin, double theMax, double theStep, QWidget* theParent ) : QtxSlider( theParent )
51 // Set value of slider
52 mySlider->setRange( int(theMin*100), int(theMax*100) );
53 mySlider->setSingleStep( int(theStep*100) );
55 // Create double spin box
56 myDoubleSpinBox = new QtxDoubleSpinBox( theMin, theMax, theStep, theParent );
57 myDoubleSpinBox->setFixedWidth( 100 );
59 // Add widget in main layout
60 mainLayout->addWidget( myDoubleSpinBox );
62 // Signals and slots connections
63 connect( myDoubleSpinBox, SIGNAL(valueChanged( double )), this, SLOT(DoubleSpinHasChanged( double )) );
64 connect( this, SIGNAL(valueUpdated( int )), this, SLOT(setValue( int )) );
68 * DESTRUCTOR of double spin box
70 QtxDoubleSpinSlider::~QtxDoubleSpinSlider()
76 SLOT: Called when the value of double spin box
78 void QtxDoubleSpinSlider::DoubleSpinHasChanged( double theValue )
81 int aNewValue = int( theValue * 100 );
82 mySlider->blockSignals( true );
83 mySlider->setValue( aNewValue );
84 mySlider->blockSignals( false );
85 emit valueChanged( theValue );
89 * Get font currently set for the double spin box
91 QFont QtxDoubleSpinSlider::font()
93 return myDoubleSpinBox->font();
97 * Set font currently set for the double spin box
99 void QtxDoubleSpinSlider::setFont( QFont& theFont )
101 myDoubleSpinBox->setFont( theFont );
105 * Get value in double spin box
107 double QtxDoubleSpinSlider::value()
109 return myDoubleSpinBox->value();
113 * Set value in double spin box
115 void QtxDoubleSpinSlider::setValue( double theValue )
117 myDoubleSpinBox->setValue( theValue );
121 * Set value in double spin box
123 void QtxDoubleSpinSlider::setValue( int theValue )
125 double aNewValue = theValue / 100.;
126 this->setValue( aNewValue );
130 * Set precision of double spin box
132 void QtxDoubleSpinSlider::setPrecision( int thePrecision )
134 myDoubleSpinBox->setPrecision( thePrecision );
138 * Get precision of double spin box
140 int QtxDoubleSpinSlider::precision()
142 return myDoubleSpinBox->getPrecision();
145 void QtxDoubleSpinSlider::setUnit( QString& theUnit )
147 myDoubleSpinBox->setSuffix( theUnit );