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