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