|
|
@@ -14,6 +14,7 @@ AppPage {
|
|
|
property var selectedImages: []
|
|
|
property bool isSelecting: false
|
|
|
property bool isFusing: false
|
|
|
+ property bool showSharp: true
|
|
|
|
|
|
// 融合按钮
|
|
|
AppButton {
|
|
|
@@ -54,6 +55,22 @@ AppPage {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 原图/锐化切换按钮
|
|
|
+ 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
|
|
|
@@ -119,73 +136,80 @@ AppPage {
|
|
|
color: "#CC000000"
|
|
|
}
|
|
|
|
|
|
- Flickable {
|
|
|
- id: flick
|
|
|
+ Item {
|
|
|
+ id: viewport
|
|
|
anchors.fill: parent
|
|
|
clip: true
|
|
|
- boundsBehavior: Flickable.DragAndOvershootBounds
|
|
|
|
|
|
Image {
|
|
|
id: image
|
|
|
- anchors.fill: parent
|
|
|
+ x: 0
|
|
|
+ y: 0
|
|
|
+ width: Math.min(implicitWidth, viewport.width)
|
|
|
+ height: Math.min(implicitHeight, viewport.height)
|
|
|
asynchronous: true
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
- width: Math.min(implicitWidth, parent.width)
|
|
|
- height: Math.min(implicitHeight, parent.height)
|
|
|
- property real scale: 1.0
|
|
|
+ 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 {
|
|
|
- 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 {
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- 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)
|
|
|
+ // 鼠标滚轮缩放
|
|
|
+ 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)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -236,8 +260,50 @@ AppPage {
|
|
|
|
|
|
function showFullscreen(path) {
|
|
|
image.source = "file://" + path
|
|
|
- fullscreenPopup.open()
|
|
|
+ // 等待图片加载出尺寸后再居中
|
|
|
resetTransform()
|
|
|
+ fullscreenPopup.open()
|
|
|
+ }
|
|
|
+
|
|
|
+ // 重置缩放为初始大小并居中
|
|
|
+ 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()
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -250,8 +316,8 @@ AppPage {
|
|
|
id: imageGridView
|
|
|
SplitView.preferredWidth: parent.width * 0.7
|
|
|
clip: true
|
|
|
- cellWidth: 200
|
|
|
- cellHeight: 200
|
|
|
+ cellWidth: Math.max(45, Math.floor((imageGridView.width - 10) / 8))
|
|
|
+ cellHeight: cellWidth
|
|
|
|
|
|
model: ListModel { id: imageListModel }
|
|
|
|
|
|
@@ -261,39 +327,69 @@ AppPage {
|
|
|
|
|
|
Rectangle {
|
|
|
anchors.fill: parent
|
|
|
- anchors.margins: 5
|
|
|
+ anchors.margins: 2
|
|
|
color: model.selected ? "#28a779" : "transparent"
|
|
|
- border.color: model.selected ? "#28a779" : "#eee"
|
|
|
- border.width: model.selected ? 3 : 1
|
|
|
- radius: 4
|
|
|
+ border.color: model.selected ? "#28a779" : (model.filePath ? "#eee" : "#bbb")
|
|
|
+ border.width: 1
|
|
|
+ radius: 3
|
|
|
|
|
|
+ // 有图片时加载缩略图,缺图时显示灰色占位
|
|
|
Image {
|
|
|
anchors.fill: parent
|
|
|
anchors.margins: 2
|
|
|
- source: "file://" + filePath
|
|
|
+ source: model.filePath ? "file://" + model.filePath : ""
|
|
|
asynchronous: true
|
|
|
sourceSize.width: 200
|
|
|
sourceSize.height: 200
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
cache: true
|
|
|
+ visible: model.filePath !== ""
|
|
|
|
|
|
BusyIndicator {
|
|
|
anchors.centerIn: parent
|
|
|
running: parent.status === Image.Loading
|
|
|
- width: 32
|
|
|
- height: 32
|
|
|
+ width: 24
|
|
|
+ height: 24
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 缺图占位提示
|
|
|
+ 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
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 选择标记(使用绝对定位代替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
|
|
|
+ x: parent.width - width
|
|
|
+ y: 0
|
|
|
+ width: 18
|
|
|
+ height: 18
|
|
|
+ color: "#28a779"
|
|
|
+ radius: 9
|
|
|
visible: model.selected // 只对已选中的图片显示勾选标记
|
|
|
|
|
|
Text {
|
|
|
@@ -307,15 +403,18 @@ AppPage {
|
|
|
// MouseArea(在外层Rectangle外面,使用delegate Item作为parent)
|
|
|
MouseArea {
|
|
|
anchors.fill: parent
|
|
|
+ enabled: model.filePath !== ""
|
|
|
onClicked: {
|
|
|
+ if (!model.filePath) return
|
|
|
if (isSelecting) {
|
|
|
toggleImageSelection(model.filePath)
|
|
|
} else {
|
|
|
- console.log("Selected image:", filePath)
|
|
|
- showFullscreen(filePath)
|
|
|
+ console.log("Selected image:", model.filePath)
|
|
|
+ showFullscreen(model.filePath)
|
|
|
}
|
|
|
}
|
|
|
onPressAndHold: {
|
|
|
+ if (!model.filePath) return
|
|
|
toggleImageSelection(model.filePath)
|
|
|
}
|
|
|
}
|
|
|
@@ -462,24 +561,81 @@ AppPage {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // PhotoArchivePage.qml
|
|
|
+ // 长按文件夹:按蛇形网格(8列x4行=32格,右上角为1)展示图片,默认显示锐化图
|
|
|
function loadFolderContents(folderPath) {
|
|
|
- imageListModel.clear()
|
|
|
-
|
|
|
+ var bySerial = {}
|
|
|
+ var byBase = {}
|
|
|
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})
|
|
|
+ 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() {
|