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>
32 class KItemListStyleOption
;
34 class LIBDOLPHINPRIVATE_EXPORT KFileItemListWidget
: public KItemListWidget
46 KFileItemListWidget(QGraphicsItem
* parent
);
47 virtual ~KFileItemListWidget();
49 void setLayout(Layout layout
);
50 Layout
layout() const;
52 void setSupportsItemExpanding(bool supportsItemExpanding
);
53 bool supportsItemExpanding() const;
55 virtual void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0);
57 virtual QRectF
iconRect() const;
58 virtual QRectF
textRect() const;
59 virtual QRectF
expansionToggleRect() const;
60 virtual QRectF
selectionToggleRect() const;
63 * Implementation of KItemListWidgetCreatorBase::itemSizeHint() when
64 * using the KItemListWidgetCreator-template.
68 static QSizeF
itemSizeHint(int index
, const KItemListView
* view
);
71 * Implementation of KItemListWidgetCreatorBase::preferredRoleColumnWidth() when
72 * using the KItemListWidgetCreator-template.
76 static qreal
preferredRoleColumnWidth(const QByteArray
& role
, int index
, const KItemListView
* view
);
80 * Invalidates the cache which results in calling KFileItemListWidget::refreshCache() as
81 * soon as the item need to gets repainted.
83 void invalidateCache();
86 * Is called if the cache got invalidated by KFileItemListWidget::invalidateCache().
87 * The default implementation is empty.
89 virtual void refreshCache();
91 void setTextColor(const QColor
& color
);
92 QColor
textColor() const;
94 void setOverlay(const QPixmap
& overlay
);
95 QPixmap
overlay() const;
97 virtual void dataChanged(const QHash
<QByteArray
, QVariant
>& current
, const QSet
<QByteArray
>& roles
= QSet
<QByteArray
>());
98 virtual void visibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
99 virtual void columnWidthChanged(const QByteArray
& role
, qreal current
, qreal previous
);
100 virtual void styleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
);
101 virtual void hoveredChanged(bool hovered
);
102 virtual void selectedChanged(bool selected
);
103 virtual void siblingsInformationChanged(const QBitArray
& current
, const QBitArray
& previous
);
104 virtual void resizeEvent(QGraphicsSceneResizeEvent
* event
);
105 virtual void showEvent(QShowEvent
* event
);
106 virtual void hideEvent(QHideEvent
* event
);
109 void slotCutItemsChanged();
116 Generic
// Mandatory last entry
119 void triggerCacheRefreshing();
120 void updateExpansionArea();
121 void updatePixmapCache();
123 void updateTextsCache();
124 void updateIconsLayoutTextCache();
125 void updateCompactLayoutTextCache();
126 void updateDetailsLayoutTextCache();
128 void updateAdditionalInfoTextColor();
130 void drawPixmap(QPainter
* painter
, const QPixmap
& pixmap
);
131 void drawSiblingsInformation(QPainter
* painter
);
133 static QPixmap
pixmapForIcon(const QString
& name
, int size
);
134 static void applyCutEffect(QPixmap
& pixmap
);
135 static void applyHiddenEffect(QPixmap
& pixmap
);
136 static RoleType
roleType(const QByteArray
& role
);
139 * @return Shown string for the role \p role of the item with the values \p values.
141 static QString
roleText(const QByteArray
& role
, const QHash
<QByteArray
, QVariant
>& values
);
147 bool m_supportsItemExpanding
;
151 QSet
<QByteArray
> m_dirtyContentRoles
;
156 QSize m_scaledPixmapSize
;
158 QRectF m_iconRect
; // Cache for KItemListWidget::iconRect()
159 QPixmap m_hoverPixmap
; // Cache for modified m_pixmap when hovering the item
164 QStaticText staticText
;
166 QHash
<QByteArray
, TextInfo
*> m_textInfo
;
170 QList
<QByteArray
> m_sortedVisibleRoles
;
172 QRectF m_expansionArea
;
174 QColor m_customTextColor
;
175 QColor m_additionalInfoTextColor
;