~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/widgets/qcombobox.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the widgets module of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef QCOMBOBOX_H
 
30
#define QCOMBOBOX_H
 
31
 
 
32
#include <QtGui/qwidget.h>
 
33
#include <QtCore/qabstractitemmodel.h>
 
34
#include <QtGui/qabstractitemdelegate.h>
 
35
#include <QtCore/qvariant.h>
 
36
 
 
37
class QAbstractItemView;
 
38
class QLineEdit;
 
39
class QComboBoxPrivate;
 
40
 
 
41
class Q_GUI_EXPORT QComboBox : public QWidget
 
42
{
 
43
    Q_OBJECT
 
44
 
 
45
    Q_ENUMS(InsertPolicy)
 
46
    Q_ENUMS(SizeAdjustPolicy)
 
47
    Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
 
48
    Q_PROPERTY(int count READ count)
 
49
    Q_PROPERTY(QString currentText READ currentText)
 
50
    Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex)
 
51
    Q_PROPERTY(int maxVisibleItems READ maxVisibleItems WRITE setMaxVisibleItems)
 
52
    Q_PROPERTY(int maxCount READ maxCount WRITE setMaxCount)
 
53
    Q_PROPERTY(InsertPolicy insertPolicy READ insertPolicy WRITE setInsertPolicy)
 
54
    Q_PROPERTY(SizeAdjustPolicy sizeAdjustPolicy READ sizeAdjustPolicy WRITE setSizeAdjustPolicy)
 
55
    Q_PROPERTY(int minimumContentsLength READ minimumContentsLength WRITE setMinimumContentsLength)
 
56
    Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
 
57
    Q_PROPERTY(bool autoCompletion READ autoCompletion WRITE setAutoCompletion)
 
58
    Q_PROPERTY(bool duplicatesEnabled READ duplicatesEnabled WRITE setDuplicatesEnabled)
 
59
    Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
 
60
    Q_PROPERTY(bool modelColumn READ modelColumn WRITE setModelColumn)
 
61
 
 
62
public:
 
63
    explicit QComboBox(QWidget *parent = 0);
 
64
    ~QComboBox();
 
65
 
 
66
    int maxVisibleItems() const;
 
67
    void setMaxVisibleItems(int maxItems);
 
68
 
 
69
    int count() const;
 
70
    void setMaxCount(int max);
 
71
    int maxCount() const;
 
72
 
 
73
    bool autoCompletion() const;
 
74
    void setAutoCompletion(bool enable);
 
75
 
 
76
    bool duplicatesEnabled() const;
 
77
    void setDuplicatesEnabled(bool enable);
 
78
 
 
79
    void setFrame(bool);
 
80
    bool hasFrame() const;
 
81
 
 
82
    inline int findText(const QString &text,
 
83
                        Qt::MatchFlags flags = Qt::MatchExactly|Qt::MatchCaseSensitive) const
 
84
        { return findData(text, Qt::EditRole, flags); }
 
85
    int findData(const QVariant &data, int role = Qt::UserRole,
 
86
                 Qt::MatchFlags flags = Qt::MatchExactly|Qt::MatchCaseSensitive) const;
 
87
 
 
88
    enum InsertPolicy {
 
89
        NoInsert,
 
90
        InsertAtTop,
 
91
        InsertAtCurrent,
 
92
        InsertAtBottom,
 
93
        InsertAfterCurrent,
 
94
        InsertBeforeCurrent
 
95
#if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN)
 
96
        ,
 
97
        NoInsertion = NoInsert,
 
98
        AtTop = InsertAtTop,
 
99
        AtCurrent = InsertAtCurrent,
 
100
        AtBottom = InsertAtBottom,
 
101
        AfterCurrent = InsertAfterCurrent,
 
102
        BeforeCurrent = InsertBeforeCurrent
 
103
#endif
 
104
    };
 
105
#ifdef QT3_SUPPORT
 
106
    typedef InsertPolicy Policy;
 
107
#endif
 
108
 
 
109
    InsertPolicy insertPolicy() const;
 
110
    void setInsertPolicy(InsertPolicy policy);
 
111
 
 
112
    enum SizeAdjustPolicy {
 
113
        AdjustToContents,
 
114
        AdjustToContentsOnFirstShow,
 
115
        AdjustToMinimumContentsLength
 
116
    };
 
117
 
 
118
    SizeAdjustPolicy sizeAdjustPolicy() const;
 
