1 /*******************************************************************************
2 * Copyright (C) 2008-2009 by Peter Penz <peter.penz@gmx.at> *
4 * This library is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Library General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2 of the License, or (at your option) any later version. *
9 * This library 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 GNU *
12 * Library General Public License for more details. *
14 * You should have received a copy of the GNU Library General Public License *
15 * along with this library; see the file COPYING.LIB. If not, write to *
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301, USA. *
18 *******************************************************************************/
20 #ifndef KFILEPREVIEWGENERATOR_H
21 #define KFILEPREVIEWGENERATOR_H
23 #include <kfile_export.h>
25 #include <QtCore/QObject>
27 class KAbstractViewAdapter
;
29 class QAbstractItemView
;
30 class QAbstractProxyModel
;
33 * @brief Generates previews for files of an item view.
35 * Per default a preview is generated for each item.
36 * Additionally the clipboard is checked for cut items.
37 * The icon state for cut items gets dimmed automatically.
39 * The following strategy is used when creating previews:
40 * - The previews for currently visible items are created before
41 * the previews for invisible items.
42 * - If the user changes the visible area by using the scrollbars,
43 * all pending previews get paused. As soon as the user stays
44 * on the same position for a short delay, the previews are
45 * resumed. Also in this case the previews for the visible items
46 * are generated first.
50 class KFILE_EXPORT KFilePreviewGenerator
: public QObject
56 * @param parent Item view containing the file items where previews should
57 * be generated. It is mandatory that the item view specifies
58 * an icon size by QAbstractItemView::setIconSize() and that
59 * the model of the view (or the source model of the proxy model)
60 * is an instance of KDirModel. Otherwise no previews will be generated.
62 KFilePreviewGenerator(QAbstractItemView
* parent
);
65 KFilePreviewGenerator(KAbstractViewAdapter
* parent
, QAbstractProxyModel
* model
);
67 virtual ~KFilePreviewGenerator();
70 * If \a show is set to true, a preview is generated for each item. If \a show
71 * is false, the MIME type icon of the item is shown instead. Per default showing
72 * the preview is turned on. Note that it is mandatory that the item view
73 * specifies an icon size by QAbstractItemView::setIconSize(), otherwise
74 * KFilePreviewGenerator::isPreviewShown() will always return false.
76 void setPreviewShown(bool show
);
77 bool isPreviewShown() const;
80 * Updates the previews for all already available items. Usually it is only
81 * necessary to invoke this method when the icon size of the abstract item view
82 * has been changed by QAbstractItemView::setIconSize().
84 void updatePreviews();
86 /** Cancels all pending previews. */
87 void cancelPreviews();
90 * Sets the list of enabled thumbnail plugins.
91 * If the list is empty, all plugins will be enabled.
92 * All plugins are enabled by default.
94 * Note that this method doesn't cause already generated previews
97 * For a list of available plugins, call KServiceTypeTrader::self()->query("ThumbCreator").
101 void setEnabledPlugins(const QStringList
& list
);
104 * Returns the list of enabled thumbnail plugins,
105 * or an empty list if all plugins are enabled.
107 * @see setEnabledPlugins
109 QStringList
enabledPlugins() const;
113 Private
* const d
; /// @internal
114 Q_DISABLE_COPY(KFilePreviewGenerator
)
116 Q_PRIVATE_SLOT(d
, void updateIcons(const KFileItemList
&))
117 Q_PRIVATE_SLOT(d
, void updateIcons(const QModelIndex
&, const QModelIndex
&))
118 Q_PRIVATE_SLOT(d
, void addToPreviewQueue(const KFileItem
&, const QPixmap
&))
119 Q_PRIVATE_SLOT(d
, void slotPreviewJobFinished(KJob
*))
120 Q_PRIVATE_SLOT(d
, void updateCutItems())
121 Q_PRIVATE_SLOT(d
, void dispatchIconUpdateQueue())
122 Q_PRIVATE_SLOT(d
, void pauseIconUpdates())
123 Q_PRIVATE_SLOT(d
, void resumeIconUpdates())
124 Q_PRIVATE_SLOT(d
, void resolveMimeType())