1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

added artwork to the stations view

This commit is contained in:
Michael Zanetti
2012-07-05 11:41:52 +02:00
parent f5b3c20c4c
commit 2d32a2db90
6 changed files with 51 additions and 14 deletions

View File

@@ -1,4 +1,5 @@
import QtQuick 1.1
import tomahawk 1.0
Rectangle {
id: scene
@@ -25,7 +26,6 @@ Rectangle {
anchors.fill: parent
anchors.margins: parent.border.width
source: "image://albumart/" + parent.artworkId
onSourceChanged: print("!*!*!*!*!*!*!*!*!", source)
}
Rectangle {
@@ -67,7 +67,7 @@ Rectangle {
id: mirroredDelegate
Item {
id: mirrorItem
id: mirroredItem
height: scene.coverSize
width: scene.coverSize
@@ -77,6 +77,18 @@ Rectangle {
property double itemOpacity: PathView.itemOpacity
property double shadowOp: PathView.shadowOpacity
Connections {
target: dynamicModel.itemFromIndex( index )
onCoverChanged: {
// We need to unset and re-set it because QML wouldn't re-query the image if it still has the same url
normalCover.item.artworkId = ""
mirroredCover.item.artworkId = ""
normalCover.item.artworkId = index
mirroredCover.item.artworkId = index
}
}
//Component.onCompleted: print("created delegate for", dynamicModel.itemFromIndex( index ) )
Loader {
id: normalCover
sourceComponent: coverImage
@@ -107,7 +119,7 @@ Rectangle {
Rectangle {
color: scene.color
anchors.fill: parent
opacity: mirrorItem.shadowOp
opacity: mirroredItem.shadowOp
}
Rectangle {
color: scene.color
@@ -118,7 +130,7 @@ Rectangle {
gradient: Gradient {
// TODO: no clue how to get the RGB component of the container rectangle color
// For now the Qt.rgba needs to be manually updated to match scene.color
GradientStop { position: 0.0; color: Qt.rgba(0, 0, 0, mirrorItem.shadowOp + ( (1 - mirrorItem.shadowOp) * .4)) }
GradientStop { position: 0.0; color: Qt.rgba(0, 0, 0, mirroredItem.shadowOp + ( (1 - mirroredItem.shadowOp) * .4)) }
GradientStop { position: 0.5; color: scene.color }
}
}
@@ -140,9 +152,6 @@ Rectangle {
delegate: mirroredDelegate
onCurrentIndexChanged: print("***************************************** current index:", currentIndex)
path: Path {
startX: scene.width / 2 + 20
startY: 155

View File

@@ -56,6 +56,7 @@ PlayableItem::PlayableItem( const Tomahawk::album_ptr& album, PlayableItem* pare
init( parent, row );
connect( album.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
connect( album.data(), SIGNAL( coverChanged() ), SIGNAL( coverChanged() ) );
}
@@ -66,6 +67,7 @@ PlayableItem::PlayableItem( const Tomahawk::artist_ptr& artist, PlayableItem* pa
init( parent, row );
connect( artist.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
connect( artist.data(), SIGNAL( coverChanged() ), SIGNAL( coverChanged() ) );
}
@@ -97,6 +99,9 @@ PlayableItem::PlayableItem( const Tomahawk::query_ptr& query, PlayableItem* pare
connect( query.data(), SIGNAL( resultsChanged() ),
SLOT( onResultsChanged() ) );
connect( query.data(), SIGNAL( coverChanged() ),
SIGNAL( coverChanged() ) );
}
@@ -121,6 +126,9 @@ PlayableItem::PlayableItem( const Tomahawk::plentry_ptr& entry, PlayableItem* pa
connect( m_query.data(), SIGNAL( resultsChanged() ),
SLOT( onResultsChanged() ) );
connect( m_query.data(), SIGNAL( coverChanged() ),
SIGNAL( coverChanged() ) );
}
@@ -164,6 +172,11 @@ PlayableItem::onResultsChanged()
emit dataChanged();
}
void PlayableItem::slotCoverChanged()
{
qDebug() << "emitted coverChanged";
}
QString
PlayableItem::name() const

View File

@@ -65,9 +65,11 @@ public:
signals:
void dataChanged();
void coverChanged();
private slots:
void onResultsChanged();
void slotCoverChanged();
private:
void init( PlayableItem* parent, int row = -1 );

View File

@@ -732,6 +732,18 @@ PlayableModel::itemFromIndex( const QModelIndex& index ) const
}
}
PlayableItem *PlayableModel::itemFromIndex(int itemIndex) const
{
QModelIndex modelIndex = index( itemIndex, 0, QModelIndex() );
if ( modelIndex.isValid() )
{
return static_cast<PlayableItem*>( modelIndex.internalPointer() );
}
else
{
return m_rootItem;
}
}
void
PlayableModel::appendArtist( const Tomahawk::artist_ptr& artist )

View File

@@ -118,6 +118,8 @@ public:
virtual void ensureResolved();
PlayableItem* itemFromIndex( const QModelIndex& index ) const;
Q_INVOKABLE PlayableItem* itemFromIndex( int itemIndex ) const;
/// Returns a flat list of all tracks in this model
QList< Tomahawk::query_ptr > queries() const;

View File

@@ -36,6 +36,9 @@ DynamicQmlWidget::DynamicQmlWidget( const dynplaylist_ptr& playlist, QWidget* pa
rootContext()->setContextProperty( "dynamicModel", m_model );
currentItemChanged( m_model->currentItem() );
// TODO: In case QML is used in more places, this should probably be moved to some generic place
qmlRegisterType<PlayableItem>("tomahawk", 1, 0, "PlayableItem");
setSource( QUrl( "qrc" RESPATH "qml/StationScene.qml" ) );
connect( m_model, SIGNAL( currentItemChanged( QPersistentModelIndex ) ), SLOT( currentItemChanged( QPersistentModelIndex ) ) );
@@ -83,8 +86,6 @@ DynamicQmlWidget::jumpToCurrentTrack()
QPixmap DynamicQmlWidget::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
qDebug() << "*!*!*!*!*!*!*!*!*!* image requested:" << id;
// We always can generate it in the requested size
int width = requestedSize.width() > 0 ? requestedSize.width() : 230;
int height = requestedSize.height() > 0 ? requestedSize.height() : 230;
@@ -96,13 +97,11 @@ QPixmap DynamicQmlWidget::requestPixmap(const QString &id, QSize *size, const QS
qDebug() << "got index" << index;
if( index.isValid() ) {
PlayableItem *item = m_model->itemFromIndex( index );
qDebug() << "got item" << item << item->query();
qDebug() << "got item" << item << item->query()->coverLoaded();
if ( !item->album().isNull() && item->album()->coverLoaded() ) {
if ( !item->album().isNull() ) {
return item->album()->cover( *size );
} else if ( !item->artist().isNull() && item->artist()->coverLoaded() ) {
} else if ( !item->artist().isNull() ) {
return item->artist()->cover( *size );
} else if ( !item->query().isNull() && item->query()->coverLoaded() ) {
} else if ( !item->query().isNull() ) {
return item->query()->cover( *size );
}
}