home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kfileivi.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  7.5 KB  |  240 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 1999, 2000, 2001, 2002 David Faure <faure@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License as published by the Free Software Foundation; either
  7.    version 2 of the License, or (at your option) any later version.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.    Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef __kfileivi_h__
  21. #define __kfileivi_h__
  22.  
  23. #include <kiconview.h>
  24. #include <kiconloader.h>
  25. #include <libkonq_export.h>
  26.  
  27. class KFileItem;
  28. class KonqIconViewWidget;
  29. class KIVDirectoryOverlay;
  30.  
  31. /**
  32.  * KFileIVI (short form of "Konq - File - IconViewItem")
  33.  * is, as expected, an improved KIconViewItem, because
  34.  * it represents a file.
  35.  * All the information about the file is contained in the KFileItem
  36.  * pointer.
  37.  */
  38. class LIBKONQ_EXPORT KFileIVI : public KIconViewItem
  39. {
  40. public:
  41.     /**
  42.      * Create an icon, within a qlistview, representing a file
  43.      * @param iconview the parent widget
  44.      * @param fileitem the file item created by KDirLister
  45.      * @param size the icon size
  46.      */
  47.     KFileIVI( KonqIconViewWidget *iconview, KFileItem* fileitem, int size );
  48.     virtual ~KFileIVI();
  49.  
  50.     /**
  51.      * Handler for return (or single/double click) on ONE icon.
  52.      * Runs the file through KRun.
  53.      */
  54.     virtual void returnPressed();
  55.  
  56.     /**
  57.      * @return the file item held by this instance
  58.      */
  59.     KFileItem * item() const { return m_fileitem; }
  60.  
  61.     /**
  62.      * @return true if dropping on this file is allowed
  63.      * Overloads QIconView::acceptDrop()
  64.      */
  65.     virtual bool acceptDrop( const QMimeSource *mime ) const;
  66.  
  67.     /**
  68.      * Changes the icon for this item.
  69.      * @param size the icon size (0 for default, otherwise size in pixels)
  70.      * @param state the state of the icon (enum in KIcon)
  71.      * @param recalc whether to update the layout of the icon view when setting the icon
  72.      * @param redraw whether to redraw the item after setting the icon
  73.      */
  74.     virtual void setIcon( int size,
  75.                           int state=KIcon::DefaultState,
  76.                           bool recalc=false,
  77.                           bool redraw=false);
  78.  
  79.     /**
  80.      * Bypass @ref setIcon. This is for animated icons, you should use setIcon
  81.      * in all other cases.
  82.      * @param pixmap the pixmap to set - it SHOULD really have the right icon size!
  83.      * @param recalc whether to update the layout of the icon view when setting the icon
  84.      * @param redraw whether to redraw the item after setting the icon
  85.      */
  86.     void setPixmapDirect( const QPixmap & pixmap,
  87.                           bool recalc=false,
  88.                           bool redraw=false);
  89.  
  90.     /**
  91.      * Notifies that all icon effects on thumbs should be invalidated,
  92.      * e.g. because the effect settings have been changed. The thumb itself
  93.      * is assumed to be still valid (use setThumbnailPixmap() instead
  94.      * otherwise).
  95.      * @param state the state of the icon (enum in KIcon)
  96.      * @param redraw whether to redraw the item after setting the icon
  97.      */
  98.     void invalidateThumb( int state, bool redraw = false );
  99.  
  100.     /**
  101.      * Our current thumbnail is not longer "current".
  102.      * Called when the file contents have changed.
  103.      */
  104.     void invalidateThumbnail();
  105.     bool isThumbnailInvalid() const;
  106.  
  107.     bool hasValidThumbnail() const { return isThumbnail() && !isThumbnailInvalid(); }
  108.  
  109.     /**
  110.      * Return the current state of the icon
  111.      * (KIcon::DefaultState, KIcon::ActiveState etc.)
  112.      */
  113.     int state() const { return m_state; }
  114.  
  115.     /**
  116.      * Return the theorical size of the icon
  117.      */
  118.     int iconSize() const { return m_size; }
  119.  
  120.     /**
  121.      * Set to true when this icon is 'cut'
  122.      */
  123.     void setDisabled( bool disabled );
  124.  
  125.     /**
  126.      * Set this when the thumbnail was loaded
  127.      */
  128.     void setThumbnailPixmap( const QPixmap & pixmap );
  129.  
  130.     /**
  131.      * Set the icon to use the specified KIconEffect
  132.      * See the docs for KIconEffect for details.
  133.      */
  134.     void setEffect( /*int group,*/ int state );
  135.  
  136.     /**
  137.      * @return true if this item is a thumbnail
  138.      */
  139.     bool isThumbnail() const { return m_bThumbnail; }
  140.  
  141.     /**
  142.      * Sets an icon to be shown over the bottom left corner of the icon.
  143.      * Currently used for directory overlays.
  144.      * setOverlay(QString::null) to remove icon.
  145.      */
  146.     void setOverlay( const QString & iconName);
  147.  
  148.     /**
  149.      * Redetermines the icon (useful if KFileItem might return another icon).
  150.      * Does nothing with thumbnails
  151.      */
  152.     virtual void refreshIcon( bool redraw );
  153.  
  154.     virtual void setKey( const QString &key );
  155.  
  156.     /**
  157.      * Paints this item. Takes care of using the normal or alpha
  158.      * blending methods depending on the configuration.
  159.      */
  160.     virtual void paintItem( QPainter *p, const QColorGroup &cg );
  161.  
  162.     virtual bool move( int x, int y );
  163.  
  164.     /**
  165.      * Enable an animation on mouseover, if there is an available mng.
  166.      * @param movieFileName the base name for the mng, e.g. "folder".
  167.      * Nothing happens if there is no animation available.
  168.      */
  169.     void setMouseOverAnimation( const QString& movieFileName );
  170.     QString mouseOverAnimation() const;
  171.  
  172.     /**
  173.      * Return true if the icon _might_ have an animation available.
  174.      * This doesn't mean the .mng exists (only determined when hovering on the
  175.      * icon - and if it doesn't exist setMouseOverAnimation(QString::null) is called),
  176.      * and it doesn't mean that it's currently running either.
  177.      */
  178.     bool hasAnimation() const;
  179.  
  180.     /** Return true if we are currently animating this icon */
  181.     bool isAnimated() const;
  182.     void setAnimated( bool );
  183.  
  184.     /** Called when the mouse is over the icon */
  185.     void setActive( bool active );
  186.  
  187.     /**
  188.      * Sets showing of directory overlays. Does nothing if this does
  189.      * not represent a folder.
  190.      */
  191.     KIVDirectoryOverlay* setShowDirectoryOverlay( bool );
  192.     bool showDirectoryOverlay( );
  193.  
  194.     virtual int compare( QIconViewItem *i ) const;
  195.  
  196. protected:
  197.     virtual void dropped( QDropEvent *e, const QValueList<QIconDragItem> &  );
  198.  
  199.     /**
  200.      * Contains the logic and code for painting the overlay pixmap.
  201.      */
  202.     void paintOverlay( QPainter *p ) const;
  203.  
  204.     /**
  205.      * Updates the colorgroup.
  206.      */
  207.     QColorGroup updateColors(const QColorGroup &c) const;
  208.  
  209.     /**
  210.      * Contains the logic and code for painting links.
  211.      */
  212.     void paintFontUpdate( QPainter *p ) const;
  213.  
  214. private:
  215.     /** You are not supposed to call this on a KFileIVI, from the outside,
  216.      * it bypasses the icons cache */
  217.     virtual void setPixmap ( const QPixmap & icon ) { KIconViewItem::setPixmap( icon ); }
  218.     virtual void setPixmap ( const QPixmap & icon, bool recalc, bool redraw = TRUE )
  219.         { KIconViewItem::setPixmap( icon, recalc, redraw ); }
  220.  
  221.     /** Check if a thumbnail will be generated and calc the size of the icon */
  222.     void updatePixmapSize();
  223.     
  224.     int m_size, m_state;
  225.     bool m_bDisabled;
  226.     bool m_bThumbnail;
  227.     /** Pointer to the file item in KDirLister's list */
  228.     KFileItem* m_fileitem;
  229.  
  230.     /**
  231.      * Private data for KFileIVI
  232.      * Implementation in kfileivi.cc
  233.      */
  234.     struct Private;
  235.  
  236.     Private *d;
  237. };
  238.  
  239. #endif
  240.