mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Try out some fading
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QTimeLine>
|
||||||
|
|
||||||
#include "Artist.h"
|
#include "Artist.h"
|
||||||
#include "Query.h"
|
#include "Query.h"
|
||||||
@@ -42,6 +43,10 @@
|
|||||||
#include "widgets/ImageButton.h"
|
#include "widgets/ImageButton.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
static const int FADE_DURATION = 90;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
AlbumItemDelegate::AlbumItemDelegate( QAbstractItemView* parent, AlbumProxyModel* proxy )
|
AlbumItemDelegate::AlbumItemDelegate( QAbstractItemView* parent, AlbumProxyModel* proxy )
|
||||||
: QStyledItemDelegate( (QObject*)parent )
|
: QStyledItemDelegate( (QObject*)parent )
|
||||||
@@ -50,7 +55,7 @@ AlbumItemDelegate::AlbumItemDelegate( QAbstractItemView* parent, AlbumProxyModel
|
|||||||
{
|
{
|
||||||
if ( m_view && m_view->metaObject()->indexOfSignal( "modelChanged()" ) > -1 )
|
if ( m_view && m_view->metaObject()->indexOfSignal( "modelChanged()" ) > -1 )
|
||||||
connect( m_view, SIGNAL( modelChanged() ), this, SLOT( modelChanged() ) );
|
connect( m_view, SIGNAL( modelChanged() ), this, SLOT( modelChanged() ) );
|
||||||
|
|
||||||
connect( m_view, SIGNAL( scrolledContents( int, int ) ), SLOT( onScrolled( int, int ) ) );
|
connect( m_view, SIGNAL( scrolledContents( int, int ) ), SLOT( onScrolled( int, int ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,33 +126,28 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
|
|
||||||
const QPixmap cover = fader->currentPixmap();
|
const QPixmap cover = fader->currentPixmap();
|
||||||
|
|
||||||
if ( false && option.state & QStyle::State_Selected )
|
|
||||||
{
|
|
||||||
#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
|
|
||||||
painter->save();
|
|
||||||
|
|
||||||
QPainterPath border;
|
|
||||||
border.addRoundedRect( r.adjusted( -2, -2, 2, 2 ), 3, 3 );
|
|
||||||
QPen borderPen( QColor( 86, 170, 243 ) );
|
|
||||||
borderPen.setWidth( 5 );
|
|
||||||
painter->setPen( borderPen );
|
|
||||||
painter->drawPath( border );
|
|
||||||
|
|
||||||
painter->restore();
|
|
||||||
#else
|
|
||||||
opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
painter->drawPixmap( r, cover );
|
painter->drawPixmap( r, cover );
|
||||||
|
|
||||||
if ( m_hoverIndex == index )
|
|
||||||
|
qreal opacity = -1.;
|
||||||
|
if ( m_hoverFaders.contains( index ) )
|
||||||
|
{
|
||||||
|
const qreal pct = ( m_hoverFaders[ index ]->currentFrame() / 100. );
|
||||||
|
opacity = 0.15 - pct * 0.15;
|
||||||
|
}
|
||||||
|
else if ( m_hoverIndex != index )
|
||||||
|
{
|
||||||
|
opacity = 0.15;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ( opacity > -1. )
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
painter->setPen( QColor( 33, 33, 33 ) );
|
painter->setPen( QColor( 240, 240, 240 ) );
|
||||||
painter->setBrush( QColor( 33, 33, 33 ) );
|
painter->setBrush( QColor( 240, 240, 240 ) );
|
||||||
painter->setOpacity( 0.5 );
|
painter->setOpacity( opacity );
|
||||||
painter->drawRect( r );
|
painter->drawRect( r );
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
@@ -236,12 +236,12 @@ AlbumItemDelegate::onPlayClicked( const QPersistentModelIndex& index )
|
|||||||
spinner->installEventFilter( this );
|
spinner->installEventFilter( this );
|
||||||
|
|
||||||
m_spinner[ index ] = spinner;
|
m_spinner[ index ] = spinner;
|
||||||
|
|
||||||
PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) );
|
PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) );
|
||||||
if ( item )
|
if ( item )
|
||||||
{
|
{
|
||||||
_detail::Closure* closure;
|
_detail::Closure* closure;
|
||||||
|
|
||||||
closure = NewClosure( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ),
|
closure = NewClosure( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ),
|
||||||
const_cast<AlbumItemDelegate*>(this), SLOT( onPlaybackStarted( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );
|
const_cast<AlbumItemDelegate*>(this), SLOT( onPlaybackStarted( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );
|
||||||
|
|
||||||
@@ -276,8 +276,8 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const
|
|||||||
bool hoveringArtist = false;
|
bool hoveringArtist = false;
|
||||||
if ( m_artistNameRects.contains( index ) )
|
if ( m_artistNameRects.contains( index ) )
|
||||||
{
|
{
|
||||||
QRect artistNameRect = m_artistNameRects[ index ];
|
const QRect artistNameRect = m_artistNameRects[ index ];
|
||||||
QMouseEvent* ev = static_cast< QMouseEvent* >( event );
|
const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
|
||||||
hoveringArtist = artistNameRect.contains( ev->pos() );
|
hoveringArtist = artistNameRect.contains( ev->pos() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,7 +288,7 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const
|
|||||||
if ( index != idx )
|
if ( index != idx )
|
||||||
m_playButton.take( idx )->deleteLater();
|
m_playButton.take( idx )->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !m_playButton.contains( index ) && !m_spinner.contains( index ) && !m_pauseButton.contains( index ) )
|
if ( !m_playButton.contains( index ) && !m_spinner.contains( index ) && !m_pauseButton.contains( index ) )
|
||||||
{
|
{
|
||||||
foreach ( ImageButton* button, m_playButton )
|
foreach ( ImageButton* button, m_playButton )
|
||||||
@@ -304,7 +304,7 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const
|
|||||||
button->setFocusPolicy( Qt::NoFocus );
|
button->setFocusPolicy( Qt::NoFocus );
|
||||||
button->installEventFilter( this );
|
button->installEventFilter( this );
|
||||||
button->show();
|
button->show();
|
||||||
|
|
||||||
NewClosure( button, SIGNAL( clicked( bool ) ),
|
NewClosure( button, SIGNAL( clicked( bool ) ),
|
||||||
const_cast<AlbumItemDelegate*>(this), SLOT( onPlayClicked( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );
|
const_cast<AlbumItemDelegate*>(this), SLOT( onPlayClicked( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );
|
||||||
|
|
||||||
@@ -325,11 +325,32 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const
|
|||||||
|
|
||||||
if ( m_hoverIndex != index )
|
if ( m_hoverIndex != index )
|
||||||
{
|
{
|
||||||
|
if ( m_hoverIndex.isValid() )
|
||||||
|
{
|
||||||
|
QTimeLine* fadeOut = createTimeline( QTimeLine::Backward );
|
||||||
|
_detail::Closure* c = NewClosure( fadeOut, SIGNAL( frameChanged( int ) ), this, SLOT( fadingFrameChanged( QPersistentModelIndex ) ), QPersistentModelIndex( m_hoverIndex ) );
|
||||||
|
c->setAutoDelete( false );
|
||||||
|
c = NewClosure( fadeOut, SIGNAL( finished() ), this, SLOT( fadingFrameFinished( QPersistentModelIndex ) ), QPersistentModelIndex( m_hoverIndex ) );
|
||||||
|
c->setAutoDelete( false );
|
||||||
|
m_hoverFaders[ m_hoverIndex ] = fadeOut;
|
||||||
|
fadeOut->start();
|
||||||
|
}
|
||||||
|
|
||||||
emit updateIndex( m_hoverIndex );
|
emit updateIndex( m_hoverIndex );
|
||||||
m_hoverIndex = index;
|
m_hoverIndex = index;
|
||||||
|
|
||||||
|
QTimeLine* fadeIn = createTimeline( QTimeLine::Forward );
|
||||||
|
_detail::Closure* c = NewClosure( fadeIn, SIGNAL( frameChanged( int ) ), this, SLOT( fadingFrameChanged( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );
|
||||||
|
c->setAutoDelete( false );
|
||||||
|
c = NewClosure( fadeIn, SIGNAL( finished() ), this, SLOT( fadingFrameFinished( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );
|
||||||
|
c->setAutoDelete( false );
|
||||||
|
|
||||||
|
m_hoverFaders[ index ] = fadeIn;
|
||||||
|
fadeIn->start();
|
||||||
|
|
||||||
emit updateIndex( index );
|
emit updateIndex( index );
|
||||||
}
|
}
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -443,7 +464,7 @@ AlbumItemDelegate::onPlaylistChanged( const QPersistentModelIndex& index )
|
|||||||
if ( AudioEngine::instance()->currentTrackPlaylist() != item->artist()->playlistInterface( Tomahawk::Mixed ) )
|
if ( AudioEngine::instance()->currentTrackPlaylist() != item->artist()->playlistInterface( Tomahawk::Mixed ) )
|
||||||
finished = true;
|
finished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( finished )
|
if ( finished )
|
||||||
{
|
{
|
||||||
if ( m_pauseButton.contains( index ) )
|
if ( m_pauseButton.contains( index ) )
|
||||||
@@ -468,7 +489,7 @@ AlbumItemDelegate::onPlaybackStarted( const QPersistentModelIndex& index )
|
|||||||
delete widget;
|
delete widget;
|
||||||
}
|
}
|
||||||
m_spinner.clear();
|
m_spinner.clear();
|
||||||
|
|
||||||
ImageButton* button = new ImageButton( m_view );
|
ImageButton* button = new ImageButton( m_view );
|
||||||
button->setPixmap( RESPATH "images/pause-rest.png" );
|
button->setPixmap( RESPATH "images/pause-rest.png" );
|
||||||
button->setPixmap( RESPATH "images/pause-pressed.png", QIcon::Off, QIcon::Active );
|
button->setPixmap( RESPATH "images/pause-pressed.png", QIcon::Off, QIcon::Active );
|
||||||
@@ -478,13 +499,45 @@ AlbumItemDelegate::onPlaybackStarted( const QPersistentModelIndex& index )
|
|||||||
button->setFocusPolicy( Qt::NoFocus );
|
button->setFocusPolicy( Qt::NoFocus );
|
||||||
button->installEventFilter( this );
|
button->installEventFilter( this );
|
||||||
button->show();
|
button->show();
|
||||||
|
|
||||||
connect( button, SIGNAL( clicked( bool ) ), AudioEngine::instance(), SLOT( playPause() ) );
|
connect( button, SIGNAL( clicked( bool ) ), AudioEngine::instance(), SLOT( playPause() ) );
|
||||||
|
|
||||||
m_pauseButton[ index ] = button;
|
m_pauseButton[ index ] = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AlbumItemDelegate::fadingFrameChanged( const QPersistentModelIndex& idx )
|
||||||
|
{
|
||||||
|
emit updateIndex( idx );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AlbumItemDelegate::fadingFrameFinished( const QPersistentModelIndex& idx )
|
||||||
|
{
|
||||||
|
if ( m_hoverFaders.contains( idx ) )
|
||||||
|
{
|
||||||
|
m_hoverFaders.take( idx )->deleteLater();
|
||||||
|
emit updateIndex( idx );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QTimeLine*
|
||||||
|
AlbumItemDelegate::createTimeline( QTimeLine::Direction direction )
|
||||||
|
{
|
||||||
|
QTimeLine* timeline = new QTimeLine( FADE_DURATION, this );
|
||||||
|
timeline->setDirection( direction );
|
||||||
|
timeline->setCurveShape( QTimeLine::LinearCurve );
|
||||||
|
timeline->setUpdateInterval( 30 );
|
||||||
|
timeline->setStartFrame( 0 );
|
||||||
|
timeline->setEndFrame( 100 );
|
||||||
|
|
||||||
|
return timeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
AlbumItemDelegate::eventFilter( QObject* obj, QEvent* event )
|
AlbumItemDelegate::eventFilter( QObject* obj, QEvent* event )
|
||||||
{
|
{
|
||||||
|
@@ -21,9 +21,11 @@
|
|||||||
#define ALBUMITEMDELEGATE_H
|
#define ALBUMITEMDELEGATE_H
|
||||||
|
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
#include <QTimeLine>
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
class QTimeLine;
|
||||||
namespace Tomahawk {
|
namespace Tomahawk {
|
||||||
class PixmapDelegateFader;
|
class PixmapDelegateFader;
|
||||||
}
|
}
|
||||||
@@ -52,15 +54,19 @@ signals:
|
|||||||
private slots:
|
private slots:
|
||||||
void modelChanged();
|
void modelChanged();
|
||||||
void doUpdateIndex( const QPersistentModelIndex& idx );
|
void doUpdateIndex( const QPersistentModelIndex& idx );
|
||||||
|
|
||||||
void onScrolled( int dx, int dy );
|
void onScrolled( int dx, int dy );
|
||||||
void onPlaybackStarted( const QPersistentModelIndex& index );
|
void onPlaybackStarted( const QPersistentModelIndex& index );
|
||||||
void onPlaybackFinished();
|
void onPlaybackFinished();
|
||||||
|
|
||||||
void onPlayClicked( const QPersistentModelIndex& index );
|
void onPlayClicked( const QPersistentModelIndex& index );
|
||||||
void onPlaylistChanged( const QPersistentModelIndex& index );
|
void onPlaylistChanged( const QPersistentModelIndex& index );
|
||||||
|
|
||||||
|
void fadingFrameChanged( const QPersistentModelIndex& );
|
||||||
|
void fadingFrameFinished( const QPersistentModelIndex& );
|
||||||
private:
|
private:
|
||||||
|
QTimeLine* createTimeline( QTimeLine::Direction direction );
|
||||||
|
|
||||||
QAbstractItemView* m_view;
|
QAbstractItemView* m_view;
|
||||||
AlbumProxyModel* m_model;
|
AlbumProxyModel* m_model;
|
||||||
|
|
||||||
@@ -75,6 +81,8 @@ private:
|
|||||||
mutable QHash< QPersistentModelIndex, QWidget* > m_spinner;
|
mutable QHash< QPersistentModelIndex, QWidget* > m_spinner;
|
||||||
mutable QHash< QPersistentModelIndex, ImageButton* > m_playButton;
|
mutable QHash< QPersistentModelIndex, ImageButton* > m_playButton;
|
||||||
mutable QHash< QPersistentModelIndex, ImageButton* > m_pauseButton;
|
mutable QHash< QPersistentModelIndex, ImageButton* > m_pauseButton;
|
||||||
|
|
||||||
|
mutable QHash< QPersistentModelIndex, QTimeLine* > m_hoverFaders;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ALBUMITEMDELEGATE_H
|
#endif // ALBUMITEMDELEGATE_H
|
||||||
|
@@ -29,8 +29,6 @@
|
|||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
#define COVER_FADEIN 1000
|
|
||||||
|
|
||||||
QWeakPointer< TomahawkUtils::SharedTimeLine > PixmapDelegateFader::s_stlInstance = QWeakPointer< TomahawkUtils::SharedTimeLine >();
|
QWeakPointer< TomahawkUtils::SharedTimeLine > PixmapDelegateFader::s_stlInstance = QWeakPointer< TomahawkUtils::SharedTimeLine >();
|
||||||
|
|
||||||
|
|
||||||
@@ -126,7 +124,7 @@ void
|
|||||||
PixmapDelegateFader::setSize( const QSize& size )
|
PixmapDelegateFader::setSize( const QSize& size )
|
||||||
{
|
{
|
||||||
m_size = size;
|
m_size = size;
|
||||||
|
|
||||||
if ( m_defaultImage )
|
if ( m_defaultImage )
|
||||||
{
|
{
|
||||||
// No cover loaded yet, use default and don't fade in
|
// No cover loaded yet, use default and don't fade in
|
||||||
|
Reference in New Issue
Block a user