]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kfileitemlistview.h
KItemListView fix valgrind issue "Conditional jump or move depends on uninitialised...
[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 KServiceTypeTrader::self()->query("ThumbCreator").
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 /**
75 * If set to true, directories contents are scanned to determine their size
76 * Default true
77 */
78 void setScanDirectories(bool enabled);
79 bool scanDirectories();
80
81 QPixmap createDragPixmap(const KItemSet& indexes) const override;
82
83 /**
84 * Notifies the view of a change in the hover state on an item.
85 *
86 * @param itemUrl URL of the item that is hovered, or an empty URL if no item is hovered.
87 * @param seqIdx The current hover sequence index. While an item is hovered,
88 * this method will be called repeatedly with increasing values
89 * for this parameter.
90 */
91 void setHoverSequenceState(const QUrl& itemUrl, int seqIdx);
92
93 protected:
94 KItemListWidgetCreatorBase* defaultWidgetCreator() const override;
95 void initializeItemListWidget(KItemListWidget* item) override;
96 virtual void onPreviewsShownChanged(bool shown);
97 void onItemLayoutChanged(ItemLayout current, ItemLayout previous) override;
98 void onModelChanged(KItemModelBase* current, KItemModelBase* previous) override;
99 void onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous) override;
100 void onItemSizeChanged(const QSizeF& current, const QSizeF& previous) override;
101 void onScrollOffsetChanged(qreal current, qreal previous) override;
102 void onVisibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous) override;
103 void onStyleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous) override;
104 void onSupportsItemExpandingChanged(bool supportsExpanding) override;
105 void onTransactionBegin() override;
106 void onTransactionEnd() override;
107 void resizeEvent(QGraphicsSceneResizeEvent* event) override;
108
109 protected Q_SLOTS:
110 void slotItemsRemoved(const KItemRangeList& itemRanges) override;
111 void slotSortRoleChanged(const QByteArray& current, const QByteArray& previous) override;
112
113 private Q_SLOTS:
114 void triggerVisibleIndexRangeUpdate();
115 void updateVisibleIndexRange();
116
117 void triggerIconSizeUpdate();
118 void updateIconSize();
119
120 private:
121 /**
122 * Applies the roles defined by KItemListView::visibleRoles() to the
123 * KFileItemModel and KFileItemModelRolesUpdater. As the model does not
124 * distinct between visible and invisible roles also internal roles
125 * are applied that are mandatory for having a working KFileItemModel.
126 */
127 void applyRolesToModel();
128
129 /**
130 * @return Size that is available for the icons. The size might be larger than specified by
131 * KItemListStyleOption::iconSize: With the IconsLayout also the empty left area left
132 * and right of an icon will be included.
133 */
134 QSize availableIconSize() const;
135
136 private:
137 KFileItemModelRolesUpdater* m_modelRolesUpdater;
138 QTimer* m_updateVisibleIndexRangeTimer;
139 QTimer* m_updateIconSizeTimer;
140 bool m_scanDirectories;
141
142 friend class KFileItemListViewTest; // For unit testing
143 };
144
145 #endif
146
147