summaryrefslogtreecommitdiffstats
path: root/libkonq/kfileivi.h
blob: d1f1d9ab7f55b9486ea99f9a26f45778922fb729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/* This file is part of the KDE project
   Copyright (C) 1999, 2000, 2001, 2002 David Faure <[email protected]>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef __kfileivi_h__
#define __kfileivi_h__

#include <kiconview.h>
#include <kiconloader.h>
#include <libkonq_export.h>

class KFileItem;
class KonqIconViewWidget;
class KIVDirectoryOverlay;

/**
 * KFileIVI (short form of "Konq - File - IconViewItem")
 * is, as expected, an improved KIconViewItem, because
 * it represents a file.
 * All the information about the file is contained in the KFileItem
 * pointer.
 */
class LIBKONQ_EXPORT KFileIVI : public KIconViewItem
{
public:
    /**
     * Create an icon, within a qlistview, representing a file
     * @param iconview the parent widget
     * @param fileitem the file item created by KDirLister
     * @param size the icon size
     */
    KFileIVI( KonqIconViewWidget *iconview, KFileItem* fileitem, int size );
    virtual ~KFileIVI();

    /**
     * Handler for return (or single/double click) on ONE icon.
     * Runs the file through KRun.
     */
    virtual void returnPressed();

    /**
     * @return the file item held by this instance
     */
    KFileItem * item() const { return m_fileitem; }

    /**
     * @return true if dropping on this file is allowed
     * Overloads QIconView::acceptDrop()
     */
    virtual bool acceptDrop( const QMimeSource *mime ) const;

    /**
     * Changes the icon for this item.
     * @param size the icon size (0 for default, otherwise size in pixels)
     * @param state the state of the icon (enum in KIcon)
     * @param recalc whether to update the layout of the icon view when setting the icon
     * @param redraw whether to redraw the item after setting the icon
     */
    virtual void setIcon( int size,
                          int state=KIcon::DefaultState,
                          bool recalc=false,
                          bool redraw=false);

    /**
     * Bypass @ref setIcon. This is for animated icons, you should use setIcon
     * in all other cases.
     * @param pixmap the pixmap to set - it SHOULD really have the right icon size!
     * @param recalc whether to update the layout of the icon view when setting the icon
     * @param redraw whether to redraw the item after setting the icon
     */
    void setPixmapDirect( const QPixmap & pixmap,
                          bool recalc=false,
                          bool redraw=false);

    /**
     * Notifies that all icon effects on thumbs should be invalidated,
     * e.g. because the effect settings have been changed. The thumb itself
     * is assumed to be still valid (use setThumbnailPixmap() instead
     * otherwise).
     * @param state the state of the icon (enum in KIcon)
     * @param redraw whether to redraw the item after setting the icon
     */
    void invalidateThumb( int state, bool redraw = false );

    /**
     * Our current thumbnail is not longer "current".
     * Called when the file contents have changed.
     */
    void invalidateThumbnail();
    bool isThumbnailInvalid() const;

    bool hasValidThumbnail() const { return isThumbnail() && !isThumbnailInvalid(); }

    /**
     * Return the current state of the icon
     * (KIcon::DefaultState, KIcon::ActiveState etc.)
     */
    int state() const { return m_state; }

    /**
     * Return the theorical size of the icon
     */
    int iconSize() const { return m_size; }

    /**
     * Set to true when this icon is 'cut'
     */
    void setDisabled( bool disabled );

    /**
     * Set this when the thumbnail was loaded
     */
    void setThumbnailPixmap( const QPixmap & pixmap );

    /**
     * Set the icon to use the specified KIconEffect
     * See the docs for KIconEffect for details.
     */
    void setEffect( /*int group,*/ int state );

    /**
     * @return true if this item is a thumbnail
     */
    bool isThumbnail() const { return m_bThumbnail; }

    /**
     * Sets an icon to be shown over the bottom left corner of the icon.
     * Currently used for directory overlays.
     * setOverlay(QString::null) to remove icon.
     */
    void setOverlay( const QString & iconName);

    /**
     * Redetermines the icon (useful if KFileItem might return another icon).
     * Does nothing with thumbnails
     */
    virtual void refreshIcon( bool redraw );

    virtual void setKey( const QString &key );

    /**
     * Paints this item. Takes care of using the normal or alpha
     * blending methods depending on the configuration.
     */
    virtual void paintItem( QPainter *p, const QColorGroup &cg );

    virtual bool move( int x, int y );

    /**
     * Enable an animation on mouseover, if there is an available mng.
     * @param movieFileName the base name for the mng, e.g. "folder".
     * Nothing happens if there is no animation available.
     */
    void setMouseOverAnimation( const QString& movieFileName );
    QString mouseOverAnimation() const;

    /**
     * Return true if the icon _might_ have an animation available.
     * This doesn't mean the .mng exists (only determined when hovering on the
     * icon - and if it doesn't exist setMouseOverAnimation(QString::null) is called),
     * and it doesn't mean that it's currently running either.
     */
    bool hasAnimation() const;

    /** Return true if we are currently animating this icon */
    bool isAnimated() const;
    void setAnimated( bool );

    /** Called when the mouse is over the icon */
    void setActive( bool active );

    /**
     * Sets showing of directory overlays. Does nothing if this does
     * not represent a folder.
     */
    KIVDirectoryOverlay* setShowDirectoryOverlay( bool );
    bool showDirectoryOverlay( );

    virtual int compare( QIconViewItem *i ) const;

protected:
    virtual void dropped( QDropEvent *e, const QValueList<QIconDragItem> &  );

    /**
     * Contains the logic and code for painting the overlay pixmap.
     */
    void paintOverlay( QPainter *p ) const;

    /**
     * Updates the colorgroup.
     */
    QColorGroup updateColors(const QColorGroup &c) const;

    /**
     * Contains the logic and code for painting links.
     */
    void paintFontUpdate( QPainter *p ) const;

private:
    /** You are not supposed to call this on a KFileIVI, from the outside,
     * it bypasses the icons cache */
    virtual void setPixmap ( const QPixmap & icon ) { KIconViewItem::setPixmap( icon ); }
    virtual void setPixmap ( const QPixmap & icon, bool recalc, bool redraw = TRUE )
        { KIconViewItem::setPixmap( icon, recalc, redraw ); }

    /** Check if a thumbnail will be generated and calc the size of the icon */
    void updatePixmapSize();
    
    int m_size, m_state;
    bool m_bDisabled;
    bool m_bThumbnail;
    /** Pointer to the file item in KDirLister's list */
    KFileItem* m_fileitem;

    /**
     * Private data for KFileIVI
     * Implementation in kfileivi.cc
     */
    struct Private;

    Private *d;
};

#endif