1 /**********************************************************************
2 ** $Id: qt/qcombobox.h   3.3.8   edited Jan 11 14:38 $
3 **
4 ** Definition of QComboBox class
5 **
6 ** Created : 950426
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 QCOMBOBOX_H
39 #define QCOMBOBOX_H
40 
41 #ifndef QT_H
42 #include "qwidget.h"
43 #endif // QT_H
44 
45 #ifndef QT_NO_COMBOBOX
46 
47 
48 class QStrList;
49 class QStringList;
50 class QLineEdit;
51 class QValidator;
52 class QListBox;
53 class QComboBoxData;
54 class QWheelEvent;
55 
56 class Q_EXPORT QComboBox : public QWidget
57 {
58     Q_OBJECT
59     Q_ENUMS( Policy )
60     Q_PROPERTY( bool editable READ editable WRITE setEditable )
61     Q_PROPERTY( int count READ count )
62     Q_PROPERTY( QString currentText READ currentText WRITE setCurrentText DESIGNABLE false )
63     Q_PROPERTY( int currentItem READ currentItem WRITE setCurrentItem )
64     Q_PROPERTY( bool autoResize READ autoResize WRITE setAutoResize DESIGNABLE false )
65     Q_PROPERTY( int sizeLimit READ sizeLimit WRITE setSizeLimit )
66     Q_PROPERTY( int maxCount READ maxCount WRITE setMaxCount )
67     Q_PROPERTY( Policy insertionPolicy READ insertionPolicy WRITE setInsertionPolicy )
68     Q_PROPERTY( bool autoCompletion READ autoCompletion WRITE setAutoCompletion )
69     Q_PROPERTY( bool duplicatesEnabled READ duplicatesEnabled WRITE setDuplicatesEnabled )
70     Q_OVERRIDE( bool autoMask DESIGNABLE true SCRIPTABLE true )
71 
72 public:
73     QComboBox( QWidget* parent=0, const char* name=0 );
74     QComboBox( bool rw, QWidget* parent=0, const char* name=0 );
75     ~QComboBox();
76 
77     int		count() const;
78 
79     void	insertStringList( const QStringList &, int index=-1 );
80     void	insertStrList( const QStrList &, int index=-1 );
81     void	insertStrList( const QStrList *, int index=-1 );
82     void	insertStrList( const char **, int numStrings=-1, int index=-1);
83 
84     void	insertItem( const QString &text, int index=-1 );
85     void	insertItem( const QPixmap &pixmap, int index=-1 );
86     void	insertItem( const QPixmap &pixmap, const QString &text, int index=-1 );
87 
88     void	removeItem( int index );
89 
90     int		currentItem() const;
91     virtual void setCurrentItem( int index );
92 
93     QString 	currentText() const;
94     virtual void setCurrentText( const QString& );
95 
96     QString 	text( int index ) const;
97     const QPixmap *pixmap( int index ) const;
98 
99     void	changeItem( const QString &text, int index );
100     void	changeItem( const QPixmap &pixmap, int index );
101     void	changeItem( const QPixmap &pixmap, const QString &text, int index );
102 
103     bool	autoResize()	const;
104     virtual void setAutoResize( bool );
105     QSize	sizeHint() const;
106 
107     void	setPalette( const QPalette & );
108     void	setFont( const QFont & );
109     void	setEnabled( bool );
110 
111     virtual void setSizeLimit( int );
112     int		sizeLimit() const;
113 
114     virtual void setMaxCount( int );
115     int		maxCount() const;
116 
117     enum Policy { NoInsertion, AtTop, AtCurrent, AtBottom,
118 		  AfterCurrent, BeforeCurrent };
119 
120     virtual void setInsertionPolicy( Policy policy );
121     Policy	insertionPolicy() const;
122 
123     virtual void setValidator( const QValidator * );
124     const QValidator * validator() const;
125 
126     virtual void setListBox( QListBox * );
127     QListBox *	listBox() const;
128 
129     virtual void setLineEdit( QLineEdit *edit );
130     QLineEdit*	lineEdit() const;
131 
132     virtual void setAutoCompletion( bool );
133     bool	autoCompletion() const;
134 
135     bool	eventFilter( QObject *object, QEvent *event );
136 
137     void	setDuplicatesEnabled( bool enable );
138     bool	duplicatesEnabled() const;
139 
140     bool	editable() const;
141     void	setEditable( bool );
142 
143     virtual void popup();
144 
145     void	hide();
146 
147 public slots:
148     void	clear();
149     void	clearValidator();
150     void	clearEdit();
151     virtual void setEditText( const QString &);
152 
153 signals:
154     void	activated( int index );
155     void	highlighted( int index );
156     void	activated( const QString &);
157     void	highlighted( const QString &);
158     void	textChanged( const QString &);
159 
160 private slots:
161     void	internalActivate( int );
162     void	internalHighlight( int );
163     void	internalClickTimeout();
164     void	returnPressed();
165 
166 protected:
167     void	paintEvent( QPaintEvent * );
168     void	resizeEvent( QResizeEvent * );
169     void	mousePressEvent( QMouseEvent * );
170     void	mouseMoveEvent( QMouseEvent * );
171     void	mouseReleaseEvent( QMouseEvent * );
172     void	mouseDoubleClickEvent( QMouseEvent * );
173     void	keyPressEvent( QKeyEvent *e );
174     void	focusInEvent( QFocusEvent *e );
175     void	focusOutEvent( QFocusEvent *e );
176 #ifndef QT_NO_WHEELEVENT
177     void	wheelEvent( QWheelEvent *e );
178 #endif
179     void	styleChange( QStyle& );
180 
181     void	updateMask();
182 
183 private:
184     void	setUpListBox();
185     void	setUpLineEdit();
186     void	popDownListBox();
187     void	reIndex();
188     void	currentChanged();
189     int		completionIndex( const QString &, int ) const;
190 
191     QComboBoxData	*d;
192 
193 private:	// Disabled copy constructor and operator=
194 #if defined(Q_DISABLE_COPY)
195     QComboBox( const QComboBox & );
196     QComboBox &operator=( const QComboBox & );
197 #endif
198 };
199 
200 
201 #endif // QT_NO_COMBOBOX
202 
203 #endif // QCOMBOBOX_H
204