Commit 3f7cea5f authored by Matthieu Gallien's avatar Matthieu Gallien 🎵

implement navigation of tree models

parent 7e7538bd
......@@ -64,6 +64,7 @@ RowLayout {
genreFilterText: genreNameFilter,
artistFilter: artistNameFilter,
isSubPage: (browseStackView.depth >= 2),
haveTreeModel: isTreeModel,
stackView: browseStackView,
opacity: 0,
})
......@@ -94,7 +95,8 @@ RowLayout {
displaySingleAlbum: displaySingleAlbum,
showSection: showDiscHeaders,
opacity: 0,
radioCase: radioCase
radioCase: radioCase,
haveTreeModel: isTreeModel,
})
}
......@@ -127,8 +129,13 @@ RowLayout {
}
onPopOneView: {
if (browseStackView.currentItem.haveTreeModel) {
browseStackView.currentItem.goToBack()
}
if (browseStackView.depth > 2) {
browseStackView.pop() }
browseStackView.pop()
}
}
}
......
......@@ -24,6 +24,7 @@ FocusScope {
property alias delegateDisplaySecondaryText: gridView.delegateDisplaySecondaryText
property alias isSubPage: gridView.isSubPage
property alias expandedFilterView: gridView.expandedFilterView
property alias haveTreeModel: gridView.haveTreeModel
property string genreFilterText
property string artistFilter
property bool modelIsInitialized: false
......@@ -62,6 +63,10 @@ FocusScope {
modelIsInitialized = true
}
function goToBack() {
gridView.goToBack()
}
GridBrowserView {
id: gridView
......@@ -79,7 +84,9 @@ FocusScope {
onOpen: viewManager.openChildView(innerMainTitle, innerSecondaryTitle, innerImage, databaseId, dataType)
onGoBack: viewManager.goBack()
onGoBackRequested: {
viewManager.goBack()
}
Loader {
id: busyIndicatorLoader
......
......@@ -19,6 +19,7 @@ FocusScope {
property int databaseId
property alias showSection: listView.showSection
property alias expandedFilterView: listView.expandedFilterView
property alias haveTreeModel: listView.haveTreeModel
property alias image: listView.image
property var modelType
property AbstractItemModel realModel
......@@ -90,6 +91,10 @@ FocusScope {
modelType, filterType, mainTitle, secondaryTitle, databaseId)
}
function goToBack() {
listView.goToBack()
}
Loader {
id: metadataLoader
active: false
......@@ -210,7 +215,7 @@ FocusScope {
viewManager.openChildView(secondaryTitle, '', elisaTheme.artistIcon, 0, ElisaUtils.Artist)
}
onGoBack: viewManager.goBack()
onGoBackRequested: viewManager.goBack()
Loader {
anchors.centerIn: parent
......
......@@ -20,17 +20,28 @@ FocusScope {
property string mainTitle
property string secondaryTitle
property url image
property alias contentModel: contentDirectoryView.model
property alias contentModel: delegateModel.model
property alias showRating: navigationBar.showRating
property bool delegateDisplaySecondaryText: true
property alias expandedFilterView: navigationBar.expandedFilterView
property bool haveTreeModel: false
property var stackView
property url defaultIcon
property int depth: 1
signal enqueue(var fullData, string name)
signal replaceAndPlay(var fullData, string name)
signal open(string innerMainTitle, string innerSecondaryTitle, url innerImage, int databaseId, var dataType)
signal goBack()
signal goBackRequested()
function goToBack() {
if (haveTreeModel) {
delegateModel.rootIndex = delegateModel.parentModelIndex()
--depth
} else {
gridView.goBackRequested()
}
}
ColumnLayout {
anchors.fill: parent
......@@ -42,7 +53,7 @@ FocusScope {
mainTitle: gridView.mainTitle
secondaryTitle: gridView.secondaryTitle
image: gridView.image
enableGoBack: isSubPage
enableGoBack: gridView.isSubPage || depth > 1
sortOrder: if (contentModel) {contentModel.sortedAscending} else true
Layout.fillWidth: true
......@@ -72,11 +83,60 @@ FocusScope {
onReplaceAndPlay:contentModel.replaceAndPlayOfPlayList()
onGoBack: gridView.goBack()
onGoBack: {
gridView.goToBack()
}
onSort: contentModel.sortModel(order)
}
DelegateModel {
id: delegateModel
delegate: GridBrowserDelegate {
width: elisaTheme.gridDelegateSize
height: contentDirectoryView.cellHeight
focus: true
isSelected: contentDirectoryView.currentIndex === index
isPartial: false
mainText: model.display
fileUrl: if (model.url) { model.url } else { '' }
secondaryText: if (gridView.delegateDisplaySecondaryText) {model.secondaryText} else {""}
imageUrl: model.imageUrl ? model.imageUrl : ''
imageFallbackUrl: defaultIcon
databaseId: model.databaseId
delegateDisplaySecondaryText: gridView.delegateDisplaySecondaryText
entryType: model.dataType
onEnqueue: gridView.enqueue(model.fullData, model.display)
onReplaceAndPlay: gridView.replaceAndPlay(model.fullData, model.display)
onOpen: {
if (haveTreeModel) {
delegateModel.rootIndex = delegateModel.modelIndex(model.index)
++depth
} else {
gridView.open(model.display, model.secondaryText,
(model && model.imageUrl && model.imageUrl.toString() !== "" ? model.imageUrl : defaultIcon),
model.databaseId, model.dataType)
}
}
onSelected: {
forceActiveFocus()
contentDirectoryView.currentIndex = model.index
}
onActiveFocusChanged: {
if (activeFocus && contentDirectoryView.currentIndex !== model.index) {
contentDirectoryView.currentIndex = model.index
}
}
}
}
FocusScope {
Layout.fillHeight: true
......@@ -91,6 +151,8 @@ FocusScope {
activeFocusOnTab: true
keyNavigationEnabled: true
model: delegateModel
anchors.fill: parent
anchors.leftMargin: (LayoutMirroring.enabled && scrollBar.visible) ? 0 : Kirigami.Units.largeSpacing
anchors.rightMargin: (!LayoutMirroring.enabled && scrollBar.visible) ? 0 : Kirigami.Units.largeSpacing
......@@ -115,42 +177,6 @@ FocusScope {
cellWidth: Math.floor(availableWidth / Math.max(Math.floor(availableWidth / elisaTheme.gridDelegateSize), 2))
cellHeight: elisaTheme.gridDelegateSize + Kirigami.Units.gridUnit * 2 + Kirigami.Units.largeSpacing
delegate: GridBrowserDelegate {
width: elisaTheme.gridDelegateSize
height: contentDirectoryView.cellHeight
focus: true
isSelected: contentDirectoryView.currentIndex === index
isPartial: false
mainText: model.display
fileUrl: if (model.url) { model.url } else { '' }
secondaryText: if (gridView.delegateDisplaySecondaryText) {model.secondaryText} else {""}
imageUrl: model.imageUrl ? model.imageUrl : ''
imageFallbackUrl: defaultIcon
databaseId: model.databaseId
delegateDisplaySecondaryText: gridView.delegateDisplaySecondaryText
entryType: model.dataType
onEnqueue: gridView.enqueue(model.fullData, model.display)
onReplaceAndPlay: gridView.replaceAndPlay(model.fullData, model.display)
onOpen: gridView.open(model.display, model.secondaryText,
(model && model.imageUrl && model.imageUrl.toString() !== "" ? model.imageUrl : defaultIcon),
model.databaseId, model.dataType)
onSelected: {
forceActiveFocus()
contentDirectoryView.currentIndex = model.index
}
onActiveFocusChanged: {
if (activeFocus && contentDirectoryView.currentIndex !== model.index) {
contentDirectoryView.currentIndex = model.index
}
}
}
}
}
}
......
......@@ -21,10 +21,11 @@ FocusScope {
property alias secondaryTitle: navigationBar.secondaryTitle
property alias image: navigationBar.image
property int databaseId
property alias delegate: contentDirectoryView.delegate
property alias delegate: delegateModel.delegate
property bool showSection: false
property alias contentModel: contentDirectoryView.model
property alias contentModel: delegateModel.model
property alias expandedFilterView: navigationBar.expandedFilterView
property bool haveTreeModel: false
property alias showRating: navigationBar.showRating
property alias allowArtistNavigation: navigationBar.allowArtistNavigation
property var delegateWidth: scrollBar.visible ? contentDirectoryView.width - scrollBar.width : contentDirectoryView.width
......@@ -34,10 +35,20 @@ FocusScope {
property alias showEnqueueButton: navigationBar.showEnqueueButton
property alias showCreateRadioButton: navigationBar.showCreateRadioButton
property alias navigationBar: navigationBar
property int depth: 1
signal goBack()
signal goBackRequested()
signal showArtist(var name)
function goToBack() {
if (haveTreeModel) {
delegateModel.rootIndex = delegateModel.parentModelIndex()
--depth
} else {
listView.goBackRequested()
}
}
SystemPalette {
id: myPalette
colorGroup: SystemPalette.Active
......@@ -47,6 +58,10 @@ FocusScope {
id: elisaTheme
}
DelegateModel {
id: delegateModel
}
ColumnLayout {
anchors.fill: parent
spacing: 0
......@@ -54,7 +69,7 @@ FocusScope {
NavigationActionBar {
id: navigationBar
enableGoBack: listView.isSubPage
enableGoBack: listView.isSubPage || depth > 1
sortOrder: contentModel.sortedAscending
Layout.fillWidth: true
......@@ -75,7 +90,9 @@ FocusScope {
onReplaceAndPlay: contentModel.replaceAndPlayOfPlayList()
onGoBack: listView.goBack()
onGoBack: {
listView.goToBack()
}
onShowArtist: listView.showArtist(listView.contentModel.sourceModel.author)
......@@ -100,6 +117,8 @@ FocusScope {
activeFocusOnTab: true
keyNavigationEnabled: true
model: delegateModel
currentIndex: -1
section.property: (showSection ? 'discNumber' : '')
......
......@@ -32,7 +32,8 @@ public:
Qt::AscendingOrder,
ViewManager::SingleAlbum,
ViewManager::DiscHeaders,
ViewManager::IsTrack}},
ViewManager::IsTrack,
ViewManager::IsFlatModel}},
{ElisaUtils::Genre, {{},
QUrl{QStringLiteral("image://icon/view-media-artist")},
ViewManager::GridView,
......@@ -41,7 +42,8 @@ public:
ElisaUtils::Artist,
QUrl{QStringLiteral("image://icon/view-media-artist")},
ViewManager::DelegateWithoutSecondaryText,
ViewManager::ViewHideRating}},
ViewManager::ViewHideRating,
ViewManager::IsFlatModel}},
{ElisaUtils::Artist, {{},
QUrl{QStringLiteral("image://icon/view-media-album-cover")},
ViewManager::GridView,
......@@ -50,7 +52,8 @@ public:
ElisaUtils::Album,
QUrl{QStringLiteral("image://icon/media-optical-audio")},
ViewManager::DelegateWithSecondaryText,
ViewManager::ViewShowRating}},
ViewManager::ViewShowRating,
ViewManager::IsFlatModel}},
};
int mViewIndex = 0;
......@@ -219,12 +222,14 @@ void ViewManager::openViewFromData(const ViewParameters &viewParamaters)
<< viewParamaters.mMainImage << viewParamaters.mDataType
<< viewParamaters.mModelType << viewParamaters.mFallbackItemIcon
<< viewParamaters.mGenreNameFilter << viewParamaters.mArtistNameFilter
<< viewParamaters.mViewCanBeRated << viewParamaters.mShowSecondaryTextOnDelegates;
<< viewParamaters.mViewCanBeRated << viewParamaters.mShowSecondaryTextOnDelegates
<< viewParamaters.mIsTreeModel;
Q_EMIT openGridView(viewParamaters.mFilterType, viewParamaters.mDepth,
viewParamaters.mMainTitle, viewParamaters.mSecondaryTitle, viewParamaters.mMainImage,
viewParamaters.mDataType, newModel, proxyModel, viewParamaters.mFallbackItemIcon,
viewParamaters.mGenreNameFilter, viewParamaters.mArtistNameFilter,
viewParamaters.mViewCanBeRated, viewParamaters.mShowSecondaryTextOnDelegates);
viewParamaters.mViewCanBeRated, viewParamaters.mShowSecondaryTextOnDelegates,
viewParamaters.mIsTreeModel);
break;
case ViewPresentationType::ListView:
qCDebug(orgKdeElisaViews()) << "ViewManager::openViewFromData" << viewParamaters.mFilterType
......@@ -232,11 +237,13 @@ void ViewManager::openViewFromData(const ViewParameters &viewParamaters)
<< viewParamaters.mDatabaseIdFilter << viewParamaters.mMainImage
<< viewParamaters.mModelType << viewParamaters.mDataType
<< viewParamaters.mSortRole << viewParamaters.mSortOrder << viewParamaters.mAlbumCardinality
<< viewParamaters.mAlbumViewStyle << viewParamaters.mRadioSpecificStyle;
<< viewParamaters.mAlbumViewStyle << viewParamaters.mRadioSpecificStyle
<< viewParamaters.mIsTreeModel;
Q_EMIT openListView(viewParamaters.mFilterType, viewParamaters.mDepth, viewParamaters.mMainTitle, viewParamaters.mSecondaryTitle,
viewParamaters.mDatabaseIdFilter, viewParamaters.mMainImage, viewParamaters.mDataType,
newModel, proxyModel, viewParamaters.mSortRole, viewParamaters.mSortOrder,
viewParamaters.mAlbumCardinality, viewParamaters.mAlbumViewStyle, viewParamaters.mRadioSpecificStyle);
viewParamaters.mAlbumCardinality, viewParamaters.mAlbumViewStyle, viewParamaters.mRadioSpecificStyle,
viewParamaters.mIsTreeModel);
break;
case ViewPresentationType::FileBrowserView:
qCDebug(orgKdeElisaViews()) << "ViewManager::openViewFromData" << viewParamaters.mViewPresentationType
......@@ -258,13 +265,13 @@ void ViewManager::openViewFromData(const ViewParameters &viewParamaters)
void ViewManager::goBack()
{
qCDebug(orgKdeElisaViews()) << "ViewManager::goBack" << d->mViewParametersStack.size();
if (d->mViewParametersStack.size() <= 1) {
return;
}
Q_EMIT popOneView();
d->mViewParametersStack.pop_back();
d->mNextViewParameters = {};
if (d->mViewParametersStack.size() > 2) {
d->mViewParametersStack.pop_back();
d->mNextViewParameters = {};
}
}
void ViewManager::setViewsData(ViewsListData *viewsData)
......
......@@ -88,6 +88,13 @@ public:
Q_ENUM(ModelType)
enum IsTreeModelType {
IsTreeModel = true,
IsFlatModel = false,
};
Q_ENUM(IsTreeModelType)
explicit ViewManager(QObject *parent = nullptr);
~ViewManager() override;
......@@ -103,14 +110,16 @@ Q_SIGNALS:
ElisaUtils::PlayListEntryType dataType, QAbstractItemModel *model,
QAbstractProxyModel *associatedProxyModel, const QUrl &viewDefaultIcon, const QString &genreNameFilter,
const QString &artistNameFilter, ViewManager::ViewCanBeRated viewShowRating,
ViewManager::DelegateUseSecondaryText viewDelegateDisplaySecondaryText);
ViewManager::DelegateUseSecondaryText viewDelegateDisplaySecondaryText,
ViewManager::IsTreeModelType isTreeModel);
void openListView(ElisaUtils::FilterType filterType, int expectedDepth,
const QString &mainTitle, const QString &secondaryTitle, qulonglong databaseId,
const QUrl &imageUrl, ElisaUtils::PlayListEntryType dataType, QAbstractItemModel *model,
QAbstractProxyModel *associatedProxyModel, const QVariant &sortRole,
Qt::SortOrder sortOrder, ViewManager::AlbumCardinality displaySingleAlbum,
ViewManager::AlbumViewStyle showDiscHeaders, ViewManager::RadioSpecificStyle radioCase);
ViewManager::AlbumViewStyle showDiscHeaders, ViewManager::RadioSpecificStyle radioCase,
ViewManager::IsTreeModelType isTreeModel);
void switchFilesBrowserView(int expectedDepth, const QString &mainTitle, const QUrl &imageUrl);
......
......@@ -26,7 +26,8 @@ public:
Qt::DescendingOrder,
ViewManager::MultipleAlbum,
ViewManager::NoDiscHeaders,
ViewManager::IsTrack},
ViewManager::IsTrack,
ViewManager::IsFlatModel},
{{i18nc("Title of the view of frequently played tracks", "Frequently Played")},
QUrl{QStringLiteral("image://icon/view-media-playcount")},
ViewManager::ListView,
......@@ -37,7 +38,8 @@ public:
Qt::DescendingOrder,
ViewManager::MultipleAlbum,
ViewManager::NoDiscHeaders,
ViewManager::IsTrack},
ViewManager::IsTrack,
ViewManager::IsFlatModel},
{{i18nc("Title of the view of all albums", "Albums")},
QUrl{QStringLiteral("image://icon/view-media-album-cover")},
ViewManager::GridView,
......@@ -46,7 +48,8 @@ public:
ElisaUtils::Album,
QUrl{QStringLiteral("image://icon/media-optical-audio")},
ViewManager::DelegateWithSecondaryText,
ViewManager::ViewShowRating},
ViewManager::ViewShowRating,
ViewManager::IsFlatModel},
{{i18nc("Title of the view of all artists", "Artists")},
QUrl{QStringLiteral("image://icon/view-media-artist")},
ViewManager::GridView,
......@@ -55,7 +58,8 @@ public:
ElisaUtils::Artist,
QUrl{QStringLiteral("image://icon/view-media-artist")},
ViewManager::DelegateWithoutSecondaryText,
ViewManager::ViewHideRating},
ViewManager::ViewHideRating,
ViewManager::IsFlatModel},
{{i18nc("Title of the view of all tracks", "Tracks")},
QUrl{QStringLiteral("image://icon/view-media-track")},
ViewManager::ListView,
......@@ -66,7 +70,8 @@ public:
Qt::AscendingOrder,
ViewManager::MultipleAlbum,
ViewManager::NoDiscHeaders,
ViewManager::IsTrack},
ViewManager::IsTrack,
ViewManager::IsFlatModel},
{{i18nc("Title of the view of all genres", "Genres")},
QUrl{QStringLiteral("image://icon/view-media-genre")},
ViewManager::GridView,
......@@ -75,7 +80,8 @@ public:
ElisaUtils::Genre,
QUrl{QStringLiteral("image://icon/view-media-genre")},
ViewManager::DelegateWithoutSecondaryText,
ViewManager::ViewHideRating},
ViewManager::ViewHideRating,
ViewManager::IsFlatModel},
{{i18nc("Title of the file browser view", "Files")},
QUrl{QStringLiteral("image://icon/document-open-folder")},
ViewManager::GridView,
......@@ -84,7 +90,8 @@ public:
ElisaUtils::FileName,
QUrl{QStringLiteral("image://icon/view-media-genre")},
ViewManager::DelegateWithoutSecondaryText,
ViewManager::ViewHideRating
ViewManager::ViewHideRating,
ViewManager::IsTreeModel
},
{{i18nc("Title of the file radios browser view", "Radios")},
QUrl{QStringLiteral("image://icon/radio")},
......@@ -96,7 +103,8 @@ public:
Qt::AscendingOrder,
ViewManager::MultipleAlbum,
ViewManager::NoDiscHeaders,
ViewManager::IsRadio}};
ViewManager::IsRadio,
ViewManager::IsFlatModel}};
};
......
......@@ -56,7 +56,8 @@ public:
ElisaUtils::PlayListEntryType dataType,
QUrl fallbackItemIcon,
ViewManager::DelegateUseSecondaryText showSecondaryTextOnDelegates,
ViewManager::ViewCanBeRated viewCanBeRated)
ViewManager::ViewCanBeRated viewCanBeRated,
ViewManager::IsTreeModelType isTreeModel)
: mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
......@@ -66,6 +67,7 @@ public:
, mFallbackItemIcon(std::move(fallbackItemIcon))
, mShowSecondaryTextOnDelegates(showSecondaryTextOnDelegates)
, mViewCanBeRated(viewCanBeRated)
, mIsTreeModel(isTreeModel)
, mIsValid(true)
{
}
......@@ -80,13 +82,15 @@ public:
Qt::SortOrder sortOrder,
ViewManager::AlbumCardinality albumCardinality,
ViewManager::AlbumViewStyle albumViewStyle,
ViewManager::RadioSpecificStyle radioSpecificStyle)
ViewManager::RadioSpecificStyle radioSpecificStyle,
ViewManager::IsTreeModelType isTreeModel)
: mMainTitle(std::move(mainTitle))
, mMainImage(std::move(mainImage))
, mViewPresentationType(viewPresentationType)
, mModelType(modelType)
, mFilterType(filterType)
, mDataType(dataType)
, mIsTreeModel(isTreeModel)
, mSortRole(sortRole)
, mSortOrder(sortOrder)
, mAlbumCardinality(albumCardinality)
......@@ -100,7 +104,7 @@ public:
return mMainTitle == other.mMainTitle && mMainImage == other.mMainImage &&
mSecondaryTitle == other.mSecondaryTitle && mViewPresentationType == other.mViewPresentationType &&
mModelType == other.mModelType && mFilterType == other.mFilterType &&
mDataType == other.mDataType && mFallbackItemIcon == other.mFallbackItemIcon &&
mDataType == other.mDataType && mIsTreeModel == other.mIsTreeModel && mFallbackItemIcon == other.mFallbackItemIcon &&
mShowSecondaryTextOnDelegates == other.mShowSecondaryTextOnDelegates && mViewCanBeRated == other.mViewCanBeRated &&
mSortRole == other.mSortRole && mSortOrder == other.mSortOrder &&
mAlbumCardinality == other.mAlbumCardinality && mAlbumViewStyle == other.mAlbumViewStyle &&
......@@ -113,7 +117,7 @@ public:
return mMainTitle != other.mMainTitle || mMainImage != other.mMainImage ||
mSecondaryTitle != other.mSecondaryTitle || mViewPresentationType != other.mViewPresentationType ||
mModelType != other.mModelType || mFilterType != other.mFilterType ||
mDataType != other.mDataType || mFallbackItemIcon != other.mFallbackItemIcon ||
mDataType != other.mDataType || mIsTreeModel != other.mIsTreeModel || mFallbackItemIcon != other.mFallbackItemIcon ||
mShowSecondaryTextOnDelegates != other.mShowSecondaryTextOnDelegates || mViewCanBeRated != other.mViewCanBeRated ||
mSortRole != other.mSortRole || mSortOrder != other.mSortOrder ||
mAlbumCardinality != other.mAlbumCardinality || mAlbumViewStyle != other.mAlbumViewStyle ||
......@@ -142,6 +146,8 @@ public:
ViewManager::ViewCanBeRated mViewCanBeRated = ViewManager::ViewHideRating;
ViewManager::IsTreeModelType mIsTreeModel = ViewManager::IsFlatModel;
int mSortRole = Qt::DisplayRole;
Qt::SortOrder mSortOrder = Qt::AscendingOrder;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment