[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
[2] | 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 | **
|
---|
[561] | 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.
|
---|
[2] | 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 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at qt-info@nokia.com.
|
---|
[2] | 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,
|
---|
[846] | 114 | Qt::MatchFlags flags = static_cast<Qt::MatchFlags>(Qt::MatchExactly|Qt::MatchCaseSensitive)) const
|
---|
[2] | 115 | { return findData(text, Qt::DisplayRole, flags); }
|
---|
| 116 | int findData(const QVariant &data, int role = Qt::UserRole,
|
---|
[846] | 117 | Qt::MatchFlags flags = static_cast<Qt::MatchFlags>(Qt::MatchExactly|Qt::MatchCaseSensitive)) const;
|
---|
[2] | 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);
|
---|
[769] | 248 | #ifndef QT_NO_WHEELEVENT
|
---|
[2] | 249 | void wheelEvent(QWheelEvent *e);
|
---|
[769] | 250 | #endif
|
---|
[2] | 251 | void contextMenuEvent(QContextMenuEvent *e);
|
---|
| 252 | void inputMethodEvent(QInputMethodEvent *);
|
---|
| 253 | QVariant inputMethodQuery(Qt::InputMethodQuery) const;
|
---|
| 254 | void initStyleOption(QStyleOptionComboBox *option) const;
|
---|
| 255 |
|
---|
| 256 | #ifdef QT3_SUPPORT
|
---|
| 257 | public:
|
---|
| 258 | QT3_SUPPORT_CONSTRUCTOR QComboBox(QWidget *parent, const char *name);
|
---|
| 259 | QT3_SUPPORT_CONSTRUCTOR QComboBox(bool rw, QWidget *parent, const char *name = 0);
|
---|
| 260 | inline QT3_SUPPORT int currentItem() const { return currentIndex(); }
|
---|
| 261 | inline QT3_SUPPORT void setCurrentItem(int index) { setCurrentIndex(index); }
|
---|
| 262 | inline QT3_SUPPORT InsertPolicy insertionPolicy() const { return insertPolicy(); }
|
---|
| 263 | inline QT3_SUPPORT void setInsertionPolicy(InsertPolicy policy) { setInsertPolicy(policy); }
|
---|
| 264 | inline QT3_SUPPORT bool editable() const { return isEditable(); }
|
---|
| 265 | inline QT3_SUPPORT void popup() { showPopup(); }
|
---|
| 266 | inline QT3_SUPPORT void setCurrentText(const QString& text) {
|
---|
| 267 | int i = findText(text);
|
---|
| 268 | if (i != -1)
|
---|
| 269 | setCurrentIndex(i);
|
---|
| 270 | else if (isEditable())
|
---|
| 271 | setEditText(text);
|
---|
| 272 | else
|
---|
| 273 | setItemText(currentIndex(), text);
|
---|
| 274 | }
|
---|
| 275 | inline QT3_SUPPORT QString text(int index) const { return itemText(index); }
|
---|
| 276 |
|
---|
| 277 | inline QT3_SUPPORT QPixmap pixmap(int index) const
|
---|
| 278 | { return itemIcon(index).pixmap(iconSize(), isEnabled() ? QIcon::Normal : QIcon::Disabled); }
|
---|
| 279 | inline QT3_SUPPORT void insertStringList(const QStringList &list, int index = -1)
|
---|
| 280 | { insertItems((index < 0 ? count() : index), list); }
|
---|
| 281 | inline QT3_SUPPORT void insertItem(const QString &text, int index = -1)
|
---|
| 282 | { insertItem((index < 0 ? count() : index), text); }
|
---|
| 283 | inline QT3_SUPPORT void insertItem(const QPixmap &pix, int index = -1)
|
---|
| 284 | { insertItem((index < 0 ? count() : index), QIcon(pix), QString()); }
|
---|
| 285 | inline QT3_SUPPORT void insertItem(const QPixmap &pix, const QString &text, int index = -1)
|
---|
| 286 | { insertItem((index < 0 ? count() : index), QIcon(pix), text); }
|
---|
| 287 | inline QT3_SUPPORT void changeItem(const QString &text, int index)
|
---|
| 288 | { setItemText(index, text); }
|
---|
| 289 | inline QT3_SUPPORT void changeItem(const QPixmap &pix, int index)
|
---|
| 290 | { setItemIcon(index, QIcon(pix)); }
|
---|
| 291 | inline QT3_SUPPORT void changeItem(const QPixmap &pix, const QString &text, int index)
|
---|
| 292 | { setItemIcon(index, QIcon(pix)); setItemText(index, text); }
|
---|
| 293 | inline QT3_SUPPORT void clearValidator() { setValidator(0); }
|
---|
| 294 | inline QT3_SUPPORT void clearEdit() { clearEditText(); }
|
---|
| 295 |
|
---|
| 296 | Q_SIGNALS:
|
---|
| 297 | QT_MOC_COMPAT void textChanged(const QString &);
|
---|
| 298 | #endif
|
---|
| 299 |
|
---|
| 300 | protected:
|
---|
| 301 | QComboBox(QComboBoxPrivate &, QWidget *);
|
---|
| 302 |
|
---|
| 303 | private:
|
---|
| 304 | Q_DECLARE_PRIVATE(QComboBox)
|
---|
| 305 | Q_DISABLE_COPY(QComboBox)
|
---|
| 306 | Q_PRIVATE_SLOT(d_func(), void _q_itemSelected(const QModelIndex &item))
|
---|
| 307 | Q_PRIVATE_SLOT(d_func(), void _q_emitHighlighted(const QModelIndex &))
|
---|
| 308 | Q_PRIVATE_SLOT(d_func(), void _q_emitCurrentIndexChanged(const QModelIndex &index))
|
---|
[561] | 309 | Q_PRIVATE_SLOT(d_func(), void _q_editingFinished())
|
---|
[2] | 310 | Q_PRIVATE_SLOT(d_func(), void _q_returnPressed())
|
---|
| 311 | Q_PRIVATE_SLOT(d_func(), void _q_resetButton())
|
---|
| 312 | Q_PRIVATE_SLOT(d_func(), void _q_dataChanged(const QModelIndex &, const QModelIndex &))
|
---|
[561] | 313 | Q_PRIVATE_SLOT(d_func(), void _q_updateIndexBeforeChange())
|
---|
[2] | 314 | Q_PRIVATE_SLOT(d_func(), void _q_rowsInserted(const QModelIndex & parent, int start, int end))
|
---|
| 315 | Q_PRIVATE_SLOT(d_func(), void _q_rowsRemoved(const QModelIndex & parent, int start, int end))
|
---|
| 316 | Q_PRIVATE_SLOT(d_func(), void _q_modelDestroyed())
|
---|
| 317 | Q_PRIVATE_SLOT(d_func(), void _q_modelReset())
|
---|
| 318 | #ifdef QT_KEYPAD_NAVIGATION
|
---|
| 319 | Q_PRIVATE_SLOT(d_func(), void _q_completerActivated())
|
---|
| 320 | #endif
|
---|
| 321 | };
|
---|
| 322 |
|
---|
| 323 | inline void QComboBox::addItem(const QString &atext, const QVariant &auserData)
|
---|
| 324 | { insertItem(count(), atext, auserData); }
|
---|
| 325 | inline void QComboBox::addItem(const QIcon &aicon, const QString &atext,
|
---|
| 326 | const QVariant &auserData)
|
---|
| 327 | { insertItem(count(), aicon, atext, auserData); }
|
---|
| 328 |
|
---|
| 329 | inline void QComboBox::insertItem(int aindex, const QString &atext,
|
---|
| 330 | const QVariant &auserData)
|
---|
| 331 | { insertItem(aindex, QIcon(), atext, auserData); }
|
---|
| 332 |
|
---|
| 333 | #endif // QT_NO_COMBOBOX
|
---|
| 334 |
|
---|
| 335 | QT_END_NAMESPACE
|
---|
| 336 |
|
---|
| 337 | QT_END_HEADER
|
---|
| 338 |
|
---|
| 339 | #endif // QCOMBOBOX_H
|
---|