From f49f5f55fd6f2dbaea8fbd9df535dc0400fa8ae5 Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Fri, 11 Apr 2014 08:12:23 +0000 Subject: [PATCH] Implement main/sub-text - using Subtitled delegate for the moment --- models/actionmodel.cpp | 12 +++++++ models/actionmodel.h | 4 +++ models/albumsmodel.cpp | 12 +------ models/albumsmodel.h | 1 - models/playqueuemodel.cpp | 36 +++++++++++---------- models/playqueuemodel.h | 9 ++---- ubuntu/qml/cantata/AlbumPage.qml | 23 ++++++++++--- ubuntu/qml/cantata/CurrentlyPlayingPage.qml | 5 +-- 8 files changed, 59 insertions(+), 43 deletions(-) diff --git a/models/actionmodel.cpp b/models/actionmodel.cpp index b04772210..c877f8397 100644 --- a/models/actionmodel.cpp +++ b/models/actionmodel.cpp @@ -29,9 +29,21 @@ QVariant ActionModel::data(const QModelIndex &index, int role) const { QVariant v; Q_UNUSED(index) + #ifndef ENABLE_UBUNTU // Should touch version return a list of action names? if (ItemView::Role_Actions==role) { v.setValue >(QList() << StdActions::self()->replacePlayQueueAction << StdActions::self()->addToPlayQueueAction); } + #endif return v; } +#ifdef ENABLE_UBUNTU +//Expose role names, so that they can be accessed via QML +QHash ActionModel::roleNames() const +{ + QHash roles; + roles[ItemView::Role_MainText] = "mainText"; + roles[ItemView::Role_SubText] = "subText"; + return roles; +} +#endif diff --git a/models/actionmodel.h b/models/actionmodel.h index 91a26f88f..546a32be6 100644 --- a/models/actionmodel.h +++ b/models/actionmodel.h @@ -27,6 +27,7 @@ #include #include #include "action.h" +#include "config.h" class ActionModel : public QAbstractItemModel { @@ -38,6 +39,9 @@ public: virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; virtual void resetModel() { beginResetModel(); endResetModel(); } + #ifdef ENABLE_UBUNTU + QHash roleNames() const; + #endif }; Q_DECLARE_METATYPE(QList) diff --git a/models/albumsmodel.cpp b/models/albumsmodel.cpp index b2d3b93fb..b00e82e2c 100644 --- a/models/albumsmodel.cpp +++ b/models/albumsmodel.cpp @@ -176,14 +176,6 @@ QModelIndex AlbumsModel::index(int row, int col, const QModelIndex &parent) cons return row AlbumsModel::roleNames() const { - QHash roles; - roles[Qt::DisplayRole] = "album"; - roles[ItemView::Role_SubText] = "artist"; - return roles; -} - QVariant AlbumsModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { @@ -236,9 +228,7 @@ QVariant AlbumsModel::data(const QModelIndex &index, int role) const } break; case ItemView::Role_MainText: - if (Sort_ArtistYearAlbum==sortAlbums) { - return al->albumDisplay(); - } + return al->albumDisplay(); case ItemView::Role_BriefMainText: return al->album; case ItemView::Role_ImageSize: diff --git a/models/albumsmodel.h b/models/albumsmodel.h index 3aeb5349e..773ff60dc 100644 --- a/models/albumsmodel.h +++ b/models/albumsmodel.h @@ -112,7 +112,6 @@ public: int columnCount(const QModelIndex&) const { return 1; } QModelIndex parent(const QModelIndex &index) const; QModelIndex index(int row, int column, const QModelIndex &parent) const; - QHash roleNames() const; QVariant data(const QModelIndex &, int) const; Qt::ItemFlags flags(const QModelIndex &index) const; QStringList filenames(const QModelIndexList &indexes, bool allowPlaylists=false) const; diff --git a/models/playqueuemodel.cpp b/models/playqueuemodel.cpp index e24ddb3ad..e604be1a8 100644 --- a/models/playqueuemodel.cpp +++ b/models/playqueuemodel.cpp @@ -42,6 +42,9 @@ #include "config.h" #include "action.h" #include "actioncollection.h" +#ifdef ENABLE_UBUNTU +#include "itemview.h" +#endif #ifdef ENABLE_DEVICES_SUPPORT #include "devicesmodel.h" #if defined CDDB_FOUND || defined MUSICBRAINZ5_FOUND @@ -300,14 +303,16 @@ static QString basicPath(const Song &song) return -1==marker ? path : path.left(marker); } +#ifdef ENABLE_UBUNTU //Expose role names, so that they can be accessed via QML -QHash PlayQueueModel::roleNames() const { +QHash PlayQueueModel::roleNames() const +{ QHash roles; - roles[QmlRole_Track] = "track"; - roles[QmlRole_Title] = "title"; - roles[QmlRole_Artist] = "artist"; + roles[ItemView::Role_MainText] = "mainText"; + roles[ItemView::Role_SubText] = "subText"; return roles; } +#endif QVariant PlayQueueModel::data(const QModelIndex &index, int role) const { @@ -325,6 +330,16 @@ QVariant PlayQueueModel::data(const QModelIndex &index, int role) const // } switch (role) { + #ifdef ENABLE_UBUNTU + case ItemView::Role_MainText: { + Song s=songs.at(index.row()); + return s.title; + } + case ItemView::Role_SubText: { + Song s=songs.at(index.row()); + return s.artist+QLatin1String(" - ")+s.displayAlbum(); + } + #endif case GroupedView::Role_IsCollection: return false; case GroupedView::Role_CollectionId: @@ -517,19 +532,6 @@ QVariant PlayQueueModel::data(const QModelIndex &index, int role) const } break; } - //Seperate roles for QML, as there is no support for different columns - case QmlRole_Track: { - Song s=songs.at(index.row()); - return s.track; - } - case QmlRole_Title: { - Song s=songs.at(index.row()); - return s.title; - } - case QmlRole_Artist: { - Song s=songs.at(index.row()); - return s.artist; - } default: break; } diff --git a/models/playqueuemodel.h b/models/playqueuemodel.h index 8984c9606..1623eb295 100644 --- a/models/playqueuemodel.h +++ b/models/playqueuemodel.h @@ -61,13 +61,6 @@ public: COL_COUNT }; - //Seperate roles for QML, as there is no support for different columns - enum QmlRoles { - QmlRole_Track = Qt::UserRole+450, - QmlRole_Title, - QmlRole_Artist - }; - struct UndoItem { bool operator==(const UndoItem &o) const { return priority==o.priority && files==o.files; } @@ -91,7 +84,9 @@ public: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &) const { return COL_COUNT; } + #ifdef ENABLE_UBUNTU QHash roleNames() const; + #endif QVariant data(const QModelIndex &, int) const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); void updateCurrentSong(quint32 id); diff --git a/ubuntu/qml/cantata/AlbumPage.qml b/ubuntu/qml/cantata/AlbumPage.qml index f451272ca..497cdfda8 100644 --- a/ubuntu/qml/cantata/AlbumPage.qml +++ b/ubuntu/qml/cantata/AlbumPage.qml @@ -91,12 +91,13 @@ Page { model: albumsProxyModel clip: true - delegate: ListItem.Standard { - text: model.album + " (" + model.artist + ")" + delegate: ListItem.Subtitled { + text: model.mainText + subText: model.subText // progression: true //Removed due to the app showdown, will be implemented later - control: Row { - spacing: units.gu(1) + //control: Row { + // spacing: units.gu(1) Image { width: units.gu(3) @@ -105,6 +106,12 @@ Page { source: "../../icons/toolbar/add.svg" opacity: 0.9 + anchors { + right: parent.right + rightMargin: units.gu(0) + verticalCenter: parent.verticalCenter + } + MouseArea { onClicked: { backend.addAlbum(index, false) @@ -121,6 +128,12 @@ Page { source: "../../icons/toolbar/media-playback-start-light.svg" opacity: 0.9 + anchors { + right: parent.right + rightMargin: units.gu(4) + verticalCenter: parent.verticalCenter + } + MouseArea { onClicked: { backend.addAlbum(index, true) @@ -130,7 +143,7 @@ Page { preventStealing: true } } - } + //} } } diff --git a/ubuntu/qml/cantata/CurrentlyPlayingPage.qml b/ubuntu/qml/cantata/CurrentlyPlayingPage.qml index f16fdf997..38bcd756e 100644 --- a/ubuntu/qml/cantata/CurrentlyPlayingPage.qml +++ b/ubuntu/qml/cantata/CurrentlyPlayingPage.qml @@ -211,8 +211,9 @@ Page { bottomMargin: isPhone?0:(-units.gu(2)) } - delegate: ListItem.Standard { - text: (track < 10 ? '0' : '') + track + " " + title + " (" + artist + ")" + delegate: ListItem.Subtitled { + text: model.mainText + subText: model.subText confirmRemoval: true removable: true onItemRemoved: {