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 * Orders the items \a items in a way that the visible items
157 * are moved to the front of the list. When passing this
158 * list to a preview job, the visible items will get generated
161 void orderItems(KFileItemList
& items
);
164 /** Remembers the pixmap for an item specified by an URL. */
174 * True, if m_pendingItems and m_dispatchedItems should be
175 * cleared when the preview jobs have been finished.
177 bool m_clearItemQueues
;
179 QAbstractItemView
* m_view
;
180 QTimer
* m_previewTimer
;
181 QTimer
* m_scrollAreaTimer
;
182 QList
<KJob
*> m_previewJobs
;
183 DolphinModel
* m_dolphinModel
;
184 DolphinSortFilterProxyModel
* m_proxyModel
;
186 KMimeTypeResolver
* m_mimeTypeResolver
;
188 QList
<ItemInfo
> m_cutItemsCache
;
189 QList
<ItemInfo
> m_previews
;
192 * Contains all items where a preview must be generated, but
193 * where the preview job has not dispatched the items yet.
195 KFileItemList m_pendingItems
;
198 * Contains all items, where a preview has already been
199 * generated by the preview jobs.
201 KFileItemList m_dispatchedItems
;
204 inline bool IconManager::showPreview() const
206 return m_showPreview
;