1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QCOMBOBOX_H
|
---|
43 | #define QCOMBOBOX_H
|
---|
44 |
|
---|
45 | #include <QtGui/qwidget.h>
|
---|
46 | #include <QtGui/qabstractitemdelegate.h>
|
---|
47 | #include <QtCore/qabstractitemmodel.h>
|
---|
48 | #include <QtCore/qvariant.h>
|
---|
49 |
|
---|
50 | QT_BEGIN_HEADER
|
---|
51 |
|
---|
52 | QT_BEGIN_NAMESPACE
|
---|
53 |
|
---|
54 | QT_MODULE(Gui)
|
---|
55 |
|
---|
56 | #ifndef QT_NO_COMBOBOX
|
---|
57 |
|
---|
58 | class QAbstractItemView;
|
---|
59 | class QLineEdit;
|
---|
60 | class QComboBoxPrivate;
|
---|
61 | class QCompleter;
|
---|
62 |
|
---|
63 | class Q_GUI_EXPORT QComboBox : public QWidget
|
---|
64 | {
|
---|
65 | Q_OBJECT
|
---|
66 |
|
---|
67 | Q_ENUMS(InsertPolicy)
|
---|
68 | Q_ENUMS(SizeAdjustPolicy)
|
---|
69 | Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
|
---|
70 | Q_PROPERTY(int count READ count)
|
---|
71 | Q_PROPERTY(QString currentText READ currentText)
|
---|
72 | Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
|
---|
73 | Q_PROPERTY(int maxVisibleItems READ maxVisibleItems WRITE setMaxVisibleItems)
|
---|
74 | Q_PROPERTY(int maxCount READ maxCount WRITE setMaxCount)
|
---|
75 | Q_PROPERTY(InsertPolicy insertPolicy READ insertPolicy WRITE setInsertPolicy)
|
---|
76 | Q_PROPERTY(SizeAdjustPolicy sizeAdjustPolicy READ sizeAdjustPolicy WRITE setSizeAdjustPolicy)
|
---|
77 | Q_PROPERTY(int minimumContentsLength READ minimumContentsLength WRITE setMinimumContentsLength)
|
---|
78 | Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
|
---|
79 |
|
---|
80 | #ifndef QT_NO_COMPLETER
|
---|
81 | Q_PROPERTY(bool autoCompletion READ autoCompletion WRITE setAutoCompletion DESIGNABLE false)
|
---|
82 | Q_PROPERTY(Qt::CaseSensitivity autoCompletionCaseSensitivity READ autoCompletionCaseSensitivity WRITE setAutoCompletionCaseSensitivity DESIGNABLE false)
|
---|
83 | #endif // QT_NO_COMPLETER
|
---|
84 |
|
---|
85 | Q_PROPERTY(bool duplicatesEnabled READ duplicatesEnabled WRITE setDuplicatesEnabled)
|
---|
86 | Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
|
---|
87 | Q_PROPERTY(int modelColumn READ modelColumn WRITE setModelColumn)
|
---|
88 |
|
---|
89 | public:
|
---|
90 | explicit QComboBox(QWidget *parent = 0);
|
---|
91 | ~QComboBox();
|
---|
92 |
|
---|
93 | int maxVisibleItems() const;
|
---|
94 | void setMaxVisibleItems(int maxItems);
|
---|
95 |
|
---|
96 | int count() const;
|
---|
97 | void setMaxCount(int max);
|
---|
98 | int maxCount() const;
|
---|
99 |
|
---|
100 | #ifndef QT_NO_COMPLETER
|
---|
101 | bool autoCompletion() const;
|
---|
102 | void setAutoCompletion(bool enable);
|
---|
103 |
|
---|
104 | Qt::CaseSensitivity autoCompletionCaseSensitivity() const;
|
---|
105 | void setAutoCompletionCaseSensitivity(Qt::CaseSensitivity sensitivity);
|
---|
106 | #endif
|
---|
107 |
|
---|
108 | bool duplicatesEnabled() const;
|
---|
109 | void setDuplicatesEnabled(bool enable);
|
---|
110 |
|
---|
111 | void setFrame(bool);
|
---|
112 | bool hasFrame() const;
|
---|
113 |
|
---|
114 | inline int findText(const QString &text,
|
---|
115 | Qt::MatchFlags flags = Qt::MatchExactly|Qt::MatchCaseSensitive) const
|
---|
116 | { return findData(text, Qt::DisplayRole, flags); }
|
---|
117 | int findData(const QVariant &data, int role = Qt::UserRole,
|
---|
118 | Qt::MatchFlags flags = Qt::MatchExactly|Qt::MatchCaseSensitive) const;
|
---|
119 |
|
---|
120 | enum InsertPolicy {
|
---|
121 | NoInsert,
|
---|
122 | InsertAtTop,
|
---|
123 | InsertAtCurrent,
|
---|
124 | InsertAtBottom,
|
---|
125 | InsertAfterCurrent,
|
---|
126 | InsertBeforeCurrent,
|
---|
127 | InsertAlphabetically
|
---|
128 | #if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN)
|
---|
129 | ,
|
---|
130 | NoInsertion = NoInsert,
|
---|
131 | AtTop = InsertAtTop,
|
---|
132 | AtCurrent = InsertAtCurrent,
|
---|
133 | AtBottom = InsertAtBottom,
|
---|
134 | AfterCurrent = InsertAfterCurrent,
|
---|
135 | BeforeCurrent = InsertBeforeCurrent
|
---|
136 | #endif
|
---|
137 | };
|
---|
138 | #ifdef QT3_SUPPORT
|
---|
139 | typedef InsertPolicy Policy;
|
---|
140 | #endif
|
---|
141 |
|
---|
142 | InsertPolicy insertPolicy() const;
|
---|
143 | void setInsertPolicy(InsertPolicy policy);
|
---|
144 |
|
---|
145 | enum SizeAdjustPolicy {
|
---|
146 | AdjustToContents,
|
---|
147 | AdjustToContentsOnFirstShow,
|
---|
148 | AdjustToMinimumContentsLength, // ### Qt 5: remove
|
---|
149 | AdjustToMinimumContentsLengthWithIcon
|
---|
150 | };
|
---|
151 |
|
---|
152 | SizeAdjustPolicy sizeAdjustPolicy() const;
|
---|
153 | void setSizeAdjustPolicy(SizeAdjustPolicy policy);
|
---|
154 | int minimumContentsLength() const;
|
---|
155 | void setMinimumContentsLength(int characters);
|
---|
156 | QSize iconSize() const;
|
---|
157 | void setIconSize(const QSize &size);
|
---|
158 |
|
---|
159 | bool isEditable() const;
|
---|
160 | void setEditable(bool editable);
|
---|
161 | void setLineEdit(QLineEdit *edit);
|
---|
162 | QLineEdit *lineEdit() const;
|
---|
163 | #ifndef QT_NO_VALIDATOR
|
---|
164 | void setValidator(const QValidator *v);
|
---|
165 | const QValidator *validator() const;
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | #ifndef QT_NO_COMPLETER
|
---|
169 | void setCompleter(QCompleter *c);
|
---|
170 | QCompleter *completer() const;
|
---|
171 | #endif
|
---|
172 |
|
---|
173 | QAbstractItemDelegate *itemDelegate() const;
|
---|
174 | void setItemDelegate(QAbstractItemDelegate *delegate);
|
---|
175 |
|
---|
176 | QAbstractItemModel *model() const;
|
---|
177 | void setModel(QAbstractItemModel *model);
|
---|
178 |
|
---|
179 | QModelIndex rootModelIndex() const;
|
---|
180 | void setRootModelIndex(const QModelIndex &index);
|
---|
181 |
|
---|
182 | int modelColumn() const;
|
---|
183 | void setModelColumn(int visibleColumn);
|
---|
184 |
|
---|
185 | int currentIndex() const;
|
---|
186 |
|
---|
187 | QString currentText() const;
|
---|
188 |
|
---|
189 | QString itemText(int index) const;
|
---|
190 | QIcon itemIcon(int index) const;
|
---|
191 | QVariant itemData(int index, int role = Qt::UserRole) const;
|
---|
192 |
|
---|
193 | inline void addItem(const QString &text, const QVariant &userData = QVariant());
|
---|
194 | inline void addItem(const QIcon &icon, const QString &text,
|
---|
195 | const QVariant &userData = QVariant());
|
---|
196 | inline void addItems(const QStringList &texts)
|
---|
197 | { insertItems(count(), texts); }
|
---|
198 |
|
---|
199 | inline void insertItem(int index, const QString &text, const QVariant &userData = QVariant());
|
---|
200 | void insertItem(int index, const QIcon &icon, const QString &text,
|
---|
201 | const QVariant &userData = QVariant());
|
---|
202 | void insertItems(int index, const QStringList &texts);
|
---|
203 | void insertSeparator(int index);
|
---|
204 |
|
---|
205 | void removeItem(int index);
|
---|
206 |
|
---|
207 | void setItemText(int index, const QString &text);
|
---|
208 | void setItemIcon(int index, const QIcon &icon);
|
---|
209 | void setItemData(int index, const QVariant &value, int role = Qt::UserRole);
|
---|
210 |
|
---|
211 | QAbstractItemView *view() const;
|
---|
212 | void setView(QAbstractItemView *itemView);
|
---|
213 |
|
---|
214 | QSize sizeHint() const;
|
---|
215 | QSize minimumSizeHint() const;
|
---|
216 |
|
---|
217 | virtual void showPopup();
|
---|
218 | virtual void hidePopup();
|
---|
219 |
|
---|
220 | bool event(QEvent *event);
|
---|
221 |
|
---|
222 | public Q_SLOTS:
|
---|
223 | void clear();
|
---|
224 | void clearEditText();
|
---|
225 | void setEditText(const QString &text);
|
---|
226 | void setCurrentIndex(int index);
|
---|
227 |
|
---|
228 | Q_SIGNALS:
|
---|
229 | void editTextChanged(const QString &);
|
---|
230 | void activated(int index);
|
---|
231 | void activated(const QString &);
|
---|
232 | void highlighted(int index);
|
---|
233 | void highlighted(const QString &);
|
---|
234 | void currentIndexChanged(int index);
|
---|
235 | void currentIndexChanged(const QString &);
|
---|
236 |
|
---|
237 | protected:
|
---|
238 | void focusInEvent(QFocusEvent *e);
|
---|
239 | void focusOutEvent(QFocusEvent *e);
|
---|
240 | void changeEvent(QEvent *e);
|
---|
241 | void resizeEvent(QResizeEvent *e);
|
---|
242 | void paintEvent(QPaintEvent *e);
|
---|
243 | void showEvent(QShowEvent *e);
|
---|
244 | void hideEvent(QHideEvent *e);
|
---|
245 | void mousePressEvent(QMouseEvent *e);
|
---|
246 | void mouseReleaseEvent(QMouseEvent *e);
|
---|
247 | void keyPressEvent(QKeyEvent *e);
|
---|
248 | void keyReleaseEvent(QKeyEvent *e);
|
---|
249 | void wheelEvent(QWheelEvent *e);
|
---|
250 | void contextMenuEvent(QContextMenuEvent *e);
|
---|
251 | void inputMethodEvent(QInputMethodEvent *);
|
---|
252 | QVariant inputMethodQuery(Qt::InputMethodQuery) const;
|
---|
253 | void initStyleOption(QStyleOptionComboBox *option) const;
|
---|
254 |
|
---|
255 | #ifdef QT3_SUPPORT
|
---|
256 | public:
|
---|
257 | QT3_SUPPORT_CONSTRUCTOR QComboBox(QWidget *parent, const char *name);
|
---|
258 | QT3_SUPPORT_CONSTRUCTOR QComboBox(bool rw, QWidget *parent, const char *name = 0);
|
---|
259 | inline QT3_SUPPORT int currentItem() const { return currentIndex(); }
|
---|
260 | inline QT3_SUPPORT void setCurrentItem(int index) { setCurrentIndex(index); }
|
---|
261 | inline QT3_SUPPORT InsertPolicy insertionPolicy() const { return insertPolicy(); }
|
---|
262 | inline QT3_SUPPORT void setInsertionPolicy(InsertPolicy policy) { setInsertPolicy(policy); }
|
---|
263 | inline QT3_SUPPORT bool editable() const { return isEditable(); }
|
---|
264 | inline QT3_SUPPORT void popup() { showPopup(); }
|
---|
265 | inline QT3_SUPPORT void setCurrentText(const QString& text) {
|
---|
266 | int i = findText(text);
|
---|
267 | if (i != -1)
|
---|
268 | setCurrentIndex(i);
|
---|
269 | else if (isEditable())
|
---|
270 | setEditText(text);
|
---|
271 | else
|
---|
272 | setItemText(currentIndex(), text);
|
---|
273 | }
|
---|
274 | inline QT3_SUPPORT QString text(int index) const { return itemText(index); }
|
---|
275 |
|
---|
276 | inline QT3_SUPPORT QPixmap pixmap(int index) const
|
---|
277 | { return itemIcon(index).pixmap(iconSize(), isEnabled() ? QIcon::Normal : QIcon::Disabled); }
|
---|
278 | inline QT3_SUPPORT void insertStringList(const QStringList &list, int index = -1)
|
---|
279 | { insertItems((index < 0 ? count() : index), list); }
|
---|
280 | inline QT3_SUPPORT void insertItem(const QString &text, int index = -1)
|
---|
281 | { insertItem((index < 0 ? count() : index), text); }
|
---|
282 | inline QT3_SUPPORT void insertItem(const QPixmap &pix, int index = -1)
|
---|
283 | { insertItem((index < 0 ? count() : index), QIcon(pix), QString()); }
|
---|
284 | inline QT3_SUPPORT void insertItem(const QPixmap &pix, const QString &text, int index = -1)
|
---|
285 | { insertItem((index < 0 ? count() : index), QIcon(pix), text); }
|
---|
286 | inline QT3_SUPPORT void changeItem(const QString &text, int index)
|
---|
287 | { setItemText(index, text); }
|
---|
288 | inline QT3_SUPPORT void changeItem(const QPixmap &pix, int index)
|
---|
289 | { setItemIcon(index, QIcon(pix)); }
|
---|
290 | inline QT3_SUPPORT void changeItem(const QPixmap &pix, const QString &text, int index)
|
---|
291 | { setItemIcon(index, QIcon(pix)); setItemText(index, text); }
|
---|
292 | inline QT3_SUPPORT void clearValidator() { setValidator(0); }
|
---|
293 | inline QT3_SUPPORT void clearEdit() { clearEditText(); }
|
---|
294 |
|
---|
295 | Q_SIGNALS:
|
---|
296 | QT_MOC_COMPAT void textChanged(const QString &);
|
---|
297 | #endif
|
---|
298 |
|
---|
299 | protected:
|
---|
300 | QComboBox(QComboBoxPrivate &, QWidget *);
|
---|
301 |
|
---|
302 | private:
|
---|
303 | Q_DECLARE_PRIVATE(QComboBox)
|
---|
304 | Q_DISABLE_COPY(QComboBox)
|
---|
305 | Q_PRIVATE_SLOT(d_func(), void _q_itemSelected(const QModelIndex &item))
|
---|
306 | Q_PRIVATE_SLOT(d_func(), void _q_emitHighlighted(const QModelIndex &))
|
---|
307 | Q_PRIVATE_SLOT(d_func(), void _q_emitCurrentIndexChanged(const QModelIndex &index))
|
---|
308 | Q_PRIVATE_SLOT(d_func(), void _q_returnPressed())
|
---|
309 | Q_PRIVATE_SLOT(d_func(), void _q_resetButton())
|
---|
310 | Q_PRIVATE_SLOT(d_func(), void _q_dataChanged(const QModelIndex &, const QModelIndex &))
|
---|
311 | Q_PRIVATE_SLOT(d_func(), void _q_rowsAboutToBeInserted(const QModelIndex & parent, int start, int end))
|
---|
312 | Q_PRIVATE_SLOT(d_func(), void _q_rowsInserted(const QModelIndex & parent, int start, int end))
|
---|
313 | Q_PRIVATE_SLOT(d_func(), void _q_rowsAboutToBeRemoved(const QModelIndex & parent, int start, int end))
|
---|
314 | Q_PRIVATE_SLOT(d_func(), void _q_rowsRemoved(const QModelIndex & parent, int start, int end))
|
---|
315 | Q_PRIVATE_SLOT(d_func(), void _q_modelDestroyed())
|
---|
316 | Q_PRIVATE_SLOT(d_func(), void _q_modelReset())
|
---|
317 | #ifdef QT_KEYPAD_NAVIGATION
|
---|
318 | Q_PRIVATE_SLOT(d_func(), void _q_completerActivated())
|
---|
319 | #endif
|
---|
320 | };
|
---|
321 |
|
---|
322 | inline void QComboBox::addItem(const QString &atext, const QVariant &auserData)
|
---|
323 | { insertItem(count(), atext, auserData); }
|
---|
324 | inline void QComboBox::addItem(const QIcon &aicon, const QString &atext,
|
---|
325 | const QVariant &auserData)
|
---|
326 | { insertItem(count(), aicon, atext, auserData); }
|
---|
327 |
|
---|
328 | inline void QComboBox::insertItem(int aindex, const QString &atext,
|
---|
329 | const QVariant &auserData)
|
---|
330 | { insertItem(aindex, QIcon(), atext, auserData); }
|
---|
331 |
|
---|
332 | #endif // QT_NO_COMBOBOX
|
---|
333 |
|
---|
334 | QT_END_NAMESPACE
|
---|
335 |
|
---|
336 | QT_END_HEADER
|
---|
337 |
|
---|
338 | #endif // QCOMBOBOX_H
|
---|