Eneboo - Documentación para desarrolladores
src/qt/src/widgets/qlistview.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qlistview.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of QListView widget class
00005 **
00006 ** Created : 970809
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 QLISTVIEW_H
00039 #define QLISTVIEW_H
00040 
00041 #ifndef QT_H
00042 #include "qscrollview.h"
00043 #endif // QT_H
00044 
00045 #ifndef QT_NO_LISTVIEW
00046 
00047 
00048 class QPixmap;
00049 class QFont;
00050 class QHeader;
00051 class QIconSet;
00052 
00053 class QListView;
00054 struct QListViewPrivate;
00055 struct QCheckListItemPrivate;
00056 class QListViewItemIterator;
00057 struct QListViewItemIteratorPrivate;
00058 class QDragObject;
00059 class QMimeSource;
00060 class QLineEdit;
00061 class QListViewToolTip;
00062 
00063 class Q_EXPORT QListViewItem : public Qt
00064 {
00065     friend class QListViewItemIterator;
00066     friend class QListViewToolTip;
00067 
00068 public:
00069     QListViewItem( QListView * parent );
00070     QListViewItem( QListViewItem * parent );
00071     QListViewItem( QListView * parent, QListViewItem * after );
00072     QListViewItem( QListViewItem * parent, QListViewItem * after );
00073 
00074     QListViewItem( QListView * parent,
00075                    QString,     QString = QString::null,
00076                    QString = QString::null, QString = QString::null,
00077                    QString = QString::null, QString = QString::null,
00078                    QString = QString::null, QString = QString::null );
00079     QListViewItem( QListViewItem * parent,
00080                    QString,     QString = QString::null,
00081                    QString = QString::null, QString = QString::null,
00082                    QString = QString::null, QString = QString::null,
00083                    QString = QString::null, QString = QString::null );
00084 
00085     QListViewItem( QListView * parent, QListViewItem * after,
00086                    QString,     QString = QString::null,
00087                    QString = QString::null, QString = QString::null,
00088                    QString = QString::null, QString = QString::null,
00089                    QString = QString::null, QString = QString::null );
00090     QListViewItem( QListViewItem * parent, QListViewItem * after,
00091                    QString,     QString = QString::null,
00092                    QString = QString::null, QString = QString::null,
00093                    QString = QString::null, QString = QString::null,
00094                    QString = QString::null, QString = QString::null );
00095     virtual ~QListViewItem();
00096 
00097     virtual void insertItem( QListViewItem * );
00098     virtual void takeItem( QListViewItem * );
00099     virtual void removeItem( QListViewItem *item ) { takeItem( item ); } //obsolete, use takeItem instead
00100 
00101     int height() const;
00102     virtual void invalidateHeight();
00103     int totalHeight() const;
00104     virtual int width( const QFontMetrics&,
00105                        const QListView*, int column) const;
00106     void widthChanged(int column=-1) const;
00107     int depth() const;
00108 
00109     virtual void setText( int, const QString &);
00110     virtual QString text( int ) const;
00111 
00112     virtual void setPixmap( int, const QPixmap & );
00113     virtual const QPixmap * pixmap( int ) const;
00114 
00115     virtual QString key( int, bool ) const;
00116     virtual int compare( QListViewItem *i, int col, bool ) const;
00117     virtual void sortChildItems( int, bool );
00118 
00119     int childCount() const { return nChildren; }
00120 
00121     bool isOpen() const { return open; }
00122     virtual void setOpen( bool );
00123     virtual void setup();
00124 
00125     virtual void setSelected( bool );
00126     bool isSelected() const { return selected; }
00127 
00128     virtual void paintCell( QPainter *, const QColorGroup & cg,
00129                             int column, int width, int alignment );
00130     virtual void paintBranches( QPainter * p, const QColorGroup & cg,
00131                                 int w, int y, int h );
00132     virtual void paintFocus( QPainter *, const QColorGroup & cg,
00133                              const QRect & r );
00134 
00135     QListViewItem * firstChild() const;
00136     QListViewItem * nextSibling() const { return siblingItem; }
00137     QListViewItem * parent() const;
00138 
00139     QListViewItem * itemAbove();
00140     QListViewItem * itemBelow();
00141 
00142     int itemPos() const;
00143 
00144     QListView *listView() const;
00145 
00146     virtual void setSelectable( bool enable );
00147     bool isSelectable() const { return selectable && enabled; }
00148 
00149     virtual void setExpandable( bool );
00150     bool isExpandable() const { return expandable; }
00151 
00152     void repaint() const;
00153 
00154     virtual void sort();
00155     void moveItem( QListViewItem *after );
00156 
00157     virtual void setDragEnabled( bool allow );
00158     virtual void setDropEnabled( bool allow );
00159     bool dragEnabled() const;
00160     bool dropEnabled() const;
00161     virtual bool acceptDrop( const QMimeSource *mime ) const;
00162 
00163     void setVisible( bool b );
00164     bool isVisible() const;
00165 
00166     virtual void setRenameEnabled( int col, bool b );
00167     bool renameEnabled( int col ) const;
00168     virtual void startRename( int col );
00169 
00170     virtual void setEnabled( bool b );
00171     bool isEnabled() const;
00172 
00173     virtual int rtti() const;
00174     // ### Qt 4: make const or better use an enum
00175     static int RTTI;
00176 
00177     virtual void setMultiLinesEnabled( bool b );
00178     bool multiLinesEnabled() const;
00179 
00180 protected:
00181     virtual void enforceSortOrder() const;
00182     virtual void setHeight( int );
00183     virtual void activate();
00184 
00185     bool activatedPos( QPoint & );
00186 #ifndef QT_NO_DRAGANDDROP
00187     virtual void dropped( QDropEvent *e );
00188 #endif
00189     virtual void dragEntered();
00190     virtual void dragLeft();
00191     virtual void okRename( int col );
00192     virtual void cancelRename( int col );
00193 
00194     void ignoreDoubleClick();
00195 
00196 private:
00197     void init();
00198     void moveToJustAfter( QListViewItem * );
00199     void enforceSortOrderBackToRoot();
00200     void removeRenameBox();
00201 
00202     int ownHeight;
00203     int maybeTotalHeight;
00204     int nChildren;
00205 
00206     uint lsc: 14;
00207     uint lso: 1;
00208     uint open : 1;
00209     uint selected : 1;
00210     uint selectable: 1;
00211     uint configured: 1;
00212     uint expandable: 1;
00213     uint is_root: 1;
00214     uint allow_drag : 1;
00215     uint allow_drop : 1;
00216     uint visible : 1;
00217     uint enabled : 1;
00218     uint mlenabled : 1;
00219 
00220     QListViewItem * parentItem;
00221     QListViewItem * siblingItem;
00222     QListViewItem * childItem;
00223     QLineEdit *renameBox;
00224     int renameCol;
00225 
00226     void * columns;
00227 
00228     friend class QListView;
00229 };
00230 
00231 class QCheckListItem;
00232 
00233 class Q_EXPORT QListView: public QScrollView
00234 {
00235     friend class QListViewItemIterator;
00236     friend class QListViewItem;
00237     friend class QCheckListItem;
00238     friend class QListViewToolTip;
00239 
00240     Q_OBJECT
00241     Q_ENUMS( SelectionMode ResizeMode RenameAction )
00242     Q_PROPERTY( int columns READ columns )
00243     Q_PROPERTY( bool multiSelection READ isMultiSelection WRITE setMultiSelection DESIGNABLE false )
00244     Q_PROPERTY( SelectionMode selectionMode READ selectionMode WRITE setSelectionMode )
00245     Q_PROPERTY( int childCount READ childCount )
00246     Q_PROPERTY( bool allColumnsShowFocus READ allColumnsShowFocus WRITE setAllColumnsShowFocus )
00247     Q_PROPERTY( bool showSortIndicator READ showSortIndicator WRITE setShowSortIndicator )
00248     Q_PROPERTY( int itemMargin READ itemMargin WRITE setItemMargin )
00249     Q_PROPERTY( bool rootIsDecorated READ rootIsDecorated WRITE setRootIsDecorated )
00250     Q_PROPERTY( bool showToolTips READ showToolTips WRITE setShowToolTips )
00251     Q_PROPERTY( ResizeMode resizeMode READ resizeMode WRITE setResizeMode )
00252     Q_PROPERTY( int treeStepSize READ treeStepSize WRITE setTreeStepSize )
00253     Q_PROPERTY( RenameAction defaultRenameAction READ defaultRenameAction WRITE setDefaultRenameAction )
00254 
00255 public:
00256     QListView( QWidget* parent=0, const char* name=0, WFlags f = 0 );
00257     ~QListView();
00258 
00259     int treeStepSize() const;
00260     virtual void setTreeStepSize( int );
00261 
00262     virtual void insertItem( QListViewItem * );
00263     virtual void takeItem( QListViewItem * );
00264     virtual void removeItem( QListViewItem *item ) { takeItem( item ); } // obsolete, use takeItem instead
00265 
00266     QHeader * header() const;
00267 
00268     virtual int addColumn( const QString &label, int size = -1);
00269     virtual int addColumn( const QIconSet& iconset, const QString &label, int size = -1);
00270     virtual void removeColumn( int index );
00271     virtual void setColumnText( int column, const QString &label );
00272     virtual void setColumnText( int column, const QIconSet& iconset, const QString &label );
00273     QString columnText( int column ) const;
00274     virtual void setColumnWidth( int column, int width );
00275     int columnWidth( int column ) const;
00276     enum WidthMode { Manual, Maximum };
00277     virtual void setColumnWidthMode( int column, WidthMode );
00278     WidthMode columnWidthMode( int column ) const;
00279     int columns() const;
00280 
00281     virtual void setColumnAlignment( int, int );
00282     int columnAlignment( int ) const;
00283 
00284     void show();
00285 
00286     QListViewItem * itemAt( const QPoint & screenPos ) const;
00287     QRect itemRect( const QListViewItem * ) const;
00288     int itemPos( const QListViewItem * );
00289 
00290     void ensureItemVisible( const QListViewItem * );
00291 
00292     void repaintItem( const QListViewItem * ) const;
00293 
00294     virtual void setMultiSelection( bool enable );
00295     bool isMultiSelection() const;
00296 
00297     enum SelectionMode { Single, Multi, Extended, NoSelection  };
00298     void setSelectionMode( SelectionMode mode );
00299     SelectionMode selectionMode() const;
00300 
00301     virtual void clearSelection();
00302     virtual void setSelected( QListViewItem *, bool );
00303     void setSelectionAnchor( QListViewItem * );
00304     bool isSelected( const QListViewItem * ) const;
00305     QListViewItem * selectedItem() const;
00306     virtual void setOpen( QListViewItem *, bool );
00307     bool isOpen( const QListViewItem * ) const;
00308 
00309     virtual void setCurrentItem( QListViewItem * );
00310     QListViewItem * currentItem() const;
00311 
00312     QListViewItem * firstChild() const;
00313     QListViewItem * lastItem() const;
00314 
00315     int childCount() const;
00316 
00317     virtual void setAllColumnsShowFocus( bool );
00318     bool allColumnsShowFocus() const;
00319 
00320     virtual void setItemMargin( int );
00321     int itemMargin() const;
00322 
00323     virtual void setRootIsDecorated( bool );
00324     bool rootIsDecorated() const;
00325 
00326     virtual void setSorting( int column, bool ascending = TRUE );
00327     int sortColumn() const;
00328     void setSortColumn( int column );
00329     SortOrder sortOrder() const;
00330     void setSortOrder( SortOrder order );
00331     virtual void sort();
00332 
00333     virtual void setFont( const QFont & );
00334     virtual void setPalette( const QPalette & );
00335 
00336     bool eventFilter( QObject * o, QEvent * );
00337 
00338     QSize sizeHint() const;
00339     QSize minimumSizeHint() const;
00340 
00341     virtual void setShowSortIndicator( bool show );
00342     bool showSortIndicator() const;
00343     virtual void setShowToolTips( bool b );
00344     bool showToolTips() const;
00345 
00346     enum ResizeMode { NoColumn, AllColumns, LastColumn };
00347     virtual void setResizeMode( ResizeMode m );
00348     ResizeMode resizeMode() const;
00349 
00350     QListViewItem * findItem( const QString& text, int column, ComparisonFlags compare = ExactMatch | CaseSensitive ) const;
00351 
00352     enum RenameAction { Accept, Reject };
00353     virtual void setDefaultRenameAction( RenameAction a );
00354     RenameAction defaultRenameAction() const;
00355     bool isRenaming() const;
00356 
00357     void hideColumn( int column );
00358 
00359 public slots:
00360     virtual void clear();
00361     virtual void invertSelection();
00362     virtual void selectAll( bool select );
00363     void triggerUpdate();
00364     void setContentsPos( int x, int y );
00365     void adjustColumn( int col );
00366 
00367 signals:
00368     void selectionChanged();
00369     void selectionChanged( QListViewItem * );
00370     void currentChanged( QListViewItem * );
00371     void clicked( QListViewItem * );
00372     void clicked( QListViewItem *, const QPoint &, int );
00373     void pressed( QListViewItem * );
00374     void pressed( QListViewItem *, const QPoint &, int );
00375 
00376     void doubleClicked( QListViewItem * );
00377     void doubleClicked( QListViewItem *, const QPoint&, int );
00378     void returnPressed( QListViewItem * );
00379     void spacePressed( QListViewItem * );
00380     void rightButtonClicked( QListViewItem *, const QPoint&, int );
00381     void rightButtonPressed( QListViewItem *, const QPoint&, int );
00382     void mouseButtonPressed( int, QListViewItem *, const QPoint& , int );
00383     void mouseButtonClicked( int, QListViewItem *,  const QPoint&, int );
00384 
00385     void contextMenuRequested( QListViewItem *, const QPoint &, int );
00386 
00387     void onItem( QListViewItem *item );
00388     void onViewport();
00389 
00390     void expanded( QListViewItem *item );
00391     void collapsed( QListViewItem *item );
00392 #ifndef QT_NO_DRAGANDDROP
00393     void dropped( QDropEvent *e );
00394 #endif
00395     void itemRenamed( QListViewItem *item, int col, const QString & );
00396     void itemRenamed( QListViewItem *item, int col  );
00397 
00398 protected:
00399     void contentsMousePressEvent( QMouseEvent * e );
00400     void contentsMouseReleaseEvent( QMouseEvent * e );
00401     void contentsMouseMoveEvent( QMouseEvent * e );
00402     void contentsMouseDoubleClickEvent( QMouseEvent * e );
00403     void contentsContextMenuEvent( QContextMenuEvent * e );
00404 #ifndef QT_NO_DRAGANDDROP
00405     void contentsDragEnterEvent( QDragEnterEvent *e );
00406     void contentsDragMoveEvent( QDragMoveEvent *e );
00407     void contentsDragLeaveEvent( QDragLeaveEvent *e );
00408     void contentsDropEvent( QDropEvent *e );
00409     virtual QDragObject *dragObject();
00410     virtual void startDrag();
00411 #endif
00412 
00413     void focusInEvent( QFocusEvent * e );
00414     void focusOutEvent( QFocusEvent * e );
00415 
00416     void keyPressEvent( QKeyEvent *e );
00417 
00418     void resizeEvent( QResizeEvent *e );
00419     void viewportResizeEvent( QResizeEvent *e );
00420 
00421     void showEvent( QShowEvent * );
00422 
00423     void drawContentsOffset( QPainter *, int ox, int oy,
00424                              int cx, int cy, int cw, int ch );
00425 
00426     virtual void paintEmptyArea( QPainter *, const QRect & );
00427     void styleChange( QStyle& );
00428     void windowActivationChange( bool );
00429 
00430 protected slots:
00431     void updateContents();
00432     void doAutoScroll();
00433 
00434 private slots:
00435     void changeSortColumn( int );
00436     void handleIndexChange();
00437     void updateDirtyItems();
00438     void makeVisible();
00439     void handleSizeChange( int, int, int );
00440     void startRename();
00441     void openFocusItem();
00442 
00443 private:
00444     void contentsMousePressEventEx( QMouseEvent * e );
00445     void contentsMouseReleaseEventEx( QMouseEvent * e );
00446     void init();
00447     void updateGeometries();
00448     void buildDrawableList() const;
00449     void reconfigureItems();
00450     void widthChanged(const QListViewItem*, int c);
00451     void handleItemChange( QListViewItem *old, bool shift, bool control );
00452     void selectRange( QListViewItem *from, QListViewItem *to, bool invert, bool includeFirst, bool clearSel = FALSE );
00453     bool selectRange( QListViewItem *newItem, QListViewItem *oldItem, QListViewItem *anchorItem );
00454     bool clearRange( QListViewItem *from, QListViewItem *to, bool includeFirst = TRUE );
00455     void doAutoScroll( const QPoint &cursorPos );
00456 
00457     QListViewPrivate * d;
00458 
00459 private:        // Disabled copy constructor and operator=
00460 #if defined(Q_DISABLE_COPY)
00461     QListView( const QListView & );
00462     QListView &operator=( const QListView & );
00463 #endif
00464 };
00465 
00466 
00467 class Q_EXPORT QCheckListItem : public QListViewItem
00468 {
00469 public:
00470     enum Type { RadioButton,
00471                 CheckBox,
00472                 Controller,
00473                 RadioButtonController=Controller,
00474                 CheckBoxController };
00475     // ### should be integrated with qbutton in ver4 perhaps
00476     enum ToggleState { Off, NoChange, On };
00477 
00478     QCheckListItem( QCheckListItem *parent, const QString &text,
00479                     Type = RadioButtonController );
00480     QCheckListItem( QCheckListItem *parent, QListViewItem *after,
00481                     const QString &text, Type = RadioButtonController );
00482     QCheckListItem( QListViewItem *parent, const QString &text,
00483                     Type = RadioButtonController );
00484     QCheckListItem( QListViewItem *parent, QListViewItem *after,
00485                     const QString &text, Type = RadioButtonController );
00486     QCheckListItem( QListView *parent, const QString &text,
00487                     Type = RadioButtonController );
00488     QCheckListItem( QListView *parent, QListViewItem *after,
00489                     const QString &text, Type = RadioButtonController );
00490     QCheckListItem( QListViewItem *parent, const QString &text,
00491                     const QPixmap & );
00492     QCheckListItem( QListView *parent, const QString &text,
00493                     const QPixmap & );
00494     ~QCheckListItem();
00495 
00496     void paintCell( QPainter *,  const QColorGroup & cg,
00497                     int column, int width, int alignment );
00498     virtual void paintFocus( QPainter *, const QColorGroup & cg,
00499                              const QRect & r );
00500     int width( const QFontMetrics&, const QListView*, int column) const;
00501     void setup();
00502 
00503     virtual void setOn( bool ); // ### should be replaced by setChecked in ver4
00504     bool isOn() const { return on; }
00505     Type type() const { return myType; }
00506     QString text() const { return QListViewItem::text( 0 ); }
00507     QString text( int n ) const { return QListViewItem::text( n ); }
00508 
00509     void setTristate( bool );
00510     bool isTristate() const;
00511     ToggleState state() const;
00512     void setState( ToggleState s);
00513 
00514     int rtti() const;
00515     static int RTTI;
00516 
00517 protected:
00518     void activate();
00519     void turnOffChild();
00520     virtual void stateChange( bool );
00521 
00522 private:
00523     void init();
00524     ToggleState internalState() const;
00525     void setStoredState( ToggleState newState, void *key );
00526     ToggleState storedState( void *key ) const;
00527     void stateChange( ToggleState s );
00528     void restoreState( void *key, int depth = 0 );
00529     void updateController( bool update = TRUE , bool store = FALSE );
00530     void updateStoredState( void *key );
00531     void setState( ToggleState s, bool update, bool store );
00532     void setCurrentState( ToggleState s );
00533 
00534     Type myType;
00535     bool on; // ### remove in ver4
00536     QCheckListItemPrivate *d;
00537 };
00538 
00539 class Q_EXPORT QListViewItemIterator
00540 {
00541     friend struct QListViewPrivate;
00542     friend class QListView;
00543     friend class QListViewItem;
00544 
00545 public:
00546     enum IteratorFlag {
00547         Visible =               0x00000001,
00548         Invisible =             0x00000002,
00549         Selected =              0x00000004,
00550         Unselected =            0x00000008,
00551         Selectable =            0x00000010,
00552         NotSelectable =         0x00000020,
00553         DragEnabled =           0x00000040,
00554         DragDisabled =          0x00000080,
00555         DropEnabled =           0x00000100,
00556         DropDisabled =          0x00000200,
00557         Expandable =            0x00000400,
00558         NotExpandable =         0x00000800,
00559         Checked =               0x00001000,
00560         NotChecked =            0x00002000
00561     };
00562 
00563     QListViewItemIterator();
00564     QListViewItemIterator( QListViewItem *item );
00565     QListViewItemIterator( QListViewItem *item, int iteratorFlags );
00566 
00567     QListViewItemIterator( const QListViewItemIterator &it );
00568     QListViewItemIterator( QListView *lv );
00569     QListViewItemIterator( QListView *lv, int iteratorFlags );
00570 
00571     QListViewItemIterator &operator=( const QListViewItemIterator &it );
00572 
00573     ~QListViewItemIterator();
00574 
00575     QListViewItemIterator &operator++();
00576     const QListViewItemIterator operator++( int );
00577     QListViewItemIterator &operator+=( int j );
00578 
00579     QListViewItemIterator &operator--();
00580     const QListViewItemIterator operator--( int );
00581     QListViewItemIterator &operator-=( int j );
00582 
00583     QListViewItem* operator*();
00584     QListViewItem *current() const;
00585 
00586 protected:
00587     QListViewItem *curr;
00588     QListView *listView;
00589 
00590 private:
00591     QListViewItemIteratorPrivate* d() const;
00592     void init( int flags );
00593     void addToListView();
00594     void currentRemoved();
00595     bool matchesFlags( const QListViewItem* ) const;
00596     bool testPair( QListViewItemIterator::IteratorFlag, QListViewItemIterator::IteratorFlag, bool ) const;
00597     bool isChecked( const QListViewItem* ) const;
00598 };
00599 
00600 #endif // QT_NO_LISTVIEW
00601 
00602 #endif // QLISTVIEW_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'