Salome HOME
Copyright update: 2016
[modules/gui.git] / src / Qtx / QtxDoubleSpinSlider.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : QtxDoubleSpinSlider.cxx
23 // Author : Maxim GLIBIN, OpenCASCADE S.A.S. (maxim.glibin@opencascade.com)
24
25 #include "QtxDoubleSpinSlider.h"
26
27 /*!
28  * CONSTRUCTOR of double spin box
29  */
30 QtxDoubleSpinSlider::QtxDoubleSpinSlider( QWidget* theParent ) : QtxSlider( theParent )
31 {
32   // Get default value of slider
33   double aMin = mySlider->minimum() / 100.;
34   double aMax = mySlider->maximum() / 100.;
35   double aStep = mySlider->singleStep() / 100.;
36   
37   // Create double spin box
38   myDoubleSpinBox = new QtxDoubleSpinBox( aMin, aMax, aStep, theParent );
39   myDoubleSpinBox->setFixedWidth( 100 );
40
41   // Add widget in main layout
42   mainLayout->addWidget( myDoubleSpinBox );
43
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 )) );
47 }
48
49 QtxDoubleSpinSlider::QtxDoubleSpinSlider( double theMin, double theMax, double theStep, QWidget* theParent ) : QtxSlider( theParent )
50 {
51   // Set value of slider
52   mySlider->setRange( int(theMin*100), int(theMax*100) );
53   mySlider->setSingleStep( int(theStep*100) );
54   
55   // Create double spin box
56   myDoubleSpinBox = new QtxDoubleSpinBox( theMin, theMax, theStep, theParent );
57   myDoubleSpinBox->setFixedWidth( 100 );
58
59   // Add widget in main layout
60   mainLayout->addWidget( myDoubleSpinBox );
61
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 )) );
65 }
66
67 /*!
68  * DESTRUCTOR of double spin box
69  */
70 QtxDoubleSpinSlider::~QtxDoubleSpinSlider()
71 {
72   // Empty
73 }
74
75 /*!
76   SLOT: Called when the value of double spin box
77 */
78 void QtxDoubleSpinSlider::DoubleSpinHasChanged( double theValue )
79 {
80   
81   int aNewValue = int( theValue * 100 );
82   mySlider->blockSignals( true );
83   mySlider->setValue( aNewValue );
84   mySlider->blockSignals( false );
85   emit valueChanged( theValue );
86 }
87
88 /*!
89  * Get font currently set for the double spin box
90 */
91 QFont QtxDoubleSpinSlider::font()
92 {
93   return myDoubleSpinBox->font();
94 }
95
96 /*!
97  * Set font currently set for the double spin box
98 */
99 void QtxDoubleSpinSlider::setFont( QFont& theFont )
100 {
101   myDoubleSpinBox->setFont( theFont );
102 }
103
104 /*!
105  * Get value in double spin box
106 */
107 double QtxDoubleSpinSlider::value()
108 {
109   return myDoubleSpinBox->value();
110 }
111
112 /*!
113  * Set value in double spin box
114 */
115 void QtxDoubleSpinSlider::setValue( double theValue )
116 {
117   myDoubleSpinBox->setValue( theValue );
118 }
119
120 /*!
121  * Set value in double spin box
122 */
123 void QtxDoubleSpinSlider::setValue( int theValue )
124 {
125   double aNewValue = theValue / 100.;
126   this->setValue( aNewValue );
127 }
128
129 /*!
130  * Set precision of double spin box
131 */
132 void QtxDoubleSpinSlider::setPrecision( int thePrecision )
133 {
134   myDoubleSpinBox->setPrecision( thePrecision );
135 }
136
137 /*!
138  * Get precision of double spin box
139 */
140 int QtxDoubleSpinSlider::precision()
141 {
142  return myDoubleSpinBox->getPrecision();
143 }
144
145 void QtxDoubleSpinSlider::setUnit( QString& theUnit )
146 {
147   myDoubleSpinBox->setSuffix( theUnit );
148 }