1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-13 20:41:58 +02:00

cache the mimedata so we can paint the items after the dropLeaveEvent and made animations a bit faster

This commit is contained in:
Michael Zanetti 2011-08-24 00:29:59 +02:00
parent 39af693de1
commit 52037d8847
4 changed files with 17 additions and 10 deletions

View File

@ -7,14 +7,13 @@ AnimationHelper::AnimationHelper( const QModelIndex& index, QObject *parent )
, m_index( index )
, m_fullyExpanded( false )
, m_expandAnimation( 0 )
, m_forceClosing( false )
{
m_expandTimer.setSingleShot( true );
m_expandTimer.setInterval( 1000 );
m_expandTimer.setInterval( 600 );
connect( &m_expandTimer, SIGNAL(timeout()), SLOT(expandTimeout()));
m_collapseTimer.setSingleShot( true );
m_collapseTimer.setInterval( 1000 );
m_collapseTimer.setInterval( 600 );
connect( &m_collapseTimer, SIGNAL(timeout()), SLOT(collapseTimeout()));
}
@ -70,7 +69,6 @@ void AnimationHelper::collapse( bool immediately )
if ( immediately )
{
m_forceClosing = true;
m_fullyExpanded = false;
m_collapseAnimation->start();
}
@ -80,9 +78,6 @@ void AnimationHelper::collapse( bool immediately )
bool AnimationHelper::partlyExpanded()
{
if ( m_forceClosing )
return false;
return m_size != m_startSize;
// return m_fullyExpanded
// || ( m_expandAnimation->state() == QPropertyAnimation::Running && m_expandAnimation->currentTime() > 250 )

View File

@ -49,7 +49,6 @@ private:
QTimer m_collapseTimer;
bool m_fullyExpanded;
bool m_forceClosing;
QPropertyAnimation *m_expandAnimation;
QPropertyAnimation *m_collapseAnimation;

View File

@ -36,6 +36,13 @@ SourceDelegate::SourceDelegate( QAbstractItemView* parent )
m_dropTypeImageMap.insert( 2, QPixmap( ":/data/images/drop-all-songs.png" ).scaledToHeight( 32, Qt::SmoothTransformation ) );
m_dropTypeImageMap.insert( 3, QPixmap( ":/data/images/drop-local-songs.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) );
m_dropTypeImageMap.insert( 4, QPixmap( ":/data/images/drop-top-songs.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) );
m_dropMimeData = new QMimeData();
}
SourceDelegate::~SourceDelegate()
{
delete m_dropMimeData;
}
QSize
@ -53,7 +60,7 @@ SourceDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex&
qDebug() << "droptypecount is " << dropTypes;
QSize originalSize = QStyledItemDelegate::sizeHint( option, index );
QSize targetSize = originalSize + QSize( 0, dropTypes == 0 ? 0 : 56 );
m_expandedMap.value( index )->initialize( originalSize, targetSize, 500 );
m_expandedMap.value( index )->initialize( originalSize, targetSize, 300 );
m_expandedMap.value( index )->expand();
}
QMetaObject::invokeMethod( m_parent, "update", Qt::QueuedConnection, Q_ARG( QModelIndex, index ) );
@ -380,7 +387,12 @@ SourceDelegate::hovered(const QModelIndex &index, const QMimeData *mimeData)
}
m_newDropHoverIndex = index;
m_dropMimeData = const_cast< QMimeData* >( mimeData );
m_dropMimeData->clear();
foreach ( const QString &mimeDataFormat, mimeData->formats() )
{
m_dropMimeData->setData( mimeDataFormat, mimeData->data( mimeDataFormat ) );
}
m_expandedMap.insert( m_newDropHoverIndex, new AnimationHelper( m_newDropHoverIndex ) );
connect( m_expandedMap.value( m_newDropHoverIndex ), SIGNAL( finished( QModelIndex ) ), SLOT( animationFinished( QModelIndex ) ) );

View File

@ -14,6 +14,7 @@ class SourceDelegate : public QStyledItemDelegate
Q_OBJECT
public:
SourceDelegate( QAbstractItemView* parent = 0 );
~SourceDelegate();
void hovered( const QModelIndex &index, const QMimeData *mimeData );
void dragLeaveEvent();