| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975 |
- import Felgo
- import QtQuick
- import QtQuick.Controls
- import QtQuick.Layouts
- import "../controls"
- import "../common"
- import Frames 0.1
- import QtMultimedia
- AppPage {
- id: photoArchivePage
- navigationBarHidden: true
- backgroundColor: app.theme_backgroundColor
- property bool isLoading: false
- property bool rootExpanded: false
- property var selectedImages: []
- property bool isSelecting: false
- property bool isFusing: false
- property bool showSharp: true
- // 融合按钮
- AppButton {
- id: fuseButton
- anchors.bottom: parent.bottom
- anchors.right: parent.right
- anchors.margins: 20
- text: "图像融合"
- visible: selectedImages.length >= 2 && !isFusing
- backgroundColor: "#28a779"
- textColor: "white"
- z: 100
- onClicked: {
- if (selectedImages.length >= 2) {
- isFusing = true
- console.log("开始融合", selectedImages.length, "张图片")
- app.isGlobalFusing = true
- app.globalFusionMessage = "开始融合..."
- app.globalFusionPercent = 0
- opencvFunc.fuseImagesAsync(selectedImages)
- }
- }
- }
- // 取消选择按钮
- AppButton {
- id: cancelButton
- anchors.bottom: parent.bottom
- anchors.left: parent.left
- anchors.margins: 20
- text: "取消选择"
- visible: isSelecting && !isFusing
- backgroundColor: "#e74c3c"
- textColor: "white"
- z: 100
- onClicked: {
- clearSelection()
- }
- }
- // 原图/锐化切换按钮
- AppButton {
- id: sharpToggleButton
- anchors.bottom: parent.bottom
- anchors.horizontalCenter: parent.horizontalCenter
- anchors.margins: 20
- text: showSharp ? "切换到原图" : "切换到锐化图"
- visible: imageListModel.count > 0 && !isSelecting && !isFusing
- backgroundColor: "#3b82f6"
- textColor: "white"
- z: 100
- onClicked: {
- setShowSharp(!showSharp)
- }
- }
- // 连接融合完成信号
- Connections {
- target: opencvFunc
- function onFuseFinished(resultPath) {
- isFusing = false
- app.isGlobalFusing = false
- if (resultPath) {
- console.log("融合完成:", resultPath)
- // 显示融合结果
- imageListModel.append({filePath: resultPath, isFused: true, selected: false})
- // 清除选择
- clearSelection()
- } else {
- console.error("融合失败")
- }
- }
- // 融合进度信号
- function onFusionProgress(message, percent) {
- console.log("融合进度:", message, percent + "%")
- // 全局弹窗由 Main.qml 监听
- }
- }
- function clearSelection() {
- selectedImages = []
- isSelecting = false
- for (var i = 0; i < imageListModel.count; i++) {
- imageListModel.setProperty(i, "selected", false)
- }
- }
- function toggleImageSelection(filePath) {
- // 创建新数组以触发QML属性绑定更新
- var temp = selectedImages.slice()
- var idx = temp.indexOf(filePath)
- if (idx >= 0) {
- temp.splice(idx, 1)
- } else {
- temp.push(filePath)
- }
- selectedImages = temp
- isSelecting = selectedImages.length > 0
- // 更新model中的selected状态
- for (var i = 0; i < imageListModel.count; i++) {
- if (imageListModel.get(i).filePath === filePath) {
- imageListModel.setProperty(i, "selected", idx < 0)
- break
- }
- }
- }
- // 全屏查看组件
- Popup {
- id: fullscreenPopup
- width: parent.width
- height: parent.height
- modal: true
- closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
- background: Rectangle {
- color: "#CC000000"
- }
- Item {
- id: viewport
- anchors.fill: parent
- clip: true
- Image {
- id: image
- x: 0
- y: 0
- width: Math.min(implicitWidth, viewport.width)
- height: Math.min(implicitHeight, viewport.height)
- asynchronous: true
- fillMode: Image.PreserveAspectFit
- transformOrigin: Item.TopLeft
- scale: 1.0
- property real minZoom: 1.0
- property real maxZoom: 5.0
- onStatusChanged: {
- if (status === Image.Ready) {
- clampPos()
- }
- }
- }
- // 平移
- DragHandler {
- id: dragHandler
- target: null
- acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchScreen
- property real startX: 0
- property real startY: 0
- onActiveChanged: {
- if (active) {
- startX = image.x
- startY = image.y
- }
- }
- onTranslationChanged: {
- image.x = startX + translation.x
- image.y = startY + translation.y
- clampPos()
- }
- }
- // 捏合缩放 (触摸):双指缩放在视口中心缩放,保持图像居中
- PinchArea {
- id: pinchArea
- anchors.fill: parent
- pinch.target: null
- pinch.minimumRotation: 0
- pinch.maximumRotation: 0
- pinch.minimumScale: 1.0
- pinch.maximumScale: 5.0
- property real pinchStartZoom: 1.0
- onPinchStarted: {
- pinchStartZoom = image.scale
- }
- onPinchUpdated: {
- var newZoom = Math.max(image.minZoom, Math.min(image.maxZoom, pinchStartZoom * pinch.scale))
- // 以视口中心为锚点缩放,图像保持居中
- zoomToPoint(viewport.width / 2, viewport.height / 2, newZoom)
- }
- }
- // 鼠标滚轮缩放
- WheelHandler {
- id: wheelHandler
- target: null
- acceptedDevices: PointerDevice.Mouse
- onWheel: (event) => {
- var factor = event.angleDelta.y > 0 ? 1.15 : (1 / 1.15)
- var newZoom = Math.max(image.minZoom, Math.min(image.maxZoom, image.scale * factor))
- zoomToPoint(event.x, event.y, newZoom)
- }
- }
- }
- // 关闭按钮
- RoundButton {
- id: closeBtn
- text: "关闭" // 设置按钮文本
- radius: height/2 // 确保圆形
- // 基础样式
- width: 80
- height: 40
- font.pixelSize: 14
- font.bold: true
- // 颜色配置
- palette {
- button: "#e74c3c" // 背景色
- buttonText: "white" // 文字颜色
- }
- // 点击效果
- background: Rectangle {
- radius: closeBtn.radius
- color: closeBtn.palette.button
- border.color: Qt.darker(color, 1.2)
- border.width: 1
- Rectangle {
- anchors.fill: parent
- radius: parent.radius
- color: "transparent"
- border.color: Qt.lighter(parent.color, 1.2)
- border.width: closeBtn.down ? 2 : 0
- opacity: closeBtn.down ? 0.5 : 0
- Behavior on opacity { NumberAnimation { duration: 100 } }
- }
- }
- // 点击事件
- onClicked: {
- console.log("关闭操作触发")
- fullscreenPopup.close()
- // 添加具体关闭逻辑
- }
- }
- }
- function showFullscreen(path) {
- image.source = "file://" + path
- // 等待图片加载出尺寸后再居中
- resetTransform()
- fullscreenPopup.open()
- }
- // ===== 原始视频流(.rawv)播放 =====
- RawVideoPlayer {
- id: rawPlayer
- videoSink: videoOutput.videoSink
- }
- // 分析/融合结果(与视频同目录,命名与拍照图片一致)
- Connections {
- target: rawPlayer
- function onAnalyzeFinished(path) {
- if (path) {
- console.log("分析完成:", path)
- nativeUtils.displayMessageBox("提示", "分析完成,已保存:\n" + path.split("/").pop(), 1)
- } else {
- nativeUtils.displayMessageBox("提示", "分析失败,请重试!", 1)
- }
- }
- function onFuseFinished(path) {
- if (path) {
- console.log("融合完成:", path)
- nativeUtils.displayMessageBox("提示", "融合完成,已保存:\n" + path.split("/").pop(), 1)
- } else {
- nativeUtils.displayMessageBox("提示", "融合失败,请重试!", 1)
- }
- }
- // 录制视频流文件已被删除:关闭播放并刷新界面上的相关条目
- function onFileRemoved(path) {
- console.log("录制视频流已删除:", path)
- closeVideo()
- for (var i = imageListModel.count - 1; i >= 0; i--) {
- if (imageListModel.get(i).filePath === path)
- imageListModel.remove(i)
- }
- treeModel.resetModel() //归档树重新加载,去掉已删除的条目
- nativeUtils.displayMessageBox("提示", "已删除:\n" + path.split("/").pop(), 1)
- }
- }
- // 打开原始视频流文件并开始播放
- function openVideo(filePath) {
- console.log("播放原始视频流:", filePath)
- if (rawPlayer.open(filePath)) {
- videoPopup.videoTitle = filePath.split("/").pop()
- videoPopup.open()
- rawPlayer.play()
- } else {
- nativeUtils.displayMessageBox("提示", "无法播放该视频流文件!", 1)
- }
- }
- function closeVideo() {
- rawPlayer.stop()
- rawPlayer.close()
- videoPopup.close()
- }
- Popup {
- id: videoPopup
- width: parent.width
- height: parent.height
- modal: true
- closePolicy: Popup.NoAutoClose
- property string videoTitle: ""
- background: Rectangle {
- color: "#000000"
- }
- VideoOutput {
- id: videoOutput
- anchors.fill: parent
- anchors.bottomMargin: dp(80)
- fillMode: VideoOutput.PreserveAspectFit
- }
- Column {
- anchors.top: parent.top
- anchors.topMargin: dp(12)
- anchors.horizontalCenter: parent.horizontalCenter
- spacing: dp(4)
- Text {
- anchors.horizontalCenter: parent.horizontalCenter
- text: videoPopup.videoTitle
- color: "white"
- font.bold: true
- font.pixelSize: 14
- }
- Text {
- anchors.horizontalCenter: parent.horizontalCenter
- text: rawPlayer.position + " / " + rawPlayer.frameCount + " 帧"
- color: "#28a779"
- font.pixelSize: 12
- }
- }
- Row {
- anchors.bottom: parent.bottom
- anchors.bottomMargin: dp(16)
- anchors.horizontalCenter: parent.horizontalCenter
- spacing: dp(16)
- AppButton {
- text: rawPlayer.playing ? "暂停" : "播放"
- textColor: "white"
- backgroundColor: "#28a779"
- flat: false
- enabled: !rawPlayer.busy
- minimumHeight: dp(40)
- minimumWidth: dp(80)
- onClicked: {
- if (rawPlayer.playing) rawPlayer.pause()
- else rawPlayer.play()
- }
- }
- AppButton {
- text: "分析"
- textColor: "white"
- backgroundColor: "#3b82f6"
- flat: false
- enabled: !rawPlayer.busy
- minimumHeight: dp(40)
- minimumWidth: dp(80)
- onClicked: {
- rawPlayer.pause()
- rawPlayer.analyzeSharpestFrame()
- }
- }
- AppButton {
- text: "融合"
- textColor: "white"
- backgroundColor: "#8b5cf6"
- flat: false
- enabled: !rawPlayer.busy
- minimumHeight: dp(40)
- minimumWidth: dp(80)
- onClicked: {
- rawPlayer.pause()
- rawPlayer.fuseVideoFrames()
- }
- }
- AppButton {
- text: "删除"
- textColor: "white"
- backgroundColor: "#e74c3c"
- flat: false
- enabled: !rawPlayer.busy
- minimumHeight: dp(40)
- minimumWidth: dp(80)
- onClicked: deleteConfirmDialog.open()
- }
- AppButton {
- text: "关闭"
- textColor: "white"
- backgroundColor: "#555555"
- flat: false
- minimumHeight: dp(40)
- minimumWidth: dp(80)
- onClicked: closeVideo()
- }
- }
- Rectangle {
- anchors.fill: parent
- visible: rawPlayer.busy
- color: "#99000000"
- z: 10
- Column {
- anchors.centerIn: parent
- spacing: dp(10)
- BusyIndicator {
- anchors.horizontalCenter: parent.horizontalCenter
- running: rawPlayer.busy
- width: dp(48)
- height: dp(48)
- }
- Text {
- anchors.horizontalCenter: parent.horizontalCenter
- text: "正在处理,请稍候..."
- color: "white"
- font.pixelSize: 15
- }
- }
- }
- }
- // 删除录制视频流前的确认框(用 Popup 实现,避免与 Felgo 的 Dialog 同名冲突)
- Popup {
- id: deleteConfirmDialog
- width: parent.width * 0.8
- height: dp(170)
- x: (parent.width - width) / 2
- y: (parent.height - height) / 2
- padding: 0
- modal: true
- closePolicy: Popup.NoAutoClose
- background: Rectangle {
- color: "white"
- radius: dp(6)
- }
- Text {
- id: confirmTitle
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.top: parent.top
- anchors.margins: dp(12)
- color: "#333333"
- font.bold: true
- font.pixelSize: 15
- text: "删除视频流"
- }
- Text {
- id: confirmText
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.top: confirmTitle.bottom
- anchors.leftMargin: dp(12)
- anchors.rightMargin: dp(12)
- anchors.topMargin: dp(8)
- color: "black"
- wrapMode: Text.Wrap
- text: "确定删除该录制视频流文件?\n" + videoPopup.videoTitle
- }
- Row {
- anchors.horizontalCenter: parent.horizontalCenter
- anchors.top: confirmText.bottom
- anchors.topMargin: dp(16)
- spacing: dp(10)
- AppButton {
- text: "取消"
- flat: false
- textColor: "black"
- backgroundColor: "#e9e9e9"
- minimumHeight: dp(36)
- minimumWidth: dp(70)
- onClicked: deleteConfirmDialog.close()
- }
- AppButton {
- text: "删除"
- flat: false
- textColor: "white"
- backgroundColor: "#e74c3c"
- minimumHeight: dp(36)
- minimumWidth: dp(70)
- onClicked: {
- deleteConfirmDialog.close()
- deleteCurrentVideo()
- }
- }
- }
- }
- // 删除当前正在播放的录制视频流文件(.rawv,保留分析/融合结果图片)
- function deleteCurrentVideo() {
- if (rawPlayer.source === "")
- return
- if (!rawPlayer.removeCurrentFile())
- nativeUtils.displayMessageBox("提示", "删除失败,请重试!", 1)
- }
- // 重置缩放为初始大小并居中
- function resetTransform() {
- image.scale = 1.0
- clampPos()
- }
- // 约束图片位置:小于视口时居中,大于视口时限制不露出空白边缘
- function clampPos() {
- var sw = image.width * image.scale
- var sh = image.height * image.scale
- var minX, maxX, minY, maxY
- if (sw <= viewport.width) {
- minX = (viewport.width - sw) / 2
- maxX = minX
- } else {
- minX = viewport.width - sw
- maxX = 0
- }
- if (sh <= viewport.height) {
- minY = (viewport.height - sh) / 2
- maxY = minY
- } else {
- minY = viewport.height - sh
- maxY = 0
- }
- image.x = Math.max(minX, Math.min(maxX, image.x))
- image.y = Math.max(minY, Math.min(maxY, image.y))
- }
- // 以视口坐标点(px,py)为锚点缩放图片到 newZoom,保证锚点内容不漂移
- function zoomToPoint(px, py, newZoom) {
- var oldZoom = image.scale
- // 锚点相对图片左上角的偏移(未缩放坐标)
- var relX = (px - image.x) / oldZoom
- var relY = (py - image.y) / oldZoom
- image.scale = newZoom
- image.x = px - relX * newZoom
- image.y = py - relY * newZoom
- clampPos()
- }
- SplitView {
- anchors.fill: parent
- orientation: Qt.Horizontal
- // 图片显示区域 (70%)
- GridView {
- id: imageGridView
- SplitView.preferredWidth: parent.width * 0.7
- clip: true
- cellWidth: Math.max(45, Math.floor((imageGridView.width - 10) / 8))
- cellHeight: cellWidth
- model: ListModel { id: imageListModel }
- delegate: Item {
- width: imageGridView.cellWidth - 5
- height: imageGridView.cellHeight - 5
- // 是否为原始视频流文件(.rawv)
- readonly property bool isVideo: model.filePath ? rawPlayer.isRawVideo(model.filePath) : false
- Rectangle {
- anchors.fill: parent
- anchors.margins: 2
- color: model.selected ? "#28a779" : "transparent"
- border.color: model.selected ? "#28a779" : (model.filePath ? "#eee" : "#bbb")
- border.width: 1
- radius: 3
- // 有图片时加载缩略图,缺图时显示灰色占位
- Image {
- anchors.fill: parent
- anchors.margins: 2
- source: model.filePath ? "file://" + model.filePath : ""
- asynchronous: true
- sourceSize.width: 200
- sourceSize.height: 200
- fillMode: Image.PreserveAspectFit
- cache: true
- visible: model.filePath !== "" && !isVideo
- BusyIndicator {
- anchors.centerIn: parent
- running: parent.status === Image.Loading
- width: 24
- height: 24
- }
- }
- // 视频流文件占位:显示播放标识与文件名
- Rectangle {
- anchors.fill: parent
- anchors.margins: 2
- visible: isVideo
- color: "#1b1b1b"
- radius: 3
- Column {
- anchors.centerIn: parent
- spacing: 2
- Text {
- anchors.horizontalCenter: parent.horizontalCenter
- text: "▶"
- color: "#28a779"
- font.pixelSize: 20
- }
- Text {
- width: imageGridView.cellWidth - 15
- anchors.horizontalCenter: parent.horizontalCenter
- text: model.filePath ? model.filePath.split("/").pop() : ""
- color: "white"
- font.pixelSize: 9
- elide: Text.ElideMiddle
- horizontalAlignment: Text.AlignHCenter
- }
- }
- }
- // 缺图占位提示
- Text {
- anchors.centerIn: parent
- visible: model.filePath === ""
- text: "缺图"
- color: "#999"
- font.pixelSize: 11
- }
- // 序号角标(左上角,右上角为1)
- Rectangle {
- x: 0
- y: 0
- width: 18
- height: 18
- color: Qt.rgba(0, 0, 0, 0.55)
- radius: 9
- visible: model.serial !== undefined && model.serial >= 1
- Text {
- anchors.centerIn: parent
- text: model.serial
- color: "white"
- font.bold: true
- font.pixelSize: 11
- }
- }
- }
- // 选择标记(右侧勾选)
- Rectangle {
- x: parent.width - width
- y: 0
- width: 18
- height: 18
- color: "#28a779"
- radius: 9
- visible: model.selected // 只对已选中的图片显示勾选标记
- Text {
- anchors.centerIn: parent
- text: "✓"
- color: "white"
- font.bold: true
- }
- }
- // MouseArea(在外层Rectangle外面,使用delegate Item作为parent)
- MouseArea {
- anchors.fill: parent
- enabled: model.filePath !== ""
- onClicked: {
- if (!model.filePath) return
- // 视频流文件直接打开播放
- if (isVideo) {
- openVideo(model.filePath)
- return
- }
- if (isSelecting) {
- toggleImageSelection(model.filePath)
- } else {
- console.log("Selected image:", model.filePath)
- showFullscreen(model.filePath)
- }
- }
- onPressAndHold: {
- if (!model.filePath) return
- if (isVideo) return
- toggleImageSelection(model.filePath)
- }
- }
- }
- }
- // 归档树形列表 (30%)
- ScrollView {//滚动容器
- SplitView.preferredWidth: parent.width * 0.3
- SplitView.minimumWidth: 200
- clip: true
- // AppText {
- // text: "图片按年月日归档"
- // }
- TreeView {
- id: archiveTreeView
- model: treeModel
- anchors.fill: parent
- selectionModel: ItemSelectionModel {} // 处理选择状态
- selectionBehavior: TreeView.SelectRows // 整行选择
- delegate: Item {
- id: root
- implicitWidth: archiveTreeView.width
- implicitHeight: 40
- // 必须声明的 required 属性(由 TreeView 自动填充)
- required property TreeView treeView
- required property var model
- //其他列中的delegate Item将将此属性设置为,并将显示模型中其余列的数据(通常不缩进)。
- required property bool isTreeNode
- //绘制的model Item是否在视图中展开
- required property bool expanded
- //绘制的model Item是否在模型中有子项
- required property int hasChildren
- //包含delegate绘制的model Item的深度。model Item的深度与其在模型中的祖先数量相同
- required property int depth
- required property int type
- Rectangle {
- // width: parent.width
- // height: parent.height
- Row {
- spacing: 8
- anchors.leftMargin: 10 + depth * 20
- // 展开/折叠指示器
- Text {
- id: indicator
- visible: root.type===0 || root.type === 1 || root.type===2 || root.type===3 || root.type===4 || root.type===5
- text: root.expanded ? "▼" : "▶"
- color: "#666"
- anchors.verticalCenter: parent.verticalCenter
- //anchors.verticalCenter: parent.verticalCenter
- // --- 添加旋转动画 ---
- RotationAnimation on rotation {
- id: rotationAnim
- duration: 200
- easing.type: Easing.InOutQuad
- }
- // 监听 expanded 属性变化以触发动画
- onVisibleChanged: {
- if(visible) {
- rotation = root.expanded ? 90 : 0; // 初始角度
- }
- }
- Connections {
- target: root
- function onExpandedChanged() {
- if(indicator.visible) {
- rotationAnim.to = root.expanded ? 90 : 0;
- rotationAnim.restart();
- }
- }
- }
- }
- TapHandler{
- onSingleTapped: {
- if(root.type===6){
- // 原始视频流文件(.rawv):直接打开播放
- if (rawPlayer.isRawVideo(model.path)) {
- openVideo(model.path)
- return
- }
- imageListModel.clear()
- imageListModel.append({filePath: model.path})
- }else{
- let index = treeView.model.index(row, column)
- console.log("row,column",row,column)
- treeModel.loadChildren(index); // 同步加载子节点(阻塞直到完成)
- treeView.toggleExpanded(row); // 显式展开(确保视图刷新)
- }
- console.log("root.type:", root.type)
- }
- onLongPressed: {
- console.log("长按:", root.type)
- if (model.type===4 || model.type===5) {
- // 加载文件夹内容到图片区(支持相册和位置文件夹)
- loadFolderContents(model.path)
- }
- }
- }
- // 名称
- Text {
- text: {
- if(root.type===5||root.type===4||root.type===3||root.type===2||root.type===1||root.type===0){
- return model.name + " (" + model.childCount + ")"
- }
- return model.name
- }
- color: (root.type===0 || root.type === 1 || root.type===2 || root.type===3 || root.type===4 || root.type===5) ? "#333" : "#666"
- font.bold: root.type===0 || root.type === 1 || root.type===2 || root.type===3 || root.type===4 || root.type===5
- anchors.verticalCenter: parent.verticalCenter
- elide: Text.ElideRight
- width: archiveTreeView.width// - 50 - depth * 20
- }
- }
- }
- }
- }
- }
- }
- Connections {
- target: treeModel
- function onLoadingChanged() {
- // C++ 里的 loadRootFolders() 跑完之后会把 loading 设回 false
- if (!treeModel.loading && !rootExpanded) {
- console.log("TreeModel 加载完成,展开根节点")
- isLoading = false
- // 第一个可见行是第一个年份节点(root 是不可见的内部节点)
- var yearIndex = treeModel.index(0, 0)
- if (yearIndex.valid) {
- // 让 C++ 把该年份下面的 月/日/相册/图片 全部加载好
- treeModel.loadChildren(yearIndex)
- // 展开第 0 行(Qt.labs.treeview 的 TreeView 用 row 作为参数)
- archiveTreeView.expand(0)
- rootExpanded = true
- }
- }
- }
- }
- // 长按文件夹:按蛇形网格(8列x4行=32格,右上角为1)展示图片,默认显示锐化图
- function loadFolderContents(folderPath) {
- var bySerial = {}
- var byBase = {}
- var stack = [folderPath]
- while (stack.length > 0) {
- var currentPath = stack.pop()
- var files = treeModel.getFolderContents(currentPath)
- for (var i = 0; i < files.length; i++) {
- if (files[i].isFolder) {
- stack.push(files[i].path)
- } else {
- collectImageFile(files[i].path, bySerial, byBase)
- }
- }
- }
- rebuildImageGrid(bySerial, byBase)
- }
- // 解析图片文件名:有序号(1-32)归入 bySerial 蛇形网格,无序号归入 byBase 按基础名(时间戳)排序
- function collectImageFile(path, bySerial, byBase) {
- var base = path.slice(path.lastIndexOf('/') + 1)
- var dot = base.lastIndexOf('.')
- var stem = dot > 0 ? base.slice(0, dot) : base
- var isSharp = stem.indexOf('_sharp_') >= 0
- // 去掉 sharp 后缀得到基础名(用于原图/锐化配对)
- var key = isSharp ? stem.replace('_sharp', '') : stem
- var us = key.lastIndexOf('_')
- var serial = us >= 0 ? parseInt(key.slice(us + 1)) : 0
- if (serial >= 1 && serial <= 32) {
- if (!bySerial[serial]) bySerial[serial] = {orig: "", sharp: ""}
- if (isSharp) bySerial[serial].sharp = path
- else bySerial[serial].orig = path
- } else {
- // 无序号:按基础名(通常含时间戳)配对,用于按时间先后排序
- if (!byBase[key]) byBase[key] = {orig: "", sharp: "", name: key}
- if (isSharp) byBase[key].sharp = path
- else byBase[key].orig = path
- }
- }
- // 按蛇形显示顺序重建网格(模型顺序=画面从左到右、从上到下),无序号图片按时间先后追加在末尾
- function rebuildImageGrid(bySerial, byBase) {
- imageListModel.clear()
- var order = [
- 32,25,24,17,16,9,8,1,
- 31,26,23,18,15,10,7,2,
- 30,27,22,19,14,11,6,3,
- 29,28,21,20,13,12,5,4
- ]
- for (var i = 0; i < order.length; i++) {
- var s = order[i]
- var e = bySerial[s] || {orig: "", sharp: ""}
- var fp = showSharp ? (e.sharp || e.orig) : (e.orig || e.sharp)
- imageListModel.append({filePath: fp, serial: s, origPath: e.orig, sharpPath: e.sharp, selected: false})
- }
- // 无序号图片:按基础名(时间戳)先后排序追加
- var names = []
- for (var k in byBase) names.push(k)
- names.sort()
- for (var j = 0; j < names.length; j++) {
- var be = byBase[names[j]]
- var bfp = showSharp ? (be.sharp || be.orig) : (be.orig || be.sharp)
- imageListModel.append({filePath: bfp, serial: -1, origPath: be.orig, sharpPath: be.sharp, selected: false})
- }
- }
- // 切换显示 原图/锐化图
- function setShowSharp(v) {
- showSharp = v
- for (var i = 0; i < imageListModel.count; i++) {
- var it = imageListModel.get(i)
- var fp = showSharp ? (it.sharpPath || it.origPath) : (it.origPath || it.sharpPath)
- imageListModel.setProperty(i, "filePath", fp)
- }
- }
- function loadRootDirectory() {
- if(isLoading) return
- rootExpanded = false
- console.log("开始加载根目录...")
- // 触发 C++ 里的 resetModel(),异步加载年份目录
- treeModel.resetModel()
- }
- Component.onCompleted: {
- loadRootDirectory()
- }
- }
|