Commit 7fc25d31 authored by Till Adam's avatar Till Adam
Browse files

Allow the delegate to be used with non-tree views.

svn path=/trunk/KDE/kdepimlibs/; revision=1180256
parent ee01e86d
......@@ -27,6 +27,7 @@
#include <QtGui/QStyle>
#include <QtGui/QStyleOption>
#include <QtGui/QStyleOptionViewItemV4>
#include <QtGui/QAbstractItemView>
#include <QtGui/QTreeView>
#include "entitytreemodel.h"
......@@ -47,13 +48,13 @@ enum CountType
class CollectionStatisticsDelegatePrivate
{
public:
QTreeView *parent;
QAbstractItemView *parent;
bool drawUnreadAfterFolder;
DelegateAnimator *animator;
QColor mSelectedUnreadColor;
QColor mDeselectedUnreadColor;
CollectionStatisticsDelegatePrivate( QTreeView *treeView )
CollectionStatisticsDelegatePrivate( QAbstractItemView *treeView )
: parent( treeView ),
drawUnreadAfterFolder( false ),
animator( 0 )
......@@ -86,7 +87,7 @@ class CollectionStatisticsDelegatePrivate
}
CollectionStatisticsDelegate::CollectionStatisticsDelegate( QTreeView *parent )
CollectionStatisticsDelegate::CollectionStatisticsDelegate( QAbstractItemView *parent )
: QStyledItemDelegate( parent ),
d_ptr( new CollectionStatisticsDelegatePrivate( parent ) )
{
......@@ -208,7 +209,8 @@ void CollectionStatisticsDelegate::paint( QPainter *painter,
// When checking if the item is expanded, we need to check that for the first
// column, as Qt only recogises the index as expanded for the first column
QModelIndex firstColumn = index.model()->index( index.row(), 0, index.parent() );
bool expanded = d->parent->isExpanded( firstColumn );
QTreeView* treeView = qobject_cast<QTreeView*>( d->parent );
bool expanded = treeView && treeView->isExpanded( firstColumn );
if ( option.state & QStyle::State_Selected ) {
painter->setPen( option.palette.highlightedText().color() );
......
......@@ -23,7 +23,7 @@
#include <QtGui/QStyledItemDelegate>
class QTreeView;
class QAbstractItemView;
namespace Akonadi {
......@@ -71,7 +71,7 @@ class AKONADI_EXPORT CollectionStatisticsDelegate : public QStyledItemDelegate
*
* @param parent The parent tree view, which will also take ownership.
*/
explicit CollectionStatisticsDelegate( QTreeView *parent );
explicit CollectionStatisticsDelegate( QAbstractItemView *parent );
/**
* Destroys the collection statistics delegate.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment