1 | /* |
2 | SPDX-FileCopyrightText: 2008-2009 Peter Penz <peter.penz@gmx.at> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef KFILEPREVIEWGENERATOR_H |
8 | #define KFILEPREVIEWGENERATOR_H |
9 | |
10 | #include "kiofilewidgets_export.h" |
11 | |
12 | #include <QObject> |
13 | |
14 | #include <memory> |
15 | |
16 | class KAbstractViewAdapter; |
17 | class KDirModel; |
18 | class QAbstractItemView; |
19 | class QAbstractProxyModel; |
20 | |
21 | class KFilePreviewGeneratorPrivate; |
22 | |
23 | /*! |
24 | * \class KFilePreviewGenerator |
25 | * \inmodule KIOFileWidgets |
26 | * |
27 | * \brief Generates previews for files of an item view. |
28 | * |
29 | * Per default a preview is generated for each item. |
30 | * Additionally the clipboard is checked for cut items. |
31 | * The icon state for cut items gets dimmed automatically. |
32 | * |
33 | * The following strategy is used when creating previews: |
34 | * \list |
35 | * \li The previews for currently visible items are created before |
36 | * the previews for invisible items. |
37 | * \li If the user changes the visible area by using the scrollbars, |
38 | * all pending previews get paused. As soon as the user stays |
39 | * on the same position for a short delay, the previews are |
40 | * resumed. Also in this case the previews for the visible items |
41 | * are generated first. |
42 | * \endlist |
43 | * |
44 | */ |
45 | class KIOFILEWIDGETS_EXPORT KFilePreviewGenerator : public QObject |
46 | { |
47 | Q_OBJECT |
48 | |
49 | public: |
50 | /*! |
51 | * \a parent Item view containing the file items where previews should |
52 | * be generated. It is mandatory that the item view specifies |
53 | * an icon size by QAbstractItemView::setIconSize() and that |
54 | * the model of the view (or the source model of the proxy model) |
55 | * is an instance of KDirModel. Otherwise no previews will be generated. |
56 | */ |
57 | KFilePreviewGenerator(QAbstractItemView *parent); |
58 | |
59 | /*! \internal */ |
60 | KFilePreviewGenerator(KAbstractViewAdapter *parent, QAbstractProxyModel *model); |
61 | |
62 | ~KFilePreviewGenerator() override; |
63 | |
64 | /*! |
65 | * If \a show is set to true, a preview is generated for each item. If \a show |
66 | * is false, the MIME type icon of the item is shown instead. Per default showing |
67 | * the preview is turned on. Note that it is mandatory that the item view |
68 | * specifies an icon size by QAbstractItemView::setIconSize(), otherwise |
69 | * KFilePreviewGenerator::isPreviewShown() will always return false. |
70 | */ |
71 | void setPreviewShown(bool show); |
72 | |
73 | /*! |
74 | * |
75 | */ |
76 | bool isPreviewShown() const; |
77 | |
78 | /*! |
79 | * Sets the list of enabled thumbnail plugins. |
80 | * Per default all plugins enabled in the KConfigGroup "PreviewSettings" |
81 | * are used. |
82 | * |
83 | * Note that this method doesn't cause already generated previews |
84 | * to be regenerated. |
85 | * |
86 | * For a list of available plugins, call KIO::PreviewJob::availableThumbnailerPlugins(). |
87 | * |
88 | * \sa enabledPlugins |
89 | */ |
90 | void setEnabledPlugins(const QStringList &list); |
91 | |
92 | /*! |
93 | * Returns the list of enabled thumbnail plugins. |
94 | * \sa setEnabledPlugins |
95 | */ |
96 | QStringList enabledPlugins() const; |
97 | |
98 | public Q_SLOTS: |
99 | /*! |
100 | * Updates the icons for all items. Usually it is only |
101 | * necessary to invoke this method when the icon size of the abstract item view |
102 | * has been changed by QAbstractItemView::setIconSize(). Note that this method |
103 | * should also be invoked if previews have been turned off, as the icons for |
104 | * cut items must be updated when the icon size has changed. |
105 | */ |
106 | void updateIcons(); |
107 | |
108 | /*! Cancels all pending previews. */ |
109 | void cancelPreviews(); |
110 | |
111 | private: |
112 | friend class KFilePreviewGeneratorPrivate; |
113 | std::unique_ptr<KFilePreviewGeneratorPrivate> const d; |
114 | |
115 | Q_DISABLE_COPY(KFilePreviewGenerator) |
116 | |
117 | Q_PRIVATE_SLOT(d, void pauseIconUpdates()) |
118 | }; |
119 | |
120 | #endif |
121 | |