Commit 67b65c0b authored by Matthieu Gallien's avatar Matthieu Gallien

add a section header before embedded entries in ViewSelector

done with Kirigami.ListSectionHeader
parent 39d128dc
......@@ -8,6 +8,8 @@
#include "viewslistdata.h"
#include <KI18n/KLocalizedString>
class ViewsModelPrivate
{
......@@ -38,6 +40,7 @@ QHash<int, QByteArray> ViewsModel::roleNames() const
result[DatabaseIdRole] = "databaseId";
result[UseSecondTitleRole] = "useSecondTitle";
result[SecondTitleRole] = "secondTitle";
result[EntryCategoryRole] = "entryCategory";
return result;
}
......@@ -95,6 +98,33 @@ QVariant ViewsModel::data(const QModelIndex &index, int role) const
break;
case ColumnRoles::UseSecondTitleRole:
result = d->mViewsData->useSecondTitle(index.row());
break;
case ColumnRoles::EntryCategoryRole:
if (d->mViewsData->defaultEntry(index.row())) {
result = QStringLiteral("default");
} else {
switch (d->mViewsData->embeddedCategory())
{
case ElisaUtils::Album:
result = i18nc("Title of the view of all albums", "Albums");
break;
case ElisaUtils::Genre:
result = i18nc("Title of the view of all genres", "Genres");
break;
case ElisaUtils::Artist:
result = i18nc("Title of the view of all artists", "Artists");
break;
case ElisaUtils::Radio:
case ElisaUtils::Track:
case ElisaUtils::Unknown:
case ElisaUtils::Composer:
case ElisaUtils::FileName:
case ElisaUtils::Lyricist:
case ElisaUtils::Container:
break;
}
}
break;
}
......
......@@ -33,6 +33,7 @@ public:
DatabaseIdRole,
EntryTypeRole,
UseColorOverlayRole,
EntryCategoryRole,
};
explicit ViewsModel(QObject *parent = nullptr);
......
......@@ -8,7 +8,7 @@ import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQml.Models 2.2
import QtGraphicalEffects 1.0
import org.kde.kirigami 2.5 as Kirigami
import org.kde.kirigami 2.10 as Kirigami
import org.kde.elisa 1.0
FocusScope {
......@@ -90,6 +90,12 @@ FocusScope {
}
}
section.property: 'entryCategory'
section.delegate: Kirigami.ListSectionHeader {
label: (section != 'default' ? section : '')
height: if (section == 'default') 0
}
onCurrentItemChanged: if (!ignoreCurrentItemChanges) switchView(currentIndex)
}
......
......@@ -177,6 +177,11 @@ qulonglong ViewsListData::databaseId(int index) const
return d->mViewsParameters[index].mDataFilter.databaseId();
}
bool ViewsListData::defaultEntry(int index) const
{
return d->mEmbeddedCategory == ElisaUtils::Unknown || d->mViewsParameters[index].mEntryType != d->mEmbeddedCategory;
}
int ViewsListData::indexFromEmbeddedDatabaseId(qulonglong databaseId) const
{
auto result = std::find_if(d->mViewsParameters.begin(), d->mViewsParameters.end(), [this, databaseId](auto data) {
......
......@@ -295,6 +295,8 @@ public:
qulonglong databaseId(int index) const;
bool defaultEntry(int index) const;
int indexFromEmbeddedDatabaseId(qulonglong databaseId) const;
int indexFromEmbeddedName(const QString &name) const;
......
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