File indexing completed on 2024-04-28 15:26:44

0001 /*
0002     SPDX-FileCopyrightText: 2008-2009 Peter Penz <peter.penz@gmx.at>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KFILEPREVIEWGENERATOR_H
0008 #define KFILEPREVIEWGENERATOR_H
0009 
0010 #include "kiofilewidgets_export.h"
0011 
0012 #include <QObject>
0013 
0014 #include <memory>
0015 
0016 class KAbstractViewAdapter;
0017 class KDirModel;
0018 class QAbstractItemView;
0019 class QAbstractProxyModel;
0020 
0021 class KFilePreviewGeneratorPrivate;
0022 
0023 /**
0024  * @class KFilePreviewGenerator kfilepreviewgenerator.h <KFilePreviewGenerator>
0025  *
0026  * @brief Generates previews for files of an item view.
0027  *
0028  * Per default a preview is generated for each item.
0029  * Additionally the clipboard is checked for cut items.
0030  * The icon state for cut items gets dimmed automatically.
0031  *
0032  * The following strategy is used when creating previews:
0033  * - The previews for currently visible items are created before
0034  *   the previews for invisible items.
0035  * - If the user changes the visible area by using the scrollbars,
0036  *   all pending previews get paused. As soon as the user stays
0037  *   on the same position for a short delay, the previews are
0038  *   resumed. Also in this case the previews for the visible items
0039  *   are generated first.
0040  *
0041  * @since 4.2
0042  */
0043 class KIOFILEWIDGETS_EXPORT KFilePreviewGenerator : public QObject
0044 {
0045     Q_OBJECT
0046 
0047 public:
0048     /**
0049      * @param parent  Item view containing the file items where previews should
0050      *                be generated. It is mandatory that the item view specifies
0051      *                an icon size by QAbstractItemView::setIconSize() and that
0052      *                the model of the view (or the source model of the proxy model)
0053      *                is an instance of KDirModel. Otherwise no previews will be generated.
0054      */
0055     KFilePreviewGenerator(QAbstractItemView *parent);
0056 
0057     /** @internal */
0058     KFilePreviewGenerator(KAbstractViewAdapter *parent, QAbstractProxyModel *model);
0059 
0060     ~KFilePreviewGenerator() override;
0061 
0062     /**
0063      * If \a show is set to true, a preview is generated for each item. If \a show
0064      * is false, the MIME type icon of the item is shown instead. Per default showing
0065      * the preview is turned on. Note that it is mandatory that the item view
0066      * specifies an icon size by QAbstractItemView::setIconSize(), otherwise
0067      * KFilePreviewGenerator::isPreviewShown() will always return false.
0068      */
0069     void setPreviewShown(bool show);
0070     bool isPreviewShown() const;
0071 
0072 #if KIOFILEWIDGETS_ENABLE_DEPRECATED_SINCE(4, 3)
0073     /**
0074      * @deprecated Since 4.3, use KFilePreviewGenerator::updateIcons() instead.
0075      */
0076     KIOFILEWIDGETS_DEPRECATED_VERSION(4, 3, "Use KFilePreviewGenerator::updateIcons()")
0077     void updatePreviews();
0078 #endif
0079 
0080     /**
0081      * Sets the list of enabled thumbnail plugins.
0082      * Per default all plugins enabled in the KConfigGroup "PreviewSettings"
0083      * are used.
0084      *
0085      * Note that this method doesn't cause already generated previews
0086      * to be regenerated.
0087      *
0088      * For a list of available plugins, call KIO::PreviewJob::availableThumbnailerPlugins().
0089      *
0090      * @see enabledPlugins
0091      */
0092     void setEnabledPlugins(const QStringList &list);
0093 
0094     /**
0095      * Returns the list of enabled thumbnail plugins.
0096      * @see setEnabledPlugins
0097      */
0098     QStringList enabledPlugins() const;
0099 
0100 public Q_SLOTS:
0101     /**
0102      * Updates the icons for all items. Usually it is only
0103      * necessary to invoke this method when the icon size of the abstract item view
0104      * has been changed by QAbstractItemView::setIconSize(). Note that this method
0105      * should also be invoked if previews have been turned off, as the icons for
0106      * cut items must be updated when the icon size has changed.
0107      * @since 4.3
0108      */
0109     void updateIcons();
0110 
0111     /** Cancels all pending previews. */
0112     void cancelPreviews();
0113 
0114 private:
0115     friend class KFilePreviewGeneratorPrivate;
0116     std::unique_ptr<KFilePreviewGeneratorPrivate> const d;
0117 
0118     Q_DISABLE_COPY(KFilePreviewGenerator)
0119 
0120     Q_PRIVATE_SLOT(d, void pauseIconUpdates())
0121 };
0122 
0123 #endif