119
    void setSizeAdjustPolicy(SizeAdjustPolicy policy);
 
120
    int minimumContentsLength() const;
 
121
    void setMinimumContentsLength(int characters);
 
122
    QSize iconSize() const;
 
123
    void setIconSize(const QSize &size);
 
124
 
 
125
    bool isEditable() const;
 
126
    void setEditable(bool editable);
 
127
    void setLineEdit(QLineEdit *edit);
 
128
    QLineEdit *lineEdit() const;
 
129
    void setValidator(const QValidator *v);
 
130
    const QValidator *validator() const;
 
131
 
 
132
    QAbstractItemDelegate *itemDelegate() const;
 
133
    void setItemDelegate(QAbstractItemDelegate *delegate);
 
134
 
 
135
    QAbstractItemModel *model() const;
 
136
    void setModel(QAbstractItemModel *model);
 
137
 
 
138
    QModelIndex rootModelIndex() const;
 
139
    void setRootModelIndex(const QModelIndex &index);
 
140
 
 
141
    int modelColumn() const;
 
142
    void setModelColumn(int visibleColumn);
 
143
 
 
144
    int currentIndex() const;
 
145
    void setCurrentIndex(int index);
 
146
 
 
147
    QString currentText() const;
 
148
 
 
149
    QString itemText(int index) const;
 
150
    QIcon itemIcon(int index) const;
 
151
    QVariant itemData(int index, int role = Qt::UserRole) const;
 
152
 
 
153
    inline void addItem(const QString &text, const QVariant &userData = QVariant());
 
154
    inline void addItem(const QIcon &icon, const QString &text,
 
155
                        const QVariant &userData = QVariant());
 
156
    inline void addItems(const QStringList &texts)
 
157
        { insertItems(count(), texts); }
 
158
 
 
159
    inline void insertItem(int index, const QString &text, const QVariant &userData = QVariant());
 
160
    void insertItem(int index, const QIcon &icon, const QString &text,
 
161
                    const QVariant &userData = QVariant());
 
162
    void insertItems(int index, const QStringList &texts);
 
163
 
 
164
    void removeItem(int index);
 
165
 
 
166
    void setItemText(int index, const QString &text);
 
167
    void setItemIcon(int index, const QIcon &icon);
 
168
    void setItemData(int index, const QVariant &value, int role = Qt::UserRole);
 
169
 
 
170
    QAbstractItemView *view() const;
 
171
    void setView(QAbstractItemView *itemView);
 
172
 
 
173
    QSize sizeHint() const;
 
174
    QSize minimumSizeHint() const;
 
175
 
 
176
    virtual void showPopup();
 
177
    virtual void hidePopup();
 
178
 
 
179
    bool event(QEvent *event);
 
180
 
 
181
public slots:
 
182
    void clear();
 
183
    void clearEditText();
 
184
    void setEditText(const QString &text);
 
185
 
 
186
signals:
 
187
    void editTextChanged(const QString &);
 
188
    void activated(int index);
 
189
    void activated(const QString &);
 
190
    void highlighted(int index);
 
191
    void highlighted(const QString &);
 
192
 
 
193
protected:
 
194
    void focusInEvent(QFocusEvent *e);
 
195
    void focusOutEvent(QFocusEvent *e);
 
196
    void changeEvent(QEvent *e);
 
197
    void resizeEvent(QResizeEvent *e);
 
198
    void paintEvent(QPaintEvent *e);
 
199
    void showEvent(QShowEvent *e);
 
200
    void hideEvent(QHideEvent *e);
 
201
    void mousePressEvent(QMouseEvent *e);
 
202
    void mouseReleaseEvent(QMouseEvent *e);
 
203
    void keyPressEvent(QKeyEvent *e);
 
204
    void keyReleaseEvent(QKeyEvent *e);
 
205
    void wheelEvent(QWheelEvent *e);
 
206
    void inputMethodEvent(QInputMethodEvent *);
 
207
    QVariant inputMethodQuery(Qt::InputMethodQuery) const;
 
208
 
 
209
#ifdef QT3_SUPPORT
 
210
public:
 
211
    QT3_SUPPORT_CONSTRUCTOR QComboBox(QWidget *parent, const char *name);
 
212
    QT3_SUPPORT_CONSTRUCTOR QComboBox(bool rw, QWidget *parent, const char *name = 0);
 
213
    inline QT3_SUPPORT int currentItem() const { return currentIndex(); }
 
