Eneboo - Documentación para desarrolladores
src/qt/include/qlistbox.h
Ir a la documentación de este archivo.
00001 /**********************************************************************
00002 ** $Id: qt/qlistbox.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of QListBox widget class
00005 **
00006 ** Created : 941121
00007 **
00008 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
00009 **
00010 ** This file is part of the widgets module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech ASA of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QLISTBOX_H
00039 #define QLISTBOX_H
00040 
00041 #ifndef QT_H
00042 #include "qscrollview.h"
00043 #include "qpixmap.h"
00044 #endif // QT_H
00045 
00046 #ifndef QT_NO_LISTBOX
00047 
00048 
00049 class QListBoxPrivate;
00050 class QListBoxItem;
00051 class QString;
00052 class QStrList;
00053 class QStringList;
00054 
00055 
00056 class Q_EXPORT QListBox : public QScrollView
00057 {
00058     friend class QListBoxItem;
00059     friend class QListBoxPrivate;
00060 
00061     Q_OBJECT
00062     Q_ENUMS( SelectionMode LayoutMode )
00063     Q_PROPERTY( uint count READ count )
00064     Q_PROPERTY( int numItemsVisible READ numItemsVisible )
00065     Q_PROPERTY( int currentItem READ currentItem WRITE setCurrentItem )
00066     Q_PROPERTY( QString currentText READ currentText )
00067     Q_PROPERTY( int topItem READ topItem WRITE setTopItem DESIGNABLE false )
00068     Q_PROPERTY( SelectionMode selectionMode READ selectionMode WRITE setSelectionMode )
00069     Q_PROPERTY( bool multiSelection READ isMultiSelection WRITE setMultiSelection DESIGNABLE false )
00070     Q_PROPERTY( LayoutMode columnMode READ columnMode WRITE setColumnMode )
00071     Q_PROPERTY( LayoutMode rowMode READ rowMode WRITE setRowMode )
00072     Q_PROPERTY( int numColumns READ numColumns )
00073     Q_PROPERTY( int numRows READ numRows )
00074     Q_PROPERTY( bool variableWidth READ variableWidth WRITE setVariableWidth )
00075     Q_PROPERTY( bool variableHeight READ variableHeight WRITE setVariableHeight )
00076 
00077 public:
00078     QListBox( QWidget* parent=0, const char* name=0, WFlags f=0  );
00079     ~QListBox();
00080 
00081     virtual void setFont( const QFont & );
00082 
00083     uint count() const;
00084 
00085     void insertStringList( const QStringList&, int index=-1 );
00086     void insertStrList( const QStrList *, int index=-1 );
00087     void insertStrList( const QStrList &, int index=-1 );
00088     void insertStrList( const char **,
00089                         int numStrings=-1, int index=-1 );
00090 
00091     void insertItem( const QListBoxItem *, int index=-1 );
00092     void insertItem( const QListBoxItem *, const QListBoxItem *after );
00093     void insertItem( const QString &text, int index=-1 );
00094     void insertItem( const QPixmap &pixmap, int index=-1 );
00095     void insertItem( const QPixmap &pixmap, const QString &text, int index=-1 );
00096 
00097     void removeItem( int index );
00098 
00099     QString text( int index )   const;
00100     const QPixmap *pixmap( int index )  const;
00101 
00102     void changeItem( const QListBoxItem *, int index );
00103     void changeItem( const QString &text, int index );
00104     void changeItem( const QPixmap &pixmap, int index );
00105     void changeItem( const QPixmap &pixmap, const QString &text, int index );
00106 
00107     void takeItem( const QListBoxItem * );
00108 
00109     int numItemsVisible() const;
00110 
00111     int currentItem() const;
00112     QString currentText() const { return text(currentItem()); }
00113     virtual void setCurrentItem( int index );
00114     virtual void setCurrentItem( QListBoxItem * );
00115     void centerCurrentItem() { ensureCurrentVisible(); }
00116     int topItem() const;
00117     virtual void setTopItem( int index );
00118     virtual void setBottomItem( int index );
00119 
00120     long maxItemWidth() const;
00121 
00122     enum SelectionMode { Single, Multi, Extended, NoSelection };
00123     virtual void setSelectionMode( SelectionMode );
00124     SelectionMode selectionMode() const;
00125 
00126     void setMultiSelection( bool multi );
00127     bool isMultiSelection() const;
00128 
00129     virtual void setSelected( QListBoxItem *, bool );
00130     void setSelected( int, bool );
00131     bool isSelected( int ) const;
00132     bool isSelected( const QListBoxItem * ) const;
00133     QListBoxItem* selectedItem() const;
00134 
00135     QSize sizeHint() const;
00136     QSize       minimumSizeHint() const;
00137 
00138     QListBoxItem *item( int index ) const;
00139     int index( const QListBoxItem * ) const;
00140     QListBoxItem *findItem( const QString &text, ComparisonFlags compare = BeginsWith ) const;
00141 
00142     void triggerUpdate( bool doLayout );
00143 
00144     bool itemVisible( int index );
00145     bool itemVisible( const QListBoxItem * );
00146 
00147     enum LayoutMode { FixedNumber,
00148                       FitToWidth, FitToHeight = FitToWidth,
00149                       Variable };
00150     virtual void setColumnMode( LayoutMode );
00151     virtual void setColumnMode( int );
00152     virtual void setRowMode( LayoutMode );
00153     virtual void setRowMode( int );
00154 
00155     LayoutMode columnMode() const;
00156     LayoutMode rowMode() const;
00157 
00158     int numColumns() const;
00159     int numRows() const;
00160 
00161     bool variableWidth() const;
00162     virtual void setVariableWidth( bool );
00163 
00164     bool variableHeight() const;
00165     virtual void setVariableHeight( bool );
00166 
00167     void viewportPaintEvent( QPaintEvent * );
00168 
00169 #ifndef QT_NO_COMPAT
00170     bool dragSelect() const { return TRUE; }
00171     void setDragSelect( bool ) {}
00172     bool autoScroll() const { return TRUE; }
00173     void setAutoScroll( bool ) {}
00174     bool autoScrollBar() const { return vScrollBarMode() == Auto; }
00175     void setAutoScrollBar( bool enable ) { setVScrollBarMode( enable ? Auto : AlwaysOff ); }
00176     bool scrollBar() const { return vScrollBarMode() != AlwaysOff; }
00177     void setScrollBar( bool enable ) { setVScrollBarMode( enable ? AlwaysOn : AlwaysOff ); }
00178     bool autoBottomScrollBar() const { return hScrollBarMode() == Auto; }
00179     void setAutoBottomScrollBar( bool enable ) { setHScrollBarMode( enable ? Auto : AlwaysOff ); }
00180     bool bottomScrollBar() const { return hScrollBarMode() != AlwaysOff; }
00181     void setBottomScrollBar( bool enable ) { setHScrollBarMode( enable ? AlwaysOn : AlwaysOff ); }
00182     bool smoothScrolling() const { return FALSE; }
00183     void setSmoothScrolling( bool ) {}
00184     bool autoUpdate() const { return TRUE; }
00185     void setAutoUpdate( bool ) {}
00186     void setFixedVisibleLines( int lines ) { setRowMode( lines ); }
00187     int inSort( const QListBoxItem * );
00188     int inSort( const QString& text );
00189     int cellHeight( int i ) const { return itemHeight(i); }
00190     int cellHeight() const { return itemHeight(); }
00191     int cellWidth() const { return maxItemWidth(); }
00192     int cellWidth(int i) const { Q_ASSERT(i==0); Q_UNUSED(i) return maxItemWidth(); }
00193     int numCols() const { return numColumns(); }
00194 #endif
00195 
00196     int itemHeight( int index = 0 ) const;
00197     QListBoxItem * itemAt( const QPoint & ) const;
00198 
00199     QRect itemRect( QListBoxItem *item ) const;
00200 
00201     QListBoxItem *firstItem() const;
00202 
00203     void sort( bool ascending = TRUE );
00204 
00205 public slots:
00206     void clear();
00207     virtual void ensureCurrentVisible();
00208     virtual void clearSelection();
00209     virtual void selectAll( bool select );
00210     virtual void invertSelection();
00211 
00212 signals:
00213     void highlighted( int index );
00214     void selected( int index );
00215     void highlighted( const QString &);
00216     void selected( const QString &);
00217     void highlighted( QListBoxItem * );
00218     void selected( QListBoxItem * );
00219 
00220     void selectionChanged();
00221     void selectionChanged( QListBoxItem * );
00222     void currentChanged( QListBoxItem * );
00223     void clicked( QListBoxItem * );
00224     void clicked( QListBoxItem *, const QPoint & );
00225     void pressed( QListBoxItem * );
00226     void pressed( QListBoxItem *, const QPoint & );
00227 
00228     void doubleClicked( QListBoxItem * );
00229     void returnPressed( QListBoxItem * );
00230     void rightButtonClicked( QListBoxItem *, const QPoint & );
00231     void rightButtonPressed( QListBoxItem *, const QPoint & );
00232     void mouseButtonPressed( int, QListBoxItem*, const QPoint& );
00233     void mouseButtonClicked( int, QListBoxItem*, const QPoint& );
00234 
00235     void contextMenuRequested( QListBoxItem *, const QPoint & );
00236 
00237     void onItem( QListBoxItem *item );
00238     void onViewport();
00239 
00240 protected:
00241     void mousePressEvent( QMouseEvent * );
00242     void mouseReleaseEvent( QMouseEvent * );
00243     void mouseDoubleClickEvent( QMouseEvent * );
00244     void mouseMoveEvent( QMouseEvent * );
00245     void contentsContextMenuEvent( QContextMenuEvent * );
00246 
00247     void keyPressEvent( QKeyEvent *e );
00248     void focusInEvent( QFocusEvent *e );
00249     void focusOutEvent( QFocusEvent *e );
00250     void resizeEvent( QResizeEvent * );
00251     void showEvent( QShowEvent * );
00252 
00253     bool eventFilter( QObject *o, QEvent *e );
00254 
00255     void updateItem( int index );
00256     void updateItem( QListBoxItem * );
00257 
00258 #ifndef QT_NO_COMPAT
00259     void updateCellWidth() { }
00260     int totalWidth() const { return contentsWidth(); }
00261     int totalHeight() const { return contentsHeight(); }
00262 #endif
00263 
00264     virtual void paintCell( QPainter *, int row, int col );
00265 
00266     void toggleCurrentItem();
00267     bool isRubberSelecting() const;
00268 
00269     void doLayout() const;
00270 
00271     void windowActivationChange( bool );
00272 
00273 #ifndef QT_NO_COMPAT
00274     bool itemYPos( int index, int *yPos ) const;
00275     int findItem( int yPos ) const { return index(itemAt(QPoint(0,yPos)) ); }
00276 #endif
00277 
00278 protected slots:
00279     void clearInputString();
00280 
00281 private slots:
00282     void refreshSlot();
00283     void doAutoScroll();
00284     void adjustItems();
00285 
00286 private:
00287     void mousePressEventEx( QMouseEvent * );
00288     void tryGeometry( int, int ) const;
00289     int currentRow() const;
00290     int currentColumn() const;
00291     void updateSelection();
00292     void repaintSelection();
00293     void drawRubber();
00294     void doRubberSelection( const QRect &old, const QRect &rubber );
00295     void handleItemChange( QListBoxItem *old, bool shift, bool control );
00296     void selectRange( QListBoxItem *from, QListBoxItem *to, bool invert, bool includeFirst, bool clearSel = FALSE );
00297 
00298     void emitChangedSignal( bool );
00299 
00300     int columnAt( int ) const;
00301     int rowAt( int ) const;
00302 
00303     QListBoxPrivate * d;
00304 
00305     static QListBox * changedListBox;
00306 
00307 private:        // Disabled copy constructor and operator=
00308 #if defined(Q_DISABLE_COPY)
00309     QListBox( const QListBox & );
00310     QListBox &operator=( const QListBox & );
00311 #endif
00312 };
00313 
00314 
00315 class Q_EXPORT QListBoxItem
00316 {
00317 public:
00318     QListBoxItem( QListBox* listbox = 0 );
00319     QListBoxItem( QListBox* listbox, QListBoxItem *after );
00320     virtual ~QListBoxItem();
00321 
00322     virtual QString text() const;
00323     virtual const QPixmap *pixmap() const;
00324 
00325     virtual int  height( const QListBox * ) const;
00326     virtual int  width( const QListBox * )  const;
00327 
00328     bool isSelected() const { return s; }
00329     bool isCurrent() const;
00330 
00331 #ifndef QT_NO_COMPAT
00332     bool selected() const { return isSelected(); }
00333     bool current() const { return isCurrent(); }
00334 #endif
00335 
00336     QListBox *listBox() const;
00337 
00338     void setSelectable( bool b );
00339     bool isSelectable() const;
00340 
00341     QListBoxItem *next() const;
00342     QListBoxItem *prev() const;
00343 
00344     virtual int rtti() const;
00345     static int RTTI;
00346 
00347 protected:
00348     virtual void paint( QPainter * ) = 0;
00349     virtual void setText( const QString &text ) { txt = text; }
00350     void setCustomHighlighting( bool );
00351 
00352 private:
00353     QString txt;
00354     uint s:1;
00355     uint dirty:1;
00356     uint custom_highlight : 1;
00357     int x, y;
00358     QListBoxItem * p, * n;
00359     QListBox* lbox;
00360     friend class QListBox;
00361     friend class QListBoxPrivate;
00362     friend class QComboBox;
00363     friend class QComboBoxPopupItem;
00364 
00365 private:        // Disabled copy constructor and operator=
00366 #if defined(Q_DISABLE_COPY)
00367     QListBoxItem( const QListBoxItem & );
00368     QListBoxItem &operator=( const QListBoxItem & );
00369 #endif
00370 };
00371 
00372 
00373 class Q_EXPORT QListBoxText : public QListBoxItem
00374 {
00375 public:
00376     QListBoxText( QListBox* listbox, const QString & text=QString::null );
00377     QListBoxText( const QString & text=QString::null );
00378     QListBoxText( QListBox* listbox, const QString & text, QListBoxItem *after );
00379    ~QListBoxText();
00380 
00381     int  height( const QListBox * ) const;
00382     int  width( const QListBox * )  const;
00383 
00384     int rtti() const;
00385     static int RTTI;
00386 
00387 protected:
00388     void  paint( QPainter * );
00389 
00390 private:        // Disabled copy constructor and operator=
00391 #if defined(Q_DISABLE_COPY)
00392     QListBoxText( const QListBoxText & );
00393     QListBoxText &operator=( const QListBoxText & );
00394 #endif
00395 };
00396 
00397 
00398 class Q_EXPORT QListBoxPixmap : public QListBoxItem
00399 {
00400 public:
00401     QListBoxPixmap( QListBox* listbox, const QPixmap & );
00402     QListBoxPixmap( const QPixmap & );
00403     QListBoxPixmap( QListBox* listbox, const QPixmap & pix, QListBoxItem *after );
00404     QListBoxPixmap( QListBox* listbox, const QPixmap &, const QString& );
00405     QListBoxPixmap( const QPixmap &, const QString& );
00406     QListBoxPixmap( QListBox* listbox, const QPixmap & pix, const QString&, QListBoxItem *after );
00407    ~QListBoxPixmap();
00408 
00409     const QPixmap *pixmap() const { return ± }
00410 
00411     int  height( const QListBox * ) const;
00412     int  width( const QListBox * )  const;
00413 
00414     int rtti() const;
00415     static int RTTI;
00416 
00417 protected:
00418     void paint( QPainter * );
00419 
00420 private:
00421     QPixmap pm;
00422 private:        // Disabled copy constructor and operator=
00423 #if defined(Q_DISABLE_COPY)
00424     QListBoxPixmap( const QListBoxPixmap & );
00425     QListBoxPixmap &operator=( const QListBoxPixmap & );
00426 #endif
00427 };
00428 
00429 
00430 #endif // QT_NO_LISTBOX
00431 
00432 #endif // QLISTBOX_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'