Commit 1231231f authored by Till Adam's avatar Till Adam
Browse files

Optionally enable progress animation in the

collectionstatisticsdelegate. Use that in the entitylistview as well.

svn path=/trunk/KDE/kdepimlibs/; revision=1141458
parent 373664e5
......@@ -32,6 +32,7 @@
#include "entitytreemodel.h"
#include "collectionstatistics.h"
#include "collection.h"
#include "progressspinnerdelegate_p.h"
using namespace Akonadi;
......@@ -48,10 +49,12 @@ class CollectionStatisticsDelegatePrivate
public:
QTreeView *parent;
bool drawUnreadAfterFolder;
DelegateAnimator *animator;
CollectionStatisticsDelegatePrivate( QTreeView *treeView )
: parent( treeView ),
drawUnreadAfterFolder( false )
drawUnreadAfterFolder( false ),
animator( 0 )
{
}
......@@ -81,6 +84,7 @@ CollectionStatisticsDelegate::CollectionStatisticsDelegate( QTreeView *parent )
: QStyledItemDelegate( parent ),
d_ptr( new CollectionStatisticsDelegatePrivate( parent ) )
{
}
CollectionStatisticsDelegate::~CollectionStatisticsDelegate()
......@@ -100,13 +104,56 @@ bool CollectionStatisticsDelegate::unreadCountShown() const
return d->drawUnreadAfterFolder;
}
void CollectionStatisticsDelegate::setProgressAnimationEnabled( bool enable )
{
Q_D( CollectionStatisticsDelegate );
if ( enable ) {
Akonadi::DelegateAnimator *animator = new Akonadi::DelegateAnimator( d->parent );
d->animator = animator;
} else {
delete d->animator;
d->animator = 0;
}
}
bool CollectionStatisticsDelegate::progressAnimationEnabled() const
{
Q_D( const CollectionStatisticsDelegate );
return d->animator != 0;
}
void CollectionStatisticsDelegate::initStyleOption( QStyleOptionViewItem *option,
const QModelIndex &index ) const
{
Q_D( const CollectionStatisticsDelegate );
QStyleOptionViewItemV4 *noTextOption =
qstyleoption_cast<QStyleOptionViewItemV4 *>( option );
QStyledItemDelegate::initStyleOption( noTextOption, index );
noTextOption->text.clear();
if ( d->animator ) {
const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (!collection.isValid())
{
d->animator->pop(index);
return;
}
if (index.data(Akonadi::EntityTreeModel::FetchStateRole).toInt() != Akonadi::EntityTreeModel::FetchingState)
{
d->animator->pop(index);
return;
}
d->animator->push(index);
if (QStyleOptionViewItemV4 *v4 = qstyleoption_cast<QStyleOptionViewItemV4 *>(option)) {
v4->icon = d->animator->sequenceFrame(index);
}
}
}
void CollectionStatisticsDelegate::paint( QPainter *painter,
......
......@@ -95,6 +95,10 @@ class AKONADI_EXPORT CollectionStatisticsDelegate : public QStyledItemDelegate
*/
bool unreadCountShown() const;
void setProgressAnimationEnabled( bool enable );
bool progressAnimationEnabled() const;
protected:
virtual void paint( QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index ) const;
......
......@@ -44,6 +44,8 @@
#include <akonadi/item.h>
#include <akonadi/entitytreemodel.h>
#include <progressspinnerdelegate_p.h>
using namespace Akonadi;
/**
......@@ -80,6 +82,10 @@ void EntityListView::Private::init()
mParent->connect( mParent, SIGNAL( doubleClicked( const QModelIndex& ) ),
mParent, SLOT( itemDoubleClicked( const QModelIndex& ) ) );
DelegateAnimator *animator = new DelegateAnimator(mParent);
ProgessSpinnerDelegate *customDelegate = new ProgessSpinnerDelegate(animator, mParent);
mParent->setItemDelegate(customDelegate);
Control::widgetNeedsAkonadi( mParent );
}
......
......@@ -26,6 +26,8 @@
#include <QTimerEvent>
#include <QAbstractItemView>
using namespace Akonadi;
DelegateAnimator::DelegateAnimator(QAbstractItemView *view)
: QObject(view), m_view(view)
{
......@@ -95,7 +97,7 @@ void ProgessSpinnerDelegate::initStyleOption(QStyleOptionViewItem* option, const
}
}
uint qHash(DelegateAnimator::Animation anim)
uint Akonadi::qHash(Akonadi::DelegateAnimator::Animation anim)
{
return qHash(anim.index);
}
......@@ -27,6 +27,8 @@
#include <kpixmapsequence.h>
namespace Akonadi {
class DelegateAnimator : public QObject
{
Q_OBJECT
......@@ -65,7 +67,7 @@ private:
KPixmapSequence m_pixmapSequence;
};
uint qHash(DelegateAnimator::Animation anim);
uint qHash(Akonadi::DelegateAnimator::Animation anim);
/**
*
......@@ -83,4 +85,6 @@ private:
DelegateAnimator *m_animator;
};
}
#endif
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