1 /****************************************************************************
2 ** $Id: qt/qspinbox.h   3.3.8   edited Jan 11 14:38 $
3 **
4 ** Definition of QSpinBox widget class
5 **
6 ** Created : 970101
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 QSPINBOX_H
39 #define QSPINBOX_H
40 
41 #ifndef QT_H
42 #include "qwidget.h"
43 #include "qrangecontrol.h"
44 #endif // QT_H
45 
46 #ifndef QT_NO_SPINBOX
47 
48 class QLineEdit;
49 class QValidator;
50 class QSpinBoxPrivate;
51 
52 class Q_EXPORT QSpinBox: public QWidget, public QRangeControl
53 {
54     Q_OBJECT
55     Q_ENUMS( ButtonSymbols )
56     Q_PROPERTY( QString text READ text )
57     Q_PROPERTY( QString prefix READ prefix WRITE setPrefix )
58     Q_PROPERTY( QString suffix READ suffix WRITE setSuffix )
59     Q_PROPERTY( QString cleanText READ cleanText )
60     Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText )
61     Q_PROPERTY( bool wrapping READ wrapping WRITE setWrapping )
62     Q_PROPERTY( ButtonSymbols buttonSymbols READ buttonSymbols WRITE setButtonSymbols )
63     Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
64     Q_PROPERTY( int minValue READ minValue WRITE setMinValue )
65     Q_PROPERTY( int lineStep READ lineStep WRITE setLineStep )
66     Q_PROPERTY( int value READ value WRITE setValue )
67 
68 public:
69     QSpinBox( QWidget* parent=0, const char* name=0 );
70     QSpinBox( int minValue, int maxValue, int step = 1,
71 	      QWidget* parent=0, const char* name=0 );
72     ~QSpinBox();
73 
74     QString		text() const;
75 
76     virtual QString	prefix() const;
77     virtual QString	suffix() const;
78     virtual QString	cleanText() const;
79 
80     virtual void	setSpecialValueText( const QString &text );
81     QString		specialValueText() const;
82 
83     virtual void	setWrapping( bool on );
84     bool		wrapping() const;
85 
86     enum ButtonSymbols { UpDownArrows, PlusMinus };
87     virtual void	setButtonSymbols( ButtonSymbols );
88     ButtonSymbols	buttonSymbols() const;
89 
90     virtual void	setValidator( const QValidator* v );
91     const QValidator * validator() const;
92 
93     QSize		sizeHint() const;
94     QSize		minimumSizeHint() const;
95 
96     int	 minValue() const;
97     int	 maxValue() const;
98     void setMinValue( int );
99     void setMaxValue( int );
100     int	 lineStep() const;
101     void setLineStep( int );
102     int  value() const;
103 
104     QRect		upRect() const;
105     QRect		downRect() const;
106 
107 public slots:
108     virtual void	setValue( int value );
109     virtual void	setPrefix( const QString &text );
110     virtual void	setSuffix( const QString &text );
111     virtual void	stepUp();
112     virtual void	stepDown();
113     virtual void 	setEnabled( bool enabled );
114     virtual void 	selectAll();
115 
116 signals:
117     void		valueChanged( int value );
118     void		valueChanged( const QString &valueText );
119 
120 protected:
121     virtual QString	mapValueToText( int value );
122     virtual int		mapTextToValue( bool* ok );
123     QString		currentValueText();
124 
125     virtual void	updateDisplay();
126     virtual void	interpretText();
127 
128     QLineEdit*		editor() const;
129 
130     virtual void	valueChange();
131     virtual void	rangeChange();
132 
133     bool		eventFilter( QObject* obj, QEvent* ev );
134     void		resizeEvent( QResizeEvent* ev );
135 #ifndef QT_NO_WHEELEVENT
136     void		wheelEvent( QWheelEvent * );
137 #endif
138     void		leaveEvent( QEvent* );
139 
140     void		styleChange( QStyle& );
141 
142 protected slots:
143     void		textChanged();
144 
145 private:
146     void initSpinBox();
147     QSpinBoxPrivate* d;
148     QLineEdit* vi;
149     QValidator* validate;
150     QString pfix;
151     QString sfix;
152     QString specText;
153 
154     uint wrap		: 1;
155     uint edited		: 1;
156 
157     void arrangeWidgets();
158 
159 private:	// Disabled copy constructor and operator=
160 #if defined(Q_DISABLE_COPY)
161     QSpinBox( const QSpinBox& );
162     QSpinBox& operator=( const QSpinBox& );
163 #endif
164 
165 };
166 
167 #endif // QT_NO_SPINBOX
168 
169 #endif // QSPINBOX_H
170