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

started integrating the breadcrumb

This commit is contained in:
Michael Zanetti
2012-12-14 01:37:41 +01:00
parent b8c2d1b0af
commit ac576046c9
3 changed files with 172 additions and 20 deletions

View File

@@ -15,6 +15,27 @@ Rectangle {
ListElement { label: "By Year"; image: "image://albumart/foobar"; creatorContent: "year" }
}
Connections {
target: stationView
onPagePicked: {
switch(createBy) {
case StationWidget.CreateByArtist:
stationCreator.content = "stations/CreateByArtist.qml";
break;
case StationWidget.CreateByGenre:
stationCreator.content = "stations/CreateByGenre.qml";
break;
case StationWidget.CreateByYear:
stationCreator.content = "stations/CreateByYear.qml";
break;
}
print("########", createBy, stationCreator.content)
stationListView.currentIndex = page;
}
}
VisualItemModel {
id: stationVisualModel
@@ -65,34 +86,34 @@ Rectangle {
}
}
RoundedButton {
Image {
id: backButton
text: "<"
height: defaultFontHeight * 4
width: height
hidden: stationListView.currentIndex == 0
opacity: stationListView.currentIndex == 0 ? 0 : 1
source: "../images/back-rest.svg"
smooth: true
anchors {
left: parent.left
bottom: parent.bottom
margins: defaultFontHeight * 2
}
onClicked: stationListView.decrementCurrentIndex()
MouseArea {
anchors.fill: parent
onClicked: stationListView.decrementCurrentIndex()
}
}
RoundedButton {
id: nextButton
text: stationListView.currentIndex == 2 ? "+" : ">"
Image {
height: defaultFontHeight * 4
//hidden: stationListView.currentIndex == 0 || !rootView.configured // This should work once rootView.configured works
hidden: stationListView.currentIndex != 2
opacity: stationListView.currentIndex != 2 ? 0 : 1
source: stationListView.currentIndex == 2 ? "../images/list-add.svg" : "../images/skip-rest.svg"
smooth: true
anchors {
right: parent.right
bottom: parent.bottom
margins: defaultFontHeight * 2
}
onClicked: stationListView.incrementCurrentIndex()
}
}

View File

@@ -14,9 +14,11 @@
#include "widgets/DeclarativeCoverArtProvider.h"
#include "utils/TomahawkUtilsGui.h"
#include "utils/Logger.h"
#include "widgets/Breadcrumb.h"
#include <QUrl>
#include <QSize>
#include <QVBoxLayout>
#include <qdeclarative.h>
#include <QDeclarativeContext>
@@ -24,7 +26,7 @@ namespace Tomahawk
{
DynamicQmlWidget::DynamicQmlWidget( const dynplaylist_ptr& playlist, QWidget* parent )
: DeclarativeView( parent )
: QWidget( parent )
, m_playlist( playlist )
, m_runningOnDemand( false )
, m_activePlaylist( false )
@@ -40,13 +42,30 @@ DynamicQmlWidget::DynamicQmlWidget( const dynplaylist_ptr& playlist, QWidget* pa
m_artistChartsModel = new PlayableModel( this );
QVBoxLayout *vLayout = new QVBoxLayout();
setLayout(vLayout);
TomahawkUtils::unmarginLayout(vLayout);
createStationModel();
m_breadcrumb = new Breadcrumb();
connect(m_breadcrumb, SIGNAL(activateIndex(QModelIndex)), SLOT(breadcrumbChanged(QModelIndex)));
m_breadcrumb->setModel(m_createStationModel);
m_breadcrumb->setRootIcon( TomahawkUtils::defaultPixmap( TomahawkUtils::Charts, TomahawkUtils::Original ) );
vLayout->addWidget(m_breadcrumb);
DeclarativeView *m_declarativeView = new DeclarativeView();
vLayout->addWidget(m_declarativeView);
qRegisterMetaType<CreateBy>("CreateBy");
qmlRegisterUncreatableType<GeneratorInterface>("tomahawk", 1, 0, "Generator", "you cannot create it on your own - should be set in context");
qmlRegisterUncreatableType<DynamicQmlWidget>("tomahawk", 1, 0, "StationWidget", "bla");
rootContext()->setContextProperty( "dynamicModel", m_proxyModel );
rootContext()->setContextProperty( "artistChartsModel", m_artistChartsModel );
rootContext()->setContextProperty( "generator", m_playlist->generator().data() );
m_declarativeView->rootContext()->setContextProperty( "dynamicModel", m_proxyModel );
m_declarativeView->rootContext()->setContextProperty( "artistChartsModel", m_artistChartsModel );
m_declarativeView->rootContext()->setContextProperty( "generator", m_playlist->generator().data() );
m_declarativeView->rootContext()->setContextProperty( "stationView", this );
setSource( QUrl( "qrc" RESPATH "qml/StationScene.qml" ) );
m_declarativeView->setSource( QUrl( "qrc" RESPATH "qml/StationScene.qml" ) );
connect( m_model, SIGNAL( currentItemChanged(QPersistentModelIndex)), SLOT( currentIndexChanged( QPersistentModelIndex ) ) );
connect( m_model, SIGNAL( loadingStarted() ), SIGNAL(loadingChanged() ) );
@@ -147,7 +166,7 @@ void DynamicQmlWidget::startStationFromGenre(const QString &genre)
void DynamicQmlWidget::currentIndexChanged( const QPersistentModelIndex &currentIndex )
{
tDebug() << "current index is" << currentIndex.row();
rootContext()->setContextProperty( "currentlyPlayedIndex", m_proxyModel->mapFromSource( currentIndex ).row() );
m_declarativeView->rootContext()->setContextProperty( "currentlyPlayedIndex", m_proxyModel->mapFromSource( currentIndex ).row() );
}
void
@@ -248,5 +267,94 @@ DynamicQmlWidget::onArtistCharts( const QList< Tomahawk::artist_ptr >& artists )
m_artistChartsModel->clear();
m_artistChartsModel->appendArtists( artists );
QStandardItem *byArtistItem = 0;
for(int i = 0; i < m_createStationModel->rowCount(); ++i) {
QStandardItem *item = m_createStationModel->itemFromIndex(m_createStationModel->index(i, 0));
tDebug() << "##" << item->data(Qt::UserRole);
if(item->data(RoleCreateBy).toInt() == CreateByArtist) {
byArtistItem = item;
break;
}
}
if(!byArtistItem) {
// huh? no "...by artist selection? Cannot continue...
return;
}
QStandardItem *selectArtistItem = new QStandardItem("choose artist...");
selectArtistItem->setData(1, RolePage);
selectArtistItem->setData(CreateByArtist, RoleCreateBy);
byArtistItem->appendRow(selectArtistItem);
foreach(const Tomahawk::artist_ptr &artist, artists) {
QStandardItem *artistItem = new QStandardItem(artist->name());
artistItem->setData(2, RolePage);
artistItem->setData(CreateByNone, RoleCreateBy);
byArtistItem->appendRow(artistItem);
}
m_breadcrumb->setModel(m_createStationModel);
}
void DynamicQmlWidget::createStationModel()
{
m_createStationModel = new QStandardItemModel(this);
// Create Station by...
QStandardItem *selectionItem = new QStandardItem("Start...");
selectionItem->setData(0, RolePage);
selectionItem->setData(CreateByNone, RoleCreateBy);
m_createStationModel->insertRow(0, selectionItem);
QStandardItem *byArtistItem = new QStandardItem("...by Artist");
byArtistItem->setData(1, RolePage);
byArtistItem->setData(CreateByArtist, RoleCreateBy);
m_createStationModel->insertRow(0, byArtistItem);
QStandardItem *byGenreItem = new QStandardItem("...by Genre");
byArtistItem->setData(1, RolePage);
byGenreItem->setData(CreateByGenre, RoleCreateBy);
m_createStationModel->insertRow(0, byGenreItem);
QStandardItem *byYearItem = new QStandardItem("...by Year");
byArtistItem->setData(1, RolePage);
byYearItem->setData(CreateByYear, RoleCreateBy);
m_createStationModel->insertRow(0, byYearItem);
// Fill in genres (static for now)
QStringList genres;
genres << "acoustic" << "alternative" << "alternative rock" << "classic" << "folk" << "indie" << "pop" <<
"rock" << "hip-hop" << "punk" << "grunge" << "indie" << "electronic" << "country" << "jazz" <<
"psychodelic" << "soundtrack" << "reggae" << "house" << "drum and base";
QStandardItem *selectGenreItem = new QStandardItem("choose genre...");
selectGenreItem->setData(1, RolePage);
selectGenreItem->setData(CreateByGenre, RoleCreateBy);
byGenreItem->appendRow(selectGenreItem);
foreach(const QString &genre, genres) {
QStandardItem *genreItem = new QStandardItem(genre);
genreItem->setData(2, RolePage);
genreItem->setData(CreateByNone, RoleCreateBy);
byGenreItem->appendRow(genreItem);
}
// Fill in years (static for now)
QStringList years;
years << "50" << "60" << "70" << "80" << "90";
QStandardItem *selectYearItem = new QStandardItem("choose year...");
selectYearItem->setData(1, RolePage);
selectYearItem->setData(CreateByYear, RoleCreateBy);
byYearItem->appendRow(selectYearItem);
foreach(const QString &year, years) {
QStandardItem *yearItem = new QStandardItem(year);
yearItem->setData(2, RolePage);
yearItem->setData(CreateByNone, RoleCreateBy);
byYearItem->appendRow(yearItem);
}
}
void DynamicQmlWidget::breadcrumbChanged(const QModelIndex &index)
{
tDebug() << "**************************************" << index.data(RolePage).toInt() << index.data(RoleCreateBy);
emit pagePicked(index.data(RolePage).toInt(), index.data(RoleCreateBy).toInt());
}
}

View File

@@ -24,6 +24,7 @@
#include "widgets/DeclarativeView.h"
#include <QDeclarativeImageProvider>
#include <QStandardItemModel>
class PlayableModel;
class PlayableProxyModel;
@@ -31,17 +32,26 @@ class PlayableProxyModel;
namespace Tomahawk
{
class Breadcrumb;
class DynamicModel;
class DynamicQmlWidget : public DeclarativeView, public Tomahawk::ViewPage
class DynamicQmlWidget : public QWidget, public Tomahawk::ViewPage
{
Q_OBJECT
Q_ENUMS(CreateBy)
Q_PROPERTY(QString title READ title)
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
Q_PROPERTY(bool configured READ configured NOTIFY configuredChanged)
public:
enum CreateBy {
CreateByNone,
CreateByArtist,
CreateByGenre,
CreateByYear
};
explicit DynamicQmlWidget( const dynplaylist_ptr& playlist, QWidget* parent = 0 );
virtual ~DynamicQmlWidget();
@@ -66,6 +76,7 @@ public:
signals:
void loadingChanged();
void configuredChanged();
void pagePicked(int page, int createBy);
public slots:
void playItem(int index);
@@ -91,17 +102,29 @@ private slots:
void loadArtistCharts();
void onArtistCharts( const QList< Tomahawk::artist_ptr >& artists );
void createStationModel();
void breadcrumbChanged(const QModelIndex &index);
private:
enum Roles {
RolePage = Qt::UserRole,
RoleCreateBy,
};
DynamicModel* m_model;
PlayableProxyModel* m_proxyModel;
dynplaylist_ptr m_playlist;
PlayableModel* m_artistChartsModel;
QStandardItemModel *m_createStationModel;
Breadcrumb *m_breadcrumb;
DeclarativeView *m_declarativeView;
bool m_runningOnDemand;
bool m_activePlaylist;
};
}
Q_DECLARE_METATYPE(Tomahawk::DynamicQmlWidget::CreateBy);
#endif // DYNAMIC_QML_WIDGET_H