File indexing completed on 2024-04-28 05:45:03

0001 /*
0002  * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KFILEITEMLISTVIEW_H
0008 #define KFILEITEMLISTVIEW_H
0009 
0010 #include "dolphin_export.h"
0011 #include "kitemviews/kstandarditemlistview.h"
0012 
0013 #include <KFileItem>
0014 
0015 class KFileItemModelRolesUpdater;
0016 class QTimer;
0017 
0018 /**
0019  * @brief View that allows to show the content of file-items.
0020  *
0021  * The corresponding model set by the controller must be an instance
0022  * of KFileItemModel. Per default KFileItemListWidget is set as widget creator
0023  * value and KItemListGroupHeader as group-header creator value. Use
0024  * KItemListView::setWidgetCreator() and KItemListView::setGroupHeaderCreator()
0025  * to apply customized generators.
0026  */
0027 class DOLPHIN_EXPORT KFileItemListView : public KStandardItemListView
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     explicit KFileItemListView(QGraphicsWidget *parent = nullptr);
0033     ~KFileItemListView() override;
0034 
0035     void setPreviewsShown(bool show);
0036     bool previewsShown() const;
0037 
0038     /**
0039      * If enabled a small preview gets upscaled to the icon size in case where
0040      * the icon size is larger than the preview. Per default enlarging is
0041      * enabled.
0042      */
0043     void setEnlargeSmallPreviews(bool enlarge);
0044     bool enlargeSmallPreviews() const;
0045 
0046     /**
0047      * Sets the list of enabled thumbnail plugins that are used for previews.
0048      * Per default all plugins enabled in the KConfigGroup "PreviewSettings"
0049      * are used.
0050      *
0051      * For a list of available plugins, call KIO::PreviewJob::availableThumbnailerPlugins().
0052      *
0053      * @see enabledPlugins
0054      */
0055     void setEnabledPlugins(const QStringList &list);
0056 
0057     /**
0058      * Returns the list of enabled thumbnail plugins.
0059      * @see setEnabledPlugins
0060      */
0061     QStringList enabledPlugins() const;
0062 
0063     /**
0064      * Sets the maximum file size of local files for which
0065      * previews will be generated (if enabled). A value of 0
0066      * indicates no file size limit.
0067      * Per default the value from KConfigGroup "PreviewSettings"
0068      * MaximumSize is used, 0 otherwise.
0069      * @param size
0070      */
0071     void setLocalFileSizePreviewLimit(qlonglong size);
0072     qlonglong localFileSizePreviewLimit() const;
0073 
0074     QPixmap createDragPixmap(const KItemSet &indexes) const override;
0075 
0076     /**
0077      * Notifies the view of a change in the hover state on an item.
0078      *
0079      * @param itemUrl URL of the item that is hovered, or an empty URL if no item is hovered.
0080      * @param seqIdx The current hover sequence index. While an item is hovered,
0081      *               this method will be called repeatedly with increasing values
0082      *               for this parameter.
0083      */
0084     void setHoverSequenceState(const QUrl &itemUrl, int seqIdx);
0085 
0086 protected:
0087     KItemListWidgetCreatorBase *defaultWidgetCreator() const override;
0088     void initializeItemListWidget(KItemListWidget *item) override;
0089     virtual void onPreviewsShownChanged(bool shown);
0090     void onItemLayoutChanged(ItemLayout current, ItemLayout previous) override;
0091     void onModelChanged(KItemModelBase *current, KItemModelBase *previous) override;
0092     void onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous) override;
0093     void onItemSizeChanged(const QSizeF &current, const QSizeF &previous) override;
0094     void onScrollOffsetChanged(qreal current, qreal previous) override;
0095     void onVisibleRolesChanged(const QList<QByteArray> &current, const QList<QByteArray> &previous) override;
0096     void onStyleOptionChanged(const KItemListStyleOption &current, const KItemListStyleOption &previous) override;
0097     void onSupportsItemExpandingChanged(bool supportsExpanding) override;
0098     void onTransactionBegin() override;
0099     void onTransactionEnd() override;
0100     void resizeEvent(QGraphicsSceneResizeEvent *event) override;
0101     void focusInEvent(QFocusEvent *event) override;
0102     void focusOutEvent(QFocusEvent *event) override;
0103 
0104 protected Q_SLOTS:
0105     void slotItemsRemoved(const KItemRangeList &itemRanges) override;
0106     void slotSortRoleChanged(const QByteArray &current, const QByteArray &previous) override;
0107 
0108 private Q_SLOTS:
0109     void triggerVisibleIndexRangeUpdate();
0110     void updateVisibleIndexRange();
0111 
0112     void triggerIconSizeUpdate();
0113     void updateIconSize();
0114 
0115 private:
0116     /**
0117      * Applies the roles defined by KItemListView::visibleRoles() to the
0118      * KFileItemModel and KFileItemModelRolesUpdater. As the model does not
0119      * distinct between visible and invisible roles also internal roles
0120      * are applied that are mandatory for having a working KFileItemModel.
0121      */
0122     void applyRolesToModel();
0123 
0124     /**
0125      * @return Size that is available for the icons. The size might be larger than specified by
0126      *         KItemListStyleOption::iconSize: With the IconsLayout also the empty left area left
0127      *         and right of an icon will be included.
0128      */
0129     QSize availableIconSize() const;
0130 
0131 private:
0132     void updateSelectedWidgets();
0133 
0134     KFileItemModelRolesUpdater *m_modelRolesUpdater;
0135     QTimer *m_updateVisibleIndexRangeTimer;
0136     QTimer *m_updateIconSizeTimer;
0137 
0138     friend class KFileItemListViewTest; // For unit testing
0139 };
0140 
0141 #endif