00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KLISTVIEW_H
00021 #define KLISTVIEW_H
00022
00023 #include <qlistview.h>
00024
00025 #include <qptrlist.h>
00026 #include <kdelibs_export.h>
00027
00028 class QDragObject;
00029 class KConfig;
00030 class KLineEdit;
00053 class KDEUI_EXPORT KListView : public QListView
00054 {
00055 friend class KListViewItem;
00056
00057 Q_OBJECT
00058 Q_ENUMS( SelectionModeExt )
00059 Q_PROPERTY( bool fullWidth READ fullWidth WRITE setFullWidth )
00060 Q_PROPERTY( bool itemsMovable READ itemsMovable WRITE setItemsMovable )
00061 Q_PROPERTY( bool itemsRenameable READ itemsRenameable WRITE setItemsRenameable )
00062 Q_PROPERTY( bool dragEnabled READ dragEnabled WRITE setDragEnabled )
00063 Q_PROPERTY( bool autoOpen READ autoOpen WRITE setAutoOpen )
00064 Q_PROPERTY( bool dropVisualizer READ dropVisualizer WRITE setDropVisualizer )
00065 Q_PROPERTY( int tooltipColumn READ tooltipColumn WRITE setTooltipColumn )
00066 Q_PROPERTY( int dropVisualizerWidth READ dropVisualizerWidth WRITE setDropVisualizerWidth )
00067 Q_PROPERTY( QColor alternateBackground READ alternateBackground WRITE setAlternateBackground )
00068 Q_PROPERTY( bool shadeSortColumn READ shadeSortColumn WRITE setShadeSortColumn )
00069
00070 Q_OVERRIDE( SelectionModeExt selectionMode READ selectionModeExt WRITE setSelectionModeExt )
00071
00072 public:
00104 enum SelectionModeExt {
00105 Single = QListView::Single,
00106 Multi = QListView::Multi,
00107 Extended = QListView::Extended,
00108 NoSelection = QListView::NoSelection,
00109 FileManager
00110 };
00111
00118 KListView (QWidget *parent = 0, const char *name = 0);
00119
00123 virtual ~KListView();
00124
00132 virtual void setAcceptDrops (bool);
00133
00143 virtual bool isExecuteArea( const QPoint& point );
00144
00150 bool isExecuteArea( int x );
00151
00157 QPtrList<QListViewItem> selectedItems() const;
00158
00169 QPtrList<QListViewItem> selectedItems(bool includeHiddenItems) const;
00170
00177 void moveItem(QListViewItem *item, QListViewItem *parent, QListViewItem *after);
00178
00184 QListViewItem *lastItem() const;
00185
00191 QListViewItem* lastChild () const;
00192
00199 KLineEdit* renameLineEdit() const;
00200
00207 bool itemsMovable() const;
00208
00214 bool itemsRenameable() const;
00215
00221 bool dragEnabled() const;
00222
00228 bool autoOpen() const;
00229
00235 bool isRenameable (int column) const;
00236
00242 bool dropVisualizer() const;
00243
00249 int tooltipColumn() const;
00250
00257 bool createChildren() const KDE_DEPRECATED;
00258
00264 bool dropHighlighter() const;
00265
00272 int dropVisualizerWidth () const;
00273
00280 SelectionModeExt selectionModeExt () const;
00281
00287 int itemIndex( const QListViewItem *item ) const;
00288
00294 QListViewItem* itemAtIndex(int index);
00295
00300 void setFullWidth() KDE_DEPRECATED;
00301
00307 void setFullWidth(bool fullWidth);
00308
00314 bool fullWidth() const;
00315
00321 virtual int addColumn(const QString& label, int width = -1);
00325 virtual int addColumn(const QIconSet& iconset, const QString& label, int width = -1);
00331 virtual void removeColumn(int index);
00332
00342 void setAlternateBackground(const QColor &c);
00348 const QColor &alternateBackground() const;
00349
00357 void saveLayout(KConfig *config, const QString &group) const;
00365 void restoreLayout(KConfig *config, const QString &group);
00372 virtual void setSorting(int column, bool ascending = true);
00373
00377 int columnSorted(void) const;
00378
00382 bool ascendingSort(void) const;
00383
00387 virtual void takeItem(QListViewItem *i);
00388
00395 void setShadeSortColumn(bool shadeSortColumn);
00396
00403 bool shadeSortColumn(void) const;
00404 signals:
00405
00415 void executed( QListViewItem *item );
00416
00428 void executed( QListViewItem *item, const QPoint &pos, int c );
00429
00440 void dropped (QDropEvent * e, QListViewItem *after);
00441
00454 void dropped (KListView* list, QDropEvent* e, QListViewItem* after);
00455
00468 void dropped (KListView* list, QDropEvent* e, QListViewItem* parent, QListViewItem* after);
00469
00481 void dropped (QDropEvent* e, QListViewItem* parent, QListViewItem* after);
00482
00489 void moved();
00490
00499 void aboutToMove();
00500
00512 void moved (QListViewItem *item, QListViewItem *afterFirst, QListViewItem *afterNow);
00513
00514
00520 void moved(QPtrList<QListViewItem> &items, QPtrList<QListViewItem> &afterFirst, QPtrList<QListViewItem> &afterNow);
00521
00529 void itemRenamed(QListViewItem* item, const QString &str, int col);
00530
00534 void itemRenamed(QListViewItem* item);
00535
00546 void menuShortCutPressed (KListView* list, QListViewItem* item);
00547
00556 void contextMenu (KListView* l, QListViewItem* i, const QPoint& p);
00557
00558 void itemAdded(QListViewItem *item);
00559 void itemRemoved(QListViewItem *item);
00560
00561 public slots:
00565 virtual void rename(QListViewItem *item, int c);
00566
00577 void setRenameable (int column, bool yesno=true);
00578
00585 virtual void setItemsMovable(bool b);
00586
00594 virtual void setItemsRenameable(bool b);
00595
00600 virtual void setDragEnabled(bool b);
00601
00605 virtual void setAutoOpen(bool b);
00606
00612 virtual void setDropVisualizer(bool b);
00613
00618 void setDropVisualizerWidth (int w);
00619
00626 virtual void setTooltipColumn(int column);
00627
00633 virtual void setDropHighlighter(bool b);
00634
00641 virtual void setCreateChildren(bool b) KDE_DEPRECATED;
00642
00648 void setSelectionModeExt (SelectionModeExt mode);
00649
00654 void setTabOrderedRenaming(bool b);
00655
00660 bool tabOrderedRenaming() const;
00661
00662 protected:
00671 inline bool below (const QRect& rect, const QPoint& p)
00672 {
00673 return (p.y() > (rect.top() + (rect.bottom() - rect.top())/2));
00674 }
00675
00685 inline bool below (QListViewItem* i, const QPoint& p)
00686 {
00687 return below (itemRect(i), contentsToViewport(p));
00688 }
00689
00694 virtual bool event( QEvent * );
00695
00700 void emitExecute( QListViewItem *item, const QPoint &pos, int c );
00701
00709 virtual void focusInEvent(QFocusEvent* fe);
00710
00718 virtual void focusOutEvent( QFocusEvent *fe );
00719
00727 virtual void leaveEvent( QEvent *e );
00728
00732 virtual QString tooltip(QListViewItem* item, int column) const;
00733
00737 virtual bool showTooltip(QListViewItem *item, const QPoint &pos, int column) const;
00738
00746 virtual void contentsDragMoveEvent (QDragMoveEvent *event);
00747
00755 virtual void contentsMousePressEvent( QMouseEvent *e );
00756
00764 virtual void contentsMouseMoveEvent( QMouseEvent *e );
00765
00773 virtual void contentsMouseDoubleClickEvent ( QMouseEvent *e );
00774
00782 virtual void contentsDragLeaveEvent (QDragLeaveEvent *event);
00783
00791 virtual void contentsMouseReleaseEvent (QMouseEvent*);
00792
00800 virtual void contentsDropEvent (QDropEvent*);
00801
00809 virtual void contentsDragEnterEvent (QDragEnterEvent *);
00810
00816 virtual QDragObject *dragObject();
00817
00823 virtual bool acceptDrag (QDropEvent* event) const;
00824
00832 virtual QRect drawDropVisualizer (QPainter *p, QListViewItem *parent, QListViewItem *after);
00833
00840 virtual QRect drawItemHighlighter(QPainter *painter, QListViewItem *item);
00841
00848 virtual void startDrag();
00849
00857 virtual void keyPressEvent (QKeyEvent*);
00858
00866 virtual void viewportPaintEvent(QPaintEvent*);
00867
00872 void activateAutomaticSelection();
00877 void deactivateAutomaticSelection();
00883 bool automaticSelection() const;
00884
00888 virtual void viewportResizeEvent(QResizeEvent* e);
00889
00897 void disableAutoSelection();
00898
00904 void resetAutoSelection();
00905
00910
00911 void doubleClicked( QListViewItem *item, const QPoint &pos, int c );
00912
00913 protected slots:
00918 void slotSettingsChanged(int);
00919
00920 void slotMouseButtonClicked( int btn, QListViewItem *item, const QPoint &pos, int c );
00921 void doneEditing(QListViewItem *item, int row);
00922
00926 void cleanDropVisualizer();
00927
00931 void cleanItemHighlighter();
00932
00936 void emitContextMenu (QListViewItem*, const QPoint&, int);
00937
00941 void emitContextMenu (KListView*, QListViewItem*);
00942
00947 void slotOnItem( QListViewItem *item );
00948
00953 void slotOnViewport();
00954
00959 void slotAutoSelect();
00960
00961 void slotDragExpand();
00962
00967 void slotHeaderChanged();
00968
00969 protected:
00973 virtual void movableDropEvent (QListViewItem* parent, QListViewItem* afterme);
00974
00981 virtual void findDrop(const QPoint &pos, QListViewItem *&parent, QListViewItem *&after);
00982
00986 void fileManagerKeyPressEvent (QKeyEvent*);
00987
00991 int depthToPixels( int depth );
00992
00993 private:
00994 class Tooltip;
00995 protected:
00996 virtual void virtual_hook( int id, void* data );
00997 private:
00998 class KListViewPrivate;
00999 KListViewPrivate* const d;
01000 bool isExecuteArea( int x, QListViewItem* item );
01001 };
01002
01009 class KDEUI_EXPORT KListViewItem : public QListViewItem
01010 {
01011 friend class KListView;
01012 public:
01019 KListViewItem(QListView *parent);
01020 KListViewItem(QListViewItem *parent);
01021 KListViewItem(QListView *parent, QListViewItem *after);
01022 KListViewItem(QListViewItem *parent, QListViewItem *after);
01023
01024 KListViewItem(QListView *parent,
01025 QString, QString = QString::null,
01026 QString = QString::null, QString = QString::null,
01027 QString = QString::null, QString = QString::null,
01028 QString = QString::null, QString = QString::null);
01029
01030 KListViewItem(QListViewItem *parent,
01031 QString, QString = QString::null,
01032 QString = QString::null, QString = QString::null,
01033 QString = QString::null, QString = QString::null,
01034 QString = QString::null, QString = QString::null);
01035
01036 KListViewItem(QListView *parent, QListViewItem *after,
01037 QString, QString = QString::null,
01038 QString = QString::null, QString = QString::null,
01039 QString = QString::null, QString = QString::null,
01040 QString = QString::null, QString = QString::null);
01041
01042 KListViewItem(QListViewItem *parent, QListViewItem *after,
01043 QString, QString = QString::null,
01044 QString = QString::null, QString = QString::null,
01045 QString = QString::null, QString = QString::null,
01046 QString = QString::null, QString = QString::null);
01047
01048 virtual ~KListViewItem();
01049
01050 virtual void insertItem(QListViewItem *item);
01051 virtual void takeItem(QListViewItem *item);
01055 bool isAlternate();
01059 const QColor &backgroundColor() KDE_DEPRECATED;
01060
01069 QColor backgroundColor(int column);
01070
01071 virtual void paintCell(QPainter *p, const QColorGroup &cg,
01072 int column, int width, int alignment);
01073
01074 private:
01075 void init();
01076
01077 private:
01078 uint m_odd : 1;
01079 uint m_known : 1;
01080 uint m_unused : 30;
01081 };
01082
01083 #endif
01084
01085