diff --git a/data/qml/StationCreator.qml b/data/qml/StationCreator.qml index 9d03f474f..e1c8f8a4d 100644 --- a/data/qml/StationCreator.qml +++ b/data/qml/StationCreator.qml @@ -72,7 +72,7 @@ Item { Row { function createStation() { - rootView.startStationFromArtist(artistInputField.text) + mainView.startStationFromArtist(artistInputField.text) } anchors.fill: parent @@ -106,7 +106,7 @@ Item { showPlayButton: true onClicked: { - rootView.startStationFromArtist(modelData); + mainView.startStationFromArtist(modelData); stationCreator.next() } } @@ -131,7 +131,7 @@ Item { anchors.centerIn: parent width: parent.width onAccepted: { - rootView.startStationFromArtist(text) + mainView.startStationFromArtist(text) stationCreator.next() } } @@ -145,7 +145,7 @@ Item { id: createByGenre Row { function createStation() { - rootView.startStationFromGenre(genreInputField.text) + mainView.startStationFromGenre(genreInputField.text) } anchors.fill: parent @@ -167,7 +167,7 @@ Item { model: styleModel//generator.styles() onTagClicked: { - rootView.startStationFromGenre(item) + mainView.startStationFromGenre(item) stationCreator.next() } @@ -192,7 +192,7 @@ Item { anchors.centerIn: parent width: parent.width onAccepted: { - rootView.startStationFromGenre(text) + mainView.startStationFromGenre(text) stationCreator.next() } } @@ -224,7 +224,7 @@ Item { spacing: selectYearText.height function decadeClicked(decade) { - rootView.startStationFromYear(decade) + mainView.startStationFromYear(decade) stationCreator.next() } @@ -251,7 +251,7 @@ Item { anchors.centerIn: parent width: parent.width onAccepted: { - rootView.startStationFromYear(text) + mainView.startStationFromYear(text) stationCreator.next() } } diff --git a/data/qml/StationCreatorPage1.qml b/data/qml/StationCreatorPage1.qml index 023034a2f..e7c8540ee 100644 --- a/data/qml/StationCreatorPage1.qml +++ b/data/qml/StationCreatorPage1.qml @@ -10,6 +10,16 @@ Item { signal itemClicked(int index) + Text { + text: "Listen to radio..." + color: "white" + anchors { + left: parent.left + top: parent.top + margins: height * 2 + } + } + GridView { id: gridView anchors.centerIn: parent diff --git a/data/qml/StationView.qml b/data/qml/StationView.qml index 2b4c7b27a..17d925bd2 100644 --- a/data/qml/StationView.qml +++ b/data/qml/StationView.qml @@ -14,7 +14,7 @@ Item { anchors.centerIn: parent height: backButton.height width: height - visible: rootView.loading + visible: mainView.loading RotationAnimation { target: busyIndicator; from: 360; to: 0; duration: 1500; running: visible; loops: Animation.Infinite } } @@ -29,11 +29,11 @@ Item { currentIndex: currentlyPlayedIndex onItemPlayPauseClicked: { - rootView.playItem(index) + mainView.playItem(index) } onItemClicked: { - rootView.playItem(index) + mainView.playItem(index) } } @@ -51,7 +51,7 @@ Item { font.pointSize: 18 width: parent.width elide: Text.ElideRight - text: rootView.title + text: mainView.title } Text { color: "white" diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 4586c9b89..51dfae778 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -149,6 +149,7 @@ set( libGuiSources widgets/SocialPlaylistWidget.cpp widgets/SourceTreePopupDialog.cpp widgets/DeclarativeCoverArtProvider.cpp + widgets/DeclarativeView.cpp widgets/infowidgets/SourceInfoWidget.cpp widgets/infowidgets/ArtistInfoWidget.cpp widgets/infowidgets/AlbumInfoWidget.cpp diff --git a/src/libtomahawk/playlist/QmlGridView.cpp b/src/libtomahawk/playlist/QmlGridView.cpp index 6860224e3..cc2e48669 100644 --- a/src/libtomahawk/playlist/QmlGridView.cpp +++ b/src/libtomahawk/playlist/QmlGridView.cpp @@ -1,3 +1,21 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Michael Zanetti + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + #include "QmlGridView.h" #include "widgets/DeclarativeCoverArtProvider.h" #include "PlayableProxyModelPlaylistInterface.h" @@ -5,7 +23,6 @@ #include "audio/AudioEngine.h" #include -#include using namespace Tomahawk; @@ -39,20 +56,14 @@ private: QWeakPointer m_view; }; -QmlGridView::QmlGridView(QWidget *parent) : QDeclarativeView(parent) +QmlGridView::QmlGridView(QWidget *parent) : DeclarativeView(parent) { m_proxyModel = new PlayableProxyModel( this ); m_playlistInterface = playlistinterface_ptr( new QmlGridPlaylistInterface( m_proxyModel, this ) ); - setResizeMode( QDeclarativeView::SizeRootObjectToView ); - - // QML image providers will be deleted by the view - engine()->addImageProvider( "albumart", new DeclarativeCoverArtProvider( m_proxyModel ) ); - rootContext()->setContextProperty( "mainModel", m_proxyModel ); - rootContext()->setContextProperty( "rootView", this ); - setSource( QUrl( "qrc" RESPATH "qml/GridView.qml" ) ); + setSource( QUrl( "qrc" RESPATH "qml/GridView.qml" ) ); } QmlGridView::~QmlGridView() diff --git a/src/libtomahawk/playlist/QmlGridView.h b/src/libtomahawk/playlist/QmlGridView.h index 0b05cc75a..93bc29ab9 100644 --- a/src/libtomahawk/playlist/QmlGridView.h +++ b/src/libtomahawk/playlist/QmlGridView.h @@ -20,7 +20,7 @@ #ifndef QMLGRIDVIEW_H #define QMLGRIDVIEW_H -#include +#include #include #include @@ -39,7 +39,7 @@ class GridItemDelegate; class PlayableModel; class GridPlaylistInterface; -class DLLEXPORT QmlGridView : public QDeclarativeView, public Tomahawk::ViewPage +class DLLEXPORT QmlGridView : public Tomahawk::DeclarativeView, public Tomahawk::ViewPage { Q_OBJECT public: diff --git a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp index 90ef05123..e8a714aa6 100644 --- a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp +++ b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp @@ -12,48 +12,33 @@ #include "audio/AudioEngine.h" #include +#include #include #include -#include -#include namespace Tomahawk { DynamicQmlWidget::DynamicQmlWidget( const dynplaylist_ptr& playlist, QWidget* parent ) - : QDeclarativeView( parent ) + : DeclarativeView( parent ) , m_playlist( playlist ) , m_runningOnDemand( false ) , m_activePlaylist( false ) { - - - setResizeMode( QDeclarativeView::SizeRootObjectToView ); - m_model = new DynamicModel( this ); m_proxyModel = new PlayableProxyModel( this ); m_proxyModel->setSourcePlayableModel( m_model ); m_proxyModel->setShowOfflineResults( false ); - // QML image providers will be deleted by the view - engine()->addImageProvider( "albumart", new DeclarativeCoverArtProvider( m_proxyModel ) ); - m_model->loadPlaylist( m_playlist ); - qDebug() << "###got" << m_playlist->generator()->controls().size() << "controls"; - - // TODO: In case QML is used in more places, this should probably be moved to some generic place - qmlRegisterType("tomahawk", 1, 0, "PlayableItem"); qmlRegisterUncreatableType("tomahawk", 1, 0, "Generator", "you cannot create it on your own - should be set in context"); - qmlRegisterUncreatableType("tomahawk", 1, 0, "PlayableItem", "you cannot create it on your own - they will appear in the model"); - rootContext()->setContextProperty( "dynamicModel", m_proxyModel ); rootContext()->setContextProperty( "generator", m_playlist->generator().data() ); - rootContext()->setContextProperty( "rootView", this ); setSource( QUrl( "qrc" RESPATH "qml/StationScene.qml" ) ); @@ -67,9 +52,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 ) ) ); - -// m_playlist->generator()->generate( 20 ); - } diff --git a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.h b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.h index e252269f7..313f8f454 100644 --- a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.h +++ b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.h @@ -21,8 +21,8 @@ #include "ViewPage.h" #include "Typedefs.h" +#include "widgets/DeclarativeView.h" -#include #include class PlayableProxyModel; @@ -32,7 +32,7 @@ namespace Tomahawk class DynamicModel; -class DynamicQmlWidget : public QDeclarativeView, public Tomahawk::ViewPage +class DynamicQmlWidget : public DeclarativeView, public Tomahawk::ViewPage { Q_OBJECT diff --git a/src/libtomahawk/widgets/DeclarativeCoverArtProvider.cpp b/src/libtomahawk/widgets/DeclarativeCoverArtProvider.cpp index 1ee55abbb..644b3f3e5 100644 --- a/src/libtomahawk/widgets/DeclarativeCoverArtProvider.cpp +++ b/src/libtomahawk/widgets/DeclarativeCoverArtProvider.cpp @@ -13,9 +13,8 @@ namespace Tomahawk { -DeclarativeCoverArtProvider::DeclarativeCoverArtProvider( PlayableProxyModel *model ) +DeclarativeCoverArtProvider::DeclarativeCoverArtProvider( ) : QDeclarativeImageProvider( QDeclarativeImageProvider::Pixmap ) - , m_model( model ) { } @@ -34,22 +33,9 @@ QPixmap DeclarativeCoverArtProvider::requestPixmap(const QString &id, QSize *siz if( size ) *size = QSize( width, height ); -// PlayableItem *item = m_model->itemFromIndex( id.toInt() ); -// if( item ) { -// qDebug() << "item:" << item; -// qDebug() << "item2:" << item->artistName() << item->name(); -// if ( !item->query().isNull() ) { -// return item->query()->displayQuery()->cover( *size ); -// } -// } - QPixmap cover; tDebug() << "Getting by id:" << id << requestedSize; -/* query_ptr query = Query::getByCoverId( id ); - if ( !query.isNull() ) { - return query->cover( requestedSize ); - }*/ album_ptr album = Album::getByCoverId( id ); if ( !album.isNull() ) diff --git a/src/libtomahawk/widgets/DeclarativeCoverArtProvider.h b/src/libtomahawk/widgets/DeclarativeCoverArtProvider.h index af3e3426f..361407095 100644 --- a/src/libtomahawk/widgets/DeclarativeCoverArtProvider.h +++ b/src/libtomahawk/widgets/DeclarativeCoverArtProvider.h @@ -13,13 +13,10 @@ namespace Tomahawk class DeclarativeCoverArtProvider: public QDeclarativeImageProvider { public: - DeclarativeCoverArtProvider( PlayableProxyModel *model ); + DeclarativeCoverArtProvider(); ~DeclarativeCoverArtProvider(); QPixmap requestPixmap( const QString &id, QSize *size, const QSize &requestedSize ); - -private: - PlayableProxyModel *m_model; }; } diff --git a/src/libtomahawk/widgets/DeclarativeView.cpp b/src/libtomahawk/widgets/DeclarativeView.cpp new file mode 100644 index 000000000..70ecbd4ad --- /dev/null +++ b/src/libtomahawk/widgets/DeclarativeView.cpp @@ -0,0 +1,52 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Michael Zanetti + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "DeclarativeView.h" +#include "playlist/PlayableItem.h" +#include "DeclarativeCoverArtProvider.h" + +#include +#include +#include + +namespace Tomahawk +{ + +DeclarativeView::DeclarativeView( QWidget *parent ): + QDeclarativeView( parent ) +{ + + // Needed to make the QML contents scale with tomahawk + setResizeMode( QDeclarativeView::SizeRootObjectToView ); + + // This types seem to be needed everywhere anyways, lets the register here + qmlRegisterUncreatableType( "tomahawk", 1, 0, "PlayableItem", "bla" ); + + // QML image providers will be deleted by the view + engine()->addImageProvider( "albumart", new DeclarativeCoverArtProvider() ); + + // Register the view itself to make it easy to invoke the view's slots from QML + rootContext()->setContextProperty( "mainView", this ); +} + +DeclarativeView::~DeclarativeView() +{ + +} + +} diff --git a/src/libtomahawk/widgets/DeclarativeView.h b/src/libtomahawk/widgets/DeclarativeView.h new file mode 100644 index 000000000..59ae070b5 --- /dev/null +++ b/src/libtomahawk/widgets/DeclarativeView.h @@ -0,0 +1,59 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Michael Zanetti + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef DECLARATIVEVIEW_H +#define DECLARATIVEVIEW_H + +#include + +class QAbstractItemModel; + +/** + * @class This is the main class for Tomahawk's declarative views + * + * DeclarativeView inherits from QDeclarativeView and registers some + * common types, properties and functions used by all of Tomhawk's + * declarative views: + * + * Registered Types: + * - PlayableItem + * + * Set context properties: + * - mainView: This view, so you can invoke this view's slots from QML + * + * It also registers an albumart image provider. You can access album art + * in QML with the source url "image://albumart/". + * The cover id can be obtained by the CoverIdRole in PlayableModels + * + * After subclassing this, all you have to do is call setSource() to + * load the QML file and optionally setModel(). + */ + +namespace Tomahawk +{ + +class DeclarativeView: public QDeclarativeView +{ + Q_OBJECT +public: + DeclarativeView(QWidget *parent = 0); + ~DeclarativeView(); +}; + +} +#endif