From b59db2fadd9bdfe52dbb90d6feb575dc25520113 Mon Sep 17 00:00:00 2001 From: reionwong Date: Wed, 18 Aug 2021 05:52:05 +0800 Subject: [PATCH] SideBar: Add section --- model/placesitem.cpp | 11 +++++++++++ model/placesitem.h | 4 ++++ model/placesmodel.cpp | 5 +++++ model/placesmodel.h | 3 ++- qml/SideBar.qml | 19 +++++++++++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/model/placesitem.cpp b/model/placesitem.cpp index 8497d8f..fb6c127 100644 --- a/model/placesitem.cpp +++ b/model/placesitem.cpp @@ -26,6 +26,7 @@ PlacesItem::PlacesItem(const QString &displayName, : QObject(parent) , m_displayName(displayName) , m_url(url) + , m_category("") , m_isAccessible(false) { } @@ -132,3 +133,13 @@ void PlacesItem::onAccessibilityChanged(bool isAccessible) emit itemChanged(this); } + +QString PlacesItem::category() const +{ + return m_category; +} + +void PlacesItem::setCategory(const QString &category) +{ + m_category = category; +} diff --git a/model/placesitem.h b/model/placesitem.h index e19ec00..be8f18c 100644 --- a/model/placesitem.h +++ b/model/placesitem.h @@ -56,6 +56,9 @@ public: bool isDevice(); bool setupNeeded(); + QString category() const; + void setCategory(const QString &category); + signals: void itemChanged(PlacesItem *); @@ -69,6 +72,7 @@ private: QString m_iconPath; QString m_udi; QUrl m_url; + QString m_category; bool m_isAccessible; diff --git a/model/placesmodel.cpp b/model/placesmodel.cpp index e3b7fff..9c27838 100644 --- a/model/placesmodel.cpp +++ b/model/placesmodel.cpp @@ -106,6 +106,7 @@ PlacesModel::PlacesModel(QObject *parent) for (const Solid::Device &device : deviceList) { PlacesItem *deviceItem = new PlacesItem; deviceItem->setUdi(device.udi()); + deviceItem->setCategory(tr("Drives")); m_items.append(deviceItem); } } @@ -124,6 +125,7 @@ QHash PlacesModel::roleNames() const roleNames[PlacesModel::PathRole] = "path"; roleNames[PlacesModel::IsDeviceRole] = "isDevice"; roleNames[PlacesModel::setupNeededRole] = "setupNeeded"; + roleNames[PlacesModel::CategoryRole] = "category"; return roleNames; } @@ -170,6 +172,9 @@ QVariant PlacesModel::data(const QModelIndex &index, int role) const case PlacesModel::setupNeededRole: return item->setupNeeded(); break; + case PlacesModel::CategoryRole: + return item->category(); + break; default: break; } diff --git a/model/placesmodel.h b/model/placesmodel.h index fbeb4d3..204739e 100644 --- a/model/placesmodel.h +++ b/model/placesmodel.h @@ -36,7 +36,8 @@ public: UrlRole, PathRole, IsDeviceRole, - setupNeededRole + setupNeededRole, + CategoryRole }; Q_ENUMS(DataRole); diff --git a/qml/SideBar.qml b/qml/SideBar.qml index d72c4c9..590ad84 100644 --- a/qml/SideBar.qml +++ b/qml/SideBar.qml @@ -55,6 +55,25 @@ ListView { color: FishUI.Theme.highlightColor } + section.property: "category" + section.delegate: Item { + width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin + height: FishUI.Units.fontMetrics.height + FishUI.Units.largeSpacing + FishUI.Units.smallSpacing + + Text { + anchors.left: parent.left + anchors.top: parent.top + anchors.leftMargin: Qt.application.layoutDirection === Qt.RightToLeft ? 0 : FishUI.Units.smallSpacing + anchors.rightMargin: FishUI.Units.smallSpacing + anchors.topMargin: FishUI.Units.largeSpacing + anchors.bottomMargin: FishUI.Units.smallSpacing + color: FishUI.Theme.textColor + font.pointSize: 9 + font.bold: true + text: section + } + } + delegate: Item { id: _item width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin