diff --git a/AicsKnowledgeBase/qml/component/FileList.qml b/AicsKnowledgeBase/qml/component/FileList.qml index 1f7e4b8..46d02a8 100644 --- a/AicsKnowledgeBase/qml/component/FileList.qml +++ b/AicsKnowledgeBase/qml/component/FileList.qml @@ -8,8 +8,9 @@ Window { width: 800 height: 600 title: "File List Test1" + signal search(string tag) + signal open(string file) Item { - anchors.fill: parent ListView { id: listView @@ -25,27 +26,45 @@ Window { id: fileListItemHeaderItem width: ListView.view.width height: 48 - FluBreadcrumbBar { - id: header - width: parent.width - height: parent.height - separator: ">" - items: [{ - "title": "Home" - }, { - "title": "Documents" - }, { - "title": "File List" - }] - onClickItem: function (model) { - if (model.index + 1 !== count()) { - items = items.slice(0, model.index + 1) + RowLayout { + FluBreadcrumbBar { + id: header + width: parent.width + height: parent.height + separator: ">" + items: [{ + "title": "Home" + }, { + "title": "Documents" + }, { + "title": "File List" + }] + onClickItem: function (model) { + if (model.index + 1 !== count()) { + items = items.slice(0, model.index + 1) + } + } + onItemsChanged: { + fileListItemHeaderItem.update() } } - onItemsChanged: { - 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) { listView.headerItem.children[0].items = listView.headerItem.children[0].items.concat([{ @@ -55,14 +74,37 @@ Window { function update() { // combine all header items to a path var path = "" - for (var i = 0; i < listView.headerItem.children[0].items.length; i++) { - path += listView.headerItem.children[0].items[i].title + "/" - } + // for (var i = 0; i < listView.headerItem.children[0].items.length; i++) { + // path += listView.headerItem.children[0].items[i].title + "/" + // } 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 - // fileListModel.clear() - // fileListModel.append(newListModel) + fileListModel.clear() + fileListModel.append(newListModel) + // set ListView currentItem to null + listView.currentIndex = -1 } } } @@ -71,9 +113,10 @@ Window { Rectangle { id: fileListItemRect width: ListView.view.width - height: 100 + height: 120 color: !ListView.isCurrentItem ? "lightgray" : "red" FileListItem { + id: fileListItem width: parent.width height: parent.height title: model.title @@ -84,14 +127,19 @@ Window { date: model.date pageView: model.pageView stars: model.stars + // split string to array + tags: model.tags.split(",") + onTagClicked: { + emit: search(tag) + console.log(tag) + } } - MouseArea { - anchors.fill: parent - onClicked: { - listView.currentIndex = index - if (model.isDir) { - listView.headerItem.add(model.title) - } + function doubleClicked() { + listView.currentIndex = index + if (model.isDir) { + listView.headerItem.add(model.title) + } else { + emit: open(model.uid) } } } @@ -105,6 +153,7 @@ Window { type: "FOLDER" } ListElement { + uid: "2" title: "File 2" isDir: false brief: "This is a test file" @@ -115,6 +164,7 @@ Window { stars: 10 } ListElement { + uid: "3" title: "File 3" isDir: false brief: "This is a test file" diff --git a/AicsKnowledgeBase/qml/component/FileListItem.qml b/AicsKnowledgeBase/qml/component/FileListItem.qml index a578dd7..611cf93 100644 --- a/AicsKnowledgeBase/qml/component/FileListItem.qml +++ b/AicsKnowledgeBase/qml/component/FileListItem.qml @@ -16,53 +16,80 @@ Item { property var tags: [] property var notes: [] property int stars - + property var colorList: ["blue", "green", "orange", "red", "yellow", "purple", "pink", "brown", "teal", "cyan", "gray", "darkgray"] + signal tagClicked(string tag) ColumnLayout { id: row anchors.fill: parent anchors.margins: 10 spacing: 10 - RowLayout { - Image { - id: icon - source: type ? - "qrc:/AicsKnowledgeBase/res/" + type + ".png" : "" - Layout.preferredHeight: 18 - Layout.preferredWidth: 18 + ColumnLayout { + id: clickable + anchors.fill: parent + MouseArea { + anchors.fill: parent + onDoubleClicked: { + fileItem.parent.doubleClicked() + } } - FluText { - id: title - text: fileItem.title + RowLayout { + id: titleRow + Image { + id: icon + source: type ? "qrc:/AicsKnowledgeBase/res/" + type + ".png" : "" + Layout.preferredHeight: 18 + Layout.preferredWidth: 18 + } + FluText { + id: title + text: fileItem.title + } } - } - FluText { - id: brief - visible: !fileItem.isDir - text: fileItem.brief + FluText { + id: brief + visible: !fileItem.isDir + 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 { 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 + "浏览" - } - FluText { - id: stars - text: fileItem.stars + "收藏" + 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) + } + } } } } diff --git a/AicsKnowledgeBase/src/main.cpp b/AicsKnowledgeBase/src/main.cpp index 676475b..edc0d6b 100644 --- a/AicsKnowledgeBase/src/main.cpp +++ b/AicsKnowledgeBase/src/main.cpp @@ -36,7 +36,7 @@ int main(int argc, char* argv[]) qmlRegisterSingletonInstance("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, &app, [url](QObject* obj, const QUrl& objUrl) { if (!obj && url == objUrl)