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

« back to all changes in this revision

Viewing changes to src/qt3support/itemviews/q3listbox.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 Qt 3 compatibility classes 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 Q3LISTBOX_H
 
30
#define Q3LISTBOX_H
 
31
 
 
32
#include "Qt3Support/q3scrollview.h"
 
33
#include "QtGui/qpixmap.h"
 
34
 
 
35
#ifndef QT_NO_LISTBOX
 
36
 
 
37
class Q3ListBoxPrivate;
 
38
class Q3ListBoxItem;
 
39
class QString;
 
40
class QStringList;
 
41
 
 
42
 
 
43
class Q_COMPAT_EXPORT Q3ListBox : public Q3ScrollView
 
44
{
 
45
    friend class Q3ListBoxItem;
 
46
    friend class Q3ListBoxPrivate;
 
47
 
 
48
    Q_OBJECT
 
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)
 
63
 
 
64
public:
 
65
    Q3ListBox(QWidget* parent=0, const char* name=0, Qt::WFlags f=0 );
 
66
    ~Q3ListBox();
 
67
 
 
68
    uint count() const;
 
69
 
 
70
    void insertStringList(const QStringList&, int index=-1);
 
71
// ### fix before Qt 4.0
 
72
#if 0
 
73
    void insertStrList(const QStrList *, int index=-1);
 
74
    void insertStrList(const QStrList &, int index=-1);
 
75
#endif
 
76
    void insertStrList(const char **,
 
77
                        int numStrings=-1, int index=-1);
 
78
 
 
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);
 
84
 
 
85
    void removeItem(int index);
 
86
 
 
87
    QString text(int index)        const;
 
88
    const QPixmap *pixmap(int index)        const;
 
89
 
 
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);
 
94
 
 
95
    void takeItem(const Q3ListBoxItem *);
 
96
 
 
97
    int numItemsVisible() const;
 
98
 
 
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(); }
 
104
    int topItem() const;
 
105
    virtual void setTopItem(int index);
 
106
    virtual void setBottomItem(int index);
 
107
 
 
108
    long maxItemWidth() const;
 
109
 
 
110
    enum SelectionMode { Single, Multi, Extended, NoSelection };
 
111
    virtual void setSelectionMode(SelectionMode);
 
112
    SelectionMode selectionMode() const;
 
113
 
 
114
    void setMultiSelection(bool multi);
 
115
    bool isMultiSelection() const;
 
116
 
 
117
    QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
 
118
 
 
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;
 
124
 
 
125
    QSize sizeHint() const;
 
126
    QSize        minimumSizeHint() const;
 
127
 
 
128
    Q3ListBoxItem *item(int index) const;
 
129
    int index(const Q3ListBoxItem *) const;
 
130
 
 
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
 
137
    };
 
138
    typedef uint ComparisonFlags;
 
139
    Q3ListBoxItem *findItem(const QString &text, ComparisonFlags compare = BeginsWith) const;
 
140
 
 
141
    void triggerUpdate(bool doLayout);
 
142
 
 
143
    bool itemVisible(int index);
 
144
    bool itemVisible(const Q3ListBoxItem *);
 
145
 
 
146
    enum LayoutMode { FixedNumber,
 
147
                      FitToWidth, FitToHeight = FitToWidth,
 
148
                      Variable };
 
149
    virtual void setColumnMode(LayoutMode);
 
150
    virtual void setColumnMode(int);
 
151
    virtual void setRowMode(LayoutMode);
 
152
    virtual void setRowMode(int);
 
153
 
 
154
    LayoutMode columnMode() const;
 
155
    LayoutMode rowMode() const;
 
156
 
 
157
    int numColumns() const;
 
158
    int numRows() const;
 
159
 
 
160
    bool variableWidth() const;
 
161
    virtual void setVariableWidth(bool);
 
162
 
 
163
    bool variableHeight() const;
 
164
    virtual void setVariableHeight(bool);
 
165
 
 
166
    void viewportPaintEvent(QPaintEvent *);
 
167
 
 
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(); }
 
192
 
 
193
    int itemHeight(int index = 0) const;
 
194
    Q3ListBoxItem * itemAt(const QPoint &) const;
 
195
 
 
196
    QRect itemRect(Q3ListBoxItem *item) const;
 
197
 
 
198
    Q3ListBoxItem *firstItem() const;
 
199
 
 
200
    void sort(bool ascending = true);
 
201
 
 
202
public slots:
 
203
    void clear();
 
204
    virtual void ensureCurrentVisible();
 
205
    virtual void clearSelection();
 
206
    virtual void selectAll(bool select);
 
207
    virtual void invertSelection();
 
208
 
 
209
signals:
 
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 *);
 
216
 
 
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 &);
 
224
 
 
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&);
 
231
 
 
232
    void contextMenuRequested(Q3ListBoxItem *, const QPoint &);
 
233
 
 
234
    void onItem(Q3ListBoxItem *item);
 
235
    void onViewport();
 
236
 
 
237
protected:
 
238
    void changeEvent(QEvent *);
 
239
    void mousePressEvent(QMouseEvent *);
 
240
    void mouseReleaseEvent(QMouseEvent *);
 
241
    void mouseDoubleClickEvent(QMouseEvent *);
 
242
    void mouseMoveEvent(QMouseEvent *);
 
243
    void contentsContextMenuEvent(QContextMenuEvent *);
 
244
 
 
245
    void keyPressEvent(QKeyEvent *e);
 
246
    void focusInEvent(QFocusEvent *e);
 
247
    void focusOutEvent(QFocusEvent *e);
 
248
    void resizeEvent(QResizeEvent *);
 
