tdelistview.h
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org> 00003 Copyright (C) 2000 Charles Samuels <charles@kde.org> 00004 Copyright (C) 2000 Peter Putzer <putzer@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License version 2 as published by the Free Software Foundation. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef TDELISTVIEW_H 00022 #define TDELISTVIEW_H 00023 00024 #include <tqheader.h> 00025 #include <tqlistview.h> 00026 #include <tdeshortcut.h> 00027 #include <tqptrlist.h> 00028 #include <tdelibs_export.h> 00029 00030 class TQDragObject; 00031 class TDEConfig; 00032 class KLineEdit; 00033 00034 // Used to set the 'move to next/previous item' after renaming is completed 00035 class TDEListViewRenameSettings 00036 { 00037 public: 00038 bool m_useRenameSignals; // if true, emits renameNext/renamePrev signals 00039 TDEShortcut m_SCNext; // the shortcut key for moving to the next cell 00040 TDEShortcut m_SCPrev; // the shortcut key for moving to the previous cell 00041 00042 TDEListViewRenameSettings() 00043 : m_useRenameSignals(false), m_SCNext(), m_SCPrev() {} 00044 00045 TDEListViewRenameSettings(bool useRenameSignals, TDEShortcut scNext, TDEShortcut scPrev) 00046 : m_useRenameSignals(useRenameSignals), m_SCNext(scNext), m_SCPrev(scPrev) {} 00047 00048 TDEListViewRenameSettings(const TDEListViewRenameSettings &that) 00049 : m_useRenameSignals(that.m_useRenameSignals), m_SCNext(that.m_SCNext), m_SCPrev(that.m_SCPrev) {} 00050 00051 TDEListViewRenameSettings& operator=(const TDEListViewRenameSettings &that) 00052 { 00053 if (this==&that) return *this; 00054 m_useRenameSignals = that.m_useRenameSignals; 00055 m_SCNext = that.m_SCNext; 00056 m_SCPrev = that.m_SCPrev; 00057 return *this; 00058 } 00059 }; 00060 00061 00084 class TDEUI_EXPORT TDEListView : public TQListView 00085 { 00086 friend class TDEListViewItem; 00087 00088 Q_OBJECT 00089 00090 TQ_ENUMS( SelectionModeExt ) 00091 TQ_PROPERTY( bool fullWidth READ fullWidth WRITE setFullWidth ) 00092 TQ_PROPERTY( bool itemsMovable READ itemsMovable WRITE setItemsMovable ) 00093 TQ_PROPERTY( bool itemsRenameable READ itemsRenameable WRITE setItemsRenameable ) 00094 TQ_PROPERTY( bool dragEnabled READ dragEnabled WRITE setDragEnabled ) 00095 TQ_PROPERTY( bool autoOpen READ autoOpen WRITE setAutoOpen ) 00096 TQ_PROPERTY( bool dropVisualizer READ dropVisualizer WRITE setDropVisualizer ) 00097 TQ_PROPERTY( int tooltipColumn READ tooltipColumn WRITE setTooltipColumn ) 00098 TQ_PROPERTY( int dropVisualizerWidth READ dropVisualizerWidth WRITE setDropVisualizerWidth ) 00099 TQ_PROPERTY( TQColor alternateBackground READ alternateBackground WRITE setAlternateBackground ) 00100 TQ_PROPERTY( bool shadeSortColumn READ shadeSortColumn WRITE setShadeSortColumn ) 00101 00102 TQ_OVERRIDE( SelectionModeExt selectionMode READ selectionModeExt WRITE setSelectionModeExt ) 00103 00104 public: 00136 enum SelectionModeExt { 00137 Single = TQListView::Single, 00138 Multi = TQListView::Multi, 00139 Extended = TQListView::Extended, 00140 NoSelection = TQListView::NoSelection, 00141 FileManager 00142 }; 00143 00150 TDEListView (TQWidget *parent = 0, const char *name = 0); 00151 00155 virtual ~TDEListView(); 00156 00164 virtual void setAcceptDrops (bool); 00165 00175 virtual bool isExecuteArea( const TQPoint& point ); 00176 00182 bool isExecuteArea( int x ); 00183 00189 TQPtrList<TQListViewItem> selectedItems() const; 00190 00201 TQPtrList<TQListViewItem> selectedItems(bool includeHiddenItems) const; // ### BIC: KDE 4: use an implicitly shared class! (QValutList?) and merge with above, default to true 00202 00209 void moveItem(TQListViewItem *item, TQListViewItem *parent, TQListViewItem *after); 00210 00216 TQListViewItem *lastItem() const; 00217 00223 TQListViewItem* lastChild () const; 00224 00231 KLineEdit* renameLineEdit() const; 00232 00239 bool itemsMovable() const; 00240 00246 bool itemsRenameable() const; 00247 00253 bool dragEnabled() const; 00254 00260 bool autoOpen() const; 00261 00267 bool isRenameable (int column) const; 00268 00274 bool dropVisualizer() const; 00275 00281 int tooltipColumn() const; 00282 00289 bool createChildren() const KDE_DEPRECATED; 00290 00296 bool dropHighlighter() const; 00297 00304 int dropVisualizerWidth () const; 00305 00312 SelectionModeExt selectionModeExt () const; 00313 00319 int itemIndex( const TQListViewItem *item ) const; 00320 00326 TQListViewItem* itemAtIndex(int index); 00327 00332 void setFullWidth() KDE_DEPRECATED; 00333 00339 void setFullWidth(bool fullWidth); 00340 00346 bool fullWidth() const; 00347 00353 virtual int addColumn(const TQString& label, int width = -1); 00357 virtual int addColumn(const TQIconSet& iconset, const TQString& label, int width = -1); 00363 virtual void removeColumn(int index); 00364 00374 void setAlternateBackground(const TQColor &c); 00380 const TQColor &alternateBackground() const; 00381 00389 void saveLayout(TDEConfig *config, const TQString &group) const; 00397 void restoreLayout(TDEConfig *config, const TQString &group); 00404 virtual void setSorting(int column, bool ascending = true); 00405 00409 int columnSorted(void) const; 00410 00414 bool ascendingSort(void) const; 00415 00419 virtual void takeItem(TQListViewItem *i); 00420 00427 void setShadeSortColumn(bool shadeSortColumn); 00428 00435 bool shadeSortColumn(void) const; 00436 00443 void setUseSmallExecuteArea(bool enable); 00444 00450 bool useSmallExecuteArea() const; 00451 00460 void setRenameSettings(const TDEListViewRenameSettings &renSett); 00461 00462 00463 signals: 00464 00474 void executed( TQListViewItem *item ); 00475 00487 void executed( TQListViewItem *item, const TQPoint &pos, int c ); 00488 00499 void dropped (TQDropEvent * e, TQListViewItem *after); 00500 00513 void dropped (TDEListView* list, TQDropEvent* e, TQListViewItem* after); 00514 00527 void dropped (TDEListView* list, TQDropEvent* e, TQListViewItem* parent, TQListViewItem* after); 00528 00540 void dropped (TQDropEvent* e, TQListViewItem* parent, TQListViewItem* after); 00541 00548 void moved(); 00549 00558 void aboutToMove(); 00559 00571 void moved (TQListViewItem *item, TQListViewItem *afterFirst, TQListViewItem *afterNow); 00572 00573 00579 void moved(TQPtrList<TQListViewItem> &items, TQPtrList<TQListViewItem> &afterFirst, TQPtrList<TQListViewItem> &afterNow); 00580 00588 void itemRenamed(TQListViewItem* item, const TQString &str, int col); 00589 00593 void itemRenamed(TQListViewItem* item); 00594 00605 void menuShortCutPressed (TDEListView* list, TQListViewItem* item); 00606 00615 void contextMenu(TDEListView* l, TQListViewItem* i, const TQPoint& p); 00616 00617 void itemAdded(TQListViewItem *item); 00618 void itemRemoved(TQListViewItem *item); 00619 00631 void renameNext(TQListViewItem* item, int col); 00632 00644 void renamePrev(TQListViewItem* item, int col); 00645 00646 public slots: 00650 virtual void rename(TQListViewItem *item, int c); 00651 00662 void setRenameable (int column, bool yesno=true); 00663 00670 virtual void setItemsMovable(bool b); 00671 00679 virtual void setItemsRenameable(bool b); 00680 00685 virtual void setDragEnabled(bool b); 00686 00690 virtual void setAutoOpen(bool b); 00691 00697 virtual void setDropVisualizer(bool b); 00698 00703 void setDropVisualizerWidth (int w); 00704 00711 virtual void setTooltipColumn(int column); 00712 00718 virtual void setDropHighlighter(bool b); 00719 00726 virtual void setCreateChildren(bool b) KDE_DEPRECATED; 00727 00733 void setSelectionModeExt (SelectionModeExt mode); 00734 00739 void setTabOrderedRenaming(bool b); 00740 00745 bool tabOrderedRenaming() const; 00746 00753 virtual void selectAll( bool select ); 00754 00755 protected: 00764 inline bool below (const TQRect& rect, const TQPoint& p) 00765 { 00766 return (p.y() > (rect.top() + (rect.bottom() - rect.top())/2)); 00767 } 00768 00778 inline bool below (TQListViewItem* i, const TQPoint& p) 00779 { 00780 return below (itemRect(i), contentsToViewport(p)); 00781 } 00782 00787 virtual bool event( TQEvent * ); 00788 00793 void emitExecute( TQListViewItem *item, const TQPoint &pos, int c ); 00794 00802 virtual void focusInEvent(TQFocusEvent* fe); 00803 00811 virtual void focusOutEvent( TQFocusEvent *fe ); 00812 00820 virtual void leaveEvent( TQEvent *e ); 00821 00825 virtual TQString tooltip(TQListViewItem* item, int column) const; 00826 00830 virtual bool showTooltip(TQListViewItem *item, const TQPoint &pos, int column) const; 00831 00839 virtual void contentsDragMoveEvent (TQDragMoveEvent *event); 00840 00848 virtual void contentsMousePressEvent( TQMouseEvent *e ); 00849 00857 virtual void contentsMouseMoveEvent( TQMouseEvent *e ); 00858 00866 virtual void contentsMouseDoubleClickEvent ( TQMouseEvent *e ); 00867 00875 virtual void contentsDragLeaveEvent (TQDragLeaveEvent *event); 00876 00884 virtual void contentsMouseReleaseEvent (TQMouseEvent*); 00885 00893 virtual void contentsDropEvent (TQDropEvent*); 00894 00902 virtual void contentsDragEnterEvent (TQDragEnterEvent *); 00903 00909 virtual TQDragObject *dragObject(); 00910 00916 virtual bool acceptDrag (TQDropEvent* event) const; 00917 00925 virtual TQRect drawDropVisualizer (TQPainter *p, TQListViewItem *parent, TQListViewItem *after); 00926 00933 virtual TQRect drawItemHighlighter(TQPainter *painter, TQListViewItem *item); 00934 00941 virtual void startDrag(); 00942 00950 virtual void keyPressEvent (TQKeyEvent*); 00951 00959 virtual void viewportPaintEvent(TQPaintEvent*); 00960 00965 void activateAutomaticSelection(); 00970 void deactivateAutomaticSelection(); 00976 bool automaticSelection() const; 00977 00981 virtual void viewportResizeEvent(TQResizeEvent* e); 00982 00990 void disableAutoSelection(); 00991 00997 void resetAutoSelection(); 00998 01004 void resetKeyboardSelectionOperation(); 01005 01012 void setActiveMultiSelectItem(TQListViewItem *item); 01013 01018 // KDE 4: remove 01019 void doubleClicked( TQListViewItem *item, const TQPoint &pos, int c ); 01020 01021 protected slots: 01026 void slotSettingsChanged(int); 01027 void slotMouseButtonClicked( int btn, TQListViewItem *item, const TQPoint &pos, int c ); 01028 void doneEditing(TQListViewItem *item, int row); 01029 void renameNextProxy(TQListViewItem *item, int col); 01030 void renamePrevProxy(TQListViewItem *item, int col); 01031 01035 void cleanDropVisualizer(); 01036 01040 void cleanItemHighlighter(); 01041 01045 void emitContextMenu (TQListViewItem*, const TQPoint&, int); 01046 01050 void emitContextMenu (TDEListView*, TQListViewItem*); 01051 01056 void slotOnItem( TQListViewItem *item ); 01057 01062 void slotOnViewport(); 01063 01068 void slotAutoSelect(); 01069 01070 void slotDragExpand(); 01071 01076 void slotHeaderChanged(); 01077 01078 protected: 01082 virtual void movableDropEvent (TQListViewItem* parent, TQListViewItem* afterme); 01083 01090 virtual void findDrop(const TQPoint &pos, TQListViewItem *&parent, TQListViewItem *&after); 01091 01095 void fileManagerKeyPressEvent (TQKeyEvent*); 01096 01100 int depthToPixels( int depth ); 01101 01102 private: 01103 class Tooltip; 01104 protected: 01105 virtual void virtual_hook( int id, void* data ); 01106 private: 01107 class TDEListViewPrivate; 01108 TDEListViewPrivate* const d; 01109 bool isExecuteArea( int x, TQListViewItem* item ); 01110 }; 01111 01118 class TDEUI_EXPORT TDEListViewItem : public TQListViewItem 01119 { 01120 friend class TDEListView; 01121 public: 01128 TDEListViewItem(TQListView *parent); 01129 TDEListViewItem(TQListViewItem *parent); 01130 TDEListViewItem(TQListView *parent, TQListViewItem *after); 01131 TDEListViewItem(TQListViewItem *parent, TQListViewItem *after); 01132 01133 TDEListViewItem(TQListView *parent, 01134 TQString, TQString = TQString::null, 01135 TQString = TQString::null, TQString = TQString::null, 01136 TQString = TQString::null, TQString = TQString::null, 01137 TQString = TQString::null, TQString = TQString::null); 01138 01139 TDEListViewItem(TQListViewItem *parent, 01140 TQString, TQString = TQString::null, 01141 TQString = TQString::null, TQString = TQString::null, 01142 TQString = TQString::null, TQString = TQString::null, 01143 TQString = TQString::null, TQString = TQString::null); 01144 01145 TDEListViewItem(TQListView *parent, TQListViewItem *after, 01146 TQString, TQString = TQString::null, 01147 TQString = TQString::null, TQString = TQString::null, 01148 TQString = TQString::null, TQString = TQString::null, 01149 TQString = TQString::null, TQString = TQString::null); 01150 01151 TDEListViewItem(TQListViewItem *parent, TQListViewItem *after, 01152 TQString, TQString = TQString::null, 01153 TQString = TQString::null, TQString = TQString::null, 01154 TQString = TQString::null, TQString = TQString::null, 01155 TQString = TQString::null, TQString = TQString::null); 01156 01157 virtual ~TDEListViewItem(); 01158 01159 virtual void insertItem(TQListViewItem *item); 01160 virtual void takeItem(TQListViewItem *item); 01164 bool isAlternate(); 01168 const TQColor &backgroundColor() KDE_DEPRECATED; // #### should be removed in 4.0; use below instead 01169 01178 TQColor backgroundColor(int column); 01179 01180 virtual void paintCell(TQPainter *p, const TQColorGroup &cg, 01181 int column, int width, int alignment); 01182 01183 private: 01184 void init(); 01185 01186 private: 01187 uint m_odd : 1; 01188 uint m_known : 1; 01189 uint m_unused : 30; 01190 }; 01191 01192 #endif 01193 01194 // vim: ts=2 sw=2 et