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