PhotostitcherPage.qml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. import Felgo
  2. import QtQuick
  3. import QtQuick.Controls
  4. import QtQuick.Layouts
  5. import "../controls"
  6. import "../common"
  7. AppPage {
  8. id: photoArchivePage
  9. navigationBarHidden: true
  10. backgroundColor: app.theme_backgroundColor
  11. property bool isLoading: false
  12. property bool rootExpanded: false
  13. // 全屏查看组件
  14. Popup {
  15. id: fullscreenPopup
  16. width: parent.width
  17. height: parent.height
  18. modal: true
  19. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
  20. background: Rectangle {
  21. color: "#CC000000"
  22. }
  23. Flickable {
  24. id: flick
  25. anchors.fill: parent
  26. clip: true
  27. boundsBehavior: Flickable.DragAndOvershootBounds
  28. Image {
  29. id: image
  30. anchors.fill: parent
  31. asynchronous: true
  32. fillMode: Image.PreserveAspectFit
  33. width: Math.min(implicitWidth, parent.width)
  34. height: Math.min(implicitHeight, parent.height)
  35. property real scale: 1.0
  36. }
  37. PinchArea {
  38. anchors.fill: parent
  39. pinch.target: image
  40. pinch.minimumRotation: -360
  41. pinch.maximumRotation: 360
  42. pinch.minimumScale: 0.1
  43. pinch.maximumScale: 10
  44. pinch.dragAxis: Pinch.XAndYAxis
  45. // MouseArea handles drag gestures
  46. MouseArea {
  47. anchors.fill: parent
  48. drag.target: image
  49. drag.minimumX: -image.width
  50. drag.maximumX: fullscreenPopup.width
  51. drag.minimumY: -image.height
  52. drag.maximumY: fullscreenPopup.height
  53. }
  54. onPinchStarted: {
  55. // 保存当前缩放中心和比例
  56. pinchStartScale = image.scale
  57. pinchStartCenter = Qt.point(pinch.center.x, pinch.center.y)
  58. }
  59. onPinchUpdated: {
  60. // 计算新的缩放比例
  61. var newScale = pinchStartScale * pinch.scale
  62. // 限制缩放范围
  63. newScale = Math.max(image.minScale, Math.min(image.maxScale, newScale))
  64. // 应用缩放
  65. image.scale = newScale
  66. // 计算缩放中心点相对于图片的坐标
  67. var imageCenterX = (pinch.center.x - flick.contentX) / image.scale
  68. var imageCenterY = (pinch.center.y - flick.contentY) / image.scale
  69. // 调整内容位置以保持缩放中心
  70. flick.contentX = pinch.center.x - imageCenterX * image.scale
  71. flick.contentY = pinch.center.y - imageCenterY * image.scale
  72. }
  73. onPinchFinished: {
  74. flick.returnToBounds()
  75. }
  76. property real pinchStartScale: 1.0
  77. property point pinchStartCenter: Qt.point(0, 0)
  78. }
  79. }
  80. // 关闭按钮
  81. RoundButton {
  82. id: closeBtn
  83. text: "关闭" // 设置按钮文本
  84. radius: height/2 // 确保圆形
  85. // 基础样式
  86. width: 80
  87. height: 40
  88. font.pixelSize: 14
  89. font.bold: true
  90. // 颜色配置
  91. palette {
  92. button: "#e74c3c" // 背景色
  93. buttonText: "white" // 文字颜色
  94. }
  95. // 点击效果
  96. background: Rectangle {
  97. radius: closeBtn.radius
  98. color: closeBtn.palette.button
  99. border.color: Qt.darker(color, 1.2)
  100. border.width: 1
  101. Rectangle {
  102. anchors.fill: parent
  103. radius: parent.radius
  104. color: "transparent"
  105. border.color: Qt.lighter(parent.color, 1.2)
  106. border.width: closeBtn.down ? 2 : 0
  107. opacity: closeBtn.down ? 0.5 : 0
  108. Behavior on opacity { NumberAnimation { duration: 100 } }
  109. }
  110. }
  111. // 点击事件
  112. onClicked: {
  113. console.log("关闭操作触发")
  114. fullscreenPopup.close()
  115. // 添加具体关闭逻辑
  116. }
  117. }
  118. }
  119. function showFullscreen(path) {
  120. image.source = "file://" + path
  121. fullscreenPopup.open()
  122. }
  123. SplitView {
  124. anchors.fill: parent
  125. orientation: Qt.Horizontal
  126. // 图片显示区域 (70%)
  127. GridView {
  128. id: imageGridView
  129. SplitView.preferredWidth: parent.width * 0.7
  130. clip: true
  131. cellWidth: 200
  132. cellHeight: 200
  133. model: ListModel { id: imageListModel }
  134. delegate: Item {
  135. width: imageGridView.cellWidth - 5
  136. height: imageGridView.cellHeight - 5
  137. Rectangle {
  138. anchors.fill: parent
  139. anchors.margins: 5
  140. color: "transparent"
  141. border.color: "#eee"
  142. radius: 4
  143. Image {
  144. anchors.fill: parent
  145. anchors.margins: 2
  146. source: "file://" + filePath
  147. asynchronous: true
  148. sourceSize.width: 200
  149. sourceSize.height: 200
  150. fillMode: Image.PreserveAspectFit
  151. cache: true
  152. BusyIndicator {
  153. anchors.centerIn: parent
  154. running: parent.status === Image.Loading
  155. width: 32
  156. height: 32
  157. }
  158. }
  159. MouseArea {
  160. anchors.fill: parent
  161. onClicked: {
  162. // 处理图片点击
  163. console.log("Selected image:", filePath)
  164. // 显示大图
  165. showFullscreen(filePath)
  166. }
  167. }
  168. }
  169. }
  170. }
  171. // 归档树形列表 (30%)
  172. ScrollView {//滚动容器
  173. SplitView.preferredWidth: parent.width * 0.3
  174. SplitView.minimumWidth: 200
  175. clip: true
  176. // AppText {
  177. // text: "图片按年月日归档"
  178. // }
  179. TreeView {
  180. id: archiveTreeView
  181. model: treeModel
  182. anchors.fill: parent
  183. selectionModel: ItemSelectionModel {} // 处理选择状态
  184. selectionBehavior: TreeView.SelectRows // 整行选择
  185. delegate: Item {
  186. id: root
  187. implicitWidth: archiveTreeView.width
  188. implicitHeight: 40
  189. // 必须声明的 required 属性(由 TreeView 自动填充)
  190. required property TreeView treeView
  191. required property var model
  192. //其他列中的delegate Item将将此属性设置为,并将显示模型中其余列的数据(通常不缩进)。
  193. required property bool isTreeNode
  194. //绘制的model Item是否在视图中展开
  195. required property bool expanded
  196. //绘制的model Item是否在模型中有子项
  197. required property int hasChildren
  198. //包含delegate绘制的model Item的深度。model Item的深度与其在模型中的祖先数量相同
  199. required property int depth
  200. required property int type
  201. Rectangle {
  202. // width: parent.width
  203. // height: parent.height
  204. Row {
  205. spacing: 8
  206. anchors.leftMargin: 10 + depth * 20
  207. // 展开/折叠指示器
  208. Text {
  209. id: indicator
  210. visible: root.type===0 || root.type === 1 || root.type===2 || root.type===3 || root.type===4
  211. text: root.expanded ? "▼" : "▶"
  212. color: "#666"
  213. anchors.verticalCenter: parent.verticalCenter
  214. //anchors.verticalCenter: parent.verticalCenter
  215. // --- 添加旋转动画 ---
  216. RotationAnimation on rotation {
  217. id: rotationAnim
  218. duration: 200
  219. easing.type: Easing.InOutQuad
  220. }
  221. // 监听 expanded 属性变化以触发动画
  222. onVisibleChanged: {
  223. if(visible) {
  224. rotation = root.expanded ? 90 : 0; // 初始角度
  225. }
  226. }
  227. Connections {
  228. target: root
  229. function onExpandedChanged() {
  230. if(indicator.visible) {
  231. rotationAnim.to = root.expanded ? 90 : 0;
  232. rotationAnim.restart();
  233. }
  234. }
  235. }
  236. }
  237. TapHandler{
  238. onSingleTapped: {
  239. if(root.type===5){
  240. imageListModel.clear()
  241. imageListModel.append({filePath: model.path})
  242. }else{
  243. let index = treeView.model.index(row, column)
  244. console.log("row,column",row,column)
  245. // treeModel.loadChildren(index)
  246. // treeView.toggleExpanded(row)
  247. // 若未展开且有子节点,则加载并展开
  248. treeModel.loadChildren(index); // 同步加载子节点(阻塞直到完成)
  249. treeView.toggleExpanded(row); // 显式展开(确保视图刷新)
  250. }
  251. console.log("root.type:", root.type)
  252. }
  253. onLongPressed: {
  254. console.log("长按:", root.type)
  255. if (model.type===4) {
  256. // 加载文件夹内容到图片区
  257. loadFolderContents(model.path)
  258. }
  259. }
  260. }
  261. // 名称
  262. Text {
  263. text: {
  264. if(root.type===4||root.type===3||root.type===2||root.type===1||root.type===0){
  265. return model.name + " (" + model.childCount + ")"
  266. }
  267. return model.name
  268. }
  269. color: (root.type===0 || root.type === 1 || root.type===2 || root.type===3 || root.type===4) ? "#333" : "#666"
  270. font.bold: root.type===0 || root.type === 1 || root.type===2 || root.type===3 || root.type===4
  271. anchors.verticalCenter: parent.verticalCenter
  272. elide: Text.ElideRight
  273. width: archiveTreeView.width// - 50 - depth * 20
  274. }
  275. }
  276. }
  277. }
  278. }
  279. }
  280. }
  281. Connections {
  282. target: treeModel
  283. function onLoadingChanged() {
  284. // C++ 里的 loadRootFolders() 跑完之后会把 loading 设回 false
  285. if (!treeModel.loading && !rootExpanded) {
  286. console.log("TreeModel 加载完成,展开根节点")
  287. isLoading = false
  288. // 第一个可见行是第一个年份节点(root 是不可见的内部节点)
  289. var yearIndex = treeModel.index(0, 0)
  290. if (yearIndex.valid) {
  291. // 让 C++ 把该年份下面的 月/日/相册/图片 全部加载好
  292. treeModel.loadChildren(yearIndex)
  293. // 展开第 0 行(Qt.labs.treeview 的 TreeView 用 row 作为参数)
  294. archiveTreeView.expand(0)
  295. rootExpanded = true
  296. }
  297. }
  298. }
  299. }
  300. // PhotoArchivePage.qml
  301. function loadFolderContents(folderPath) {
  302. imageListModel.clear()
  303. var stack = [folderPath]
  304. while (stack.length > 0) {
  305. var currentPath = stack.pop()
  306. var dir = Qt.createQmlObject('import QtQuick 2.0; QtObject {}', parent)
  307. var files = treeModel.getFolderContents(currentPath)
  308. for (var i = 0; i < files.length; i++) {
  309. if (files[i].isFolder) {
  310. stack.push(files[i].path)
  311. } else {
  312. imageListModel.append({filePath: files[i].path})
  313. }
  314. }
  315. }
  316. }
  317. function loadRootDirectory() {
  318. if(isLoading) return
  319. rootExpanded = false
  320. console.log("开始加载根目录...")
  321. // 触发 C++ 里的 resetModel(),异步加载年份目录
  322. treeModel.resetModel()
  323. }
  324. Component.onCompleted: {
  325. loadRootDirectory()
  326. }
  327. }