Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: qt/qiconview.h 3.3.8 edited Jan 11 14:38 $ 00003 ** 00004 ** Definition of QIconView widget class 00005 ** 00006 ** Created : 990707 00007 ** 00008 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00009 ** 00010 ** This file is part of the iconview 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 QICONVIEW_H 00039 #define QICONVIEW_H 00040 00041 #ifndef QT_H 00042 #include "qscrollview.h" 00043 #include "qstring.h" 00044 #include "qrect.h" 00045 #include "qpoint.h" 00046 #include "qsize.h" 00047 #include "qfont.h" // QString->QFont conversion 00048 #include "qdragobject.h" 00049 #include "qbitmap.h" 00050 #include "qpicture.h" 00051 #endif // QT_H 00052 00053 #ifndef QT_NO_ICONVIEW 00054 00055 #if !defined( QT_MODULE_ICONVIEW ) || defined( QT_INTERNAL_ICONVIEW ) 00056 #define QM_EXPORT_ICONVIEW 00057 #else 00058 #define QM_EXPORT_ICONVIEW Q_EXPORT 00059 #endif 00060 00061 class QIconView; 00062 class QPainter; 00063 class QMimeSource; 00064 class QMouseEvent; 00065 class QDragEnterEvent; 00066 class QDragMoveEvent; 00067 class QDragLeaveEvent; 00068 class QKeyEvent; 00069 class QFocusEvent; 00070 class QShowEvent; 00071 class QIconViewItem; 00072 class QIconViewItemLineEdit; 00073 class QStringList; 00074 class QIconDragPrivate; 00075 00076 #ifndef QT_NO_DRAGANDDROP 00077 00078 class QM_EXPORT_ICONVIEW QIconDragItem 00079 { 00080 public: 00081 QIconDragItem(); 00082 virtual ~QIconDragItem(); 00083 virtual QByteArray data() const; 00084 virtual void setData( const QByteArray &d ); 00085 bool operator== ( const QIconDragItem& ) const; 00086 00087 private: 00088 QByteArray ba; 00089 00090 }; 00091 00092 class QM_EXPORT_ICONVIEW QIconDrag : public QDragObject 00093 { 00094 Q_OBJECT 00095 public: 00096 QIconDrag( QWidget * dragSource, const char* name = 0 ); 00097 virtual ~QIconDrag(); 00098 00099 void append( const QIconDragItem &item, const QRect &pr, const QRect &tr ); 00100 00101 virtual const char* format( int i ) const; 00102 static bool canDecode( QMimeSource* e ); 00103 virtual QByteArray encodedData( const char* mime ) const; 00104 00105 private: 00106 QIconDragPrivate *d; 00107 QChar endMark; 00108 00109 friend class QIconView; 00110 friend class QIconViewPrivate; 00111 #if defined(Q_DISABLE_COPY) // Disabled copy constructor and operator= 00112 QIconDrag( const QIconDrag & ); 00113 QIconDrag &operator=( const QIconDrag & ); 00114 #endif 00115 }; 00116 00117 #endif 00118 00119 class QIconViewToolTip; 00120 class QIconViewItemPrivate; 00121 00122 class QM_EXPORT_ICONVIEW QIconViewItem : public Qt 00123 { 00124 friend class QIconView; 00125 friend class QIconViewToolTip; 00126 friend class QIconViewItemLineEdit; 00127 00128 public: 00129 QIconViewItem( QIconView *parent ); 00130 QIconViewItem( QIconView *parent, QIconViewItem *after ); 00131 QIconViewItem( QIconView *parent, const QString &text ); 00132 QIconViewItem( QIconView *parent, QIconViewItem *after, const QString &text ); 00133 QIconViewItem( QIconView *parent, const QString &text, const QPixmap &icon ); 00134 QIconViewItem( QIconView *parent, QIconViewItem *after, const QString &text, const QPixmap &icon ); 00135 #ifndef QT_NO_PICTURE 00136 QIconViewItem( QIconView *parent, const QString &text, const QPicture &picture ); 00137 QIconViewItem( QIconView *parent, QIconViewItem *after, const QString &text, const QPicture &picture ); 00138 #endif 00139 virtual ~QIconViewItem(); 00140 00141 virtual void setRenameEnabled( bool allow ); 00142 virtual void setDragEnabled( bool allow ); 00143 virtual void setDropEnabled( bool allow ); 00144 00145 virtual QString text() const; 00146 virtual QPixmap *pixmap() const; 00147 #ifndef QT_NO_PICTURE 00148 virtual QPicture *picture() const; 00149 #endif 00150 virtual QString key() const; 00151 00152 bool renameEnabled() const; 00153 bool dragEnabled() const; 00154 bool dropEnabled() const; 00155 00156 QIconView *iconView() const; 00157 QIconViewItem *prevItem() const; 00158 QIconViewItem *nextItem() const; 00159 00160 int index() const; 00161 00162 virtual void setSelected( bool s, bool cb ); 00163 virtual void setSelected( bool s ); 00164 virtual void setSelectable( bool s ); 00165 00166 bool isSelected() const; 00167 bool isSelectable() const; 00168 00169 virtual void repaint(); 00170 00171 virtual bool move( int x, int y ); 00172 virtual void moveBy( int dx, int dy ); 00173 virtual bool move( const QPoint &pnt ); 00174 virtual void moveBy( const QPoint &pnt ); 00175 00176 QRect rect() const; 00177 int x() const; 00178 int y() const; 00179 int width() const; 00180 int height() const; 00181 QSize size() const; 00182 QPoint pos() const; 00183 QRect textRect( bool relative = TRUE ) const; 00184 QRect pixmapRect( bool relative = TRUE ) const; 00185 bool contains( const QPoint& pnt ) const; 00186 bool intersects( const QRect& r ) const; 00187 00188 virtual bool acceptDrop( const QMimeSource *mime ) const; 00189 00190 #ifndef QT_NO_TEXTEDIT 00191 void rename(); 00192 #endif 00193 00194 virtual int compare( QIconViewItem *i ) const; 00195 00196 virtual void setText( const QString &text ); 00197 virtual void setPixmap( const QPixmap &icon ); 00198 #ifndef QT_NO_PICTURE 00199 virtual void setPicture( const QPicture &icon ); 00200 #endif 00201 virtual void setText( const QString &text, bool recalc, bool redraw = TRUE ); 00202 virtual void setPixmap( const QPixmap &icon, bool recalc, bool redraw = TRUE ); 00203 virtual void setKey( const QString &k ); 00204 00205 virtual int rtti() const; 00206 static int RTTI; 00207 00208 protected: 00209 #ifndef QT_NO_TEXTEDIT 00210 virtual void removeRenameBox(); 00211 #endif 00212 virtual void calcRect( const QString &text_ = QString::null ); 00213 virtual void paintItem( QPainter *p, const QColorGroup &cg ); 00214 virtual void paintFocus( QPainter *p, const QColorGroup &cg ); 00215 #ifndef QT_NO_DRAGANDDROP 00216 virtual void dropped( QDropEvent *e, const QValueList<QIconDragItem> &lst ); 00217 #endif 00218 virtual void dragEntered(); 00219 virtual void dragLeft(); 00220 void setItemRect( const QRect &r ); 00221 void setTextRect( const QRect &r ); 00222 void setPixmapRect( const QRect &r ); 00223 void calcTmpText(); 00224 QString tempText() const; 00225 00226 private: 00227 void init( QIconViewItem *after = 0 00228 #ifndef QT_NO_PICTURE 00229 , QPicture *pic = 0 00230 #endif 00231 ); 00232 #ifndef QT_NO_TEXTEDIT 00233 void renameItem(); 00234 void cancelRenameItem(); 00235 #endif 00236 void checkRect(); 00237 00238 QIconView *view; 00239 QString itemText, itemKey; 00240 QString tmpText; 00241 QPixmap *itemIcon; 00242 #ifndef QT_NO_PICTURE 00243 QPicture *itemPic; 00244 #endif 00245 QIconViewItem *prev, *next; 00246 uint allow_rename : 1; 00247 uint allow_drag : 1; 00248 uint allow_drop : 1; 00249 uint selected : 1; 00250 uint selectable : 1; 00251 uint dirty : 1; 00252 uint wordWrapDirty : 1; 00253 QRect itemRect, itemTextRect, itemIconRect; 00254 #ifndef QT_NO_TEXTEDIT 00255 QIconViewItemLineEdit *renameBox; 00256 #endif 00257 QRect oldRect; 00258 00259 QIconViewItemPrivate *d; 00260 00261 }; 00262 00263 class QIconViewPrivate; /* don't touch */ 00264 00265 class QM_EXPORT_ICONVIEW QIconView : public QScrollView 00266 { 00267 friend class QIconViewItem; 00268 friend class QIconViewPrivate; 00269 friend class QIconViewToolTip; 00270 00271 Q_OBJECT 00272 // #### sorting and sort direction do not work 00273 Q_ENUMS( SelectionMode ItemTextPos Arrangement ResizeMode ) 00274 Q_PROPERTY( bool sorting READ sorting ) 00275 Q_PROPERTY( bool sortDirection READ sortDirection ) 00276 Q_PROPERTY( SelectionMode selectionMode READ selectionMode WRITE setSelectionMode ) 00277 Q_PROPERTY( int gridX READ gridX WRITE setGridX ) 00278 Q_PROPERTY( int gridY READ gridY WRITE setGridY ) 00279 Q_PROPERTY( int spacing READ spacing WRITE setSpacing ) 00280 Q_PROPERTY( ItemTextPos itemTextPos READ itemTextPos WRITE setItemTextPos ) 00281 Q_PROPERTY( QBrush itemTextBackground READ itemTextBackground WRITE setItemTextBackground ) 00282 Q_PROPERTY( Arrangement arrangement READ arrangement WRITE setArrangement ) 00283 Q_PROPERTY( ResizeMode resizeMode READ resizeMode WRITE setResizeMode ) 00284 Q_PROPERTY( int maxItemWidth READ maxItemWidth WRITE setMaxItemWidth ) 00285 Q_PROPERTY( int maxItemTextLength READ maxItemTextLength WRITE setMaxItemTextLength ) 00286 Q_PROPERTY( bool autoArrange READ autoArrange WRITE setAutoArrange ) 00287 Q_PROPERTY( bool itemsMovable READ itemsMovable WRITE setItemsMovable ) 00288 Q_PROPERTY( bool wordWrapIconText READ wordWrapIconText WRITE setWordWrapIconText ) 00289 Q_PROPERTY( bool showToolTips READ showToolTips WRITE setShowToolTips ) 00290 Q_PROPERTY( uint count READ count ) 00291 00292 public: 00293 enum SelectionMode { 00294 Single = 0, 00295 Multi, 00296 Extended, 00297 NoSelection 00298 }; 00299 enum Arrangement { 00300 LeftToRight = 0, 00301 TopToBottom 00302 }; 00303 enum ResizeMode { 00304 Fixed = 0, 00305 Adjust 00306 }; 00307 enum ItemTextPos { 00308 Bottom = 0, 00309 Right 00310 }; 00311 00312 QIconView( QWidget* parent=0, const char* name=0, WFlags f = 0 ); 00313 virtual ~QIconView(); 00314 00315 virtual void insertItem( QIconViewItem *item, QIconViewItem *after = 0L ); 00316 virtual void takeItem( QIconViewItem *item ); 00317 00318 int index( const QIconViewItem *item ) const; 00319 00320 QIconViewItem *firstItem() const; 00321 QIconViewItem *lastItem() const; 00322 QIconViewItem *currentItem() const; 00323 virtual void setCurrentItem( QIconViewItem *item ); 00324 virtual void setSelected( QIconViewItem *item, bool s, bool cb = FALSE ); 00325 00326 uint count() const; 00327 00328 public: 00329 virtual void showEvent( QShowEvent * ); 00330 00331 virtual void setSelectionMode( SelectionMode m ); 00332 SelectionMode selectionMode() const; 00333 00334 QIconViewItem *findItem( const QPoint &pos ) const; 00335 QIconViewItem *findItem( const QString &text, ComparisonFlags compare = BeginsWith ) const; 00336 virtual void selectAll( bool select ); 00337 virtual void clearSelection(); 00338 virtual void invertSelection(); 00339 00340 virtual void repaintItem( QIconViewItem *item ); 00341 void repaintSelectedItems(); 00342 00343 void ensureItemVisible( QIconViewItem *item ); 00344 QIconViewItem* findFirstVisibleItem( const QRect &r ) const; 00345 QIconViewItem* findLastVisibleItem( const QRect &r ) const; 00346 00347 virtual void clear(); 00348 00349 virtual void setGridX( int rx ); 00350 virtual void setGridY( int ry ); 00351 int gridX() const; 00352 int gridY() const; 00353 virtual void setSpacing( int sp ); 00354 int spacing() const; 00355 virtual void setItemTextPos( ItemTextPos pos ); 00356 ItemTextPos itemTextPos() const; 00357 virtual void setItemTextBackground( const QBrush &b ); 00358 QBrush itemTextBackground() const; 00359 virtual void setArrangement( Arrangement am ); 00360 Arrangement arrangement() const; 00361 virtual void setResizeMode( ResizeMode am ); 00362 ResizeMode resizeMode() const; 00363 virtual void setMaxItemWidth( int w ); 00364 int maxItemWidth() const; 00365 virtual void setMaxItemTextLength( int w ); 00366 int maxItemTextLength() const; 00367 virtual void setAutoArrange( bool b ); 00368 bool autoArrange() const; 00369 virtual void setShowToolTips( bool b ); 00370 bool showToolTips() const; 00371 00372 void setSorting( bool sort, bool ascending = TRUE ); 00373 bool sorting() const; 00374 bool sortDirection() const; 00375 00376 virtual void setItemsMovable( bool b ); 00377 bool itemsMovable() const; 00378 virtual void setWordWrapIconText( bool b ); 00379 bool wordWrapIconText() const; 00380 00381 bool eventFilter( QObject * o, QEvent * ); 00382 00383 QSize minimumSizeHint() const; 00384 QSize sizeHint() const; 00385 00386 virtual void sort( bool ascending = TRUE ); 00387 00388 virtual void setFont( const QFont & ); 00389 virtual void setPalette( const QPalette & ); 00390 00391 bool isRenaming() const; 00392 00393 public slots: 00394 virtual void arrangeItemsInGrid( const QSize &grid, bool update = TRUE ); 00395 virtual void arrangeItemsInGrid( bool update = TRUE ); 00396 virtual void setContentsPos( int x, int y ); 00397 virtual void updateContents(); 00398 00399 signals: 00400 void selectionChanged(); 00401 void selectionChanged( QIconViewItem *item ); 00402 void currentChanged( QIconViewItem *item ); 00403 void clicked( QIconViewItem * ); 00404 void clicked( QIconViewItem *, const QPoint & ); 00405 void pressed( QIconViewItem * ); 00406 void pressed( QIconViewItem *, const QPoint & ); 00407 00408 void doubleClicked( QIconViewItem *item ); 00409 void returnPressed( QIconViewItem *item ); 00410 void rightButtonClicked( QIconViewItem* item, const QPoint& pos ); 00411 void rightButtonPressed( QIconViewItem* item, const QPoint& pos ); 00412 void mouseButtonPressed( int button, QIconViewItem* item, const QPoint& pos ); 00413 void mouseButtonClicked( int button, QIconViewItem* item, const QPoint& pos ); 00414 void contextMenuRequested( QIconViewItem* item, const QPoint &pos ); 00415 00416 #ifndef QT_NO_DRAGANDDROP 00417 void dropped( QDropEvent *e, const QValueList<QIconDragItem> &lst ); 00418 #endif 00419 void moved(); 00420 void onItem( QIconViewItem *item ); 00421 void onViewport(); 00422 void itemRenamed( QIconViewItem *item, const QString & ); 00423 void itemRenamed( QIconViewItem *item ); 00424 00425 protected slots: 00426 virtual void doAutoScroll(); 00427 virtual void adjustItems(); 00428 virtual void slotUpdate(); 00429 00430 private slots: 00431 void movedContents( int dx, int dy ); 00432 00433 protected: 00434 void drawContents( QPainter *p, int cx, int cy, int cw, int ch ); 00435 void contentsMousePressEvent( QMouseEvent *e ); 00436 void contentsMouseReleaseEvent( QMouseEvent *e ); 00437 void contentsMouseMoveEvent( QMouseEvent *e ); 00438 void contentsMouseDoubleClickEvent( QMouseEvent *e ); 00439 void contentsContextMenuEvent( QContextMenuEvent *e ); 00440 00441 #ifndef QT_NO_DRAGANDDROP 00442 void contentsDragEnterEvent( QDragEnterEvent *e ); 00443 void contentsDragMoveEvent( QDragMoveEvent *e ); 00444 void contentsDragLeaveEvent( QDragLeaveEvent *e ); 00445 void contentsDropEvent( QDropEvent *e ); 00446 #endif 00447 00448 void resizeEvent( QResizeEvent* e ); 00449 void keyPressEvent( QKeyEvent *e ); 00450 void focusInEvent( QFocusEvent *e ); 00451 void focusOutEvent( QFocusEvent *e ); 00452 void enterEvent( QEvent *e ); 00453 00454 virtual void drawRubber( QPainter *p ); 00455 #ifndef QT_NO_DRAGANDDROP 00456 virtual QDragObject *dragObject(); 00457 virtual void startDrag(); 00458 #endif 00459 virtual void insertInGrid( QIconViewItem *item ); 00460 virtual void drawBackground( QPainter *p, const QRect &r ); 00461 00462 void emitSelectionChanged( QIconViewItem * i = 0 ); 00463 void emitRenamed( QIconViewItem *item ); 00464 00465 QIconViewItem *makeRowLayout( QIconViewItem *begin, int &y, bool &changed ); 00466 00467 void styleChange( QStyle& ); 00468 void windowActivationChange( bool ); 00469 00470 private: 00471 void contentsMousePressEventEx( QMouseEvent *e ); 00472 virtual void drawDragShapes( const QPoint &pnt ); 00473 #ifndef QT_NO_DRAGANDDROP 00474 virtual void initDragEnter( QDropEvent *e ); 00475 #endif 00476 void drawContents( QPainter* ); 00477 QIconViewItem* findItemByName( QIconViewItem *start ); 00478 void handleItemChange( QIconViewItem *old, bool shift, 00479 bool control, bool homeend = FALSE); 00480 00481 int calcGridNum( int w, int x ) const; 00482 QIconViewItem *rowBegin( QIconViewItem *item ) const; 00483 void updateItemContainer( QIconViewItem *item ); 00484 void appendItemContainer(); 00485 void rebuildContainers(); 00486 enum Direction { 00487 DirUp = 0, 00488 DirDown, 00489 DirLeft, 00490 DirRight 00491 }; 00492 QIconViewItem* findItem( Direction dir, 00493 const QPoint &relativeTo, 00494 const QRect &searchRect ) const; 00495 bool neighbourItem( Direction dir, 00496 const QPoint &relativeTo, 00497 const QIconViewItem *item ) const; 00498 QBitmap mask( QPixmap *pix ) const; 00499 00500 QIconViewPrivate *d; 00501 00502 private: // Disabled copy constructor and operator= 00503 #if defined(Q_DISABLE_COPY) 00504 QIconView( const QIconView & ); 00505 QIconView& operator=( const QIconView & ); 00506 #endif 00507 }; 00508 00509 #endif // QT_NO_ICONVIEW 00510 00511 #endif // QICONVIEW_H