ukui-menu/qml/AppUI/Sidebar.qml

94 lines
2.5 KiB
QML
Raw Normal View History

2022-12-23 11:32:21 +08:00
import QtQuick 2.0
import QtQuick.Layouts 1.12
2022-12-23 11:32:21 +08:00
Item {
ColumnLayout {
anchors.fill: parent
Item {
Layout.fillWidth: true
Layout.preferredHeight: 30
ListView {
id: extensionListView
anchors.fill: parent
orientation: ListView.Horizontal
model: extensionManager.extensionModel()
delegate: headerDelegate
function send(data) {
if (currentItem !== null) {
model.send(currentIndex, data);
}
}
onCurrentIndexChanged: {
if (currentItem !== null) {
currentItem.select();
}
}
}
}
Item {
Layout.fillWidth: true
Layout.fillHeight: true
Loader {
id: extensionLoader
anchors.fill: parent
clip: true
focus: true
onLoaded: {
item.send.connect(extensionListView.send);
}
}
}
}
Component {
id: headerDelegate
Item {
property var extensionData: model.data
width: 100
height: ListView.view ? ListView.view.height : 0
onExtensionDataChanged: {
if (extensionLoader.source === model.url) {
extensionLoader.item.extensionData = extensionData;
}
}
function select() {
if (extensionLoader.source !== model.url) {
extensionLoader.setSource(model.url, {extensionData: extensionData});
}
}
Text {
anchors.fill: parent
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.bold: true
wrapMode: Text.ElideRight
color: parent.ListView.isCurrentItem ? "blue" : "black"
text: model.name
}
MouseArea {
anchors.fill: parent
onClicked: {
parent.ListView.view.currentIndex = model.index;
}
}
}
}
Component.onCompleted: {
if (extensionListView.count > 0) {
extensionListView.currentIndex = 0;
}
2022-12-23 11:32:21 +08:00
}
}