1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-31 01:30:02 +02:00

replaced GridView in WelcomeWidget with QML Gridview

* Items don't hold correct CoverIDRoled yet
* Items don't hold correct IsPlayingRole yet
This commit is contained in:
Michael Zanetti
2012-12-02 12:10:22 +01:00
parent 4fdc6610e5
commit 1938fdc727
9 changed files with 242 additions and 12 deletions

View File

@@ -137,7 +137,7 @@ Item {
id: itemShadow
color: backgroundColor
anchors.fill: parent
anchors.bottomMargin: - parent.height
//anchors.bottomMargin: - parent.height
// scaling might be off a pixel... make sure that the shadow is at least as large as the image
anchors.leftMargin: -2
@@ -158,6 +158,7 @@ Item {
width: parent.width + 4
anchors.centerIn: parent
anchors.verticalCenterOffset: parent.height
visible: showMirror
gradient: Gradient {
// TODO: no clue how to get the RGB component of the container rectangle color

54
data/qml/GridView.qml Normal file
View File

@@ -0,0 +1,54 @@
import QtQuick 1.1
//import tomahawk 1.0
//import "tomahawkimports"
Rectangle {
anchors.fill: parent
color: "black"
Text {
id: fontMetrics
text: "Here's some sample text"
opacity: 0
}
GridView {
id: gridView
anchors.fill: parent
cellHeight: cellWidth
cellWidth: calculateCoverSize(gridView.width - 3)
function calculateCoverSize(rectWidth) {
var itemWidth = fontMetrics.width;
var itemsPerRow = Math.max( 1, Math.floor( rectWidth / itemWidth ) );
var remSpace = rectWidth - ( itemsPerRow * itemWidth );
var extraSpace = remSpace / itemsPerRow;
return itemWidth + extraSpace;
}
model: mainModel
delegate: CoverImage {
height: gridView.cellHeight// * 0.95
width: gridView.cellWidth// * 0.95
showLabels: true
showMirror: false
artistName: model.artistName
trackName: model.trackName
artworkId: model.coverID
showPlayButton: true
currentlyPlaying: isPlaying
onClicked: {
rootView.onItemClicked(index)
}
onPlayClicked: {
rootView.onItemPlayClicked(index)
}
}
}
}

View File

@@ -175,5 +175,6 @@
<file>data/qml/tomahawkimports/RoundedButton.qml</file>
<file>data/qml/StationCreator.qml</file>
<file>data/qml/StationCreatorPage1.qml</file>
<file>data/qml/GridView.qml</file>
</qresource>
</RCC>

View File

@@ -72,6 +72,7 @@ set( libGuiSources
playlist/AlbumModel.cpp
playlist/GridItemDelegate.cpp
playlist/GridView.cpp
playlist/QmlGridView.cpp
playlist/TreeView.cpp
playlist/ViewHeader.cpp
playlist/LovedTracksModel.cpp

View File

@@ -31,7 +31,6 @@
#include "playlist/PlayableProxyModel.h"
#include "playlist/PlayableModel.h"
#include "playlist/TreeView.h"
#include "playlist/GridView.h"
#include "playlist/AlbumModel.h"
#include "SourceList.h"
#include "TomahawkSettings.h"

View File

@@ -0,0 +1,107 @@
#include "QmlGridView.h"
#include "widgets/DeclarativeCoverArtProvider.h"
#include "PlayableProxyModelPlaylistInterface.h"
#include "ViewManager.h"
#include "audio/AudioEngine.h"
#include <QDeclarativeContext>
#include <QDeclarativeEngine>
using namespace Tomahawk;
class QmlGridPlaylistInterface : public PlayableProxyModelPlaylistInterface
{
Q_OBJECT
public:
explicit QmlGridPlaylistInterface( PlayableProxyModel* proxy, QmlGridView* view ) : PlayableProxyModelPlaylistInterface( proxy ), m_view( view ) {}
virtual bool hasChildInterface( playlistinterface_ptr playlistInterface )
{
// if ( m_view.isNull() || !m_view.data()->m_playing.isValid() )
// {
// return false;
// }
// PlayableItem* item = m_view.data()->model()->itemFromIndex( m_view.data()->proxyModel()->mapToSource( m_view.data()->m_playing ) );
// if ( item )
// {
// if ( !item->album().isNull() )
// return item->album()->playlistInterface( Tomahawk::Mixed ) == playlistInterface;
// else if ( !item->artist().isNull() )
// return item->artist()->playlistInterface( Tomahawk::Mixed ) == playlistInterface;
// else if ( !item->query().isNull() && !playlistInterface.dynamicCast< SingleTrackPlaylistInterface >().isNull() )
// return item->query() == playlistInterface.dynamicCast< SingleTrackPlaylistInterface >()->track();
// }
return false;
}
private:
QWeakPointer<QmlGridView> m_view;
};
QmlGridView::QmlGridView(QWidget *parent) : QDeclarativeView(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" ) );
}
QmlGridView::~QmlGridView()
{
}
void QmlGridView::setPlayableModel(PlayableModel *model)
{
// m_inited = false;
m_model = model;
if ( m_proxyModel )
{
m_proxyModel->setSourcePlayableModel( m_model );
m_proxyModel->sort( 0 );
}
emit modelChanged();
}
void
QmlGridView::onItemClicked( int index )
{
PlayableItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( m_proxyModel->index( index, 0) ) );
if ( item )
{
if ( !item->album().isNull() )
ViewManager::instance()->show( item->album() );
else if ( !item->artist().isNull() )
ViewManager::instance()->show( item->artist() );
else if ( !item->query().isNull() )
ViewManager::instance()->show( item->query() );
}
}
void QmlGridView::onItemPlayClicked(int index)
{
PlayableItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( m_proxyModel->index( index, 0) ) );
if ( item )
{
if ( !item->query().isNull() )
AudioEngine::instance()->playItem( Tomahawk::playlistinterface_ptr(), item->query() );
else if ( !item->album().isNull() )
AudioEngine::instance()->playItem( item->album() );
else if ( !item->artist().isNull() )
AudioEngine::instance()->playItem( item->artist() );
}
}
#include "QmlGridView.moc"

View File

@@ -0,0 +1,73 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.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 QMLGRIDVIEW_H
#define QMLGRIDVIEW_H
#include <QDeclarativeView>
#include <QSortFilterProxyModel>
#include <QTimer>
#include "ViewPage.h"
#include "PlayableProxyModel.h"
#include "widgets/OverlayWidget.h"
#include "DllMacro.h"
namespace Tomahawk
{
class ContextMenu;
};
class AnimatedSpinner;
class GridItemDelegate;
class PlayableModel;
class GridPlaylistInterface;
class DLLEXPORT QmlGridView : public QDeclarativeView, public Tomahawk::ViewPage
{
Q_OBJECT
public:
QmlGridView( QWidget *parent = 0);
~QmlGridView();
void setPlayableModel( PlayableModel* model );
// void setModel( QAbstractItemModel* model );
PlayableProxyModel* proxyModel() const { return m_proxyModel; }
QWidget *widget() { return this; }
virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return m_playlistInterface; }
virtual QString title() const { return m_model->title(); }
virtual QString description() const { return m_model->description(); }
virtual bool jumpToCurrentTrack() { return false; }
Q_INVOKABLE void onItemClicked( int index );
Q_INVOKABLE void onItemPlayClicked( int index );
private:
PlayableModel* m_model;
PlayableProxyModel* m_proxyModel;
Tomahawk::playlistinterface_ptr m_playlistInterface;
signals:
void modelChanged();
};
#endif

View File

@@ -26,6 +26,7 @@ DeclarativeCoverArtProvider::~DeclarativeCoverArtProvider()
QPixmap DeclarativeCoverArtProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
tDebug() << "requresting albumart" << 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;

View File

@@ -36,14 +36,7 @@
</widget>
</item>
<item>
<widget class="GridView" name="additionsView">
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
</widget>
<widget class="QmlGridView" name="additionsView"/>
</item>
</layout>
</widget>
@@ -87,9 +80,9 @@
<header location="global">widgets/HeaderLabel.h</header>
</customwidget>
<customwidget>
<class>GridView</class>
<class>QmlGridView</class>
<extends>QListView</extends>
<header>playlist/GridView.h</header>
<header>playlist/QmlGridView.h</header>
</customwidget>
<customwidget>
<class>PlaylistView</class>