From 2d32a2db9089c170ba80dce7802b8d430f9d9503 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 5 Jul 2012 11:41:52 +0200 Subject: [PATCH] added artwork to the stations view --- data/qml/StationScene.qml | 23 +++++++++++++------ src/libtomahawk/playlist/PlayableItem.cpp | 13 +++++++++++ src/libtomahawk/playlist/PlayableItem.h | 2 ++ src/libtomahawk/playlist/PlayableModel.cpp | 12 ++++++++++ src/libtomahawk/playlist/PlayableModel.h | 2 ++ .../dynamic/widgets/DynamicQmlWidget.cpp | 13 +++++------ 6 files changed, 51 insertions(+), 14 deletions(-) diff --git a/data/qml/StationScene.qml b/data/qml/StationScene.qml index 5595f7414..6228245be 100644 --- a/data/qml/StationScene.qml +++ b/data/qml/StationScene.qml @@ -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 diff --git a/src/libtomahawk/playlist/PlayableItem.cpp b/src/libtomahawk/playlist/PlayableItem.cpp index 0bf7237b6..ba07788d3 100644 --- a/src/libtomahawk/playlist/PlayableItem.cpp +++ b/src/libtomahawk/playlist/PlayableItem.cpp @@ -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 diff --git a/src/libtomahawk/playlist/PlayableItem.h b/src/libtomahawk/playlist/PlayableItem.h index 2c37f8cc5..5305f4b8d 100644 --- a/src/libtomahawk/playlist/PlayableItem.h +++ b/src/libtomahawk/playlist/PlayableItem.h @@ -65,9 +65,11 @@ public: signals: void dataChanged(); + void coverChanged(); private slots: void onResultsChanged(); + void slotCoverChanged(); private: void init( PlayableItem* parent, int row = -1 ); diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index 4cc14043c..22e1dd021 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -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( modelIndex.internalPointer() ); + } + else + { + return m_rootItem; + } +} void PlayableModel::appendArtist( const Tomahawk::artist_ptr& artist ) diff --git a/src/libtomahawk/playlist/PlayableModel.h b/src/libtomahawk/playlist/PlayableModel.h index 9202a5ade..f8b963bec 100644 --- a/src/libtomahawk/playlist/PlayableModel.h +++ b/src/libtomahawk/playlist/PlayableModel.h @@ -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; diff --git a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp index bd24bd303..a10ec16d5 100644 --- a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp +++ b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp @@ -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("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 ); } }