]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kfileitemlistview.h
Port away from deprecated QFontMetrics::width()
[dolphin.git] / src / kitemviews / kfileitemlistview.h
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef KFILEITEMLISTVIEW_H
21 #define KFILEITEMLISTVIEW_H
22
23 #include "dolphin_export.h"
24 #include "kitemviews/kstandarditemlistview.h"
25
26 class KFileItemModelRolesUpdater;
27 class QTimer;
28
29 /**
30 * @brief View that allows to show the content of file-items.
31 *
32 * The corresponding model set by the controller must be an instance
33 * of KFileItemModel. Per default KFileItemListWidget is set as widget creator
34 * value and KItemListGroupHeader as group-header creator value. Use
35 * KItemListView::setWidgetCreator() and KItemListView::setGroupHeaderCreator()
36 * to apply customized generators.
37 */
38 class DOLPHIN_EXPORT KFileItemListView : public KStandardItemListView
39 {
40 Q_OBJECT
41
42 public:
43 explicit KFileItemListView(QGraphicsWidget* parent = nullptr);
44 ~KFileItemListView() override;
45
46 void setPreviewsShown(bool show);
47 bool previewsShown() const;
48
49 /**
50 * If enabled a small preview gets upscaled to the icon size in case where
51 * the icon size is larger than the preview. Per default enlarging is
52 * enabled.
53 */
54 void setEnlargeSmallPreviews(bool enlarge);
55 bool enlargeSmallPreviews() const;
56
57 /**
58 * Sets the list of enabled thumbnail plugins that are used for previews.
59 * Per default all plugins enabled in the KConfigGroup "PreviewSettings"
60 * are used.
61 *
62 * For a list of available plugins, call KServiceTypeTrader::self()->query("ThumbCreator").
63 *
64 * @see enabledPlugins
65 */
66 void setEnabledPlugins(const QStringList& list);
67
68 /**
69 * Returns the list of enabled thumbnail plugins.
70 * @see setEnabledPlugins
71 */
72 QStringList enabledPlugins() const;
73
74 QPixmap createDragPixmap(const KItemSet& indexes) const override;
75
76 protected:
77 KItemListWidgetCreatorBase* defaultWidgetCreator() const override;
78 void initializeItemListWidget(KItemListWidget* item) override;
79 virtual void onPreviewsShownChanged(bool shown);
80 void onItemLayoutChanged(ItemLayout current, ItemLayout previous) override;
81 void onModelChanged(KItemModelBase* current, KItemModelBase* previous) override;
82 void onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous) override;
83 void onItemSizeChanged(const QSizeF& current, const QSizeF& previous) override;
84 void onScrollOffsetChanged(qreal current, qreal previous) override;
85 void onVisibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous) override;
86 void onStyleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous) override;
87 void onSupportsItemExpandingChanged(bool supportsExpanding) override;
88 void onTransactionBegin() override;
89 void onTransactionEnd() override;
90 void resizeEvent(QGraphicsSceneResizeEvent* event) override;
91
92 protected slots:
93 void slotItemsRemoved(const KItemRangeList& itemRanges) override;
94 void slotSortRoleChanged(const QByteArray& current, const QByteArray& previous) override;
95
96 private slots:
97 void triggerVisibleIndexRangeUpdate();
98 void updateVisibleIndexRange();
99
100 void triggerIconSizeUpdate();
101 void updateIconSize();
102
103 private:
104 /**
105 * Applies the roles defined by KItemListView::visibleRoles() to the
106 * KFileItemModel and KFileItemModelRolesUpdater. As the model does not
107 * distinct between visible and invisible roles also internal roles
108 * are applied that are mandatory for having a working KFileItemModel.
109 */
110 void applyRolesToModel();
111
112 /**
113 * @return Size that is available for the icons. The size might be larger than specified by
114 * KItemListStyleOption::iconSize: With the IconsLayout also the empty left area left
115 * and right of an icon will be included.
116 */
117 QSize availableIconSize() const;
118
119 private:
120 KFileItemModelRolesUpdater* m_modelRolesUpdater;
121 QTimer* m_updateVisibleIndexRangeTimer;
122 QTimer* m_updateIconSizeTimer;
123
124 friend class KFileItemListViewTest; // For unit testing
125 };
126
127 #endif
128
129