添加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,27 +26,45 @@ Window {
id: fileListItemHeaderItem id: fileListItemHeaderItem
width: ListView.view.width width: ListView.view.width
height: 48 height: 48
FluBreadcrumbBar { RowLayout {
id: header FluBreadcrumbBar {
width: parent.width id: header
height: parent.height width: parent.width
separator: ">" height: parent.height
items: [{ separator: ">"
"title": "Home" items: [{
}, { "title": "Home"
"title": "Documents" }, {
}, { "title": "Documents"
"title": "File List" }, {
}] "title": "File List"
onClickItem: function (model) { }]
if (model.index + 1 !== count()) { onClickItem: function (model) {
items = items.slice(0, model.index + 1) if (model.index + 1 !== count()) {
items = items.slice(0, model.index + 1)
}
}
onItemsChanged: {
fileListItemHeaderItem.update()
} }
} }
onItemsChanged: { // back to folder button
fileListItemHeaderItem.update() 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 { function doubleClicked() {
anchors.fill: parent listView.currentIndex = index
onClicked: { if (model.isDir) {
listView.currentIndex = index listView.headerItem.add(model.title)
if (model.isDir) { } else {
listView.headerItem.add(model.title) 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,53 +16,80 @@ 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
RowLayout { ColumnLayout {
Image { id: clickable
id: icon anchors.fill: parent
source: type ? MouseArea {
"qrc:/AicsKnowledgeBase/res/" + type + ".png" : "" anchors.fill: parent
Layout.preferredHeight: 18 onDoubleClicked: {
Layout.preferredWidth: 18 fileItem.parent.doubleClicked()
}
} }
FluText { RowLayout {
id: title id: titleRow
text: fileItem.title Image {
id: icon
source: type ? "qrc:/AicsKnowledgeBase/res/" + type + ".png" : ""
Layout.preferredHeight: 18
Layout.preferredWidth: 18
}
FluText {
id: title
text: fileItem.title
}
} }
}
FluText { FluText {
id: brief id: brief
visible: !fileItem.isDir visible: !fileItem.isDir
text: fileItem.brief text: fileItem.brief
}
RowLayout {
id: infoRow
visible: !fileItem.isDir
FluText {
id: date
text: fileItem.date
}
FluText {
id: size
// cast Byte size to right text size
text: fileItem.size > 1024
* 1024 ? (fileItem.size / 1024 / 1024).toFixed(
2) + "MB" : (fileItem.size / 1024).toFixed(
2) + "KB"
}
FluText {
id: pageView
text: fileItem.pageView + "浏览" + tags.length
}
FluText {
id: stars
text: fileItem.stars + "收藏"
}
}
} }
RowLayout { RowLayout {
visible: !fileItem.isDir visible: !fileItem.isDir
FluText { Repeater {
id: date model: fileItem.tags
text: fileItem.date delegate: FluTextButton {
} text: "#" + fileItem.tags[index]
FluText { normalColor: colorList[index % colorList.length]
id: size font.pixelSize: 12
// cast Byte size to right text size Layout.preferredWidth: 50
text: fileItem.size > 1024 onClicked: {
* 1024 ? (fileItem.size / 1024 / 1024).toFixed( emit: tagClicked(text)
2) + "MB" : (fileItem.size / 1024).toFixed( }
2) + "KB" }
}
FluText {
id: pageView
text: fileItem.pageView + "浏览"
}
FluText {
id: stars
text: fileItem.stars + "收藏"
} }
} }
} }

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)