1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * Based on the Itemviews NG project from Trolltech Labs: *
5 * http://qt.gitorious.org/qt-labs/itemviews-ng *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
21 ***************************************************************************/
23 #ifndef KITEMLISTWIDGET_H
24 #define KITEMLISTWIDGET_H
26 #include <libdolphin_export.h>
28 #include <kitemviews/kitemliststyleoption.h>
30 #include <QGraphicsWidget>
32 class QPropertyAnimation
;
35 * @brief Widget that shows a visible item from the model.
37 * For showing an item from a custom model it is required to at least overwrite KItemListWidget::paint().
38 * All properties are set by KItemListView, for each property there is a corresponding
39 * virtual protected method that allows to react on property changes.
41 class LIBDOLPHINPRIVATE_EXPORT KItemListWidget
: public QGraphicsWidget
46 KItemListWidget(QGraphicsItem
* parent
);
47 virtual ~KItemListWidget();
49 void setIndex(int index
);
52 void setData(const QHash
<QByteArray
, QVariant
>& data
, const QSet
<QByteArray
>& roles
= QSet
<QByteArray
>());
53 QHash
<QByteArray
, QVariant
> data() const;
56 * Draws the hover-bounding-rectangle if the item is hovered. Overwrite this method
57 * to show the data of the custom model provided by KItemListWidget::data().
60 virtual void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0);
63 * Sets the visible roles to \p roles. The integer-value defines
64 * the order of the visible role: Smaller values are ordered first.
66 void setVisibleRoles(const QHash
<QByteArray
, int>& roles
);
67 QHash
<QByteArray
, int> visibleRoles() const;
69 void setVisibleRolesSizes(const QHash
<QByteArray
, QSizeF
> rolesSizes
);
70 QHash
<QByteArray
, QSizeF
> visibleRolesSizes() const;
72 void setStyleOption(const KItemListStyleOption
& option
);
73 const KItemListStyleOption
& styleOption() const;
76 * @return True if \a point is inside KItemListWidget::hoverBoundingRect(),
77 * KItemListWidget::selectionToggleRect() or KItemListWidget::expansionToggleRect().
80 virtual bool contains(const QPointF
& point
) const;
83 * @return Bounding rectangle for the area that acts as hovering-area. Per default
84 * the bounding rectangle of the KItemListWidget is returned.
86 virtual QRectF
hoverBoundingRect() const;
89 * @return Rectangle for the selection-toggle that is used to select or deselect an item.
90 * Per default an empty rectangle is returned which means that no selection-toggle
93 virtual QRectF
selectionToggleRect() const;
96 * @return Rectangle for the expansion-toggle that is used to open a sub-tree of the model.
97 * Per default an empty rectangle is returned which means that no opening of sub-trees
100 virtual QRectF
expansionToggleRect() const;
103 virtual void dataChanged(const QHash
<QByteArray
, QVariant
>& current
, const QSet
<QByteArray
>& roles
= QSet
<QByteArray
>());
104 virtual void visibleRolesChanged(const QHash
<QByteArray
, int>& current
, const QHash
<QByteArray
, int>& previous
);
105 virtual void visibleRolesSizesChanged(const QHash
<QByteArray
, QSizeF
>& current
, const QHash
<QByteArray
, QSizeF
>& previous
);
106 virtual void styleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
);
107 virtual void resizeEvent(QGraphicsSceneResizeEvent
* event
);
110 * @return The current opacity of the hover-animation. When implementing a custom painting-code for a hover-state
111 * this opacity value should be respected.
113 qreal
hoverOpacity() const;
116 void setHoverOpacity(qreal opacity
);
120 Q_PROPERTY(qreal hoverOpacity READ hoverOpacity WRITE setHoverOpacity
)
123 QHash
<QByteArray
, QVariant
> m_data
;
124 QHash
<QByteArray
, int> m_visibleRoles
;
125 QHash
<QByteArray
, QSizeF
> m_visibleRolesSizes
;
126 KItemListStyleOption m_styleOption
;
128 qreal m_hoverOpacity
;
129 mutable QPixmap
* m_hoverCache
;
130 QPropertyAnimation
* m_hoverAnimation
;