File indexing completed on 2024-02-18 03:57:13

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  */
0042 class KIOFILEWIDGETS_EXPORT KFilePreviewGenerator : public QObject
0043 {
0044     Q_OBJECT
0045 
0046 public:
0047     /**
0048      * @param parent  Item view containing the file items where previews should
0049      *                be generated. It is mandatory that the item view specifies
0050      *                an icon size by QAbstractItemView::setIconSize() and that
0051      *                the model of the view (or the source model of the proxy model)
0052      *                is an instance of KDirModel. Otherwise no previews will be generated.
0053      */
0054     KFilePreviewGenerator(QAbstractItemView *parent);
0055 
0056     /** @internal */
0057     KFilePreviewGenerator(KAbstractViewAdapter *parent, QAbstractProxyModel *model);
0058 
0059     ~KFilePreviewGenerator() override;
0060 
0061     /**
0062      * If \a show is set to true, a preview is generated for each item. If \a show
0063      * is false, the MIME type icon of the item is shown instead. Per default showing
0064      * the preview is turned on. Note that it is mandatory that the item view
0065      * specifies an icon size by QAbstractItemView::setIconSize(), otherwise
0066      * KFilePreviewGenerator::isPreviewShown() will always return false.
0067      */
0068     void setPreviewShown(bool show);
0069     bool isPreviewShown() const;
0070 
0071     /**
0072      * Sets the list of enabled thumbnail plugins.
0073      * Per default all plugins enabled in the KConfigGroup "PreviewSettings"
0074      * are used.
0075      *
0076      * Note that this method doesn't cause already generated previews
0077      * to be regenerated.
0078      *
0079      * For a list of available plugins, call KIO::PreviewJob::availableThumbnailerPlugins().
0080      *
0081      * @see enabledPlugins
0082      */
0083     void setEnabledPlugins(const QStringList &list);
0084 
0085     /**
0086      * Returns the list of enabled thumbnail plugins.
0087      * @see setEnabledPlugins
0088      */
0089     QStringList enabledPlugins() const;
0090 
0091 public Q_SLOTS:
0092     /**
0093      * Updates the icons for all items. Usually it is only
0094      * necessary to invoke this method when the icon size of the abstract item view
0095      * has been changed by QAbstractItemView::setIconSize(). Note that this method
0096      * should also be invoked if previews have been turned off, as the icons for
0097      * cut items must be updated when the icon size has changed.
0098      */
0099     void updateIcons();
0100 
0101     /** Cancels all pending previews. */
0102     void cancelPreviews();
0103 
0104 private:
0105     friend class KFilePreviewGeneratorPrivate;
0106     std::unique_ptr<KFilePreviewGeneratorPrivate> const d;
0107 
0108     Q_DISABLE_COPY(KFilePreviewGenerator)
0109 
0110     Q_PRIVATE_SLOT(d, void pauseIconUpdates())
0111 };
0112 
0113 #endif