]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kfileitemlistwidget.h
Change signature of setVisibleRoles()
[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 LIBDOLPHINPRIVATE_EXPORT KFileItemListWidget : public KItemListWidget
32 {
33 Q_OBJECT
34
35 public:
36 enum Layout
37 {
38 IconsLayout,
39 CompactLayout,
40 DetailsLayout
41 };
42
43 KFileItemListWidget(QGraphicsItem* parent);
44 virtual ~KFileItemListWidget();
45
46 void setLayout(Layout layout);
47 Layout layout() const;
48
49 virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
50
51 virtual QRectF iconBoundingRect() const;
52 virtual QRectF textBoundingRect() const;
53 virtual QRectF expansionToggleRect() const;
54
55 protected:
56 /**
57 * Invalidates the cache which results in calling KFileItemListWidget::refreshCache() as
58 * soon as the item need to gets repainted.
59 */
60 void invalidateCache();
61
62 /**
63 * Is called if the cache got invalidated by KFileItemListWidget::invalidateCache().
64 * The default implementation is empty.
65 */
66 virtual void refreshCache();
67
68 void setTextColor(const QColor& color);
69 QColor textColor() const;
70
71 void setOverlay(const QPixmap& overlay);
72 QPixmap overlay() const;
73
74 virtual void dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles = QSet<QByteArray>());
75 virtual void visibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous);
76 virtual void visibleRolesSizesChanged(const QHash<QByteArray, QSizeF>& current, const QHash<QByteArray, QSizeF>& previous);
77 virtual void styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous);
78 virtual void hoveredChanged(bool hovered);
79 virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
80
81 private:
82 enum TextId {
83 Name,
84 Size,
85 Date,
86 Permissions,
87 Owner,
88 Group,
89 Type,
90 Destination,
91 Path,
92 TextIdCount // Mandatory last entry
93 };
94
95 void triggerCacheRefreshing();
96 void updateExpansionArea();
97 void updatePixmapCache();
98
99 void updateTextsCache();
100 void updateIconsLayoutTextCache();
101 void updateCompactLayoutTextCache();
102 void updateDetailsLayoutTextCache();
103
104 void updateAdditionalInfoTextColor();
105
106 QString roleText(TextId textId, const QVariant& roleValue) const;
107
108 void drawPixmap(QPainter* painter, const QPixmap& pixmap);
109
110 static QPixmap pixmapForIcon(const QString& name, int size);
111 static TextId roleTextId(const QByteArray& role);
112
113 private:
114 bool m_isDir;
115 bool m_dirtyLayout;
116 bool m_dirtyContent;
117 QSet<QByteArray> m_dirtyContentRoles;
118
119 Layout m_layout;
120 QPointF m_pixmapPos;
121 QPixmap m_pixmap;
122 QSize m_scaledPixmapSize;
123
124 QRectF m_hoverPixmapRect;
125 QPixmap m_hoverPixmap;
126
127 QPointF m_textPos[TextIdCount];
128 QStaticText m_text[TextIdCount];
129 QRectF m_textBoundingRect;
130
131 QList<QByteArray> m_sortedVisibleRoles;
132
133 QRectF m_expansionArea;
134
135 QColor m_customTextColor;
136 QColor m_additionalInfoTextColor;
137
138 QPixmap m_overlay;
139 };
140
141 #endif
142
143