]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kfileitemlistview.h
c1c260e93cf2e68497a48214d2c169b305ad254e
[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
25 #include <kitemviews/kstandarditemlistview.h>
26
27 class KFileItemModelRolesUpdater;
28 class QTimer;
29
30 /**
31 * @brief View that allows to show the content of file-items.
32 *
33 * The corresponding model set by the controller must be an instance
34 * of KFileItemModel. Per default KFileItemListWidget is set as widget creator
35 * value and KItemListGroupHeader as group-header creator value. Use
36 * KItemListView::setWidgetCreator() and KItemListView::setGroupHeaderCreator()
37 * to apply customized generators.
38 */
39 class DOLPHIN_EXPORT KFileItemListView : public KStandardItemListView
40 {
41 Q_OBJECT
42
43 public:
44 KFileItemListView(QGraphicsWidget* parent = 0);
45 ~KFileItemListView() override;
46
47 void setPreviewsShown(bool show);
48 bool previewsShown() const;
49
50 /**
51 * If enabled a small preview gets upscaled to the icon size in case where
52 * the icon size is larger than the preview. Per default enlarging is
53 * enabled.
54 */
55 void setEnlargeSmallPreviews(bool enlarge);
56 bool enlargeSmallPreviews() const;
57
58 /**
59 * Sets the list of enabled thumbnail plugins that are used for previews.
60 * Per default all plugins enabled in the KConfigGroup "PreviewSettings"
61 * are used.
62 *
63 * For a list of available plugins, call KServiceTypeTrader::self()->query("ThumbCreator").
64 *
65 * @see enabledPlugins
66 */
67 void setEnabledPlugins(const QStringList& list);
68
69 /**
70 * Returns the list of enabled thumbnail plugins.
71 * @see setEnabledPlugins
72 */
73 QStringList enabledPlugins() const;
74
75 QPixmap createDragPixmap(const KItemSet& indexes) const override;
76
77 protected:
78 KItemListWidgetCreatorBase* defaultWidgetCreator() const override;
79 void initializeItemListWidget(KItemListWidget* item) override;
80 virtual void onPreviewsShownChanged(bool shown);
81 void onItemLayoutChanged(ItemLayout current, ItemLayout previous) override;
82 void onModelChanged(KItemModelBase* current, KItemModelBase* previous) override;
83 void onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous) override;
84 void onItemSizeChanged(const QSizeF& current, const QSizeF& previous) override;
85 void onScrollOffsetChanged(qreal current, qreal previous) override;
86 void onVisibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous) override;
87 void onStyleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous) override;
88 void onSupportsItemExpandingChanged(bool supportsExpanding) override;
89 void onTransactionBegin() override;
90 void onTransactionEnd() override;
91 void resizeEvent(QGraphicsSceneResizeEvent* event) override;
92
93 protected slots:
94 void slotItemsRemoved(const KItemRangeList& itemRanges) override;
95 void slotSortRoleChanged(const QByteArray& current, const QByteArray& previous) override;
96
97 private slots:
98 void triggerVisibleIndexRangeUpdate();
99 void updateVisibleIndexRange();
100
101 void triggerIconSizeUpdate();
102 void updateIconSize();
103
104 private:
105 /**
106 * Applies the roles defined by KItemListView::visibleRoles() to the
107 * KFileItemModel and KFileItemModelRolesUpdater. As the model does not
108 * distinct between visible and invisible roles also internal roles
109 * are applied that are mandatory for having a working KFileItemModel.
110 */
111 void applyRolesToModel();
112
113 /**
114 * @return Size that is available for the icons. The size might be larger than specified by
115 * KItemListStyleOption::iconSize: With the IconsLayout also the empty left area left
116 * and right of an icon will be included.
117 */
118 QSize availableIconSize() const;
119
120 private:
121 KFileItemModelRolesUpdater* m_modelRolesUpdater;
122 QTimer* m_updateVisibleIndexRangeTimer;
123 QTimer* m_updateIconSizeTimer;
124
125 friend class KFileItemListViewTest; // For unit testing
126 };
127
128 #endif
129
130