]> cloud.milkyroute.net Git - dolphin.git/blob - src/iconmanager.h
There are some extractable strings in subdirs too.
[dolphin.git] / src / iconmanager.h
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #ifndef ICONMANAGER_H
21 #define ICONMANAGER_H
22
23 #include <kfileitem.h>
24 #include <kurl.h>
25
26 #include <QList>
27 #include <QObject>
28 #include <QPixmap>
29
30 class DolphinModel;
31 class DolphinSortFilterProxyModel;
32 class KJob;
33 class QAbstractItemView;
34
35 /**
36 * @brief Manages the icon state of a directory model.
37 *
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.
41 */
42 class IconManager : public QObject
43 {
44 Q_OBJECT
45
46 public:
47 IconManager(QAbstractItemView* parent, DolphinSortFilterProxyModel* model);
48 virtual ~IconManager();
49 void setShowPreview(bool show);
50 bool showPreview() const;
51 void updatePreviews();
52
53 private slots:
54 /**
55 * Generates previews for the items \a items asynchronously.
56 */
57 void generatePreviews(const KFileItemList &items);
58
59 /**
60 * Adds the preview \a pixmap for the item \a item to the preview
61 * queue and starts a timer which will dispatch the preview queue
62 * later.
63 */
64 void addToPreviewQueue(const KFileItem& item, const QPixmap& pixmap);
65
66 /**
67 * Is invoked when the preview job has been finished and
68 * set m_previewJob to 0.
69 */
70 void slotPreviewJobFinished(KJob* job);
71
72 /** Synchronizes the item icon with the clipboard of cut items. */
73 void updateCutItems();
74
75 /**
76 * Dispatches the preview queue m_previews block by block within
77 * time slices.
78 */
79 void dispatchPreviewQueue();
80
81 private:
82 /**
83 * Replaces the icon of the item with the \a url by the preview pixmap
84 * \a pixmap.
85 */
86 void replaceIcon(const KUrl& url, const QPixmap& pixmap);
87
88 /**
89 * Returns true, if the item \a item has been cut into
90 * the clipboard.
91 */
92 bool isCutItem(const KFileItem& item) const;
93
94 /** Applies an item effect to all cut items. */
95 void applyCutItemEffect();
96
97 /**
98 * Applies a frame around the icon. False is returned if
99 * no frame has been added because the icon is too small.
100 */
101 bool applyImageFrame(QPixmap& icon);
102
103 /**
104 * Resizes the icon to \a maxSize if the icon size does not
105 * fit into the maximum size. The aspect ratio of the icon
106 * is kept.
107 */
108 void limitToSize(QPixmap& icon, const QSize& maxSize);
109
110 /** Kills all ongoing preview jobs. */
111 void killJobs();
112
113 private:
114 /**
115 * Remembers the pixmap for an item specified by an URL.
116 */
117 struct ItemInfo
118 {
119 KUrl url;
120 QPixmap pixmap;
121 };
122
123 bool m_showPreview;
124
125 QAbstractItemView* m_view;
126 QTimer* m_previewTimer;
127 QList<KJob*> m_previewJobs;
128 DolphinModel* m_dolphinModel;
129 DolphinSortFilterProxyModel* m_proxyModel;
130
131 QList<ItemInfo> m_cutItemsCache;
132 QList<ItemInfo> m_previews;
133 };
134
135 inline bool IconManager::showPreview() const
136 {
137 return m_showPreview;
138 }
139
140 #endif