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 KItemListRoleEditor
;
32 class KItemListStyleOption
;
35 class LIBDOLPHINPRIVATE_EXPORT KFileItemListWidget
: public KItemListWidget
47 KFileItemListWidget(QGraphicsItem
* parent
);
48 virtual ~KFileItemListWidget();
50 void setLayout(Layout layout
);
51 Layout
layout() const;
53 void setSupportsItemExpanding(bool supportsItemExpanding
);
54 bool supportsItemExpanding() const;
56 virtual void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0);
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;
65 * Implementation of KItemListWidgetCreatorBase::itemSizeHint() when
66 * using the KItemListWidgetCreator-template.
70 static QSizeF
itemSizeHint(int index
, const KItemListView
* view
);
73 * Implementation of KItemListWidgetCreatorBase::preferredRoleColumnWidth() when
74 * using the KItemListWidgetCreator-template.
78 static qreal
preferredRoleColumnWidth(const QByteArray
& role
, int index
, const KItemListView
* view
);
82 * Invalidates the cache which results in calling KFileItemListWidget::refreshCache() as
83 * soon as the item need to gets repainted.
85 void invalidateCache();
88 * Is called if the cache got invalidated by KFileItemListWidget::invalidateCache().
89 * The default implementation is empty.
91 virtual void refreshCache();
93 void setTextColor(const QColor
& color
);
94 QColor
textColor() const;
96 void setOverlay(const QPixmap
& overlay
);
97 QPixmap
overlay() const;
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
);
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
);
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().
127 Generic
// Mandatory last entry
130 void triggerCacheRefreshing();
131 void updateExpansionArea();
132 void updatePixmapCache();
134 void updateTextsCache();
135 void updateIconsLayoutTextCache();
136 void updateCompactLayoutTextCache();
137 void updateDetailsLayoutTextCache();
139 void updateAdditionalInfoTextColor();
141 void drawPixmap(QPainter
* painter
, const QPixmap
& pixmap
);
142 void drawSiblingsInformation(QPainter
* painter
);
144 QRectF
roleEditingRect(const QByteArray
&role
) const;
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
);
152 * @return Preferred size of the rating-image based on the given
153 * style-option. The height of the font is taken as
156 static QSizeF
preferredRatingSize(const KItemListStyleOption
& option
);
159 * @return Horizontal padding in pixels that is added to the required width of
160 * a column to display the content.
162 static qreal
columnPadding(const KItemListStyleOption
& option
);
165 * @return Shown string for the role \p role of the item with the values \p values.
167 static QString
roleText(const QByteArray
& role
, const QHash
<QByteArray
, QVariant
>& values
);
173 bool m_supportsItemExpanding
;
177 QSet
<QByteArray
> m_dirtyContentRoles
;
182 QSize m_scaledPixmapSize
;
184 QRectF m_iconRect
; // Cache for KItemListWidget::iconRect()
185 QPixmap m_hoverPixmap
; // Cache for modified m_pixmap when hovering the item
190 QStaticText staticText
;
192 QHash
<QByteArray
, TextInfo
*> m_textInfo
;
196 QList
<QByteArray
> m_sortedVisibleRoles
;
198 QRectF m_expansionArea
;
200 QColor m_customTextColor
;
201 QColor m_additionalInfoTextColor
;
206 KItemListRoleEditor
* m_roleEditor
;