| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- import Felgo
- import QtQuick
- import QtQuick.Controls
- import QtQuick.Layouts
- import "../controls"
- import "../common"
- 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
- // 融合按钮
- 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, "张图片")
- opencvFunc.fuseImagesAsync(selectedImages)
- }
- }
- }
- // 融合加载动画
- BusyIndicator {
- id: fuseBusyIndicator
- anchors.bottom: parent.bottom
- anchors.right: parent.right
- anchors.margins: 20
- visible: isFusing
- width: 60
- height: 60
- z: 100
- }
- // 取消选择按钮
- 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()
- }
- }
- // 连接融合完成信号
- Connections {
- target: opencvFunc
- function onFuseFinished(resultPath) {
- isFusing = false
- if (resultPath) {
- console.log("融合完成:", resultPath)
- // 显示融合结果
- imageListModel.append({filePath: resultPath, isFused: true, selected: false})
- // 清除选择
- clearSelection()
- } else {
- console.error("融合失败")
- }
- }
- }
- 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"
- }
- Flickable {
- id: flick
- anchors.fill: parent
- clip: true
- boundsBehavior: Flickable.DragAndOvershootBounds
- Image {
- id: image
- anchors.fill: parent
- asynchronous: true
- fillMode: Image.PreserveAspectFit
- width: Math.min(implicitWidth, parent.width)
- height: Math.min(implicitHeight, parent.height)
- property real scale: 1.0
- }
- PinchArea {
- anchors.fill: parent
- pinch.target: image
- pinch.minimumRotation: -360
- pinch.maximumRotation: 360
- pinch.minimumScale: 0.1
- pinch.maximumScale: 10
- pinch.dragAxis: Pinch.XAndYAxis
- // MouseArea handles drag gestures
- MouseArea {
- anchors.fill: parent
- drag.target: image
- drag.minimumX: -image.width
- drag.maximumX: fullscreenPopup.width
- drag.minimumY: -image.height
- drag.maximumY: fullscreenPopup.height
- }
- onPinchStarted: {
- // 保存当前缩放中心和比例
- pinchStartScale = image.scale
- pinchStartCenter = Qt.point(pinch.center.x, pinch.center.y)
- }
- onPinchUpdated: {
- // 计算新的缩放比例
- var newScale = pinchStartScale * pinch.scale
- // 限制缩放范围
- newScale = Math.max(image.minScale, Math.min(image.maxScale, newScale))
- // 应用缩放
- image.scale = newScale
- // 计算缩放中心点相对于图片的坐标
- var imageCenterX = (pinch.center.x - flick.contentX) / image.scale
- var imageCenterY = (pinch.center.y - flick.contentY) / image.scale
- // 调整内容位置以保持缩放中心
- flick.contentX = pinch.center.x - imageCenterX * image.scale
- flick.contentY = pinch.center.y - imageCenterY * image.scale
- }
- onPinchFinished: {
- flick.returnToBounds()
- }
- property real pinchStartScale: 1.0
- property point pinchStartCenter: Qt.point(0, 0)
- }
- }
- // 关闭按钮
- 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
- fullscreenPopup.open()
- resetTransform()
- }
- SplitView {
- anchors.fill: parent
- orientation: Qt.Horizontal
- // 图片显示区域 (70%)
- GridView {
- id: imageGridView
- SplitView.preferredWidth: parent.width * 0.7
- clip: true
- cellWidth: 200
- cellHeight: 200
- model: ListModel { id: imageListModel }
- delegate: Item {
- width: imageGridView.cellWidth - 5
- height: imageGridView.cellHeight - 5
- Rectangle {
- anchors.fill: parent
- anchors.margins: 5
- color: model.selected ? "#28a779" : "transparent"
- border.color: model.selected ? "#28a779" : "#eee"
- border.width: model.selected ? 3 : 1
- radius: 4
- Image {
- anchors.fill: parent
- anchors.margins: 2
- source: "file://" + filePath
- asynchronous: true
- sourceSize.width: 200
- sourceSize.height: 200
- fillMode: Image.PreserveAspectFit
- cache: true
- BusyIndicator {
- anchors.centerIn: parent
- running: parent.status === Image.Loading
- width: 32
- height: 32
- }
- }
- }
- // 选择标记(使用绝对定位代替anchors.topRight)
- Rectangle {
- x: parent.width - width - 7
- y: 7
- width: 24
- height: 24
- color: model.selected ? "#28a779" : "rgba(0,0,0,0.5)"
- radius: 12
- visible: model.selected // 只对已选中的图片显示勾选标记
- Text {
- anchors.centerIn: parent
- text: "✓"
- color: "white"
- font.bold: true
- }
- }
- // MouseArea(在外层Rectangle外面,使用delegate Item作为parent)
- MouseArea {
- anchors.fill: parent
- onClicked: {
- if (isSelecting) {
- toggleImageSelection(model.filePath)
- } else {
- console.log("Selected image:", filePath)
- showFullscreen(filePath)
- }
- }
- onPressAndHold: {
- 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){
- 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
- }
- }
- }
- }
- // PhotoArchivePage.qml
- function loadFolderContents(folderPath) {
- imageListModel.clear()
- var stack = [folderPath]
- while (stack.length > 0) {
- var currentPath = stack.pop()
- var dir = Qt.createQmlObject('import QtQuick 2.0; QtObject {}', parent)
- var files = treeModel.getFolderContents(currentPath)
- for (var i = 0; i < files.length; i++) {
- if (files[i].isFolder) {
- stack.push(files[i].path)
- } else {
- imageListModel.append({filePath: files[i].path, selected: false})
- }
- }
- }
- }
- function loadRootDirectory() {
- if(isLoading) return
- rootExpanded = false
- console.log("开始加载根目录...")
- // 触发 C++ 里的 resetModel(),异步加载年份目录
- treeModel.resetModel()
- }
- Component.onCompleted: {
- loadRootDirectory()
- }
- }
|