]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kfileitemlistwidget.h
Show the ratings as stars instead of text
[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 textFocusRect() const;
60 virtual QRectF expansionToggleRect() const;
61 virtual QRectF selectionToggleRect() const;
62
63 /**
64 * Implementation of KItemListWidgetCreatorBase::itemSizeHint() when
65 * using the KItemListWidgetCreator-template.
66 *
67 * @see KItemListView
68 */
69 static QSizeF itemSizeHint(int index, const KItemListView* view);
70
71 /**
72 * Implementation of KItemListWidgetCreatorBase::preferredRoleColumnWidth() when
73 * using the KItemListWidgetCreator-template.
74 *
75 * @see KItemListView
76 */
77 static qreal preferredRoleColumnWidth(const QByteArray& role, int index, const KItemListView* view);
78
79 protected:
80 /**
81 * Invalidates the cache which results in calling KFileItemListWidget::refreshCache() as
82 * soon as the item need to gets repainted.
83 */
84 void invalidateCache();
85
86 /**
87 * Is called if the cache got invalidated by KFileItemListWidget::invalidateCache().
88 * The default implementation is empty.
89 */
90 virtual void refreshCache();
91
92 void setTextColor(const QColor& color);
93 QColor textColor() const;
94
95 void setOverlay(const QPixmap& overlay);
96 QPixmap overlay() const;
97
98 virtual void dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles = QSet<QByteArray>());
99 virtual void visibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous);
100 virtual void columnWidthChanged(const QByteArray& role, qreal current, qreal previous);
101 virtual void styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous);
102 virtual void hoveredChanged(bool hovered);
103 virtual void selectedChanged(bool selected);
104 virtual void siblingsInformationChanged(const QBitArray& current, const QBitArray& previous);
105 virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
106 virtual void showEvent(QShowEvent* event);
107 virtual void hideEvent(QHideEvent* event);
108
109 private slots:
110 void slotCutItemsChanged();
111
112 private:
113 /**
114 * Typedefinitions for roles that require a special handling
115 * and must be accessible in a fast way. The mapping of a
116 * QByteArray role to the type is done by KFileItemListWidget::roleType().
117 */
118 enum RoleType {
119 Name,
120 Size,
121 Date,
122 Rating,
123 Generic // Mandatory last entry
124 };
125
126 void triggerCacheRefreshing();
127 void updateExpansionArea();
128 void updatePixmapCache();
129
130 void updateTextsCache();
131 void updateIconsLayoutTextCache();
132 void updateCompactLayoutTextCache();
133 void updateDetailsLayoutTextCache();
134
135 void updateAdditionalInfoTextColor();
136
137 void drawPixmap(QPainter* painter, const QPixmap& pixmap);
138 void drawSiblingsInformation(QPainter* painter);
139
140 static QPixmap pixmapForIcon(const QString& name, int size);
141 static void applyCutEffect(QPixmap& pixmap);
142 static void applyHiddenEffect(QPixmap& pixmap);
143 static RoleType roleType(const QByteArray& role);
144
145 /**
146 * @return Preferred size of the rating-image based on the given
147 * style-option. The height of the font is taken as
148 * reference.
149 */
150 static QSizeF preferredRatingSize(const KItemListStyleOption& option);
151
152 /**
153 * @return Horizontal padding in pixels that is added to the required width of
154 * a column to display the content.
155 */
156 static qreal columnPadding(const KItemListStyleOption& option);
157
158 /**
159 * @return Shown string for the role \p role of the item with the values \p values.
160 */
161 static QString roleText(const QByteArray& role, const QHash<QByteArray, QVariant>& values);
162
163 private:
164 bool m_isCut;
165 bool m_isHidden;
166 bool m_isExpandable;
167 bool m_supportsItemExpanding;
168
169 bool m_dirtyLayout;
170 bool m_dirtyContent;
171 QSet<QByteArray> m_dirtyContentRoles;
172
173 Layout m_layout;
174 QPointF m_pixmapPos;
175 QPixmap m_pixmap;
176 QSize m_scaledPixmapSize;
177
178 QRectF m_iconRect; // Cache for KItemListWidget::iconRect()
179 QPixmap m_hoverPixmap; // Cache for modified m_pixmap when hovering the item
180
181 struct TextInfo
182 {
183 QPointF pos;
184 QStaticText staticText;
185 };
186 QHash<QByteArray, TextInfo*> m_textInfo;
187
188 QRectF m_textRect;
189
190 QList<QByteArray> m_sortedVisibleRoles;
191
192 QRectF m_expansionArea;
193
194 QColor m_customTextColor;
195 QColor m_additionalInfoTextColor;
196
197 QPixmap m_overlay;
198 QPixmap m_rating;
199 };
200
201 #endif
202
203