kfileiconview.h
00001 // -*- c++ -*- 00002 /* This file is part of the KDE libraries 00003 Copyright (C) 1997 Stephan Kulow <coolo@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 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 KFILEICONVIEW_H 00022 #define KFILEICONVIEW_H 00023 00024 #include <tqt.h> 00025 00026 #include <kiconview.h> 00027 #include <kiconloader.h> 00028 #include <kfileview.h> 00029 #include <kmimetyperesolver.h> 00030 #include <kfile.h> 00031 00032 class KFileItem; 00033 class TQWidget; 00034 class TQLabel; 00035 00040 class KIO_EXPORT KFileIconViewItem : public KIconViewItem 00041 { 00042 public: 00043 KFileIconViewItem( TQIconView *parent, const TQString &text, 00044 const TQPixmap &pixmap, 00045 KFileItem *fi ) 00046 : KIconViewItem( parent, text, pixmap ), inf( fi ) {} 00050 KFileIconViewItem( TQIconView *parent, KFileItem *fi ) 00051 : KIconViewItem( parent ), inf( fi ) {} 00052 00053 virtual ~KFileIconViewItem(); 00054 00058 KFileItem *fileInfo() const { 00059 return inf; 00060 } 00061 00062 private: 00063 KFileItem *inf; 00064 00065 private: 00066 class KFileIconViewItemPrivate; 00067 KFileIconViewItemPrivate *d; 00068 00069 }; 00070 00071 namespace KIO { 00072 class Job; 00073 } 00074 00083 class KIO_EXPORT KFileIconView : public KIconView, public KFileView 00084 { 00085 Q_OBJECT 00086 00087 public: 00088 KFileIconView(TQWidget *parent, const char *name); 00089 virtual ~KFileIconView(); 00090 00091 virtual TQWidget *widget() { return this; } 00092 virtual void clearView(); 00093 virtual void setAutoUpdate( bool ) {} // ### unused. remove in KDE4 00094 00095 virtual void updateView( bool ); 00096 virtual void updateView(const KFileItem*); 00097 virtual void removeItem(const KFileItem*); 00098 00099 virtual void listingCompleted(); 00100 00101 virtual void insertItem( KFileItem *i ); 00102 virtual void setSelectionMode( KFile::SelectionMode sm ); 00103 00104 virtual void setSelected(const KFileItem *, bool); 00105 virtual bool isSelected(const KFileItem *i) const; 00106 virtual void clearSelection(); 00107 virtual void selectAll(); 00108 virtual void invertSelection(); 00109 00110 virtual void setCurrentItem( const KFileItem * ); 00111 virtual KFileItem * currentFileItem() const; 00112 virtual KFileItem * firstFileItem() const; 00113 virtual KFileItem * nextItem( const KFileItem * ) const; 00114 virtual KFileItem * prevItem( const KFileItem * ) const; 00115 00119 void setIconSize( int size ); 00120 00124 void setPreviewSize( int size ); 00125 00133 void setIgnoreMaximumSize(bool ignoreSize=true); 00134 00138 int iconSize() const { return myIconSize; } 00139 00140 void ensureItemVisible( const KFileItem * ); 00141 00142 virtual void setSorting(TQDir::SortSpec sort); 00143 00144 virtual void readConfig( KConfig *, const TQString& group = TQString::null ); 00145 virtual void writeConfig( KConfig *, const TQString& group = TQString::null); 00146 00147 // for KMimeTypeResolver 00148 void mimeTypeDeterminationFinished(); 00149 void determineIcon( KFileIconViewItem *item ); 00150 TQScrollView *scrollWidget() const { return (TQScrollView*) this; } 00151 void setAcceptDrops(bool b) 00152 { 00153 KIconView::setAcceptDrops(b); 00154 viewport()->setAcceptDrops(b); 00155 } 00156 00157 public slots: 00164 void showPreviews(); 00165 00166 void zoomIn(); 00167 00168 void zoomOut(); 00169 00174 virtual void arrangeItemsInGrid( bool updated = true ); 00175 00176 protected: 00180 virtual void keyPressEvent( TQKeyEvent * ); 00181 00185 virtual void hideEvent( TQHideEvent * ); 00186 00187 // ### workaround for Qt3 bug (see #35080) 00188 virtual void showEvent( TQShowEvent * ); 00189 00190 virtual bool eventFilter( TQObject *o, TQEvent *e ); 00191 00192 // DND support 00193 virtual TQDragObject *dragObject(); 00194 virtual void contentsDragEnterEvent( TQDragEnterEvent *e ); 00195 virtual void contentsDragMoveEvent( TQDragMoveEvent *e ); 00196 virtual void contentsDragLeaveEvent( TQDragLeaveEvent *e ); 00197 virtual void contentsDropEvent( TQDropEvent *ev ); 00198 00199 // KDE4: Make virtual 00200 bool acceptDrag(TQDropEvent* e ) const; 00201 00202 private slots: 00203 void selected( TQIconViewItem *item ); 00204 void slotActivate( TQIconViewItem * ); 00205 void highlighted( TQIconViewItem *item ); 00206 void showToolTip( TQIconViewItem *item ); 00207 void removeToolTip(); 00208 void slotActivateMenu( TQIconViewItem *, const TQPoint& ); 00209 void slotSelectionChanged(); 00210 00211 void slotSmallColumns(); 00212 void slotLargeRows(); 00213 void slotPreviewsToggled( bool ); 00214 00215 void slotPreviewResult( KIO::Job * ); 00216 void gotPreview( const KFileItem *item, const TQPixmap& pix ); 00217 void slotAutoOpen(); 00218 00219 signals: 00226 void dropped(TQDropEvent *event, KFileItem *fileItem); 00233 void dropped(TQDropEvent *event, const KURL::List &urls, const KURL &url); 00234 00235 private: 00236 KMimeTypeResolver<KFileIconViewItem,KFileIconView> *m_resolver; 00237 00238 TQLabel *toolTip; 00239 int th; 00240 int myIconSize; 00241 00242 virtual void insertItem(TQIconViewItem *a, TQIconViewItem *b) { KIconView::insertItem(a, b); } 00243 virtual void setSelectionMode(TQIconView::SelectionMode m) { KIconView::setSelectionMode(m); } 00244 virtual void setSelected(TQIconViewItem *i, bool a, bool b) { KIconView::setSelected(i, a, b); } 00245 00246 bool canPreview( const KFileItem * ) const; 00247 void stopPreview(); 00248 00249 void updateIcons(); 00250 00251 inline KFileIconViewItem * viewItem( const KFileItem *item ) const { 00252 if ( item ) 00253 return (KFileIconViewItem *) item->extraData( this ); 00254 return 0L; 00255 } 00256 00257 void initItem(KFileIconViewItem *item, const KFileItem *i, 00258 bool updateTextAndPixmap ); 00259 00260 protected: 00261 virtual void virtual_hook( int id, void* data ); 00262 private: 00263 class KFileIconViewPrivate; 00264 KFileIconViewPrivate *d; 00265 }; 00266 00267 #endif // KFILESIMPLEVIEW_H