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 * Returns true, if the item \a item has been cut into
122 bool isCutItem(const KFileItem
& item
) const;
124 /** Applies an item effect to all cut items. */
125 void applyCutItemEffect();
128 * Applies a frame around the icon. False is returned if
129 * no frame has been added because the icon is too small.
131 bool applyImageFrame(QPixmap
& icon
);
134 * Resizes the icon to \a maxSize if the icon size does not
135 * fit into the maximum size. The aspect ratio of the icon
138 void limitToSize(QPixmap
& icon
, const QSize
& maxSize
);
141 * Starts a new preview job for the items \a to m_previewJobs
142 * and triggers the preview timer.
144 void startPreviewJob(const KFileItemList
& items
);
146 /** Kills all ongoing preview jobs. */
147 void killPreviewJobs();
150 * Orders the items \a items in a way that the visible items
151 * are moved to the front of the list. When passing this
152 * list to a preview job, the visible items will get generated
155 void orderItems(KFileItemList
& items
);
158 /** Remembers the pixmap for an item specified by an URL. */
168 * True, if m_pendingItems and m_dispatchedItems should be
169 * cleared when the preview jobs have been finished.
171 bool m_clearItemQueues
;
174 * True if a selection has been done which should cut items.
176 bool m_hasCutSelection
;
178 int m_pendingVisiblePreviews
;
180 QAbstractItemView
* m_view
;
181 QTimer
* m_previewTimer
;
182 QTimer
* m_scrollAreaTimer
;
183 QList
<KJob
*> m_previewJobs
;
184 DolphinModel
* m_dolphinModel
;
185 DolphinSortFilterProxyModel
* m_proxyModel
;
187 KMimeTypeResolver
* m_mimeTypeResolver
;
189 QList
<ItemInfo
> m_cutItemsCache
;
190 QList
<ItemInfo
> m_previews
;
193 * Contains all items where a preview must be generated, but
194 * where the preview job has not dispatched the items yet.
196 KFileItemList m_pendingItems
;
199 * Contains all items, where a preview has already been
200 * generated by the preview jobs.
202 KFileItemList m_dispatchedItems
;
205 inline bool IconManager::showPreview() const
207 return m_showPreview
;