1 /***************************************************************************
2 * Copyright (C) 2012 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 KSTANDARDITEMLISTWIDGET_H
21 #define KSTANDARDITEMLISTWIDGET_H
23 #include <libdolphin_export.h>
25 #include <kitemviews/kitemlistwidget.h>
29 #include <QStaticText>
31 class KItemListRoleEditor
;
32 class KItemListStyleOption
;
35 class LIBDOLPHINPRIVATE_EXPORT KStandardItemListWidgetInformant
: public KItemListWidgetInformant
38 KStandardItemListWidgetInformant();
39 virtual ~KStandardItemListWidgetInformant();
41 virtual QSizeF
itemSizeHint(int index
, const KItemListView
* view
) const;
43 virtual qreal
preferredRoleColumnWidth(const QByteArray
& role
,
45 const KItemListView
* view
) const;
48 * @return String representation of the role \a role. The representation of
49 * a role might depend on other roles, so the values of all roles
50 * are passed as parameter.
52 virtual QString
roleText(const QByteArray
& role
,
53 const QHash
<QByteArray
, QVariant
>& values
) const;
55 friend class KStandardItemListWidget
; // Accesses roleText()
59 * @brief Itemlist widget implementation for KStandardItemView and KStandardItemModel.
61 class LIBDOLPHINPRIVATE_EXPORT KStandardItemListWidget
: public KItemListWidget
73 KStandardItemListWidget(KItemListWidgetInformant
* informant
, QGraphicsItem
* parent
);
74 virtual ~KStandardItemListWidget();
76 void setLayout(Layout layout
);
77 Layout
layout() const;
79 void setSupportsItemExpanding(bool supportsItemExpanding
);
80 bool supportsItemExpanding() const;
82 virtual void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0);
84 virtual QRectF
iconRect() const;
85 virtual QRectF
textRect() const;
86 virtual QRectF
textFocusRect() const;
87 virtual QRectF
expansionToggleRect() const;
88 virtual QRectF
selectionToggleRect() const;
89 virtual QPixmap
createDragPixmap(const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0);
91 static KItemListWidgetInformant
* createInformant();
95 * Invalidates the cache which results in calling KStandardItemListWidget::refreshCache() as
96 * soon as the item need to gets repainted.
98 void invalidateCache();
101 * Is called if the cache got invalidated by KStandardItemListWidget::invalidateCache().
102 * The default implementation is empty.
104 virtual void refreshCache();
107 * @return True if the give role should be right aligned when showing it inside a column.
108 * Per default false is returned.
110 virtual bool isRoleRightAligned(const QByteArray
& role
) const;
113 * @return True if the item should be visually marked as hidden item. Per default
116 virtual bool isHidden() const;
119 * @return A font based on baseFont which is customized according to the data shown in the widget.
121 virtual QFont
customizedFont(const QFont
& baseFont
) const;
123 void setTextColor(const QColor
& color
);
124 QColor
textColor() const;
126 void setOverlay(const QPixmap
& overlay
);
127 QPixmap
overlay() const;
130 * @see KStandardItemListWidgetInformant::roleText().
132 QString
roleText(const QByteArray
& role
, const QHash
<QByteArray
, QVariant
>& values
) const;
134 virtual void dataChanged(const QHash
<QByteArray
, QVariant
>& current
, const QSet
<QByteArray
>& roles
= QSet
<QByteArray
>());
135 virtual void visibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
136 virtual void columnWidthChanged(const QByteArray
& role
, qreal current
, qreal previous
);
137 virtual void styleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
);
138 virtual void hoveredChanged(bool hovered
);
139 virtual void selectedChanged(bool selected
);
140 virtual void siblingsInformationChanged(const QBitArray
& current
, const QBitArray
& previous
);
141 virtual void editedRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
142 virtual void resizeEvent(QGraphicsSceneResizeEvent
* event
);
143 virtual void showEvent(QShowEvent
* event
);
144 virtual void hideEvent(QHideEvent
* event
);
147 void slotCutItemsChanged();
148 void slotRoleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
149 void slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
152 void triggerCacheRefreshing();
153 void updateExpansionArea();
154 void updatePixmapCache();
156 void updateTextsCache();
157 void updateIconsLayoutTextCache();
158 void updateCompactLayoutTextCache();
159 void updateDetailsLayoutTextCache();
161 void updateAdditionalInfoTextColor();
163 void drawPixmap(QPainter
* painter
, const QPixmap
& pixmap
);
164 void drawSiblingsInformation(QPainter
* painter
);
166 QRectF
roleEditingRect(const QByteArray
&role
) const;
169 * Closes the role editor and returns the focus back
170 * to the KItemListContainer.
172 void closeRoleEditor();
174 static QPixmap
pixmapForIcon(const QString
& name
, int size
);
177 * @return Preferred size of the rating-image based on the given
178 * style-option. The height of the font is taken as
181 static QSizeF
preferredRatingSize(const KItemListStyleOption
& option
);
184 * @return Horizontal padding in pixels that is added to the required width of
185 * a column to display the content.
187 static qreal
columnPadding(const KItemListStyleOption
& option
);
192 QFont m_customizedFont
;
193 QFontMetrics m_customizedFontMetrics
;
195 bool m_supportsItemExpanding
;
199 QSet
<QByteArray
> m_dirtyContentRoles
;
204 QSize m_scaledPixmapSize
;
206 QRectF m_iconRect
; // Cache for KItemListWidget::iconRect()
207 QPixmap m_hoverPixmap
; // Cache for modified m_pixmap when hovering the item
212 QStaticText staticText
;
214 QHash
<QByteArray
, TextInfo
*> m_textInfo
;
218 QList
<QByteArray
> m_sortedVisibleRoles
;
220 QRectF m_expansionArea
;
222 QColor m_customTextColor
;
223 QColor m_additionalInfoTextColor
;
228 KItemListRoleEditor
* m_roleEditor
;
230 friend class KStandardItemListWidgetInformant
; // Accesses private static methods to be able to
231 // share a common layout calculation