1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-09-02 02:12:47 +02:00

added a common DeclarativeView class that sets commonly used stuff

This commit is contained in:
Michael Zanetti
2012-12-02 17:15:30 +01:00
parent 1938fdc727
commit feede63a13
12 changed files with 162 additions and 64 deletions

View File

@@ -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()
}
}

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -1,3 +1,21 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Michael Zanetti <mzanetti@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "QmlGridView.h"
#include "widgets/DeclarativeCoverArtProvider.h"
#include "PlayableProxyModelPlaylistInterface.h"
@@ -5,7 +23,6 @@
#include "audio/AudioEngine.h"
#include <QDeclarativeContext>
#include <QDeclarativeEngine>
using namespace Tomahawk;
@@ -39,20 +56,14 @@ private:
QWeakPointer<QmlGridView> 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()

View File

@@ -20,7 +20,7 @@
#ifndef QMLGRIDVIEW_H
#define QMLGRIDVIEW_H
#include <QDeclarativeView>
#include <widgets/DeclarativeView.h>
#include <QSortFilterProxyModel>
#include <QTimer>
@@ -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:

View File

@@ -12,48 +12,33 @@
#include "audio/AudioEngine.h"
#include <QUrl>
#include <QSize>
#include <qdeclarative.h>
#include <QDeclarativeContext>
#include <QDeclarativeEngine>
#include <QSize>
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<PlayableItem>("tomahawk", 1, 0, "PlayableItem");
qmlRegisterUncreatableType<GeneratorInterface>("tomahawk", 1, 0, "Generator", "you cannot create it on your own - should be set in context");
qmlRegisterUncreatableType<PlayableItem>("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 );
}

View File

@@ -21,8 +21,8 @@
#include "ViewPage.h"
#include "Typedefs.h"
#include "widgets/DeclarativeView.h"
#include <QDeclarativeView>
#include <QDeclarativeImageProvider>
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

View File

@@ -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() )

View File

@@ -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;
};
}

View File

@@ -0,0 +1,52 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Michael Zanetti <mzanetti@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "DeclarativeView.h"
#include "playlist/PlayableItem.h"
#include "DeclarativeCoverArtProvider.h"
#include <qdeclarative.h>
#include <QDeclarativeEngine>
#include <QDeclarativeContext>
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<PlayableItem>( "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()
{
}
}

View File

@@ -0,0 +1,59 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Michael Zanetti <mzanetti@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef DECLARATIVEVIEW_H
#define DECLARATIVEVIEW_H
#include <QDeclarativeView>
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/<coverid>".
* 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