1 /****************************************************************************
2 ** $Id: qt/qslider.h   3.3.8   edited Jan 11 14:38 $
3 **
4 ** Definition of QSlider class
5 **
6 ** Created : 961019
7 **
8 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
9 **
10 ** This file is part of the widgets module of the Qt GUI Toolkit.
11 **
12 ** This file may be distributed under the terms of the Q Public License
13 ** as defined by Trolltech ASA of Norway and appearing in the file
14 ** LICENSE.QPL included in the packaging of this file.
15 **
16 ** This file may be distributed and/or modified under the terms of the
17 ** GNU General Public License version 2 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.GPL included in the
19 ** packaging of this file.
20 **
21 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22 ** licenses may use this file in accordance with the Qt Commercial License
23 ** Agreement provided with the Software.
24 **
25 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27 **
28 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29 **   information about Qt Commercial License Agreements.
30 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
31 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
32 **
33 ** Contact info@trolltech.com if any conditions of this licensing are
34 ** not clear to you.
35 **
36 **********************************************************************/
37 
38 #ifndef QSLIDER_H
39 #define QSLIDER_H
40 
41 #ifndef QT_H
42 #include "qwidget.h"
43 #include "qrangecontrol.h"
44 #endif // QT_H
45 
46 #ifndef QT_NO_SLIDER
47 
48 struct QSliderPrivate;
49 
50 class QTimer;
51 
52 class Q_EXPORT QSlider : public QWidget, public QRangeControl
53 {
54     Q_OBJECT
55     Q_ENUMS( TickSetting )
56     Q_PROPERTY( int minValue READ minValue WRITE setMinValue )
57     Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
58     Q_PROPERTY( int lineStep READ lineStep WRITE setLineStep )
59     Q_PROPERTY( int pageStep READ pageStep WRITE setPageStep )
60     Q_PROPERTY( int value READ value WRITE setValue )
61     Q_PROPERTY( bool tracking READ tracking WRITE setTracking )
62     Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
63     Q_PROPERTY( TickSetting tickmarks READ tickmarks WRITE setTickmarks )
64     Q_PROPERTY( int tickInterval READ tickInterval WRITE setTickInterval )
65 
66 public:
67     enum TickSetting { NoMarks = 0, Above = 1, Left = Above,
68 		       Below = 2, Right = Below, Both = 3 };
69 
70     QSlider( QWidget *parent, const char* name = 0 );
71     QSlider( Orientation, QWidget *parent, const char* name = 0 );
72     QSlider( int minValue, int maxValue, int pageStep, int value, Orientation,
73 	     QWidget *parent, const char* name = 0 );
74     ~QSlider();
75 
76     virtual void	setOrientation( Orientation );
77     Orientation orientation() const;
78     virtual void	setTracking( bool enable );
79     bool	tracking() const;
80     virtual void 	setPalette( const QPalette & );
81 
82     int sliderStart() const;
83     QRect sliderRect() const;
84     QSize sizeHint() const;
85     void setSizePolicy( QSizePolicy sp );
86     void setSizePolicy( QSizePolicy::SizeType hor, QSizePolicy::SizeType ver, bool hfw = FALSE );
87 
88     QSizePolicy sizePolicy() const;
89     QSize minimumSizeHint() const;
90 
91     virtual void setTickmarks( TickSetting );
tickmarks()92     TickSetting tickmarks() const { return ticks; }
93 
94     virtual void setTickInterval( int );
tickInterval()95     int 	tickInterval() const { return tickInt; }
96 
97     int	 minValue() const;
98     int	 maxValue() const;
99     void setMinValue( int );
100     void setMaxValue( int );
101     int	 lineStep() const;
102     int	 pageStep() const;
103     void setLineStep( int );
104     void setPageStep( int );
105     int  value() const;
106 
107 public slots:
108     virtual void	setValue( int );
109     void	addStep();
110     void	subtractStep();
111     void	addLine();
112     void	subtractLine();
113 
114 signals:
115     void	valueChanged( int value );
116     void	sliderPressed();
117     void	sliderMoved( int value );
118     void	sliderReleased();
119 
120 protected:
121     void	resizeEvent( QResizeEvent * );
122     void	paintEvent( QPaintEvent * );
123 
124     void	keyPressEvent( QKeyEvent * );
125     void	mousePressEvent( QMouseEvent * );
126     void	mouseReleaseEvent( QMouseEvent * );
127     void	mouseMoveEvent( QMouseEvent * );
128 #ifndef QT_NO_WHEELEVENT
129     void	wheelEvent( QWheelEvent * );
130 #endif
131     void	focusInEvent( QFocusEvent *e );
132     void	focusOutEvent( QFocusEvent *e );
133 
134     void	styleChange( QStyle& );
135 
136     void	valueChange();
137     void	rangeChange();
138 
139 private slots:
140     void	repeatTimeout();
141 
142 private:
143     enum State { Idle, Dragging, TimingUp, TimingDown };
144 
145     void	init();
146     int		positionFromValue( int ) const;
147     int		valueFromPosition( int ) const;
148     void	moveSlider( int );
149     void	reallyMoveSlider( int );
150     void	resetState();
151     int		available() const;
152     int		goodPart( const QPoint& ) const;
153     void	initTicks();
154 
155     QSliderPrivate *d;
156     QTimer	*timer;
157     QCOORD	sliderPos;
158     int		sliderVal;
159     QCOORD	clickOffset;
160     State	state;
161     bool	track;
162     QCOORD	tickOffset;
163     TickSetting	ticks;
164     int		tickInt;
165     Orientation orient;
166 
167 private:	// Disabled copy constructor and operator=
168 #if defined(Q_DISABLE_COPY)
169     QSlider( const QSlider & );
170     QSlider &operator=( const QSlider & );
171 #endif
172 };
173 
tracking()174 inline bool QSlider::tracking() const
175 {
176     return track;
177 }
178 
orientation()179 inline QSlider::Orientation QSlider::orientation() const
180 {
181     return orient;
182 }
183 
sliderStart()184 inline int QSlider::sliderStart() const
185 {
186     return sliderPos;
187 }
188 
setSizePolicy(QSizePolicy::SizeType hor,QSizePolicy::SizeType ver,bool hfw)189 inline void QSlider::setSizePolicy( QSizePolicy::SizeType hor, QSizePolicy::SizeType ver, bool hfw )
190 {
191     QWidget::setSizePolicy( hor, ver, hfw );
192 }
193 
194 #endif // QT_NO_SLIDER
195 
196 #endif // QSLIDER_H
197