SideBar: Add section

This commit is contained in:
reionwong 2021-08-18 05:52:05 +08:00
parent 4868a2e54c
commit b59db2fadd
5 changed files with 41 additions and 1 deletions

View file

@ -26,6 +26,7 @@ PlacesItem::PlacesItem(const QString &displayName,
: QObject(parent) : QObject(parent)
, m_displayName(displayName) , m_displayName(displayName)
, m_url(url) , m_url(url)
, m_category("")
, m_isAccessible(false) , m_isAccessible(false)
{ {
} }
@ -132,3 +133,13 @@ void PlacesItem::onAccessibilityChanged(bool isAccessible)
emit itemChanged(this); emit itemChanged(this);
} }
QString PlacesItem::category() const
{
return m_category;
}
void PlacesItem::setCategory(const QString &category)
{
m_category = category;
}

View file

@ -56,6 +56,9 @@ public:
bool isDevice(); bool isDevice();
bool setupNeeded(); bool setupNeeded();
QString category() const;
void setCategory(const QString &category);
signals: signals:
void itemChanged(PlacesItem *); void itemChanged(PlacesItem *);
@ -69,6 +72,7 @@ private:
QString m_iconPath; QString m_iconPath;
QString m_udi; QString m_udi;
QUrl m_url; QUrl m_url;
QString m_category;
bool m_isAccessible; bool m_isAccessible;

View file

@ -106,6 +106,7 @@ PlacesModel::PlacesModel(QObject *parent)
for (const Solid::Device &device : deviceList) { for (const Solid::Device &device : deviceList) {
PlacesItem *deviceItem = new PlacesItem; PlacesItem *deviceItem = new PlacesItem;
deviceItem->setUdi(device.udi()); deviceItem->setUdi(device.udi());
deviceItem->setCategory(tr("Drives"));
m_items.append(deviceItem); m_items.append(deviceItem);
} }
} }
@ -124,6 +125,7 @@ QHash<int, QByteArray> PlacesModel::roleNames() const
roleNames[PlacesModel::PathRole] = "path"; roleNames[PlacesModel::PathRole] = "path";
roleNames[PlacesModel::IsDeviceRole] = "isDevice"; roleNames[PlacesModel::IsDeviceRole] = "isDevice";
roleNames[PlacesModel::setupNeededRole] = "setupNeeded"; roleNames[PlacesModel::setupNeededRole] = "setupNeeded";
roleNames[PlacesModel::CategoryRole] = "category";
return roleNames; return roleNames;
} }
@ -170,6 +172,9 @@ QVariant PlacesModel::data(const QModelIndex &index, int role) const
case PlacesModel::setupNeededRole: case PlacesModel::setupNeededRole:
return item->setupNeeded(); return item->setupNeeded();
break; break;
case PlacesModel::CategoryRole:
return item->category();
break;
default: default:
break; break;
} }

View file

@ -36,7 +36,8 @@ public:
UrlRole, UrlRole,
PathRole, PathRole,
IsDeviceRole, IsDeviceRole,
setupNeededRole setupNeededRole,
CategoryRole
}; };
Q_ENUMS(DataRole); Q_ENUMS(DataRole);

View file

@ -55,6 +55,25 @@ ListView {
color: FishUI.Theme.highlightColor 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 { delegate: Item {
id: _item id: _item
width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin