1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
20 #ifndef KFILEITEMLISTVIEW_H
21 #define KFILEITEMLISTVIEW_H
23 #include <libdolphin_export.h>
25 #include <kitemviews/kitemlistview.h>
27 class KFileItemModelRolesUpdater
;
31 * @brief View that allows to show the content of file-items.
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.
39 class LIBDOLPHINPRIVATE_EXPORT KFileItemListView
: public KItemListView
51 KFileItemListView(QGraphicsWidget
* parent
= 0);
52 virtual ~KFileItemListView();
54 void setPreviewsShown(bool show
);
55 bool previewsShown() const;
57 void setItemLayout(Layout layout
);
58 Layout
itemLayout() const;
61 * Sets the list of enabled thumbnail plugins that are used for previews.
62 * Per default all plugins enabled in the KConfigGroup "PreviewSettings"
65 * For a list of available plugins, call KServiceTypeTrader::self()->query("ThumbCreator").
69 void setEnabledPlugins(const QStringList
& list
);
72 * Returns the list of enabled thumbnail plugins.
73 * @see setEnabledPlugins
75 QStringList
enabledPlugins() const;
78 virtual QSizeF
itemSizeHint(int index
) const;
81 virtual QHash
<QByteArray
, qreal
> columnWidths(const KItemRangeList
& itemRanges
) const;
84 virtual QPixmap
createDragPixmap(const QSet
<int>& indexes
) const;
87 virtual void initializeItemListWidget(KItemListWidget
* item
);
88 virtual bool itemSizeHintUpdateRequired(const QSet
<QByteArray
>& changedRoles
) const;
89 virtual void onModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
);
90 virtual void onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
91 virtual void onItemSizeChanged(const QSizeF
& current
, const QSizeF
& previous
);
92 virtual void onScrollOffsetChanged(qreal current
, qreal previous
);
93 virtual void onVisibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
94 virtual void onStyleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
);
95 virtual void onSupportsItemExpandingChanged(bool supportsExpanding
);
96 virtual void onTransactionBegin();
97 virtual void onTransactionEnd();
98 virtual void resizeEvent(QGraphicsSceneResizeEvent
* event
);
101 virtual void slotItemsRemoved(const KItemRangeList
& itemRanges
);
102 virtual void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
105 void triggerVisibleIndexRangeUpdate();
106 void updateVisibleIndexRange();
108 void triggerIconSizeUpdate();
109 void updateIconSize();
112 QSizeF
visibleRoleSizeHint(int index
, const QByteArray
& role
) const;
113 void updateLayoutOfVisibleItems();
114 void updateTimersInterval();
115 void updateMinimumRolesWidths();
118 * Applies the roles defined by KItemListView::visibleRoles() to the
119 * KFileItemModel and KFileItemModelRolesUpdater. As the model does not
120 * distinct between visible and invisible roles also internal roles
121 * are applied that are mandatory for having a working KFileItemModel.
123 void applyRolesToModel();
126 * @return Size that is available for the icons. The size might be larger than specified by
127 * KItemListStyleOption::iconSize: With the IconsLayout also the empty left area left
128 * and right of an icon will be included.
130 QSize
availableIconSize() const;
135 KFileItemModelRolesUpdater
* m_modelRolesUpdater
;
136 QTimer
* m_updateVisibleIndexRangeTimer
;
137 QTimer
* m_updateIconSizeTimer
;
139 // Cache for calculating visibleRoleSizes() in a fast way
140 QHash
<QByteArray
, int> m_minimumRolesWidths
;
142 friend class KFileItemListViewTest
; // For unit testing