249
    void showEvent(QShowEvent *);
 
250
 
 
251
    bool eventFilter(QObject *o, QEvent *e);
 
252
 
 
253
    void updateItem(int index);
 
254
    void updateItem(Q3ListBoxItem *);
 
255
 
 
256
    void updateCellWidth() { }
 
257
    int totalWidth() const { return contentsWidth(); }
 
258
    int totalHeight() const { return contentsHeight(); }
 
259
 
 
260
    virtual void paintCell(QPainter *, int row, int col);
 
261
 
 
262
    void toggleCurrentItem();
 
263
    bool isRubberSelecting() const;
 
264
 
 
265
    void doLayout() const;
 
266
 
 
267
    int findItem(int yPos) const { return index(itemAt(QPoint(0,yPos))); }
 
268
 
 
269
protected slots:
 
270
    void clearInputString();
 
271
 
 
272
private slots:
 
273
    void refreshSlot();
 
274
    void doAutoScroll();
 
275
    void adjustItems();
 
276
 
 
277
private:
 
278
    Q_DISABLE_COPY(Q3ListBox)
 
279
 
 
280
    void mousePressEventEx(QMouseEvent *);
 
281
    void tryGeometry(int, int) const;
 
282
    int currentRow() const;
 
283
    int currentColumn() const;
 
284
    void updateSelection();
 
285
    void repaintSelection();
 
286
    void drawRubber();
 
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);
 
290
 
 
291
    void emitChangedSignal(bool);
 
292
 
 
293
    int columnAt(int) const;
 
294
    int rowAt(int) const;
 
295
 
 
296
    Q3ListBoxPrivate * d;
 
297
 
 
298
    static Q3ListBox * changedListBox;
 
299
};
 
300
 
 
301
 
 
302
class Q_COMPAT_EXPORT Q3ListBoxItem
 
303
{
 
304
public:
 
305
    Q3ListBoxItem(Q3ListBox* listbox = 0);
 
306
    Q3ListBoxItem(Q3ListBox* listbox, Q3ListBoxItem *after);
 
307
    virtual ~Q3ListBoxItem();
 
308
 
 
309
    virtual QString text() const;
 
310
    virtual const QPixmap *pixmap() const;
 
311
 
 
312
    virtual int         height(const Q3ListBox *) const;
 
313
    virtual int         width(const Q3ListBox *)  const;
 
314
 
 
315
    bool isSelected() const { return s; }
 
316
    bool isCurrent() const;
 
317
 
 
318
    bool selected() const { return isSelected(); }
 
319
    bool current() const { return isCurrent(); }
 
320
 
 
321
    Q3ListBox *listBox() const;
 
322
 
 
323
    void setSelectable(bool b) { selectable = b; }
 
324
    bool isSelectable() const { return selectable; }
 
325
 
 
326
    Q3ListBoxItem *next() const;
 
327
    Q3ListBoxItem *prev() const;
 
328
 
 
329
    virtual int rtti() const;
 
330
    enum { RTTI = 0 };
 
331
 
 
332
protected:
 
333
    virtual void paint(QPainter *) = 0;
 
334
    virtual void setText(const QString &text) { txt = text; }
 
335
    void setCustomHighlighting(bool);
 
336
 
 
337
private:
 
338
    Q_DISABLE_COPY(Q3ListBoxItem)
 
339
 
 
340
    QString txt;
 
341
    uint selectable : 1;
 
342
    uint s : 1;
 
343
    uint dirty:1;
 
344
    uint custom_highlight : 1;
 
345
    uint unused : 28;
 
346
    Q3ListBoxItem * p, * n;
 
347
    Q3ListBox* lbox;
 
348
    friend class Q3ListBox;
 
349
    friend class Q3ListBoxPrivate;
 
350
    friend class QComboBox;
 
351
    friend class QComboBoxPopupItem;
 
352
};
 
353
 
 
354
 
 
355
class Q_COMPAT_EXPORT Q3ListBoxText : public Q3ListBoxItem
 
356
{
 
357
public:
 
358
    Q3ListBoxText(Q3ListBox* listbox, const QString & text=QString());
 
359
    Q3ListBoxText(const QString & text=QString());
 
360
    Q3ListBoxText(Q3ListBox* listbox, const QString & text, Q3ListBoxItem *after);
 
361
   ~Q3ListBoxText();
 
362
 
 
363
    int         height(const Q3ListBox *) const;
 
364
    int         width(const Q3ListBox *)  const;
 
365
 
 
366
    int rtti() const;
 
367
    enum { RTTI = 1 };
 
368
 
 
369
protected:
 
370
    void  paint(QPainter *);
 
371
 
 
372
private:
 
373
    Q_DISABLE_COPY(Q3ListBoxText)
 
374
};
 
375
 
 
376
 
 
377
class Q_COMPAT_EXPORT Q3ListBoxPixmap : public Q3ListBoxItem
 
378
{
 
379
public:
 
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);
 
386
   ~Q3ListBoxPixmap();
 
387
 
 
388
    const QPixmap *pixmap() const { return ± }
 
389
 
 
390
    int         height(const Q3ListBox *) const;
 
391
    int         width(const Q3ListBox *)  const;
 
392
 
 
393
    int rtti() const;
 
394
    enum { RTTI = 2 };
 
395
 
 
396
protected:
 
397
    void paint(QPainter *);
 
398
 
 
399
private:
 
400
    Q_DISABLE_COPY(Q3ListBoxPixmap)
 
401
 
 
402
    QPixmap pm;
 
403
};
 
404
 
 
405
#endif // QT_NO_LISTBOX
 
406
 
 
407
#endif // QLISTBOX_H