Salome HOME
Copyright update 2022
[modules/gui.git] / src / Qtx / QtxSlider.cxx
1 // Copyright (C) 2007-2022  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   : QtxSlider.cxx
23 // Author : Maxim GLIBIN, OpenCASCADE S.A.S. (maxim.glibin@opencascade.com)
24
25 #include "QtxSlider.h"
26
27 /*!
28  * CONSTRUCTOR of slider
29  */
30 QtxSlider::QtxSlider( QWidget* theParent ) : QWidget( theParent )
31 {
32   // Create slider
33   mySlider = new QSlider( Qt::Horizontal, theParent );
34   mySlider->setFocusPolicy( Qt::NoFocus );
35   mySlider->setMinimumSize( 250, 0 );
36   mySlider->setTracking( false );
37
38   // Add widgets in main layout
39   mainLayout = new QHBoxLayout();
40   mainLayout->addWidget( mySlider );
41   mainLayout->setContentsMargins( 0, 0, 0, 0 );
42   this->setLayout( mainLayout );
43
44   // Signals and slots connections
45   connect( mySlider, SIGNAL(sliderMoved( int )), this, SLOT(SliderHasMoved( int )) );
46   connect( mySlider, SIGNAL(valueChanged( int )), this, SLOT(SliderHasMoved( int )) );
47 }
48
49 QtxSlider::QtxSlider( int theMin, int theMax, int theStep, QWidget* theParent ) : QWidget( theParent )
50 {
51   // Create slider
52   mySlider = new QSlider( Qt::Horizontal, theParent );
53   mySlider->setFocusPolicy( Qt::NoFocus );
54   mySlider->setMinimumSize( 200, 0 );
55   mySlider->setRange( theMin, theMax );
56   mySlider->setSingleStep( theStep );
57   mySlider->setPageStep( 10 );
58   mySlider->setTracking( false );
59
60   // Add widgets in main layout
61   mainLayout = new QHBoxLayout();
62   mainLayout->addWidget( mySlider );
63   mainLayout->setContentsMargins( 0, 0, 0, 0 );
64   this->setLayout( mainLayout );
65
66   // Signals and slots connections
67   connect( mySlider, SIGNAL(sliderMoved( int )), this, SLOT(SliderHasMoved( int )) );
68   connect( mySlider, SIGNAL(valueChanged( int )), this, SLOT(SliderHasMoved( int )) );
69 }
70
71 /*!
72  * DESTRUCTOR of slider
73  */
74 QtxSlider::~QtxSlider()
75 {
76   // Empty
77 }
78
79 /*!
80   SLOT: Called when the value of slider change
81 */
82 void QtxSlider::SliderHasMoved( int theValue )
83 {
84   emit valueUpdated( theValue );
85 }
86
87 /*!
88  * Get value of slider
89 */
90 int QtxSlider::value()
91 {
92   return mySlider->value();
93 }
94
95 /*!
96  * Set value of slider
97 */
98 void QtxSlider::setValue( int theValue )
99 {
100   mySlider->setValue( theValue );
101 }
102
103 /*!
104  * Set range of slider
105 */
106 void QtxSlider::setRange( int theMin, int theMax )
107 {
108   mySlider->setRange( theMin, theMax );
109 }
110
111 /*!
112  * Set single step of slider
113 */
114 void QtxSlider::setSingleStep( int theStep )
115 {
116   mySlider->setSingleStep( theStep );
117 }