1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program 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 *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
23 #include <kfileitem.h>
31 class DolphinSortFilterProxyModel
;
33 class KMimeTypeResolver
;
34 class QAbstractItemView
;
37 * @brief Manages the icon state of a directory model.
39 * Per default a preview is generated for each item.
40 * Additionally the clipboard is checked for cut items.
41 * The icon state for cut items gets dimmed automatically.
43 * The following strategy is used when creating previews:
44 * - The previews for currently visible items are created before
45 * the previews for invisible items.
46 * - If the user changes the visible area by using the scrollbars,
47 * all pending previews get paused. As soon as the user stays
48 * on the same position for a short delay, the previews are
49 * resumed. Also in this case the previews for the visible items
50 * are generated first.
52 class IconManager
: public QObject
57 IconManager(QAbstractItemView
* parent
, DolphinSortFilterProxyModel
* model
);
58 virtual ~IconManager();
59 void setShowPreview(bool show
);
60 bool showPreview() const;
63 * Updates the previews for all already available items. It is only necessary
64 * to invoke this method when the icon size of the abstract item view has
67 void updatePreviews();
70 * Cancels all pending previews. Should be invoked when the URL of the item
71 * view has been changed.
73 void cancelPreviews();
77 * Generates previews for the items \a items asynchronously.
79 void generatePreviews(const KFileItemList
& items
);
82 * Adds the preview \a pixmap for the item \a item to the preview
83 * queue and starts a timer which will dispatch the preview queue
86 void addToPreviewQueue(const KFileItem
& item
, const QPixmap
& pixmap
);
89 * Is invoked when the preview job has been finished and
90 * removes the job from the m_previewJobs list.
92 void slotPreviewJobFinished(KJob
* job
);
94 /** Synchronizes the item icon with the clipboard of cut items. */
95 void updateCutItems();
98 * Dispatches the preview queue block by block within
101 void dispatchPreviewQueue();
104 * Pauses all preview jobs and invokes IconManager::resumePreviews()
105 * after a short delay. Is invoked as soon as the user has moved
108 void pausePreviews();
111 * Resumes the previews that have been paused after moving the
112 * scrollbar. The previews for the current visible area are
115 void resumePreviews();
119 * Replaces the icon of the item with the \a url by the preview pixmap
122 void replaceIcon(const KUrl
& url
, const QPixmap
& pixmap
);
125 * Returns true, if the item \a item has been cut into
128 bool isCutItem(const KFileItem
& item
) const;
130 /** Applies an item effect to all cut items. */
131 void applyCutItemEffect();
134 * Applies a frame around the icon. False is returned if
135 * no frame has been added because the icon is too small.
137 bool applyImageFrame(QPixmap
& icon
);
140 * Resizes the icon to \a maxSize if the icon size does not
141 * fit into the maximum size. The aspect ratio of the icon
144 void limitToSize(QPixmap
& icon
, const QSize
& maxSize
);
147 * Starts a new preview job for the items \a to m_previewJobs
148 * and triggers the preview timer.
150 void startPreviewJob(const KFileItemList
& items
);
152 /** Kills all ongoing preview jobs. */
153 void killPreviewJobs();
156 * Returns true, if the item list \a items contains an item with the
157 * URL \a url. This is a helper method for IconManager::generatePreviews().
159 bool itemListContains(const KFileItemList
& items
, const KUrl
& url
) const;
162 /** Remembers the pixmap for an item specified by an URL. */
172 * True, if m_pendingItems and m_dispatchedItems should be
173 * cleared when the preview jobs have been finished.
175 bool m_clearItemQueues
;
177 QAbstractItemView
* m_view
;
178 QTimer
* m_previewTimer
;
179 QTimer
* m_scrollAreaTimer
;
180 QList
<KJob
*> m_previewJobs
;
181 DolphinModel
* m_dolphinModel
;
182 DolphinSortFilterProxyModel
* m_proxyModel
;
184 KMimeTypeResolver
* m_mimeTypeResolver
;
186 QList
<ItemInfo
> m_cutItemsCache
;
187 QList
<ItemInfo
> m_previews
;
190 * Contains the URLs of all items where a preview must be generated, but
191 * where the preview job has not dispatched the items yet.
193 QList
<KUrl
> m_pendingItems
;
196 * Contains the URLs of all items, where a preview has already been
197 * generated by the preview jobs.
199 QList
<KUrl
> m_dispatchedItems
;
202 inline bool IconManager::showPreview() const
204 return m_showPreview
;