mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
* Show proper play buttons / spinners overlaying album items.
This commit is contained in:
@@ -93,6 +93,7 @@ inline static QString uuid()
|
|||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE( QModelIndex )
|
||||||
Q_DECLARE_METATYPE( QPersistentModelIndex )
|
Q_DECLARE_METATYPE( QPersistentModelIndex )
|
||||||
|
|
||||||
#endif // TYPEDEFS_H
|
#endif // TYPEDEFS_H
|
||||||
|
@@ -579,7 +579,6 @@ AudioEngine::playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk:
|
|||||||
void
|
void
|
||||||
AudioEngine::playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk::query_ptr& query )
|
AudioEngine::playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk::query_ptr& query )
|
||||||
{
|
{
|
||||||
tDebug() << query->toString();
|
|
||||||
if ( !query.isNull() && query->numResults() )
|
if ( !query.isNull() && query->numResults() )
|
||||||
playItem( playlist, query->results().first() );
|
playItem( playlist, query->results().first() );
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
#include "Artist.h"
|
#include "Artist.h"
|
||||||
#include "Query.h"
|
#include "Query.h"
|
||||||
@@ -35,8 +36,9 @@
|
|||||||
#include "playlist/AlbumItem.h"
|
#include "playlist/AlbumItem.h"
|
||||||
#include "playlist/AlbumProxyModel.h"
|
#include "playlist/AlbumProxyModel.h"
|
||||||
#include "AlbumView.h"
|
#include "AlbumView.h"
|
||||||
#include <QMouseEvent>
|
#include "ViewManager.h"
|
||||||
#include <ViewManager.h>
|
#include "utils/AnimatedSpinner.h"
|
||||||
|
#include "widgets/ImageButton.h"
|
||||||
|
|
||||||
|
|
||||||
AlbumItemDelegate::AlbumItemDelegate( QAbstractItemView* parent, AlbumProxyModel* proxy )
|
AlbumItemDelegate::AlbumItemDelegate( QAbstractItemView* parent, AlbumProxyModel* proxy )
|
||||||
@@ -46,6 +48,8 @@ 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 ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -156,7 +160,7 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
|
|
||||||
painter->drawPixmap( r, cover.scaled( r.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
|
painter->drawPixmap( r, cover.scaled( r.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
|
||||||
|
|
||||||
if ( m_hoverIndex == index )
|
/* if ( m_hoverIndex == index )
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
@@ -172,7 +176,7 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
painter->drawPixmap( m_playButtonRect, playButton );
|
painter->drawPixmap( m_playButtonRect, playButton );
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
@@ -250,6 +254,37 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AlbumItemDelegate::onPlayClicked( const QPersistentModelIndex& index )
|
||||||
|
{
|
||||||
|
AlbumItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) );
|
||||||
|
if ( item )
|
||||||
|
{
|
||||||
|
if ( !item->query().isNull() )
|
||||||
|
AudioEngine::instance()->playItem( Tomahawk::playlistinterface_ptr(), item->query() );
|
||||||
|
else if ( !item->album().isNull() )
|
||||||
|
AudioEngine::instance()->playItem( item->album() );
|
||||||
|
else if ( !item->artist().isNull() )
|
||||||
|
AudioEngine::instance()->playItem( item->artist() );
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint pos = m_button[ index ]->pos();
|
||||||
|
foreach ( ImageButton* button, m_button )
|
||||||
|
button->deleteLater();
|
||||||
|
m_button.clear();
|
||||||
|
|
||||||
|
_detail::Closure* closure = NewClosure( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ),
|
||||||
|
const_cast<AlbumItemDelegate*>(this), SLOT( onPlaybackStarted( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );
|
||||||
|
|
||||||
|
AnimatedSpinner* spinner = new AnimatedSpinner( m_view );
|
||||||
|
spinner->setAutoCenter( false );
|
||||||
|
spinner->fadeIn();
|
||||||
|
spinner->move( pos );
|
||||||
|
|
||||||
|
m_subWidgets[ index ] = spinner;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
|
AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
|
||||||
{
|
{
|
||||||
@@ -263,27 +298,31 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( event->type() == QEvent::MouseMove )
|
if ( event->type() == QEvent::MouseMove )
|
||||||
m_hoverIndex = index;
|
|
||||||
|
|
||||||
QMouseEvent* ev = static_cast< QMouseEvent* >( event );
|
|
||||||
if ( event->type() == QEvent::MouseButtonRelease )
|
|
||||||
{
|
{
|
||||||
if ( m_playButtonRect.contains( ev->pos() ) )
|
if ( !m_button.contains( index ) && !m_subWidgets.contains( index ) )
|
||||||
{
|
{
|
||||||
AlbumItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) );
|
foreach ( ImageButton* button, m_button )
|
||||||
|
button->deleteLater();
|
||||||
|
m_button.clear();
|
||||||
|
|
||||||
if ( !item->query().isNull() )
|
ImageButton* button = new ImageButton( m_view );
|
||||||
AudioEngine::instance()->playItem( Tomahawk::playlistinterface_ptr(), item->query() );
|
button->setPixmap( RESPATH "images/play-rest.png" );
|
||||||
else if ( !item->album().isNull() )
|
button->setPixmap( RESPATH "images/play-pressed.png", QIcon::Off, QIcon::Active );
|
||||||
AudioEngine::instance()->playItem( item->album() );
|
button->setFixedSize( 48, 48 );
|
||||||
else if ( !item->artist().isNull() )
|
button->move( option.rect.center() - QPoint( 23, 23 ) );
|
||||||
AudioEngine::instance()->playItem( item->artist() );
|
button->setContentsMargins( 0, 0, 0, 0 );
|
||||||
|
button->show();
|
||||||
|
|
||||||
|
_detail::Closure* closure = NewClosure( button, SIGNAL( clicked( bool ) ),
|
||||||
|
const_cast<AlbumItemDelegate*>(this), SLOT( onPlayClicked( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );
|
||||||
|
|
||||||
event->accept();
|
m_button[ index ] = button;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_hoverIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMouseEvent* ev = static_cast< QMouseEvent* >( event );
|
||||||
if ( m_artistNameRects.contains( index ) )
|
if ( m_artistNameRects.contains( index ) )
|
||||||
{
|
{
|
||||||
QRect artistNameRect = m_artistNameRects[ index ];
|
QRect artistNameRect = m_artistNameRects[ index ];
|
||||||
@@ -359,3 +398,27 @@ AlbumItemDelegate::doUpdateIndex( const QPersistentModelIndex& idx )
|
|||||||
emit updateIndex( idx );
|
emit updateIndex( idx );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AlbumItemDelegate::onScrolled( int dx, int dy )
|
||||||
|
{
|
||||||
|
foreach ( QWidget* widget, m_subWidgets.values() )
|
||||||
|
{
|
||||||
|
widget->move( widget->pos() + QPoint( dx, dy ) );
|
||||||
|
}
|
||||||
|
foreach ( ImageButton* button, m_button.values() )
|
||||||
|
{
|
||||||
|
button->move( button->pos() + QPoint( dx, dy ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AlbumItemDelegate::onPlaybackStarted( const QPersistentModelIndex& index )
|
||||||
|
{
|
||||||
|
foreach ( QWidget* widget, m_subWidgets.values() )
|
||||||
|
{
|
||||||
|
delete widget;
|
||||||
|
}
|
||||||
|
m_subWidgets.clear();
|
||||||
|
}
|
||||||
|
@@ -30,6 +30,7 @@ namespace Tomahawk {
|
|||||||
|
|
||||||
class QEvent;
|
class QEvent;
|
||||||
class AlbumProxyModel;
|
class AlbumProxyModel;
|
||||||
|
class ImageButton;
|
||||||
|
|
||||||
class DLLEXPORT AlbumItemDelegate : public QStyledItemDelegate
|
class DLLEXPORT AlbumItemDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
@@ -52,6 +53,11 @@ 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 onPlaybackStarted( const QPersistentModelIndex& index );
|
||||||
|
|
||||||
|
void onPlayClicked( const QPersistentModelIndex& index );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QAbstractItemView* m_view;
|
QAbstractItemView* m_view;
|
||||||
@@ -65,6 +71,8 @@ private:
|
|||||||
mutable QRect m_playButtonRect;
|
mutable QRect m_playButtonRect;
|
||||||
|
|
||||||
QPixmap m_shadowPixmap;
|
QPixmap m_shadowPixmap;
|
||||||
|
mutable QHash< QPersistentModelIndex, QWidget* > m_subWidgets;
|
||||||
|
mutable QHash< QPersistentModelIndex, ImageButton* > m_button;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ALBUMITEMDELEGATE_H
|
#endif // ALBUMITEMDELEGATE_H
|
||||||
|
@@ -158,7 +158,7 @@ AlbumModel::flags( const QModelIndex& index ) const
|
|||||||
Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
|
Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
|
||||||
|
|
||||||
if ( index.isValid() && index.column() == 0 )
|
if ( index.isValid() && index.column() == 0 )
|
||||||
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
|
return Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
|
||||||
else
|
else
|
||||||
return defaultFlags;
|
return defaultFlags;
|
||||||
}
|
}
|
||||||
|
@@ -170,6 +170,14 @@ AlbumView::onItemCountChanged( unsigned int items )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AlbumView::scrollContentsBy( int dx, int dy )
|
||||||
|
{
|
||||||
|
QListView::scrollContentsBy( dx, dy );
|
||||||
|
emit scrolledContents( dx, dy );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AlbumView::paintEvent( QPaintEvent* event )
|
AlbumView::paintEvent( QPaintEvent* event )
|
||||||
{
|
{
|
||||||
|
@@ -68,9 +68,11 @@ public slots:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void modelChanged();
|
void modelChanged();
|
||||||
|
void scrolledContents( int dx, int dy );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void startDrag( Qt::DropActions supportedActions );
|
virtual void startDrag( Qt::DropActions supportedActions );
|
||||||
|
virtual void scrollContentsBy( int dx, int dy );
|
||||||
|
|
||||||
void paintEvent( QPaintEvent* event );
|
void paintEvent( QPaintEvent* event );
|
||||||
void resizeEvent( QResizeEvent* event );
|
void resizeEvent( QResizeEvent* event );
|
||||||
|
@@ -57,12 +57,14 @@ AnimatedSpinner::AnimatedSpinner( const QSize size, bool autoStart )
|
|||||||
void
|
void
|
||||||
AnimatedSpinner::init()
|
AnimatedSpinner::init()
|
||||||
{
|
{
|
||||||
|
m_autoCenter = true;
|
||||||
|
|
||||||
m_showHide->setDuration( 300 );
|
m_showHide->setDuration( 300 );
|
||||||
m_showHide->setStartFrame( 0 );
|
m_showHide->setStartFrame( 0 );
|
||||||
m_showHide->setEndFrame( 100 );
|
m_showHide->setEndFrame( 100 );
|
||||||
m_showHide->setUpdateInterval( 20 );
|
m_showHide->setUpdateInterval( 20 );
|
||||||
if( parentWidget() )
|
|
||||||
|
if ( parentWidget() )
|
||||||
connect( m_showHide, SIGNAL( frameChanged( int ) ), this, SLOT( update() ) );
|
connect( m_showHide, SIGNAL( frameChanged( int ) ), this, SLOT( update() ) );
|
||||||
else
|
else
|
||||||
connect( m_showHide, SIGNAL( frameChanged( int ) ), this, SLOT( updatePixmap() ) );
|
connect( m_showHide, SIGNAL( frameChanged( int ) ), this, SLOT( updatePixmap() ) );
|
||||||
@@ -86,7 +88,6 @@ AnimatedSpinner::init()
|
|||||||
else
|
else
|
||||||
size = m_pixmap.size();
|
size = m_pixmap.size();
|
||||||
|
|
||||||
|
|
||||||
/// Radius is best-fit line with points (13x13, 2), (28x28, 5), (48x48, 10)
|
/// Radius is best-fit line with points (13x13, 2), (28x28, 5), (48x48, 10)
|
||||||
m_radius = qRound( ( 23. * ( size.width() - 5.) ) / 100. );
|
m_radius = qRound( ( 23. * ( size.width() - 5.) ) / 100. );
|
||||||
m_armLength = size.width()/2 - m_radius;
|
m_armLength = size.width()/2 - m_radius;
|
||||||
@@ -101,12 +102,12 @@ AnimatedSpinner::init()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AnimatedSpinner::paintEvent(QPaintEvent *event)
|
AnimatedSpinner::paintEvent( QPaintEvent* event )
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED( event );
|
||||||
if ( parentWidget() )
|
if ( m_autoCenter && parentWidget() )
|
||||||
{
|
{
|
||||||
QPoint center( ( parentWidget()->width() / 2 ) - ( width() / 2 ), ( parentWidget()->height() / 2 ) - ( height() / 2 ) );
|
QPoint center = parentWidget()->contentsRect().center();
|
||||||
if ( center != pos() )
|
if ( center != pos() )
|
||||||
{
|
{
|
||||||
move( center );
|
move( center );
|
||||||
@@ -114,7 +115,7 @@ AnimatedSpinner::paintEvent(QPaintEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QPainter p(this);
|
QPainter p( this );
|
||||||
drawFrame( &p, rect() );
|
drawFrame( &p, rect() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -49,6 +49,8 @@ public:
|
|||||||
QSize sizeHint() const;
|
QSize sizeHint() const;
|
||||||
|
|
||||||
QPixmap pixmap() const { return m_pixmap; }
|
QPixmap pixmap() const { return m_pixmap; }
|
||||||
|
|
||||||
|
void setAutoCenter( bool enabled ) { m_autoCenter = enabled; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void fadeIn();
|
void fadeIn();
|
||||||
@@ -82,6 +84,7 @@ private:
|
|||||||
int m_currentIndex;
|
int m_currentIndex;
|
||||||
QVector<qreal> m_colors;
|
QVector<qreal> m_colors;
|
||||||
QPixmap m_pixmap;
|
QPixmap m_pixmap;
|
||||||
|
bool m_autoCenter;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user