From e7ffb77cadc75cea6466c0a672aec2b522a5f6e0 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 25 Nov 2012 02:03:02 +0100 Subject: [PATCH] more qml work --- data/qml/CoverFlip.qml | 14 +- data/qml/CoverImage.qml | 20 +-- data/qml/StationScene.qml | 131 +++++++++--------- data/qml/StationView.qml | 12 +- src/libtomahawk/playlist/PlayableModel.cpp | 5 + src/libtomahawk/playlist/PlayableModel.h | 3 +- .../dynamic/echonest/EchonestGenerator.cpp | 1 + .../dynamic/widgets/DynamicQmlWidget.cpp | 11 +- .../dynamic/widgets/DynamicQmlWidget.h | 6 +- 9 files changed, 113 insertions(+), 90 deletions(-) diff --git a/data/qml/CoverFlip.qml b/data/qml/CoverFlip.qml index a334f75e7..c389ce83e 100644 --- a/data/qml/CoverFlip.qml +++ b/data/qml/CoverFlip.qml @@ -7,26 +7,29 @@ PathView { // The start coordinates for the covers // Default is left, centered in height - property int pathStartX: coverSize + property int pathStartX: 0 property int pathStartY: height / 2 // The size of the covers in the path property int coverSize: 100 + property color backgroundColor: "black" + // emitted when a cover is clicked signal itemClicked(int index) // emitted when a cover is clicked signal itemPlayPauseClicked(int index) - preferredHighlightBegin: 0.2 // scene.width / 11000 - preferredHighlightEnd: preferredHighlightBegin +// preferredHighlightBegin: 0.2 // scene.width / 11000 +// preferredHighlightEnd: preferredHighlightBegin pathItemCount: 5 //highlightMoveDuration: 500 delegate: CoverImage { height: root.coverSize width: root.coverSize + backgroundColor: coverView.backgroundColor showLabels: true showMirror: true @@ -34,7 +37,7 @@ PathView { trackName: model.trackName artworkId: model.coverID showPlayButton: true - currentyPlayed: mode.itemFromIndex(index).isPlaying + currentlyPlaying: isPlaying scale: PathView.itemScale itemBrightness: PathView.itemBrightness @@ -42,6 +45,7 @@ PathView { z: -x onPlayClicked: { + console.log("***************") coverView.itemPlayPauseClicked(index) } @@ -72,7 +76,7 @@ PathView { // // PathAttribute { name: "itemOpacity"; value: 1 } // // PathAttribute { name: "itemBrightness"; value: .5 } // // PathAttribute { name: "itemScale"; value: 0.4 } - PathLine { x: root.width; y: 0 } + PathLine { x: coverView.width; y: 0 } PathPercent { value: 1 } PathAttribute { name: "itemOpacity"; value: 1 } PathAttribute { name: "itemBrightness"; value: 0 } diff --git a/data/qml/CoverImage.qml b/data/qml/CoverImage.qml index 2878d6481..946e5d702 100644 --- a/data/qml/CoverImage.qml +++ b/data/qml/CoverImage.qml @@ -10,7 +10,7 @@ Item { property bool showPlayButton: false // if this is true, the play button will be swapped by a pause button - property bool currentyPlayed: false + property bool currentlyPlaying: false // Should the mirror be painted? property bool showMirror: false @@ -20,8 +20,6 @@ Item { property string trackName property string artworkId - onArtworkIdChanged: print("!*!*!*!*!* artworkId", artworkId) - // The border color for the cover image property color borderColor: "black" // The border width for the cover image @@ -44,7 +42,10 @@ Item { anchors.fill: parent hoverEnabled: true - onClicked: root.clicked(); + onClicked: { + print("Cover clicked"); + root.clicked(); + } } @@ -144,7 +145,7 @@ Item { 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 the backgroundColor + // For now the Qt.rgba needs to be manually updated to match the backgroundColor 454e59 GradientStop { position: 0.0; color: Qt.rgba(0, 0, 0, 1-mirrorBrightness) } GradientStop { position: 0.5; color: backgroundColor } } @@ -152,12 +153,15 @@ Item { Image { id: playButton - visible: showPlayButton ? mouseArea.containsMouse : false - source: currentyPlayed ? "../images/pause-rest.png" : "../images/play-rest.png" + visible: showPlayButton ? (mouseArea.containsMouse || currentlyPlaying) : false + source: currentlyPlaying ? "../images/pause-rest.png" : "../images/play-rest.png" anchors.centerIn: parent MouseArea { anchors.fill: parent - onClicked: root.playClicked(); + onClicked: { + print("Play button clicked"); + root.playClicked(); + } } } diff --git a/data/qml/StationScene.qml b/data/qml/StationScene.qml index 7221ecb58..4c1342606 100644 --- a/data/qml/StationScene.qml +++ b/data/qml/StationScene.qml @@ -48,79 +48,79 @@ Rectangle { id: stationVisualModel -// Column { -// height: scene.height -// width: scene.width + Column { + height: scene.height + width: scene.width -// Row { -// height: scene.height / 2 -// width: scene.width -// spacing: width * .1 + Row { + height: scene.height / 2 + width: scene.width + spacing: width * .1 -// Item { -// height: parent.height -// width: (parent.width - orText.width - parent.spacing * 2 ) * 2 / 3 -// GridView { -// id: gridView -// anchors.fill: parent -// anchors.margins: cellWidth / 2 -// model: dummyArtistModel + Item { + height: parent.height + width: (parent.width - orText.width - parent.spacing * 2 ) * 2 / 3 + GridView { + id: gridView + anchors.fill: parent + anchors.margins: cellWidth / 2 + model: dummyArtistModel -// cellWidth: gridView.width / 4 - 1 // -1 to make sure there is space for 4 items even with rounding error -// cellHeight: cellWidth + cellWidth: gridView.width / 4 - 1 // -1 to make sure there is space for 4 items even with rounding error + cellHeight: cellWidth -// delegate: Item { -// height: gridView.cellHeight * .9 -// width: height + delegate: Item { + height: gridView.cellHeight * .9 + width: height -// CoverImage { -// artistName: modelData -// anchors.fill: parent + CoverImage { + artistName: modelData + anchors.fill: parent -// onClicked: { -// echonestStation.setMainControl( EchonestStation.StationTypeArtist, modelData ); -// stationListView.incrementCurrentIndex(); -// } -// } -// } -// } -// } + onClicked: { + rootView.startStationFromArtist(modelData); + stationListView.incrementCurrentIndex(); + } + } + } + } + } -// } + } -// Row { -// height: scene.height / 2 -// width: scene.width * .9 -// anchors.horizontalCenter: parent.horizontalCenter -// spacing: width * .1 + Row { + height: scene.height / 2 + width: scene.width * .9 + anchors.horizontalCenter: parent.horizontalCenter + spacing: width * .1 -// TagCloud { -// height: parent.height -// width: (parent.width - orText.width - parent.spacing * 2 ) * 2 / 3 -// model: styleModel//generator.styles() -// opacity: echonestStation.configured ? 0 : 1 + TagCloud { + height: parent.height + width: (parent.width - orText.width - parent.spacing * 2 ) * 2 / 3 + model: styleModel//generator.styles() + opacity: echonestStation.configured ? 0 : 1 -// onTagClicked: { -// echonestStation.setMainControl( EchonestStation.StationTypeStyle, item ); -// stationListView.incrementCurrentIndex(); -// } + onTagClicked: { + echonestStation.setMainControl( EchonestStation.StationTypeStyle, item ); + stationListView.incrementCurrentIndex(); + } -// Behavior on opacity { -// NumberAnimation { duration: 300 } -// } -// } -// Text { -// id: orText -// text: "or" -// color: "white" -// anchors.verticalCenter: parent.verticalCenter -// } -// InputField { -// anchors.verticalCenter: parent.verticalCenter -// width: (parent.width - orText.width - parent.spacing * 2 ) * 1 / 3 -// } -// } -// } + Behavior on opacity { + NumberAnimation { duration: 300 } + } + } + Text { + id: orText + text: "or" + color: "white" + anchors.verticalCenter: parent.verticalCenter + } + InputField { + anchors.verticalCenter: parent.verticalCenter + width: (parent.width - orText.width - parent.spacing * 2 ) * 1 / 3 + } + } + } StationView { coverSize: Math.min(scene.height, scene.width) / 2 @@ -147,12 +147,7 @@ Rectangle { orientation: ListView.Horizontal model: stationVisualModel interactive: false - //highlightMoveDuration: 400 + highlightMoveDuration: 200 -// currentIndex: 1 - -// Component.onCompleted: { -// currentIndex = 1 -// } } } diff --git a/data/qml/StationView.qml b/data/qml/StationView.qml index 2b5bbfe73..40cf0b223 100644 --- a/data/qml/StationView.qml +++ b/data/qml/StationView.qml @@ -11,8 +11,14 @@ Item { CoverFlip { id: coverView - anchors.fill: parent - anchors.leftMargin: parent.width / 2 + anchors { + top: parent.top + right: parent.right + bottom:parent.bottom + } + width: parent.width / 2 + + backgroundColor: scene.color model: dynamicModel @@ -42,7 +48,7 @@ Item { font.bold: true width: parent.width elide: Text.ElideRight - text: echonestStation.name + text: rootView.title } } diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index 9131647ce..e2fc66271 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -47,6 +47,7 @@ PlayableModel::PlayableModel( QObject* parent, bool loading ) roleNames.insert( ArtistRole, "artistName" ); roleNames.insert( TrackRole, "trackName" ); roleNames.insert( CoverIDRole, "coverID" ); + roleNames.insert( IsPlayingRole, "isPlaying" ); setRoleNames( roleNames ); connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( onPlaybackStarted( Tomahawk::result_ptr ) ), Qt::DirectConnection ); @@ -282,6 +283,10 @@ PlayableModel::data( const QModelIndex& index, int role ) const { return QVariant( columnAlignment( index.column() ) ); } + else if ( role == IsPlayingRole ) + { + return entry->isPlaying(); + } int column = index.column(); if ( role < CoverIDRole && role >= Qt::UserRole ) diff --git a/src/libtomahawk/playlist/PlayableModel.h b/src/libtomahawk/playlist/PlayableModel.h index 88c3f8e88..2314f0943 100644 --- a/src/libtomahawk/playlist/PlayableModel.h +++ b/src/libtomahawk/playlist/PlayableModel.h @@ -70,7 +70,8 @@ public: OriginRole, ScoreRole, NameRole, - CoverIDRole + CoverIDRole, + IsPlayingRole }; diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp index ec07c2dad..cf25d4309 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp @@ -429,6 +429,7 @@ EchonestGenerator::dynamicFetched() Q_ASSERT( qobject_cast< QNetworkReply* >( sender() ) ); QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() ); + tDebug() << "dynamicFetched"; try { Echonest::DynamicPlaylist::FetchPair fetched = m_dynPlaylist->parseNext( reply ); diff --git a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp index da418b8f3..73b7a174e 100644 --- a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp +++ b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp @@ -66,8 +66,6 @@ DynamicQmlWidget::DynamicQmlWidget( const dynplaylist_ptr& playlist, QWidget* pa connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), this, SLOT( trackStarted() ) ); connect( AudioEngine::instance(), SIGNAL( playlistChanged( Tomahawk::playlistinterface_ptr ) ), this, SLOT( playlistChanged( Tomahawk::playlistinterface_ptr ) ) ); - // Initially seed the playlist - m_playlist->generator()->startFromArtist( Artist::get( "Eminem" , false ) ); } @@ -117,7 +115,7 @@ playlist_ptr DynamicQmlWidget::playlist() const void DynamicQmlWidget::playItem(int index) { - qDebug() << "playItem called for cover" << index; + tDebug() << "playItem called for cover" << index; AudioEngine::instance()->playItem( m_proxyModel->playlistInterface(), m_proxyModel->itemFromIndex( index )->result() ); } @@ -126,6 +124,12 @@ void DynamicQmlWidget::pause() AudioEngine::instance()->pause(); } +void DynamicQmlWidget::startStationFromArtist(const QString &artist) +{ + tDebug() << "should start startion from artist" << artist; + m_playlist->generator()->startFromArtist(Artist::get(artist)); +} + void DynamicQmlWidget::currentItemChanged( const QPersistentModelIndex ¤tIndex ) { rootContext()->setContextProperty( "currentlyPlayedIndex", m_proxyModel->mapFromSource( currentIndex ).row() ); @@ -134,7 +138,6 @@ void DynamicQmlWidget::currentItemChanged( const QPersistentModelIndex ¤tI void DynamicQmlWidget::tracksGenerated( const QList< query_ptr >& queries ) { - qDebug() << queries.count() << "tracks generated"; m_model->tracksGenerated( queries, queries.count() ); m_playlist->resolve(); } diff --git a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.h b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.h index a9181d337..2a97cf023 100644 --- a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.h +++ b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.h @@ -34,7 +34,10 @@ class DynamicModel; class DynamicQmlWidget : public QDeclarativeView, public Tomahawk::ViewPage { -Q_OBJECT + Q_OBJECT + + Q_PROPERTY(QString title READ title) + public: explicit DynamicQmlWidget( const dynplaylist_ptr& playlist, QWidget* parent = 0 ); virtual ~DynamicQmlWidget(); @@ -57,6 +60,7 @@ public: public slots: void playItem(int index); void pause(); + void startStationFromArtist(const QString &artist); private slots: void currentItemChanged( const QPersistentModelIndex ¤tIndex );