1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
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.
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.
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.
21
** Contact info@trolltech.com if any conditions of this licensing are
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.
27
****************************************************************************/
32
#include "Qt3Support/q3scrollview.h"
33
#include "QtGui/qpixmap.h"
37
class Q3ListBoxPrivate;
43
class Q_COMPAT_EXPORT Q3ListBox : public Q3ScrollView
45
friend class Q3ListBoxItem;
46
friend class Q3ListBoxPrivate;
49
Q_ENUMS(SelectionMode LayoutMode)
50
Q_PROPERTY(uint count READ count)
51
Q_PROPERTY(int numItemsVisible READ numItemsVisible)
52
Q_PROPERTY(int currentItem READ currentItem WRITE setCurrentItem)
53
Q_PROPERTY(QString currentText READ currentText)
54
Q_PROPERTY(int topItem READ topItem WRITE setTopItem DESIGNABLE false)
55
Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
56
Q_PROPERTY(bool multiSelection READ isMultiSelection WRITE setMultiSelection DESIGNABLE false)
57
Q_PROPERTY(LayoutMode columnMode READ columnMode WRITE setColumnMode)
58
Q_PROPERTY(LayoutMode rowMode READ rowMode WRITE setRowMode)
59
Q_PROPERTY(int numColumns READ numColumns)
60
Q_PROPERTY(int numRows READ numRows)
61
Q_PROPERTY(bool variableWidth READ variableWidth WRITE setVariableWidth)
62
Q_PROPERTY(bool variableHeight READ variableHeight WRITE setVariableHeight)
65
Q3ListBox(QWidget* parent=0, const char* name=0, Qt::WFlags f=0 );
70
void insertStringList(const QStringList&, int index=-1);
71
// ### fix before Qt 4.0
73
void insertStrList(const QStrList *, int index=-1);
74
void insertStrList(const QStrList &, int index=-1);
76
void insertStrList(const char **,
77
int numStrings=-1, int index=-1);
79
void insertItem(const Q3ListBoxItem *, int index=-1);
80
void insertItem(const Q3ListBoxItem *, const Q3ListBoxItem *after);
81
void insertItem(const QString &text, int index=-1);
82
void insertItem(const QPixmap &pixmap, int index=-1);
83
void insertItem(const QPixmap &pixmap, const QString &text, int index=-1);
85
void removeItem(int index);
87
QString text(int index) const;
88
const QPixmap *pixmap(int index) const;
90
void changeItem(const Q3ListBoxItem *, int index);
91
void changeItem(const QString &text, int index);
92
void changeItem(const QPixmap &pixmap, int index);
93
void changeItem(const QPixmap &pixmap, const QString &text, int index);
95
void takeItem(const Q3ListBoxItem *);
97
int numItemsVisible() const;
99
int currentItem() const;
100
QString currentText() const { return text(currentItem()); }
101
virtual void setCurrentItem(int index);
102
virtual void setCurrentItem(Q3ListBoxItem *);
103
void centerCurrentItem() { ensureCurrentVisible(); }
105
virtual void setTopItem(int index);
106
virtual void setBottomItem(int index);
108
long maxItemWidth() const;
110
enum SelectionMode { Single, Multi, Extended, NoSelection };
111
virtual void setSelectionMode(SelectionMode);
112
SelectionMode selectionMode() const;
114
void setMultiSelection(bool multi);
115
bool isMultiSelection() const;
117
QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
119
virtual void setSelected(Q3ListBoxItem *, bool);
120
void setSelected(int, bool);
121
bool isSelected(int) const;
122
bool isSelected(const Q3ListBoxItem *) const;
123
Q3ListBoxItem* selectedItem() const;
125
QSize sizeHint() const;
126
QSize minimumSizeHint() const;
128
Q3ListBoxItem *item(int index) const;
129
int index(const Q3ListBoxItem *) const;
131
enum StringComparisonMode {
132
CaseSensitive = 0x00001, // 0 0001
133
BeginsWith = 0x00002, // 0 0010
134
EndsWith = 0x00004, // 0 0100
135
Contains = 0x00008, // 0 1000
136
ExactMatch = 0x00010 // 1 0000
138
typedef uint ComparisonFlags;
139
Q3ListBoxItem *findItem(const QString &text, ComparisonFlags compare = BeginsWith) const;
141
void triggerUpdate(bool doLayout);
143
bool itemVisible(int index);
144
bool itemVisible(const Q3ListBoxItem *);
146
enum LayoutMode { FixedNumber,
147
FitToWidth, FitToHeight = FitToWidth,
149
virtual void setColumnMode(LayoutMode);
150
virtual void setColumnMode(int);
151
virtual void setRowMode(LayoutMode);
152
virtual void setRowMode(int);
154
LayoutMode columnMode() const;
155
LayoutMode rowMode() const;
157
int numColumns() const;
160
bool variableWidth() const;
161
virtual void setVariableWidth(bool);
163
bool variableHeight() const;
164
virtual void setVariableHeight(bool);
166
void viewportPaintEvent(QPaintEvent *);
168
bool dragSelect() const { return true; }
169
void setDragSelect(bool) {}
170
bool autoScroll() const { return true; }
171
void setAutoScroll(bool) {}
172
bool autoScrollBar() const { return vScrollBarMode() == Auto; }
173
void setAutoScrollBar(bool enable) { setVScrollBarMode(enable ? Auto : AlwaysOff); }
174
bool scrollBar() const { return vScrollBarMode() != AlwaysOff; }
175
void setScrollBar(bool enable) { setVScrollBarMode(enable ? AlwaysOn : AlwaysOff); }
176
bool autoBottomScrollBar() const { return hScrollBarMode() == Auto; }
177
void setAutoBottomScrollBar(bool enable) { setHScrollBarMode(enable ? Auto : AlwaysOff); }
178
bool bottomScrollBar() const { return hScrollBarMode() != AlwaysOff; }
179
void setBottomScrollBar(bool enable) { setHScrollBarMode(enable ? AlwaysOn : AlwaysOff); }
180
bool smoothScrolling() const { return false; }
181
void setSmoothScrolling(bool) {}
182
bool autoUpdate() const { return true; }
183
void setAutoUpdate(bool) {}
184
void setFixedVisibleLines(int lines) { setRowMode(lines); }
185
int inSort(const Q3ListBoxItem *);
186
int inSort(const QString& text);
187
int cellHeight(int i) const { return itemHeight(i); }
188
int cellHeight() const { return itemHeight(); }
189
int cellWidth() const { return maxItemWidth(); }
190
int cellWidth(int i) const { Q_ASSERT(i==0); Q_UNUSED(i) return maxItemWidth(); }
191
int numCols() const { return numColumns(); }
193
int itemHeight(int index = 0) const;
194
Q3ListBoxItem * itemAt(const QPoint &) const;
196
QRect itemRect(Q3ListBoxItem *item) const;
198
Q3ListBoxItem *firstItem() const;
200
void sort(bool ascending = true);
204
virtual void ensureCurrentVisible();
205
virtual void clearSelection();
206
virtual void selectAll(bool select);
207
virtual void invertSelection();
210
void highlighted(int index);
211
void selected(int index);
212
void highlighted(const QString &);
213
void selected(const QString &);
214
void highlighted(Q3ListBoxItem *);
215
void selected(Q3ListBoxItem *);
217
void selectionChanged();
218
void selectionChanged(Q3ListBoxItem *);
219
void currentChanged(Q3ListBoxItem *);
220
void clicked(Q3ListBoxItem *);
221
void clicked(Q3ListBoxItem *, const QPoint &);
222
void pressed(Q3ListBoxItem *);
223
void pressed(Q3ListBoxItem *, const QPoint &);
225
void doubleClicked(Q3ListBoxItem *);
226
void returnPressed(Q3ListBoxItem *);
227
void rightButtonClicked(Q3ListBoxItem *, const QPoint &);
228
void rightButtonPressed(Q3ListBoxItem *, const QPoint &);
229
void mouseButtonPressed(int, Q3ListBoxItem*, const QPoint&);
230
void mouseButtonClicked(int, Q3ListBoxItem*, const QPoint&);
232
void contextMenuRequested(Q3ListBoxItem *, const QPoint &);
234
void onItem(Q3ListBoxItem *item);
238
void changeEvent(QEvent *);
239
void mousePressEvent(QMouseEvent *);
240
void mouseReleaseEvent(QMouseEvent *);
241
void mouseDoubleClickEvent(QMouseEvent *);
242
void mouseMoveEvent(QMouseEvent *);
243
void contentsContextMenuEvent(QContextMenuEvent *);
245
void keyPressEvent(QKeyEvent *e);
246
void focusInEvent(QFocusEvent *e);
247
void focusOutEvent(QFocusEvent *e);
248
void resizeEvent(QResizeEvent *);
249
void showEvent(QShowEvent *);
251
bool eventFilter(QObject *o, QEvent *e);
253
void updateItem(int index);
254
void updateItem(Q3ListBoxItem *);
256
void updateCellWidth() { }
257
int totalWidth() const { return contentsWidth(); }
258
int totalHeight() const { return contentsHeight(); }
260
virtual void paintCell(QPainter *, int row, int col);
262
void toggleCurrentItem();
263
bool isRubberSelecting() const;
265
void doLayout() const;
267
int findItem(int yPos) const { return index(itemAt(QPoint(0,yPos))); }
270
void clearInputString();
278
Q_DISABLE_COPY(Q3ListBox)
280
void mousePressEventEx(QMouseEvent *);
281
void tryGeometry(int, int) const;
282
int currentRow() const;
283
int currentColumn() const;
284
void updateSelection();
285
void repaintSelection();
287
void doRubberSelection(const QRect &old, const QRect &rubber);
288
void handleItemChange(Q3ListBoxItem *old, bool shift, bool control);
289
void selectRange(Q3ListBoxItem *from, Q3ListBoxItem *to, bool invert, bool includeFirst, bool clearSel = false);
291
void emitChangedSignal(bool);
293
int columnAt(int) const;
294
int rowAt(int) const;
296
Q3ListBoxPrivate * d;
298
static Q3ListBox * changedListBox;
302
class Q_COMPAT_EXPORT Q3ListBoxItem
305
Q3ListBoxItem(Q3ListBox* listbox = 0);
306
Q3ListBoxItem(Q3ListBox* listbox, Q3ListBoxItem *after);
307
virtual ~Q3ListBoxItem();
309
virtual QString text() const;
310
virtual const QPixmap *pixmap() const;
312
virtual int height(const Q3ListBox *) const;
313
virtual int width(const Q3ListBox *) const;
315
bool isSelected() const { return s; }
316
bool isCurrent() const;
318
bool selected() const { return isSelected(); }
319
bool current() const { return isCurrent(); }
321
Q3ListBox *listBox() const;
323
void setSelectable(bool b) { selectable = b; }
324
bool isSelectable() const { return selectable; }
326
Q3ListBoxItem *next() const;
327
Q3ListBoxItem *prev() const;
329
virtual int rtti() const;
333
virtual void paint(QPainter *) = 0;
334
virtual void setText(const QString &text) { txt = text; }
335
void setCustomHighlighting(bool);
338
Q_DISABLE_COPY(Q3ListBoxItem)
344
uint custom_highlight : 1;
346
Q3ListBoxItem * p, * n;
348
friend class Q3ListBox;
349
friend class Q3ListBoxPrivate;
350
friend class QComboBox;
351
friend class QComboBoxPopupItem;
355
class Q_COMPAT_EXPORT Q3ListBoxText : public Q3ListBoxItem
358
Q3ListBoxText(Q3ListBox* listbox, const QString & text=QString());
359
Q3ListBoxText(const QString & text=QString());
360
Q3ListBoxText(Q3ListBox* listbox, const QString & text, Q3ListBoxItem *after);
363
int height(const Q3ListBox *) const;
364
int width(const Q3ListBox *) const;
370
void paint(QPainter *);
373
Q_DISABLE_COPY(Q3ListBoxText)
377
class Q_COMPAT_EXPORT Q3ListBoxPixmap : public Q3ListBoxItem
380
Q3ListBoxPixmap(Q3ListBox* listbox, const QPixmap &);
381
Q3ListBoxPixmap(const QPixmap &);
382
Q3ListBoxPixmap(Q3ListBox* listbox, const QPixmap & pix, Q3ListBoxItem *after);
383
Q3ListBoxPixmap(Q3ListBox* listbox, const QPixmap &, const QString&);
384
Q3ListBoxPixmap(const QPixmap &, const QString&);
385
Q3ListBoxPixmap(Q3ListBox* listbox, const QPixmap & pix, const QString&, Q3ListBoxItem *after);
388
const QPixmap *pixmap() const { return ± }
390
int height(const Q3ListBox *) const;
391
int width(const Q3ListBox *) const;
397
void paint(QPainter *);
400
Q_DISABLE_COPY(Q3ListBoxPixmap)
405
#endif // QT_NO_LISTBOX