SideBar: Add section

pull/26/head
reionwong 4 years ago
parent 4868a2e54c
commit b59db2fadd

@ -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;
}

@ -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;

@ -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<int, QByteArray> 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;
}

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

@ -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

Loading…
Cancel
Save