]> cloud.milkyroute.net Git - dolphin.git/blob - src/kfilepreviewgenerator.h
* renamed AbstractViewAdapter to KAbstractViewAdapter
[dolphin.git] / src / kfilepreviewgenerator.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 KFILEPREVIEWGENERATOR_H
21 #define KFILEPREVIEWGENERATOR_H
22
23 #include <QObject>
24
25 class KAbstractViewAdapter;
26 class KDirModel;
27 class QAbstractItemView;
28 class QAbstractProxyModel;
29
30 /**
31 * @brief Generates previews for files of an item view.
32 *
33 * Per default a preview is generated for each item.
34 * Additionally the clipboard is checked for cut items.
35 * The icon state for cut items gets dimmed automatically.
36 *
37 * The following strategy is used when creating previews:
38 * - The previews for currently visible items are created before
39 * the previews for invisible items.
40 * - If the user changes the visible area by using the scrollbars,
41 * all pending previews get paused. As soon as the user stays
42 * on the same position for a short delay, the previews are
43 * resumed. Also in this case the previews for the visible items
44 * are generated first.
45 */
46 class KFilePreviewGenerator : public QObject
47 {
48 Q_OBJECT
49
50 public:
51 /**
52 * @param parent Item view containing the file items where previews should
53 * be generated. It is mandatory that the item view specifies
54 * an icon size by QAbstractItemView::setIconSize(), otherwise
55 * no previews will be generated.
56 * @param model Model of the item view.
57 */
58 KFilePreviewGenerator(QAbstractItemView* parent, QAbstractProxyModel* model);
59
60 /** @internal */
61 KFilePreviewGenerator(KAbstractViewAdapter* parent, QAbstractProxyModel* model);
62
63 virtual ~KFilePreviewGenerator();
64
65 /**
66 * If \a show is set to true, a preview is generated for each item. If \a show
67 * is false, the MIME type icon of the item is shown instead. Per default showing
68 * the preview is turned on. Note that it is mandatory that the item view
69 * specifies an icon size by QAbstractItemView::setIconSize(), otherwise
70 * KFilePreviewGenerator::showPreview() will always return false.
71 */
72 void setShowPreview(bool show);
73 bool showPreview() const;
74
75 /**
76 * Updates the previews for all already available items. Usually it is only
77 * necessary to invoke this method when the icon size of the abstract item view
78 * has been changed by QAbstractItemView::setIconSize().
79 */
80 void updatePreviews();
81
82 /** Cancels all pending previews. */
83 void cancelPreviews();
84
85 private:
86 class Private;
87 Private* const d; /// @internal
88 Q_DISABLE_COPY(KFilePreviewGenerator)
89
90 Q_PRIVATE_SLOT(d, void generatePreviews(const KFileItemList&))
91 Q_PRIVATE_SLOT(d, void addToPreviewQueue(const KFileItem&, const QPixmap&))
92 Q_PRIVATE_SLOT(d, void slotPreviewJobFinished(KJob*))
93 Q_PRIVATE_SLOT(d, void updateCutItems())
94 Q_PRIVATE_SLOT(d, void dispatchPreviewQueue())
95 Q_PRIVATE_SLOT(d, void pausePreviews())
96 Q_PRIVATE_SLOT(d, void resumePreviews())
97 };
98
99 #endif