214
    inline QT3_SUPPORT void setCurrentItem(int index) { setCurrentIndex(index); }
 
215
    inline QT3_SUPPORT InsertPolicy insertionPolicy() const { return insertPolicy(); }
 
216
    inline QT3_SUPPORT void setInsertionPolicy(InsertPolicy policy) { setInsertPolicy(policy); }
 
217
    inline QT3_SUPPORT bool editable() const { return isEditable(); }
 
218
    inline QT3_SUPPORT void popup() { showPopup(); }
 
219
    inline QT3_SUPPORT void setCurrentText(const QString& text) {
 
220
        int i = findText(text);
 
221
        if (i != -1)
 
222
            setCurrentIndex(i);
 
223
        else if (isEditable())
 
224
            setEditText(text);
 
225
        else
 
226
            setItemText(currentIndex(), text);
 
227
    }
 
228
    inline QT3_SUPPORT QString text(int index) const { return itemText(index); }
 
229
    inline QT3_SUPPORT QPixmap pixmap(int index) const { return itemIcon(index).pixmap(QSize(22,22)); }
 
230
    inline QT3_SUPPORT void insertStringList(const QStringList &list, int index = -1)
 
231
        { insertItems((index < 0 ? count() : index), list); }
 
232
    inline QT3_SUPPORT void insertItem(const QString &text, int index = -1)
 
233
        { insertItem((index < 0 ? count() : index), text); }
 
234
    inline QT3_SUPPORT void insertItem(const QPixmap &pix, int index = -1)
 
235
        { insertItem((index < 0 ? count() : index), QIcon(pix), QString()); }
 
236
    inline QT3_SUPPORT void insertItem(const QPixmap &pix, const QString &text, int index = -1)
 
237
        { insertItem((index < 0 ? count() : index), QIcon(pix), text); }
 
238
    inline QT3_SUPPORT void changeItem(const QString &text, int index)
 
239
        { setItemText(index, text); }
 
240
    inline QT3_SUPPORT void changeItem(const QPixmap &pix, int index)
 
241
        { setItemIcon(index, QIcon(pix)); }
 
242
    inline QT3_SUPPORT void changeItem(const QPixmap &pix, const QString &text, int index)
 
243
        { setItemIcon(index, QIcon(pix)); setItemText(index, text); }
 
244
    inline QT3_SUPPORT void clearValidator() { setValidator(0); }
 
245
    inline QT3_SUPPORT void clearEdit() { clearEditText(); }
 
246
 
 
247
signals:
 
248
    QT_MOC_COMPAT void textChanged(const QString &);
 
249
#endif
 
250
 
 
251
private:
 
252
    Q_DECLARE_PRIVATE(QComboBox)
 
253
    Q_DISABLE_COPY(QComboBox)
 
254
    Q_PRIVATE_SLOT(d_func(), void itemSelected(const QModelIndex &item))
 
255
    Q_PRIVATE_SLOT(d_func(), void emitHighlighted(const QModelIndex &))
 
256
    Q_PRIVATE_SLOT(d_func(), void returnPressed())
 
257
    Q_PRIVATE_SLOT(d_func(), void complete())
 
258
    Q_PRIVATE_SLOT(d_func(), void resetButton())
 
259
    Q_PRIVATE_SLOT(d_func(), void dataChanged(const QModelIndex &, const QModelIndex &))
 
260
    Q_PRIVATE_SLOT(d_func(), void rowsInserted(const QModelIndex & parent, int start, int end))
 
261
    Q_PRIVATE_SLOT(d_func(), void rowsAboutToBeRemoved(const QModelIndex & parent, int start, int end))
 
262
    Q_PRIVATE_SLOT(d_func(), void modelDestroyed())
 
263
};
 
264
 
 
265
inline void QComboBox::addItem(const QString &atext, const QVariant &auserData)
 
266
{ insertItem(count(), atext, auserData); }
 
267
inline void QComboBox::addItem(const QIcon &aicon, const QString &atext,
 
268
                               const QVariant &auserData)
 
269
{ insertItem(count(), aicon, atext, auserData); }
 
270
 
 
271
inline void QComboBox::insertItem(int aindex, const QString &atext,
 
272
                                  const QVariant &auserData)
 
273
{ insertItem(aindex, QIcon(), atext, auserData); }
 
274
 
 
275
#endif // QCOMBOBOX_H