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 QAbstractItemView
;
36 * @brief Manages the icon state of a directory model.
38 * Per default a preview is generated for each item.
39 * Additionally the clipboard is checked for cut items.
40 * The icon state for cut items gets dimmed automatically.
42 * The following strategy is used when creating previews:
43 * - The previews for currently visible items are created before
44 * the previews for invisible items.
45 * - If the user changes the visible area by using the scrollbars,
46 * all pending previews get paused. As soon as the user stays
47 * on the same position for a short delay, the previews are
48 * resumed. Also in this case the previews for the visible items
49 * are generated first.
51 class IconManager
: public QObject
56 IconManager(QAbstractItemView
* parent
, DolphinSortFilterProxyModel
* model
);
57 virtual ~IconManager();
58 void setShowPreview(bool show
);
59 bool showPreview() const;
60 void updatePreviews();
64 * Generates previews for the items \a items asynchronously.
66 void generatePreviews(const KFileItemList
&items
);
69 * Adds the preview \a pixmap for the item \a item to the preview
70 * queue and starts a timer which will dispatch the preview queue
73 void addToPreviewQueue(const KFileItem
& item
, const QPixmap
& pixmap
);
76 * Is invoked when the preview job has been finished and
77 * set m_previewJob to 0.
79 void slotPreviewJobFinished(KJob
* job
);
81 /** Synchronizes the item icon with the clipboard of cut items. */
82 void updateCutItems();
85 * Dispatches the preview queue block by block within
88 void dispatchPreviewQueue();
91 * Pauses all preview jobs and invokes IconManager::resumePreviews()
92 * after a short delay. Is invoked as soon as the user has moved
98 * Resumes the previews that have been paused after moving the
99 * scrollbar. The previews for the current visible area are
102 void resumePreviews();
106 * Replaces the icon of the item with the \a url by the preview pixmap
109 void replaceIcon(const KUrl
& url
, const QPixmap
& pixmap
);
112 * Returns true, if the item \a item has been cut into
115 bool isCutItem(const KFileItem
& item
) const;
117 /** Applies an item effect to all cut items. */
118 void applyCutItemEffect();
121 * Applies a frame around the icon. False is returned if
122 * no frame has been added because the icon is too small.
124 bool applyImageFrame(QPixmap
& icon
);
127 * Resizes the icon to \a maxSize if the icon size does not
128 * fit into the maximum size. The aspect ratio of the icon
131 void limitToSize(QPixmap
& icon
, const QSize
& maxSize
);
134 * Starts a new preview job for the items \a to m_previewJobs
135 * and triggers the preview timer.
137 void startPreviewJob(const KFileItemList
& items
);
139 /** Kills all ongoing preview jobs. */
140 void killPreviewJobs();
143 /** Remembers the pixmap for an item specified by an URL. */
153 * True, if m_pendingItems and m_dispatchedItems should be
154 * cleared when the preview jobs have been finished.
156 bool m_clearItemQueues
;
158 QAbstractItemView
* m_view
;
159 QTimer
* m_previewTimer
;
160 QTimer
* m_scrollAreaTimer
;
161 QList
<KJob
*> m_previewJobs
;
162 DolphinModel
* m_dolphinModel
;
163 DolphinSortFilterProxyModel
* m_proxyModel
;
165 QList
<ItemInfo
> m_cutItemsCache
;
166 QList
<ItemInfo
> m_previews
;
169 * Contains the URLs of all items where a preview must be generated, but
170 * where the preview job has not dispatched the items yet.
172 QList
<KUrl
> m_pendingItems
;
175 * Containts the URLs of all items, where a preview has already been
176 * generated by the preview jobs.
178 QList
<KUrl
> m_dispatchedItems
;
181 inline bool IconManager::showPreview() const
183 return m_showPreview
;