kiconview.h
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1999 Torben Weis <weis@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 #ifndef KICONVIEW_H 00019 #define KICONVIEW_H 00020 00021 #include <tqcursor.h> 00022 #include <tqiconview.h> 00023 00024 #include <tdelibs_export.h> 00025 00042 class TDEUI_EXPORT TDEIconView : public TQIconView 00043 { 00044 friend class TDEIconViewItem; 00045 Q_OBJECT 00046 TQ_ENUMS( Mode ) 00047 TQ_PROPERTY( Mode mode READ mode WRITE setMode ) 00048 00049 public: 00050 TDEIconView( TQWidget *parent = 0, const char *name = 0, WFlags f = 0 ); 00051 00052 ~TDEIconView(); 00053 00062 enum Mode { Execute, Select }; 00063 00073 void setMode( Mode m ); 00074 00078 Mode mode() const; 00079 00083 virtual void setFont( const TQFont & ); 00084 00092 void setIconTextHeight( int n ); 00093 00098 int iconTextHeight() const; 00099 00103 virtual void takeItem( TQIconViewItem * item ); 00104 00105 signals: 00106 00116 void executed( TQIconViewItem *item ); 00117 00128 void executed( TQIconViewItem *item, const TQPoint &pos ); 00129 00138 void held( TQIconViewItem *item ); 00139 00153 void doubleClicked( TQIconViewItem *item, const TQPoint &pos ); 00154 00155 protected slots: 00156 void slotOnItem( TQIconViewItem *item ); 00157 void slotOnViewport(); 00158 void slotSettingsChanged(int); 00159 00163 void slotAutoSelect(); 00164 00165 protected: 00166 void emitExecute( TQIconViewItem *item, const TQPoint &pos ); 00167 void updateDragHoldItem( TQDropEvent *e ); 00168 00169 virtual void focusOutEvent( TQFocusEvent *fe ); 00170 virtual void leaveEvent( TQEvent *e ); 00171 virtual void contentsMousePressEvent( TQMouseEvent *e ); 00172 virtual void contentsMouseDoubleClickEvent ( TQMouseEvent * e ); 00173 virtual void contentsMouseReleaseEvent( TQMouseEvent *e ); 00174 virtual void contentsDragEnterEvent( TQDragEnterEvent *e ); 00175 virtual void contentsDragLeaveEvent( TQDragLeaveEvent *e ); 00176 virtual void contentsDragMoveEvent( TQDragMoveEvent *e ); 00177 virtual void contentsDropEvent( TQDropEvent* e ); 00178 virtual void wheelEvent( TQWheelEvent *e ); 00179 00186 void cancelPendingHeldSignal(); 00187 00188 private slots: 00189 void slotMouseButtonClicked( int btn, TQIconViewItem *item, const TQPoint &pos ); 00190 void slotDragHoldTimeout(); 00191 00192 private: 00196 TQFontMetrics *itemFontMetrics() const; 00200 TQPixmap selectedIconPixmap( TQPixmap *pix, const TQColor &col ) const; 00201 00202 bool m_bUseSingle; 00203 bool m_bChangeCursorOverItem; 00204 00205 TQIconViewItem* m_pCurrentItem; 00206 00207 TQTimer* m_pAutoSelect; 00208 int m_autoSelectDelay; 00209 00210 protected: 00211 virtual void virtual_hook( int id, void* data ); 00212 private: 00213 class TDEIconViewPrivate; 00214 TDEIconViewPrivate *d; 00215 }; 00216 00217 class KWordWrap; 00226 class TDEUI_EXPORT TDEIconViewItem : public TQIconViewItem 00227 { 00228 public: 00229 // Need to redefine all the constructors - I want Java ! 00230 TDEIconViewItem( TQIconView *parent ) 00231 : TQIconViewItem( parent ) { init(); } // We need to call it because the parent ctor won't call our reimplementation :((( 00232 TDEIconViewItem( TQIconView *parent, TQIconViewItem *after ) 00233 : TQIconViewItem( parent, after ) { init(); } 00234 TDEIconViewItem( TQIconView *parent, const TQString &text ) 00235 : TQIconViewItem( parent, text ) { init(); } 00236 TDEIconViewItem( TQIconView *parent, TQIconViewItem *after, const TQString &text ) 00237 : TQIconViewItem( parent, after, text ) { init(); } 00238 TDEIconViewItem( TQIconView *parent, const TQString &text, const TQPixmap &icon ) 00239 : TQIconViewItem( parent, text, icon ) { init(); } 00240 TDEIconViewItem( TQIconView *parent, TQIconViewItem *after, const TQString &text, const TQPixmap &icon ) 00241 : TQIconViewItem( parent, after, text, icon ) { init(); } 00242 TDEIconViewItem( TQIconView *parent, const TQString &text, const TQPicture &picture ) 00243 : TQIconViewItem( parent, text, picture ) { init(); } 00244 TDEIconViewItem( TQIconView *parent, TQIconViewItem *after, const TQString &text, const TQPicture &picture ) 00245 : TQIconViewItem( parent, after, text, picture ) { init(); } 00246 virtual ~TDEIconViewItem(); 00247 00259 void setPixmapSize( const TQSize& size ); 00260 00265 TQSize pixmapSize() const; 00266 00267 protected: 00268 void init(); 00269 virtual void calcRect( const TQString& text_ = TQString::null ); 00270 virtual void paintItem( TQPainter *p, const TQColorGroup &c ); 00271 KWordWrap *wordWrap(); 00272 void paintPixmap( TQPainter *p, const TQColorGroup &c ); 00273 void paintText( TQPainter *p, const TQColorGroup &c ); 00274 00275 private: 00276 KWordWrap* m_wordWrap; 00277 struct TDEIconViewItemPrivate; 00278 TDEIconViewItemPrivate *d; 00279 }; 00280 00281 #endif