添加FileList的信号

main
karlis 2023-06-28 14:47:52 +08:00
parent a5dda60ad1
commit 4f407f42ac
3 changed files with 145 additions and 68 deletions

View File

@ -8,8 +8,9 @@ Window {
width: 800 width: 800
height: 600 height: 600
title: "File List Test1" title: "File List Test1"
signal search(string tag)
signal open(string file)
Item { Item {
anchors.fill: parent anchors.fill: parent
ListView { ListView {
id: listView id: listView
@ -25,6 +26,7 @@ Window {
id: fileListItemHeaderItem id: fileListItemHeaderItem
width: ListView.view.width width: ListView.view.width
height: 48 height: 48
RowLayout {
FluBreadcrumbBar { FluBreadcrumbBar {
id: header id: header
width: parent.width width: parent.width
@ -46,6 +48,23 @@ Window {
fileListItemHeaderItem.update() fileListItemHeaderItem.update()
} }
} }
// back to folder button
FluIconButton {
Layout.alignment: Qt.AlignVCenter
id: backButton
width: 24
height: 24
iconSource: FluentIcons.ChromeBack
onClicked: {
if (header.count() > 1) {
header.items = header.items.slice(
0, header.count() - 1)
}
fileListItemHeaderItem.update()
}
}
}
function add(folderName) { function add(folderName) {
listView.headerItem.children[0].items listView.headerItem.children[0].items
= listView.headerItem.children[0].items.concat([{ = listView.headerItem.children[0].items.concat([{
@ -55,14 +74,37 @@ Window {
function update() { function update() {
// combine all header items to a path // combine all header items to a path
var path = "" var path = ""
for (var i = 0; i < listView.headerItem.children[0].items.length; i++) { // for (var i = 0; i < listView.headerItem.children[0].items.length; i++) {
path += listView.headerItem.children[0].items[i].title + "/" // path += listView.headerItem.children[0].items[i].title + "/"
} // }
console.log(path) console.log(path)
var newListModel = [] var newListModel = [{
"title": "File 2",
"isDir": false,
"brief": "This is a test file",
"size": 500,
"type": "WORD",
"date": "2020-09-09",
"pageView": 100,
"stars": 10,
"tags": "tag1,tag2,tag3"
}, {
"title": "File 3",
"isDir": false,
"brief": "This is a test file",
"size": 500,
"type": "WORD",
"date": "2020-09-09",
"pageView": 100,
"stars": 10,
"tags"// 15 tags
: "tag1,tag2,tag3,tag4,tag5,tag6,tag7,tag8,tag9,tag10,tag11,tag12,tag13,tag14,tag15"
}]
// http request for new list data // http request for new list data
// fileListModel.clear() fileListModel.clear()
// fileListModel.append(newListModel) fileListModel.append(newListModel)
// set ListView currentItem to null
listView.currentIndex = -1
} }
} }
} }
@ -71,9 +113,10 @@ Window {
Rectangle { Rectangle {
id: fileListItemRect id: fileListItemRect
width: ListView.view.width width: ListView.view.width
height: 100 height: 120
color: !ListView.isCurrentItem ? "lightgray" : "red" color: !ListView.isCurrentItem ? "lightgray" : "red"
FileListItem { FileListItem {
id: fileListItem
width: parent.width width: parent.width
height: parent.height height: parent.height
title: model.title title: model.title
@ -84,14 +127,19 @@ Window {
date: model.date date: model.date
pageView: model.pageView pageView: model.pageView
stars: model.stars stars: model.stars
// split string to array
tags: model.tags.split(",")
onTagClicked: {
emit: search(tag)
console.log(tag)
} }
MouseArea { }
anchors.fill: parent function doubleClicked() {
onClicked: {
listView.currentIndex = index listView.currentIndex = index
if (model.isDir) { if (model.isDir) {
listView.headerItem.add(model.title) listView.headerItem.add(model.title)
} } else {
emit: open(model.uid)
} }
} }
} }
@ -105,6 +153,7 @@ Window {
type: "FOLDER" type: "FOLDER"
} }
ListElement { ListElement {
uid: "2"
title: "File 2" title: "File 2"
isDir: false isDir: false
brief: "This is a test file" brief: "This is a test file"
@ -115,6 +164,7 @@ Window {
stars: 10 stars: 10
} }
ListElement { ListElement {
uid: "3"
title: "File 3" title: "File 3"
isDir: false isDir: false
brief: "This is a test file" brief: "This is a test file"

View File

@ -16,18 +16,28 @@ Item {
property var tags: [] property var tags: []
property var notes: [] property var notes: []
property int stars property int stars
property var colorList: ["blue", "green", "orange", "red", "yellow", "purple", "pink", "brown", "teal", "cyan", "gray", "darkgray"]
signal tagClicked(string tag)
ColumnLayout { ColumnLayout {
id: row id: row
anchors.fill: parent anchors.fill: parent
anchors.margins: 10 anchors.margins: 10
spacing: 10 spacing: 10
ColumnLayout {
id: clickable
anchors.fill: parent
MouseArea {
anchors.fill: parent
onDoubleClicked: {
fileItem.parent.doubleClicked()
}
}
RowLayout { RowLayout {
id: titleRow
Image { Image {
id: icon id: icon
source: type ? source: type ? "qrc:/AicsKnowledgeBase/res/" + type + ".png" : ""
"qrc:/AicsKnowledgeBase/res/" + type + ".png" : ""
Layout.preferredHeight: 18 Layout.preferredHeight: 18
Layout.preferredWidth: 18 Layout.preferredWidth: 18
} }
@ -43,6 +53,7 @@ Item {
text: fileItem.brief text: fileItem.brief
} }
RowLayout { RowLayout {
id: infoRow
visible: !fileItem.isDir visible: !fileItem.isDir
FluText { FluText {
id: date id: date
@ -58,7 +69,7 @@ Item {
} }
FluText { FluText {
id: pageView id: pageView
text: fileItem.pageView + "浏览" text: fileItem.pageView + "浏览" + tags.length
} }
FluText { FluText {
id: stars id: stars
@ -66,4 +77,20 @@ Item {
} }
} }
} }
RowLayout {
visible: !fileItem.isDir
Repeater {
model: fileItem.tags
delegate: FluTextButton {
text: "#" + fileItem.tags[index]
normalColor: colorList[index % colorList.length]
font.pixelSize: 12
Layout.preferredWidth: 50
onClicked: {
emit: tagClicked(text)
}
}
}
}
}
} }

View File

@ -36,7 +36,7 @@ int main(int argc, char* argv[])
qmlRegisterSingletonInstance<HttpClient>("AicsKB.HttpClient", 1, 0, "HttpClient", httpClient); qmlRegisterSingletonInstance<HttpClient>("AicsKB.HttpClient", 1, 0, "HttpClient", httpClient);
const QUrl url(u"qrc:/AicsKnowledgeBase/qml/App.qml"_qs); const QUrl url(u"qrc:/AicsKnowledgeBase/qml/component/FileList.qml"_qs);
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject* obj, const QUrl& objUrl) { &app, [url](QObject* obj, const QUrl& objUrl) {
if (!obj && url == objUrl) if (!obj && url == objUrl)