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
textFocusRect() const;
60 virtual QRectF
expansionToggleRect() const;
61 virtual QRectF
selectionToggleRect() const;
64 * Implementation of KItemListWidgetCreatorBase::itemSizeHint() when
65 * using the KItemListWidgetCreator-template.
69 static QSizeF
itemSizeHint(int index
, const KItemListView
* view
);
72 * Implementation of KItemListWidgetCreatorBase::preferredRoleColumnWidth() when
73 * using the KItemListWidgetCreator-template.
77 static qreal
preferredRoleColumnWidth(const QByteArray
& role
, int index
, const KItemListView
* view
);
81 * Invalidates the cache which results in calling KFileItemListWidget::refreshCache() as
82 * soon as the item need to gets repainted.
84 void invalidateCache();
87 * Is called if the cache got invalidated by KFileItemListWidget::invalidateCache().
88 * The default implementation is empty.
90 virtual void refreshCache();
92 void setTextColor(const QColor
& color
);
93 QColor
textColor() const;
95 void setOverlay(const QPixmap
& overlay
);
96 QPixmap
overlay() const;
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
);
110 void slotCutItemsChanged();
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().
123 Generic
// Mandatory last entry
126 void triggerCacheRefreshing();
127 void updateExpansionArea();
128 void updatePixmapCache();
130 void updateTextsCache();
131 void updateIconsLayoutTextCache();
132 void updateCompactLayoutTextCache();
133 void updateDetailsLayoutTextCache();
135 void updateAdditionalInfoTextColor();
137 void drawPixmap(QPainter
* painter
, const QPixmap
& pixmap
);
138 void drawSiblingsInformation(QPainter
* painter
);
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
);
146 * @return Preferred size of the rating-image based on the given
147 * style-option. The height of the font is taken as
150 static QSizeF
preferredRatingSize(const KItemListStyleOption
& option
);
153 * @return Horizontal padding in pixels that is added to the required width of
154 * a column to display the content.
156 static qreal
columnPadding(const KItemListStyleOption
& option
);
159 * @return Shown string for the role \p role of the item with the values \p values.
161 static QString
roleText(const QByteArray
& role
, const QHash
<QByteArray
, QVariant
>& values
);
167 bool m_supportsItemExpanding
;
171 QSet
<QByteArray
> m_dirtyContentRoles
;
176 QSize m_scaledPixmapSize
;
178 QRectF m_iconRect
; // Cache for KItemListWidget::iconRect()
179 QPixmap m_hoverPixmap
; // Cache for modified m_pixmap when hovering the item
184 QStaticText staticText
;
186 QHash
<QByteArray
, TextInfo
*> m_textInfo
;
190 QList
<QByteArray
> m_sortedVisibleRoles
;
192 QRectF m_expansionArea
;
194 QColor m_customTextColor
;
195 QColor m_additionalInfoTextColor
;