1 | /**********************************************************************
|
---|
2 | ** $Id: qlistbox.h 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Definition of QListBox widget class
|
---|
5 | **
|
---|
6 | ** Created : 941121
|
---|
7 | **
|
---|
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
---|
9 | **
|
---|
10 | ** This file is part of the widgets module of the Qt GUI Toolkit.
|
---|
11 | **
|
---|
12 | ** This file may be distributed under the terms of the Q Public License
|
---|
13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
---|
14 | ** LICENSE.QPL included in the packaging of this file.
|
---|
15 | **
|
---|
16 | ** This file may be distributed and/or modified under the terms of the
|
---|
17 | ** GNU General Public License version 2 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
19 | ** packaging of this file.
|
---|
20 | **
|
---|
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
22 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
23 | ** Agreement provided with the Software.
|
---|
24 | **
|
---|
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
27 | **
|
---|
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
29 | ** information about Qt Commercial License Agreements.
|
---|
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
32 | **
|
---|
33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
34 | ** not clear to you.
|
---|
35 | **
|
---|
36 | **********************************************************************/
|
---|
37 |
|
---|
38 | #ifndef QLISTBOX_H
|
---|
39 | #define QLISTBOX_H
|
---|
40 |
|
---|
41 | #ifndef QT_H
|
---|
42 | #include "qscrollview.h"
|
---|
43 | #include "qpixmap.h"
|
---|
44 | #endif // QT_H
|
---|
45 |
|
---|
46 | #ifndef QT_NO_LISTBOX
|
---|
47 |
|
---|
48 |
|
---|
49 | class QListBoxPrivate;
|
---|
50 | class QListBoxItem;
|
---|
51 | class QString;
|
---|
52 | class QStrList;
|
---|
53 | class QStringList;
|
---|
54 |
|
---|
55 |
|
---|
56 | class Q_EXPORT QListBox : public QScrollView
|
---|
57 | {
|
---|
58 | friend class QListBoxItem;
|
---|
59 | friend class QListBoxPrivate;
|
---|
60 |
|
---|
61 | Q_OBJECT
|
---|
62 | Q_ENUMS( SelectionMode LayoutMode )
|
---|
63 | Q_PROPERTY( uint count READ count )
|
---|
64 | Q_PROPERTY( int numItemsVisible READ numItemsVisible )
|
---|
65 | Q_PROPERTY( int currentItem READ currentItem WRITE setCurrentItem )
|
---|
66 | Q_PROPERTY( QString currentText READ currentText )
|
---|
67 | Q_PROPERTY( int topItem READ topItem WRITE setTopItem DESIGNABLE false )
|
---|
68 | Q_PROPERTY( SelectionMode selectionMode READ selectionMode WRITE setSelectionMode )
|
---|
69 | Q_PROPERTY( bool multiSelection READ isMultiSelection WRITE setMultiSelection DESIGNABLE false )
|
---|
70 | Q_PROPERTY( LayoutMode columnMode READ columnMode WRITE setColumnMode )
|
---|
71 | Q_PROPERTY( LayoutMode rowMode READ rowMode WRITE setRowMode )
|
---|
72 | Q_PROPERTY( int numColumns READ numColumns )
|
---|
73 | Q_PROPERTY( int numRows READ numRows )
|
---|
74 | Q_PROPERTY( bool variableWidth READ variableWidth WRITE setVariableWidth )
|
---|
75 | Q_PROPERTY( bool variableHeight READ variableHeight WRITE setVariableHeight )
|
---|
76 |
|
---|
77 | public:
|
---|
78 | QListBox( QWidget* parent=0, const char* name=0, WFlags f=0 );
|
---|
79 | ~QListBox();
|
---|
80 |
|
---|
81 | virtual void setFont( const QFont & );
|
---|
82 |
|
---|
83 | uint count() const;
|
---|
84 |
|
---|
85 | void insertStringList( const QStringList&, int index=-1 );
|
---|
86 | void insertStrList( const QStrList *, int index=-1 );
|
---|
87 | void insertStrList( const QStrList &, int index=-1 );
|
---|
88 | void insertStrList( const char **,
|
---|
89 | int numStrings=-1, int index=-1 );
|
---|
90 |
|
---|
91 | void insertItem( const QListBoxItem *, int index=-1 );
|
---|
92 | void insertItem( const QListBoxItem *, const QListBoxItem *after );
|
---|
93 | void insertItem( const QString &text, int index=-1 );
|
---|
94 | void insertItem( const QPixmap &pixmap, int index=-1 );
|
---|
95 | void insertItem( const QPixmap &pixmap, const QString &text, int index=-1 );
|
---|
96 |
|
---|
97 | void removeItem( int index );
|
---|
98 |
|
---|
99 | QString text( int index ) const;
|
---|
100 | const QPixmap *pixmap( int index ) const;
|
---|
101 |
|
---|
102 | void changeItem( const QListBoxItem *, int index );
|
---|
103 | void changeItem( const QString &text, int index );
|
---|
104 | void changeItem( const QPixmap &pixmap, int index );
|
---|
105 | void changeItem( const QPixmap &pixmap, const QString &text, int index );
|
---|
106 |
|
---|
107 | void takeItem( const QListBoxItem * );
|
---|
108 |
|
---|
109 | int numItemsVisible() const;
|
---|
110 |
|
---|
111 | int currentItem() const;
|
---|
112 | QString currentText() const { return text(currentItem()); }
|
---|
113 | virtual void setCurrentItem( int index );
|
---|
114 | virtual void setCurrentItem( QListBoxItem * );
|
---|
115 | void centerCurrentItem() { ensureCurrentVisible(); }
|
---|
116 | int topItem() const;
|
---|
117 | virtual void setTopItem( int index );
|
---|
118 | virtual void setBottomItem( int index );
|
---|
119 |
|
---|
120 | long maxItemWidth() const;
|
---|
121 |
|
---|
122 | enum SelectionMode { Single, Multi, Extended, NoSelection };
|
---|
123 | virtual void setSelectionMode( SelectionMode );
|
---|
124 | SelectionMode selectionMode() const;
|
---|
125 |
|
---|
126 | void setMultiSelection( bool multi );
|
---|
127 | bool isMultiSelection() const;
|
---|
128 |
|
---|
129 | virtual void setSelected( QListBoxItem *, bool );
|
---|
130 | void setSelected( int, bool );
|
---|
131 | bool isSelected( int ) const;
|
---|
132 | bool isSelected( const QListBoxItem * ) const;
|
---|
133 | QListBoxItem* selectedItem() const;
|
---|
134 |
|
---|
135 | QSize sizeHint() const;
|
---|
136 | QSize minimumSizeHint() const;
|
---|
137 |
|
---|
138 | QListBoxItem *item( int index ) const;
|
---|
139 | int index( const QListBoxItem * ) const;
|
---|
140 | QListBoxItem *findItem( const QString &text, ComparisonFlags compare = BeginsWith ) const;
|
---|
141 |
|
---|
142 | void triggerUpdate( bool doLayout );
|
---|
143 |
|
---|
144 | bool itemVisible( int index );
|
---|
145 | bool itemVisible( const QListBoxItem * );
|
---|
146 |
|
---|
147 | enum LayoutMode { FixedNumber,
|
---|
148 | FitToWidth, FitToHeight = FitToWidth,
|
---|
149 | Variable };
|
---|
150 | virtual void setColumnMode( LayoutMode );
|
---|
151 | virtual void setColumnMode( int );
|
---|
152 | virtual void setRowMode( LayoutMode );
|
---|
153 | virtual void setRowMode( int );
|
---|
154 |
|
---|
155 | LayoutMode columnMode() const;
|
---|
156 | LayoutMode rowMode() const;
|
---|
157 |
|
---|
158 | int numColumns() const;
|
---|
159 | int numRows() const;
|
---|
160 |
|
---|
161 | bool variableWidth() const;
|
---|
162 | virtual void setVariableWidth( bool );
|
---|
163 |
|
---|
164 | bool variableHeight() const;
|
---|
165 | virtual void setVariableHeight( bool );
|
---|
166 |
|
---|
167 | void viewportPaintEvent( QPaintEvent * );
|
---|
168 |
|
---|
169 | #ifndef QT_NO_COMPAT
|
---|
170 | bool dragSelect() const { return TRUE; }
|
---|
171 | void setDragSelect( bool ) {}
|
---|
172 | bool autoScroll() const { return TRUE; }
|
---|
173 | void setAutoScroll( bool ) {}
|
---|
174 | bool autoScrollBar() const { return vScrollBarMode() == Auto; }
|
---|
175 | void setAutoScrollBar( bool enable ) { setVScrollBarMode( enable ? Auto : AlwaysOff ); }
|
---|
176 | bool scrollBar() const { return vScrollBarMode() != AlwaysOff; }
|
---|
177 | void setScrollBar( bool enable ) { setVScrollBarMode( enable ? AlwaysOn : AlwaysOff ); }
|
---|
178 | bool autoBottomScrollBar() const { return hScrollBarMode() == Auto; }
|
---|
179 | void setAutoBottomScrollBar( bool enable ) { setHScrollBarMode( enable ? Auto : AlwaysOff ); }
|
---|
180 | bool bottomScrollBar() const { return hScrollBarMode() != AlwaysOff; }
|
---|
181 | void setBottomScrollBar( bool enable ) { setHScrollBarMode( enable ? AlwaysOn : AlwaysOff ); }
|
---|
182 | bool smoothScrolling() const { return FALSE; }
|
---|
183 | void setSmoothScrolling( bool ) {}
|
---|
184 | bool autoUpdate() const { return TRUE; }
|
---|
185 | void setAutoUpdate( bool ) {}
|
---|
186 | void setFixedVisibleLines( int lines ) { setRowMode( lines ); }
|
---|
187 | int inSort( const QListBoxItem * );
|
---|
188 | int inSort( const QString& text );
|
---|
189 | int cellHeight( int i ) const { return itemHeight(i); }
|
---|
190 | int cellHeight() const { return itemHeight(); }
|
---|
191 | int cellWidth() const { return maxItemWidth(); }
|
---|
192 | int cellWidth(int i) const { Q_ASSERT(i==0); Q_UNUSED(i) return maxItemWidth(); }
|
---|
193 | int numCols() const { return numColumns(); }
|
---|
194 | #endif
|
---|
195 |
|
---|
196 | int itemHeight( int index = 0 ) const;
|
---|
197 | QListBoxItem * itemAt( const QPoint & ) const;
|
---|
198 |
|
---|
199 | QRect itemRect( QListBoxItem *item ) const;
|
---|
200 |
|
---|
201 | QListBoxItem *firstItem() const;
|
---|
202 |
|
---|
203 | void sort( bool ascending = TRUE );
|
---|
204 |
|
---|
205 | public slots:
|
---|
206 | void clear();
|
---|
207 | virtual void ensureCurrentVisible();
|
---|
208 | virtual void clearSelection();
|
---|
209 | virtual void selectAll( bool select );
|
---|
210 | virtual void invertSelection();
|
---|
211 |
|
---|
212 | signals:
|
---|
213 | void highlighted( int index );
|
---|
214 | void selected( int index );
|
---|
215 | void highlighted( const QString &);
|
---|
216 | void selected( const QString &);
|
---|
217 | void highlighted( QListBoxItem * );
|
---|
218 | void selected( QListBoxItem * );
|
---|
219 |
|
---|
220 | void selectionChanged();
|
---|
221 | void selectionChanged( QListBoxItem * );
|
---|
222 | void currentChanged( QListBoxItem * );
|
---|
223 | void clicked( QListBoxItem * );
|
---|
224 | void clicked( QListBoxItem *, const QPoint & );
|
---|
225 | void pressed( QListBoxItem * );
|
---|
226 | void pressed( QListBoxItem *, const QPoint & );
|
---|
227 |
|
---|
228 | void doubleClicked( QListBoxItem * );
|
---|
229 | void returnPressed( QListBoxItem * );
|
---|
230 | void rightButtonClicked( QListBoxItem *, const QPoint & );
|
---|
231 | void rightButtonPressed( QListBoxItem *, const QPoint & );
|
---|
232 | void mouseButtonPressed( int, QListBoxItem*, const QPoint& );
|
---|
233 | void mouseButtonClicked( int, QListBoxItem*, const QPoint& );
|
---|
234 |
|
---|
235 | void contextMenuRequested( QListBoxItem *, const QPoint & );
|
---|
236 |
|
---|
237 | void onItem( QListBoxItem *item );
|
---|
238 | void onViewport();
|
---|
239 |
|
---|
240 | protected:
|
---|
241 | void mousePressEvent( QMouseEvent * );
|
---|
242 | void mouseReleaseEvent( QMouseEvent * );
|
---|
243 | void mouseDoubleClickEvent( QMouseEvent * );
|
---|
244 | void mouseMoveEvent( QMouseEvent * );
|
---|
245 | void contentsContextMenuEvent( QContextMenuEvent * );
|
---|
246 |
|
---|
247 | void keyPressEvent( QKeyEvent *e );
|
---|
248 | void focusInEvent( QFocusEvent *e );
|
---|
249 | void focusOutEvent( QFocusEvent *e );
|
---|
250 | void resizeEvent( QResizeEvent * );
|
---|
251 | void showEvent( QShowEvent * );
|
---|
252 |
|
---|
253 | bool eventFilter( QObject *o, QEvent *e );
|
---|
254 |
|
---|
255 | void updateItem( int index );
|
---|
256 | void updateItem( QListBoxItem * );
|
---|
257 |
|
---|
258 | #ifndef QT_NO_COMPAT
|
---|
259 | void updateCellWidth() { }
|
---|
260 | int totalWidth() const { return contentsWidth(); }
|
---|
261 | int totalHeight() const { return contentsHeight(); }
|
---|
262 | #endif
|
---|
263 |
|
---|
264 | virtual void paintCell( QPainter *, int row, int col );
|
---|
265 |
|
---|
266 | void toggleCurrentItem();
|
---|
267 | bool isRubberSelecting() const;
|
---|
268 |
|
---|
269 | void doLayout() const;
|
---|
270 |
|
---|
271 | void windowActivationChange( bool );
|
---|
272 |
|
---|
273 | #ifndef QT_NO_COMPAT
|
---|
274 | bool itemYPos( int index, int *yPos ) const;
|
---|
275 | int findItem( int yPos ) const { return index(itemAt(QPoint(0,yPos)) ); }
|
---|
276 | #endif
|
---|
277 |
|
---|
278 | protected slots:
|
---|
279 | void clearInputString();
|
---|
280 |
|
---|
281 | private slots:
|
---|
282 | void refreshSlot();
|
---|
283 | void doAutoScroll();
|
---|
284 | void adjustItems();
|
---|
285 |
|
---|
286 | private:
|
---|
287 | void mousePressEventEx( QMouseEvent * );
|
---|
288 | void tryGeometry( int, int ) const;
|
---|
289 | int currentRow() const;
|
---|
290 | int currentColumn() const;
|
---|
291 | void updateSelection();
|
---|
292 | void repaintSelection();
|
---|
293 | void drawRubber();
|
---|
294 | void doRubberSelection( const QRect &old, const QRect &rubber );
|
---|
295 | void handleItemChange( QListBoxItem *old, bool shift, bool control );
|
---|
296 | void selectRange( QListBoxItem *from, QListBoxItem *to, bool invert, bool includeFirst, bool clearSel = FALSE );
|
---|
297 |
|
---|
298 | void emitChangedSignal( bool );
|
---|
299 |
|
---|
300 | int columnAt( int ) const;
|
---|
301 | int rowAt( int ) const;
|
---|
302 |
|
---|
303 | QListBoxPrivate * d;
|
---|
304 |
|
---|
305 | static QListBox * changedListBox;
|
---|
306 |
|
---|
307 | private: // Disabled copy constructor and operator=
|
---|
308 | #if defined(Q_DISABLE_COPY)
|
---|
309 | QListBox( const QListBox & );
|
---|
310 | QListBox &operator=( const QListBox & );
|
---|
311 | #endif
|
---|
312 | };
|
---|
313 |
|
---|
314 |
|
---|
315 | class Q_EXPORT QListBoxItem
|
---|
316 | {
|
---|
317 | public:
|
---|
318 | QListBoxItem( QListBox* listbox = 0 );
|
---|
319 | QListBoxItem( QListBox* listbox, QListBoxItem *after );
|
---|
320 | virtual ~QListBoxItem();
|
---|
321 |
|
---|
322 | virtual QString text() const;
|
---|
323 | virtual const QPixmap *pixmap() const;
|
---|
324 |
|
---|
325 | virtual int height( const QListBox * ) const;
|
---|
326 | virtual int width( const QListBox * ) const;
|
---|
327 |
|
---|
328 | bool isSelected() const { return s; }
|
---|
329 | bool isCurrent() const;
|
---|
330 |
|
---|
331 | #ifndef QT_NO_COMPAT
|
---|
332 | bool selected() const { return isSelected(); }
|
---|
333 | bool current() const { return isCurrent(); }
|
---|
334 | #endif
|
---|
335 |
|
---|
336 | QListBox *listBox() const;
|
---|
337 |
|
---|
338 | void setSelectable( bool b );
|
---|
339 | bool isSelectable() const;
|
---|
340 |
|
---|
341 | QListBoxItem *next() const;
|
---|
342 | QListBoxItem *prev() const;
|
---|
343 |
|
---|
344 | virtual int rtti() const;
|
---|
345 | static int RTTI;
|
---|
346 |
|
---|
347 | protected:
|
---|
348 | virtual void paint( QPainter * ) = 0;
|
---|
349 | virtual void setText( const QString &text ) { txt = text; }
|
---|
350 | void setCustomHighlighting( bool );
|
---|
351 |
|
---|
352 | private:
|
---|
353 | QString txt;
|
---|
354 | uint s:1;
|
---|
355 | uint dirty:1;
|
---|
356 | uint custom_highlight : 1;
|
---|
357 | int x, y;
|
---|
358 | QListBoxItem * p, * n;
|
---|
359 | QListBox* lbox;
|
---|
360 | friend class QListBox;
|
---|
361 | friend class QListBoxPrivate;
|
---|
362 | friend class QComboBox;
|
---|
363 | friend class QComboBoxPopupItem;
|
---|
364 |
|
---|
365 | private: // Disabled copy constructor and operator=
|
---|
366 | #if defined(Q_DISABLE_COPY)
|
---|
367 | QListBoxItem( const QListBoxItem & );
|
---|
368 | QListBoxItem &operator=( const QListBoxItem & );
|
---|
369 | #endif
|
---|
370 | };
|
---|
371 |
|
---|
372 |
|
---|
373 | class Q_EXPORT QListBoxText : public QListBoxItem
|
---|
374 | {
|
---|
375 | public:
|
---|
376 | QListBoxText( QListBox* listbox, const QString & text=QString::null );
|
---|
377 | QListBoxText( const QString & text=QString::null );
|
---|
378 | QListBoxText( QListBox* listbox, const QString & text, QListBoxItem *after );
|
---|
379 | ~QListBoxText();
|
---|
380 |
|
---|
381 | int height( const QListBox * ) const;
|
---|
382 | int width( const QListBox * ) const;
|
---|
383 |
|
---|
384 | int rtti() const;
|
---|
385 | static int RTTI;
|
---|
386 |
|
---|
387 | protected:
|
---|
388 | void paint( QPainter * );
|
---|
389 |
|
---|
390 | private: // Disabled copy constructor and operator=
|
---|
391 | #if defined(Q_DISABLE_COPY)
|
---|
392 | QListBoxText( const QListBoxText & );
|
---|
393 | QListBoxText &operator=( const QListBoxText & );
|
---|
394 | #endif
|
---|
395 | };
|
---|
396 |
|
---|
397 |
|
---|
398 | class Q_EXPORT QListBoxPixmap : public QListBoxItem
|
---|
399 | {
|
---|
400 | public:
|
---|
401 | QListBoxPixmap( QListBox* listbox, const QPixmap & );
|
---|
402 | QListBoxPixmap( const QPixmap & );
|
---|
403 | QListBoxPixmap( QListBox* listbox, const QPixmap & pix, QListBoxItem *after );
|
---|
404 | QListBoxPixmap( QListBox* listbox, const QPixmap &, const QString& );
|
---|
405 | QListBoxPixmap( const QPixmap &, const QString& );
|
---|
406 | QListBoxPixmap( QListBox* listbox, const QPixmap & pix, const QString&, QListBoxItem *after );
|
---|
407 | ~QListBoxPixmap();
|
---|
408 |
|
---|
409 | const QPixmap *pixmap() const { return ± }
|
---|
410 |
|
---|
411 | int height( const QListBox * ) const;
|
---|
412 | int width( const QListBox * ) const;
|
---|
413 |
|
---|
414 | int rtti() const;
|
---|
415 | static int RTTI;
|
---|
416 |
|
---|
417 | protected:
|
---|
418 | void paint( QPainter * );
|
---|
419 |
|
---|
420 | private:
|
---|
421 | QPixmap pm;
|
---|
422 | private: // Disabled copy constructor and operator=
|
---|
423 | #if defined(Q_DISABLE_COPY)
|
---|
424 | QListBoxPixmap( const QListBoxPixmap & );
|
---|
425 | QListBoxPixmap &operator=( const QListBoxPixmap & );
|
---|
426 | #endif
|
---|
427 | };
|
---|
428 |
|
---|
429 |
|
---|
430 | #endif // QT_NO_LISTBOX
|
---|
431 |
|
---|
432 | #endif // QLISTBOX_H
|
---|