]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kfileitemlistwidget.h
76d090040870a5f2e3779e48ac81812fff810ba1
[dolphin.git] / src / kitemviews / kfileitemlistwidget.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 KFILEITEMLISTWIDGET_H
21 #define KFILEITEMLISTWIDGET_H
22
23 #include <libdolphin_export.h>
24
25 #include <kitemviews/kitemlistwidget.h>
26
27 #include <QPixmap>
28 #include <QPointF>
29 #include <QStaticText>
30
31 class KItemListView;
32 class KItemListStyleOption;
33
34 class LIBDOLPHINPRIVATE_EXPORT KFileItemListWidget : public KItemListWidget
35 {
36 Q_OBJECT
37
38 public:
39 enum Layout
40 {
41 IconsLayout,
42 CompactLayout,
43 DetailsLayout
44 };
45
46 KFileItemListWidget(QGraphicsItem* parent);
47 virtual ~KFileItemListWidget();
48
49 void setLayout(Layout layout);
50 Layout layout() const;
51
52 void setSupportsItemExpanding(bool supportsItemExpanding);
53 bool supportsItemExpanding() const;
54
55 virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
56
57 virtual QRectF iconRect() const;
58 virtual QRectF textRect() const;
59 virtual QRectF expansionToggleRect() const;
60 virtual QRectF selectionToggleRect() const;
61
62 /**
63 * Implementation of KItemListWidgetCreatorBase::itemSizeHint() when
64 * using the KItemListWidgetCreator-template.
65 *
66 * @see KItemListView
67 */
68 static QSizeF itemSizeHint(int index, const KItemListView* view);
69
70 /**
71 * Implementation of KItemListWidgetCreatorBase::preferredRoleColumnWidth() when
72 * using the KItemListWidgetCreator-template.
73 *
74 * @see KItemListView
75 */
76 static qreal preferredRoleColumnWidth(const QByteArray& role, int index, const KItemListView* view);
77
78 protected:
79 /**
80 * Invalidates the cache which results in calling KFileItemListWidget::refreshCache() as
81 * soon as the item need to gets repainted.
82 */
83 void invalidateCache();
84
85 /**
86 * Is called if the cache got invalidated by KFileItemListWidget::invalidateCache().
87 * The default implementation is empty.
88 */
89 virtual void refreshCache();
90
91 void setTextColor(const QColor& color);
92 QColor textColor() const;
93
94 void setOverlay(const QPixmap& overlay);
95 QPixmap overlay() const;
96
97 virtual void dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles = QSet<QByteArray>());
98 virtual void visibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous);
99 virtual void columnWidthChanged(const QByteArray& role, qreal current, qreal previous);
100 virtual void styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous);
101 virtual void hoveredChanged(bool hovered);
102 virtual void selectedChanged(bool selected);
103 virtual void siblingsInformationChanged(const QBitArray& current, const QBitArray& previous);
104 virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
105 virtual void showEvent(QShowEvent* event);
106 virtual void hideEvent(QHideEvent* event);
107
108 private slots:
109 void slotCutItemsChanged();
110
111 private:
112 enum TextId {
113 Name,
114 Size,
115 Date,
116 Permissions,
117 Owner,
118 Group,
119 Type,
120 Destination,
121 Path,
122 TextIdCount // Mandatory last entry
123 };
124
125 void triggerCacheRefreshing();
126 void updateExpansionArea();
127 void updatePixmapCache();
128
129 void updateTextsCache();
130 void updateIconsLayoutTextCache();
131 void updateCompactLayoutTextCache();
132 void updateDetailsLayoutTextCache();
133
134 void updateAdditionalInfoTextColor();
135
136 void drawPixmap(QPainter* painter, const QPixmap& pixmap);
137 void drawSiblingsInformation(QPainter* painter);
138
139 static QPixmap pixmapForIcon(const QString& name, int size);
140 static void applyCutEffect(QPixmap& pixmap);
141 static void applyHiddenEffect(QPixmap& pixmap);
142 static TextId roleTextId(const QByteArray& role);
143
144 /**
145 * @return Shown string for the role \p role of the item with the values \p values.
146 */
147 static QString roleText(const QByteArray& role, const QHash<QByteArray, QVariant>& values);
148
149 private:
150 bool m_isCut;
151 bool m_isHidden;
152 bool m_isExpandable;
153 bool m_supportsItemExpanding;
154
155 bool m_dirtyLayout;
156 bool m_dirtyContent;
157 QSet<QByteArray> m_dirtyContentRoles;
158
159 Layout m_layout;
160 QPointF m_pixmapPos;
161 QPixmap m_pixmap;
162 QSize m_scaledPixmapSize;
163
164 QRectF m_iconRect; // Cache for KItemListWidget::iconRect()
165 QPixmap m_hoverPixmap; // Cache for modified m_pixmap when hovering the item
166
167 QPointF m_textPos[TextIdCount];
168 QStaticText m_text[TextIdCount];
169 QRectF m_textRect;
170
171 QList<QByteArray> m_sortedVisibleRoles;
172
173 QRectF m_expansionArea;
174
175 QColor m_customTextColor;
176 QColor m_additionalInfoTextColor;
177
178 QPixmap m_overlay;
179 };
180
181 #endif
182
183