1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
20 #ifndef KFILEITEMLISTWIDGET_H
21 #define KFILEITEMLISTWIDGET_H
23 #include <libdolphin_export.h>
25 #include <kitemviews/kitemlistwidget.h>
29 #include <QStaticText>
31 class LIBDOLPHINPRIVATE_EXPORT KFileItemListWidget
: public KItemListWidget
43 KFileItemListWidget(QGraphicsItem
* parent
);
44 virtual ~KFileItemListWidget();
46 void setLayout(Layout layout
);
47 Layout
layout() const;
49 virtual void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0);
51 virtual QRectF
iconRect() const;
52 virtual QRectF
textRect() const;
53 virtual QRectF
expansionToggleRect() const;
54 virtual QRectF
selectionToggleRect() const;
57 * @return Shown string for the role \p role of the item with the values \p values.
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
);
66 * Invalidates the cache which results in calling KFileItemListWidget::refreshCache() as
67 * soon as the item need to gets repainted.
69 void invalidateCache();
72 * Is called if the cache got invalidated by KFileItemListWidget::invalidateCache().
73 * The default implementation is empty.
75 virtual void refreshCache();
77 void setTextColor(const QColor
& color
);
78 QColor
textColor() const;
80 void setOverlay(const QPixmap
& overlay
);
81 QPixmap
overlay() const;
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 resizeEvent(QGraphicsSceneResizeEvent
* event
);
101 TextIdCount
// Mandatory last entry
104 void triggerCacheRefreshing();
105 void updateExpansionArea();
106 void updatePixmapCache();
108 void updateTextsCache();
109 void updateIconsLayoutTextCache();
110 void updateCompactLayoutTextCache();
111 void updateDetailsLayoutTextCache();
113 void updateAdditionalInfoTextColor();
115 void drawPixmap(QPainter
* painter
, const QPixmap
& pixmap
);
117 static QPixmap
pixmapForIcon(const QString
& name
, int size
);
118 static TextId
roleTextId(const QByteArray
& role
);
124 QSet
<QByteArray
> m_dirtyContentRoles
;
129 QSize m_scaledPixmapSize
;
131 QRectF m_hoverPixmapRect
;
132 QPixmap m_hoverPixmap
;
134 QPointF m_textPos
[TextIdCount
];
135 QStaticText m_text
[TextIdCount
];
138 QList
<QByteArray
> m_sortedVisibleRoles
;
140 QRectF m_expansionArea
;
142 QColor m_customTextColor
;
143 QColor m_additionalInfoTextColor
;
147 QPointF m_selectionTogglePos
;