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 QLISTWIDGET_H
|
---|
43 | #define QLISTWIDGET_H
|
---|
44 |
|
---|
45 | #include <QtGui/qlistview.h>
|
---|
46 | #include <QtCore/qvariant.h>
|
---|
47 | #include <QtCore/qvector.h>
|
---|
48 | #include <QtGui/qitemselectionmodel.h>
|
---|
49 |
|
---|
50 | QT_BEGIN_HEADER
|
---|
51 |
|
---|
52 | QT_BEGIN_NAMESPACE
|
---|
53 |
|
---|
54 | QT_MODULE(Gui)
|
---|
55 |
|
---|
56 | #ifndef QT_NO_LISTWIDGET
|
---|
57 |
|
---|
58 | class QListWidget;
|
---|
59 | class QListModel;
|
---|
60 | class QWidgetItemData;
|
---|
61 | class QListWidgetItemPrivate;
|
---|
62 |
|
---|
63 | class Q_GUI_EXPORT QListWidgetItem
|
---|
64 | {
|
---|
65 | friend class QListModel;
|
---|
66 | friend class QListWidget;
|
---|
67 | public:
|
---|
68 | enum ItemType { Type = 0, UserType = 1000 };
|
---|
69 | explicit QListWidgetItem(QListWidget *view = 0, int type = Type);
|
---|
70 | explicit QListWidgetItem(const QString &text, QListWidget *view = 0, int type = Type);
|
---|
71 | explicit QListWidgetItem(const QIcon &icon, const QString &text,
|
---|
72 | QListWidget *view = 0, int type = Type);
|
---|
73 | QListWidgetItem(const QListWidgetItem &other);
|
---|
74 | virtual ~QListWidgetItem();
|
---|
75 |
|
---|
76 | virtual QListWidgetItem *clone() const;
|
---|
77 |
|
---|
78 | inline QListWidget *listWidget() const { return view; }
|
---|
79 |
|
---|
80 | inline void setSelected(bool select);
|
---|
81 | inline bool isSelected() const;
|
---|
82 |
|
---|
83 | inline void setHidden(bool hide);
|
---|
84 | inline bool isHidden() const;
|
---|
85 |
|
---|
86 | inline Qt::ItemFlags flags() const { return itemFlags; }
|
---|
87 | void setFlags(Qt::ItemFlags flags);
|
---|
88 |
|
---|
89 | inline QString text() const
|
---|
90 | { return data(Qt::DisplayRole).toString(); }
|
---|
91 | inline void setText(const QString &text);
|
---|
92 |
|
---|
93 | inline QIcon icon() const
|
---|
94 | { return qvariant_cast<QIcon>(data(Qt::DecorationRole)); }
|
---|
95 | inline void setIcon(const QIcon &icon);
|
---|
96 |
|
---|
97 | inline QString statusTip() const
|
---|
98 | { return data(Qt::StatusTipRole).toString(); }
|
---|
99 | inline void setStatusTip(const QString &statusTip);
|
---|
100 |
|
---|
101 | #ifndef QT_NO_TOOLTIP
|
---|
102 | inline QString toolTip() const
|
---|
103 | { return data(Qt::ToolTipRole).toString(); }
|
---|
104 | inline void setToolTip(const QString &toolTip);
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | #ifndef QT_NO_WHATSTHIS
|
---|
108 | inline QString whatsThis() const
|
---|
109 | { return data(Qt::WhatsThisRole).toString(); }
|
---|
110 | inline void setWhatsThis(const QString &whatsThis);
|
---|
111 | #endif
|
---|
112 |
|
---|
113 | inline QFont font() const
|
---|
114 | { return qvariant_cast<QFont>(data(Qt::FontRole)); }
|
---|
115 | inline void setFont(const QFont &font);
|
---|
116 |
|
---|
117 | inline int textAlignment() const
|
---|
118 | { return data(Qt::TextAlignmentRole).toInt(); }
|
---|
119 | inline void setTextAlignment(int alignment)
|
---|
120 | { setData(Qt::TextAlignmentRole, alignment); }
|
---|
121 |
|
---|
122 | inline QColor backgroundColor() const
|
---|
123 | { return qvariant_cast<QColor>(data(Qt::BackgroundColorRole)); }
|
---|
124 | virtual void setBackgroundColor(const QColor &color)
|
---|
125 | { setData(Qt::BackgroundColorRole, color); }
|
---|
126 |
|
---|
127 | inline QBrush background() const
|
---|
128 | { return qvariant_cast<QBrush>(data(Qt::BackgroundRole)); }
|
---|
129 | inline void setBackground(const QBrush &brush)
|
---|
130 | { setData(Qt::BackgroundRole, brush); }
|
---|
131 |
|
---|
132 | inline QColor textColor() const
|
---|
133 | { return qvariant_cast<QColor>(data(Qt::TextColorRole)); }
|
---|
134 | inline void setTextColor(const QColor &color)
|
---|
135 | { setData(Qt::TextColorRole, color); }
|
---|
136 |
|
---|
137 | inline QBrush foreground() const
|
---|
138 | { return qvariant_cast<QBrush>(data(Qt::ForegroundRole)); }
|
---|
139 | inline void setForeground(const QBrush &brush)
|
---|
140 | { setData(Qt::ForegroundRole, brush); }
|
---|
141 |
|
---|
142 | inline Qt::CheckState checkState() const
|
---|
143 | { return static_cast<Qt::CheckState>(data(Qt::CheckStateRole).toInt()); }
|
---|
144 | inline void setCheckState(Qt::CheckState state)
|
---|
145 | { setData(Qt::CheckStateRole, static_cast<int>(state)); }
|
---|
146 |
|
---|
147 | inline QSize sizeHint() const
|
---|
148 | { return qvariant_cast<QSize>(data(Qt::SizeHintRole)); }
|
---|
149 | inline void setSizeHint(const QSize &size)
|
---|
150 | { setData(Qt::SizeHintRole, size); }
|
---|
151 |
|
---|
152 | virtual QVariant data(int role) const;
|
---|
153 | virtual void setData(int role, const QVariant &value);
|
---|
154 |
|
---|
155 | virtual bool operator<(const QListWidgetItem &other) const;
|
---|
156 |
|
---|
157 | #ifndef QT_NO_DATASTREAM
|
---|
158 | virtual void read(QDataStream &in);
|
---|
159 | virtual void write(QDataStream &out) const;
|
---|
160 | #endif
|
---|
161 | QListWidgetItem &operator=(const QListWidgetItem &other);
|
---|
162 |
|
---|
163 | inline int type() const { return rtti; }
|
---|
164 |
|
---|
165 | private:
|
---|
166 | int rtti;
|
---|
167 | QVector<void *> dummy;
|
---|
168 | QListWidget *view;
|
---|
169 | QListWidgetItemPrivate *d;
|
---|
170 | Qt::ItemFlags itemFlags;
|
---|
171 | };
|
---|
172 |
|
---|
173 | inline void QListWidgetItem::setText(const QString &atext)
|
---|
174 | { setData(Qt::DisplayRole, atext); }
|
---|
175 |
|
---|
176 | inline void QListWidgetItem::setIcon(const QIcon &aicon)
|
---|
177 | { setData(Qt::DecorationRole, aicon); }
|
---|
178 |
|
---|
179 | inline void QListWidgetItem::setStatusTip(const QString &astatusTip)
|
---|
180 | { setData(Qt::StatusTipRole, astatusTip); }
|
---|
181 |
|
---|
182 | #ifndef QT_NO_TOOLTIP
|
---|
183 | inline void QListWidgetItem::setToolTip(const QString &atoolTip)
|
---|
184 | { setData(Qt::ToolTipRole, atoolTip); }
|
---|
185 | #endif
|
---|
186 |
|
---|
187 | #ifndef QT_NO_WHATSTHIS
|
---|
188 | inline void QListWidgetItem::setWhatsThis(const QString &awhatsThis)
|
---|
189 | { setData(Qt::WhatsThisRole, awhatsThis); }
|
---|
190 | #endif
|
---|
191 |
|
---|
192 | inline void QListWidgetItem::setFont(const QFont &afont)
|
---|
193 | { setData(Qt::FontRole, afont); }
|
---|
194 |
|
---|
195 | #ifndef QT_NO_DATASTREAM
|
---|
196 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &out, const QListWidgetItem &item);
|
---|
197 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QListWidgetItem &item);
|
---|
198 | #endif
|
---|
199 |
|
---|
200 | class QListWidgetPrivate;
|
---|
201 |
|
---|
202 | class Q_GUI_EXPORT QListWidget : public QListView
|
---|
203 | {
|
---|
204 | Q_OBJECT
|
---|
205 | Q_PROPERTY(int count READ count)
|
---|
206 | Q_PROPERTY(int currentRow READ currentRow WRITE setCurrentRow NOTIFY currentRowChanged USER true)
|
---|
207 | Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
|
---|
208 |
|
---|
209 | friend class QListWidgetItem;
|
---|
210 | friend class QListModel;
|
---|
211 | public:
|
---|
212 | explicit QListWidget(QWidget *parent = 0);
|
---|
213 | ~QListWidget();
|
---|
214 |
|
---|
215 | QListWidgetItem *item(int row) const;
|
---|
216 | int row(const QListWidgetItem *item) const;
|
---|
217 | void insertItem(int row, QListWidgetItem *item);
|
---|
218 | void insertItem(int row, const QString &label);
|
---|
219 | void insertItems(int row, const QStringList &labels);
|
---|
220 | inline void addItem(const QString &label) { insertItem(count(), label); }
|
---|
221 | inline void addItem(QListWidgetItem *item);
|
---|
222 | inline void addItems(const QStringList &labels) { insertItems(count(), labels); }
|
---|
223 | QListWidgetItem *takeItem(int row);
|
---|
224 | int count() const;
|
---|
225 |
|
---|
226 | QListWidgetItem *currentItem() const;
|
---|
227 | void setCurrentItem(QListWidgetItem *item);
|
---|
228 | void setCurrentItem(QListWidgetItem *item, QItemSelectionModel::SelectionFlags command);
|
---|
229 |
|
---|
230 | int currentRow() const;
|
---|
231 | void setCurrentRow(int row);
|
---|
232 | void setCurrentRow(int row, QItemSelectionModel::SelectionFlags command);
|
---|
233 |
|
---|
234 | QListWidgetItem *itemAt(const QPoint &p) const;
|
---|
235 | inline QListWidgetItem *itemAt(int x, int y) const;
|
---|
236 | QRect visualItemRect(const QListWidgetItem *item) const;
|
---|
237 |
|
---|
238 | void sortItems(Qt::SortOrder order = Qt::AscendingOrder);
|
---|
239 | void setSortingEnabled(bool enable);
|
---|
240 | bool isSortingEnabled() const;
|
---|
241 |
|
---|
242 | void editItem(QListWidgetItem *item);
|
---|
243 | void openPersistentEditor(QListWidgetItem *item);
|
---|
244 | void closePersistentEditor(QListWidgetItem *item);
|
---|
245 |
|
---|
246 | QWidget *itemWidget(QListWidgetItem *item) const;
|
---|
247 | void setItemWidget(QListWidgetItem *item, QWidget *widget);
|
---|
248 | inline void removeItemWidget(QListWidgetItem *item);
|
---|
249 |
|
---|
250 | bool isItemSelected(const QListWidgetItem *item) const;
|
---|
251 | void setItemSelected(const QListWidgetItem *item, bool select);
|
---|
252 | QList<QListWidgetItem*> selectedItems() const;
|
---|
253 | QList<QListWidgetItem*> findItems(const QString &text, Qt::MatchFlags flags) const;
|
---|
254 |
|
---|
255 | bool isItemHidden(const QListWidgetItem *item) const;
|
---|
256 | void setItemHidden(const QListWidgetItem *item, bool hide);
|
---|
257 | void dropEvent(QDropEvent *event);
|
---|
258 |
|
---|
259 | public Q_SLOTS:
|
---|
260 | void scrollToItem(const QListWidgetItem *item, QAbstractItemView::ScrollHint hint = EnsureVisible);
|
---|
261 | void clear();
|
---|
262 |
|
---|
263 | Q_SIGNALS:
|
---|
264 | void itemPressed(QListWidgetItem *item);
|
---|
265 | void itemClicked(QListWidgetItem *item);
|
---|
266 | void itemDoubleClicked(QListWidgetItem *item);
|
---|
267 | void itemActivated(QListWidgetItem *item);
|
---|
268 | void itemEntered(QListWidgetItem *item);
|
---|
269 | void itemChanged(QListWidgetItem *item);
|
---|
270 |
|
---|
271 | void currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
|
---|
272 | void currentTextChanged(const QString ¤tText);
|
---|
273 | void currentRowChanged(int currentRow);
|
---|
274 |
|
---|
275 | void itemSelectionChanged();
|
---|
276 |
|
---|
277 | protected:
|
---|
278 | bool event(QEvent *e);
|
---|
279 | virtual QStringList mimeTypes() const;
|
---|
280 | virtual QMimeData *mimeData(const QList<QListWidgetItem*> items) const;
|
---|
281 | #ifndef QT_NO_DRAGANDDROP
|
---|
282 | virtual bool dropMimeData(int index, const QMimeData *data, Qt::DropAction action);
|
---|
283 | virtual Qt::DropActions supportedDropActions() const;
|
---|
284 | #endif
|
---|
285 | QList<QListWidgetItem*> items(const QMimeData *data) const;
|
---|
286 |
|
---|
287 | QModelIndex indexFromItem(QListWidgetItem *item) const;
|
---|
288 | QListWidgetItem *itemFromIndex(const QModelIndex &index) const;
|
---|
289 |
|
---|
290 | private:
|
---|
291 | void setModel(QAbstractItemModel *model);
|
---|
292 | Qt::SortOrder sortOrder() const;
|
---|
293 |
|
---|
294 | Q_DECLARE_PRIVATE(QListWidget)
|
---|
295 | Q_DISABLE_COPY(QListWidget)
|
---|
296 |
|
---|
297 | Q_PRIVATE_SLOT(d_func(), void _q_emitItemPressed(const QModelIndex &index))
|
---|
298 | Q_PRIVATE_SLOT(d_func(), void _q_emitItemClicked(const QModelIndex &index))
|
---|
299 | Q_PRIVATE_SLOT(d_func(), void _q_emitItemDoubleClicked(const QModelIndex &index))
|
---|
300 | Q_PRIVATE_SLOT(d_func(), void _q_emitItemActivated(const QModelIndex &index))
|
---|
301 | Q_PRIVATE_SLOT(d_func(), void _q_emitItemEntered(const QModelIndex &index))
|
---|
302 | Q_PRIVATE_SLOT(d_func(), void _q_emitItemChanged(const QModelIndex &index))
|
---|
303 | Q_PRIVATE_SLOT(d_func(), void _q_emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex ¤t))
|
---|
304 | Q_PRIVATE_SLOT(d_func(), void _q_sort())
|
---|
305 | Q_PRIVATE_SLOT(d_func(), void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight))
|
---|
306 | };
|
---|
307 |
|
---|
308 | inline void QListWidget::removeItemWidget(QListWidgetItem *aItem)
|
---|
309 | { setItemWidget(aItem, 0); }
|
---|
310 |
|
---|
311 | inline void QListWidget::addItem(QListWidgetItem *aitem)
|
---|
312 | { insertItem(count(), aitem); }
|
---|
313 |
|
---|
314 | inline QListWidgetItem *QListWidget::itemAt(int ax, int ay) const
|
---|
315 | { return itemAt(QPoint(ax, ay)); }
|
---|
316 |
|
---|
317 | inline void QListWidgetItem::setSelected(bool aselect)
|
---|
318 | { if (view) view->setItemSelected(this, aselect); }
|
---|
319 |
|
---|
320 | inline bool QListWidgetItem::isSelected() const
|
---|
321 | { return (view ? view->isItemSelected(this) : false); }
|
---|
322 |
|
---|
323 | inline void QListWidgetItem::setHidden(bool ahide)
|
---|
324 | { if (view) view->setItemHidden(this, ahide); }
|
---|
325 |
|
---|
326 | inline bool QListWidgetItem::isHidden() const
|
---|
327 | { return (view ? view->isItemHidden(this) : false); }
|
---|
328 |
|
---|
329 | #endif // QT_NO_LISTWIDGET
|
---|
330 |
|
---|
331 | QT_END_NAMESPACE
|
---|
332 |
|
---|
333 | QT_END_HEADER
|
---|
334 |
|
---|
335 | #endif // QLISTWIDGET_H
|
---|