]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kfileitemlistwidget.h
Whitespace cleanups and documentation fixes
[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 iconRect() const;
52 virtual QRectF textRect() const;
53 virtual QRectF expansionToggleRect() const;
54 virtual QRectF selectionToggleRect() const;
55
56 /**
57 * @return Shown string for the role \p role of the item with the values \p values.
58 */
59 // TODO: Move this method to a helper class shared by KFileItemListWidget and
60 // KFileItemListView to share information that is required to calculate the size hints
61 // in KFileItemListView and to represent the actual data in KFileItemListWidget.
62 static QString roleText(const QByteArray& role, const QHash<QByteArray, QVariant>& values);
63
64 protected:
65 /**
66 * Invalidates the cache which results in calling KFileItemListWidget::refreshCache() as
67 * soon as the item need to gets repainted.
68 */
69 void invalidateCache();
70
71 /**
72 * Is called if the cache got invalidated by KFileItemListWidget::invalidateCache().
73 * The default implementation is empty.
74 */
75 virtual void refreshCache();
76
77 void setTextColor(const QColor& color);
78 QColor textColor() const;
79
80 void setOverlay(const QPixmap& overlay);
81 QPixmap overlay() const;
82
83 virtual void dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles = QSet<QByteArray>());
84 virtual void visibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous);
85 virtual void visibleRolesSizesChanged(const QHash<QByteArray, QSizeF>& current, const QHash<QByteArray, QSizeF>& previous);
86 virtual void styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous);
87 virtual void hoveredChanged(bool hovered);
88 virtual void selectedChanged(bool selected);
89 virtual void siblingsInformationChanged(const QBitArray& current, const QBitArray& previous);
90 virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
91 virtual void showEvent(QShowEvent* event);
92 virtual void hideEvent(QHideEvent* event);
93
94 private slots:
95 void slotCutItemsChanged();
96
97 private:
98 enum TextId {
99 Name,
100 Size,
101 Date,
102 Permissions,
103 Owner,
104 Group,
105 Type,
106 Destination,
107 Path,
108 TextIdCount // Mandatory last entry
109 };
110
111 void triggerCacheRefreshing();
112 void updateExpansionArea();
113 void updatePixmapCache();
114
115 void updateTextsCache();
116 void updateIconsLayoutTextCache();
117 void updateCompactLayoutTextCache();
118 void updateDetailsLayoutTextCache();
119
120 void updateAdditionalInfoTextColor();
121
122 void drawPixmap(QPainter* painter, const QPixmap& pixmap);
123 void drawSiblingsInformation(QPainter* painter);
124
125 static QPixmap pixmapForIcon(const QString& name, int size);
126 static TextId roleTextId(const QByteArray& role);
127 static void applyCutEffect(QPixmap& pixmap);
128 static void applyHiddenEffect(QPixmap& pixmap);
129
130 private:
131 bool m_isCut;
132 bool m_isHidden;
133 bool m_isExpandable;
134
135 bool m_dirtyLayout;
136 bool m_dirtyContent;
137 QSet<QByteArray> m_dirtyContentRoles;
138
139 Layout m_layout;
140 QPointF m_pixmapPos;
141 QPixmap m_pixmap;
142 QSize m_scaledPixmapSize;
143
144 QRectF m_iconRect; // Cache for KItemListWidget::iconRect()
145 QPixmap m_hoverPixmap; // Cache for modified m_pixmap when hovering the item
146
147 QPointF m_textPos[TextIdCount];
148 QStaticText m_text[TextIdCount];
149 QRectF m_textRect;
150
151 QList<QByteArray> m_sortedVisibleRoles;
152
153 QRectF m_expansionArea;
154
155 QColor m_customTextColor;
156 QColor m_additionalInfoTextColor;
157
158 QPixmap m_overlay;
159 };
160
161 #endif
162
163