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 class IconManager
: public QObject
47 IconManager(QAbstractItemView
* parent
, DolphinSortFilterProxyModel
* model
);
48 virtual ~IconManager();
49 void setShowPreview(bool show
);
50 bool showPreview() const;
51 void updatePreviews();
55 * Updates the icons of for each item in \a items by making hidden
56 * items semitransparent and generating previews. The current preview
57 * settings (maximum size, 'Show Preview' menu) are respected.
59 void updateIcons(const KFileItemList
& items
);
62 * Replaces the icon of the item \a item by the preview pixmap
65 void replaceIcon(const KFileItem
& item
, const QPixmap
& pixmap
);
68 * Is invoked when the preview job has been finished and
69 * set m_previewJob to 0.
71 void slotPreviewJobFinished(KJob
* job
);
73 /** Synchronizes the item icon with the clipboard of cut items. */
74 void updateCutItems();
77 void generatePreviews(const KFileItemList
&items
);
80 * Returns true, if the item \a item has been cut into
83 bool isCutItem(const KFileItem
& item
) const;
85 /** Applies an item effect to all cut items. */
86 void applyCutItemEffect();
89 * Applies a frame around the icon. False is returned if
90 * no frame has been added because the icon is too small.
92 bool applyImageFrame(QPixmap
& icon
);
95 * Resizes the icon to \a maxSize if the icon size does not
96 * fit into the maximum size. The aspect ratio of the icon
99 void limitToSize(QPixmap
& icon
, const QSize
& maxSize
);
101 /** Kills all ongoing preview jobs. */
106 * Remembers the original pixmap for an item before
107 * the cut effect is applied.
117 QAbstractItemView
* m_view
;
118 QList
<KJob
*> m_previewJobs
;
119 DolphinModel
* m_dolphinModel
;
120 DolphinSortFilterProxyModel
* m_proxyModel
;
122 QList
<CutItem
> m_cutItemsCache
;
125 inline bool IconManager::showPreview() const
127 return m_showPreview
;