]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kfileitemlistview.h
GIT_SILENT Update Appstream for new release
[dolphin.git] / src / kitemviews / kfileitemlistview.h
1 /*
2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef KFILEITEMLISTVIEW_H
8 #define KFILEITEMLISTVIEW_H
9
10 #include "dolphin_export.h"
11 #include "kitemviews/kstandarditemlistview.h"
12
13 #include <KFileItem>
14
15 class KFileItemModelRolesUpdater;
16 class QTimer;
17
18 /**
19 * @brief View that allows to show the content of file-items.
20 *
21 * The corresponding model set by the controller must be an instance
22 * of KFileItemModel. Per default KFileItemListWidget is set as widget creator
23 * value and KItemListGroupHeader as group-header creator value. Use
24 * KItemListView::setWidgetCreator() and KItemListView::setGroupHeaderCreator()
25 * to apply customized generators.
26 */
27 class DOLPHIN_EXPORT KFileItemListView : public KStandardItemListView
28 {
29 Q_OBJECT
30
31 public:
32 explicit KFileItemListView(QGraphicsWidget *parent = nullptr);
33 ~KFileItemListView() override;
34
35 void setPreviewsShown(bool show);
36 bool previewsShown() const;
37
38 /**
39 * If enabled a small preview gets upscaled to the icon size in case where
40 * the icon size is larger than the preview. Per default enlarging is
41 * enabled.
42 */
43 void setEnlargeSmallPreviews(bool enlarge);
44 bool enlargeSmallPreviews() const;
45
46 /**
47 * Sets the list of enabled thumbnail plugins that are used for previews.
48 * Per default all plugins enabled in the KConfigGroup "PreviewSettings"
49 * are used.
50 *
51 * For a list of available plugins, call KIO::PreviewJob::availableThumbnailerPlugins().
52 *
53 * @see enabledPlugins
54 */
55 void setEnabledPlugins(const QStringList &list);
56
57 /**
58 * Returns the list of enabled thumbnail plugins.
59 * @see setEnabledPlugins
60 */
61 QStringList enabledPlugins() const;
62
63 /**
64 * Sets the maximum file size of local files for which
65 * previews will be generated (if enabled). A value of 0
66 * indicates no file size limit.
67 * Per default the value from KConfigGroup "PreviewSettings"
68 * MaximumSize is used, 0 otherwise.
69 * @param size
70 */
71 void setLocalFileSizePreviewLimit(qlonglong size);
72 qlonglong localFileSizePreviewLimit() const;
73
74 QPixmap createDragPixmap(const KItemSet &indexes) const override;
75
76 /**
77 * Notifies the view of a change in the hover state on an item.
78 *
79 * @param itemUrl URL of the item that is hovered, or an empty URL if no item is hovered.
80 * @param seqIdx The current hover sequence index. While an item is hovered,
81 * this method will be called repeatedly with increasing values
82 * for this parameter.
83 */
84 void setHoverSequenceState(const QUrl &itemUrl, int seqIdx);
85
86 protected:
87 KItemListWidgetCreatorBase *defaultWidgetCreator() const override;
88 void initializeItemListWidget(KItemListWidget *item) override;
89 virtual void onPreviewsShownChanged(bool shown);
90 void onItemLayoutChanged(ItemLayout current, ItemLayout previous) override;
91 void onModelChanged(KItemModelBase *current, KItemModelBase *previous) override;
92 void onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous) override;
93 void onItemSizeChanged(const QSizeF &current, const QSizeF &previous) override;
94 void onScrollOffsetChanged(qreal current, qreal previous) override;
95 void onVisibleRolesChanged(const QList<QByteArray> &current, const QList<QByteArray> &previous) override;
96 void onStyleOptionChanged(const KItemListStyleOption &current, const KItemListStyleOption &previous) override;
97 void onSupportsItemExpandingChanged(bool supportsExpanding) override;
98 void onTransactionBegin() override;
99 void onTransactionEnd() override;
100 void resizeEvent(QGraphicsSceneResizeEvent *event) override;
101 void focusInEvent(QFocusEvent *event) override;
102 void focusOutEvent(QFocusEvent *event) override;
103
104 protected Q_SLOTS:
105 void slotItemsRemoved(const KItemRangeList &itemRanges) override;
106 void slotSortRoleChanged(const QByteArray &current, const QByteArray &previous) override;
107
108 private Q_SLOTS:
109 void triggerVisibleIndexRangeUpdate();
110 void updateVisibleIndexRange();
111
112 void triggerIconSizeUpdate();
113 void updateIconSize();
114
115 private:
116 /**
117 * Applies the roles defined by KItemListView::visibleRoles() to the
118 * KFileItemModel and KFileItemModelRolesUpdater. As the model does not
119 * distinct between visible and invisible roles also internal roles
120 * are applied that are mandatory for having a working KFileItemModel.
121 */
122 void applyRolesToModel();
123
124 /**
125 * @return Size that is available for the icons. The size might be larger than specified by
126 * KItemListStyleOption::iconSize: With the IconsLayout also the empty left area left
127 * and right of an icon will be included.
128 */
129 QSize availableIconSize() const;
130
131 private:
132 void updateSelectedWidgets();
133
134 KFileItemModelRolesUpdater *m_modelRolesUpdater;
135 QTimer *m_updateVisibleIndexRangeTimer;
136 QTimer *m_updateIconSizeTimer;
137
138 friend class KFileItemListViewTest; // For unit testing
139 friend class DolphinMainWindowTest; // For unit testing
140 };
141
142 #endif