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 )
|
||||||
@@ -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();
|
||||||
@@ -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() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,8 +325,29 @@ 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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,6 +506,38 @@ AlbumItemDelegate::onPlaybackStarted( const QPersistentModelIndex& index )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
@@ -60,7 +62,11 @@ private slots:
|
|||||||
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 >();
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user