PhotostitcherPage.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. import Felgo
  2. import QtQuick
  3. import QtQuick.Controls
  4. import QtQuick.Layouts
  5. import "../controls"
  6. import "../common"
  7. import PhotoViewer 1.0
  8. AppPage {
  9. id: photoArchivePage
  10. navigationBarHidden: true
  11. backgroundColor: app.theme_backgroundColor
  12. property bool isLoading: false
  13. TreeModel {
  14. id: treeModel
  15. }
  16. // 全屏查看组件
  17. Popup {
  18. id: fullscreenPopup
  19. width: parent.width
  20. height: parent.height
  21. modal: true
  22. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
  23. background: Rectangle {
  24. color: "#CC000000"
  25. }
  26. Flickable {
  27. id: flick
  28. anchors.fill: parent
  29. contentWidth: imgFull.width * imgFull.scale
  30. contentHeight: imgFull.height * imgFull.scale
  31. interactive: contentWidth > width || contentHeight > height
  32. Image {
  33. id: imgFull
  34. x: (flick.width - width * scale)/2
  35. y: (flick.height - height * scale)/2
  36. sourceSize.width: 4096
  37. asynchronous: true
  38. fillMode: Image.PreserveAspectFit
  39. // 自动计算初始缩放比例
  40. function calculateScale() {
  41. const widthScale = flick.width / implicitWidth
  42. const heightScale = flick.height / implicitHeight
  43. initScale = Math.min(widthScale, heightScale) * 0.9
  44. scale = initScale
  45. }
  46. onStatusChanged: if(status === Image.Ready) calculateScale()
  47. }
  48. // 手势缩放
  49. PinchArea {
  50. anchors.fill: parent
  51. pinch.target: imgFull
  52. pinch.minimumScale: imgFull.minScale
  53. pinch.maximumScale: imgFull.maxScale
  54. onPinchFinished: flick.returnToBounds()
  55. }
  56. // 双击缩放
  57. MouseArea {
  58. anchors.fill: parent
  59. onDoubleClicked: {
  60. if(imgFull.scale === imgFull.initScale) {
  61. imgFull.scale = imgFull.maxScale
  62. } else {
  63. imgFull.scale = imgFull.initScale
  64. }
  65. flick.returnToBounds()
  66. }
  67. }
  68. }
  69. // 关闭按钮
  70. RoundButton {
  71. id: closeBtn
  72. text: "关闭" // 设置按钮文本
  73. radius: height/2 // 确保圆形
  74. // 基础样式
  75. width: 80
  76. height: 40
  77. font.pixelSize: 14
  78. font.bold: true
  79. // 颜色配置
  80. palette {
  81. button: "#e74c3c" // 背景色
  82. buttonText: "white" // 文字颜色
  83. }
  84. // 点击效果
  85. background: Rectangle {
  86. radius: closeBtn.radius
  87. color: closeBtn.palette.button
  88. border.color: Qt.darker(color, 1.2)
  89. border.width: 1
  90. Rectangle {
  91. anchors.fill: parent
  92. radius: parent.radius
  93. color: "transparent"
  94. border.color: Qt.lighter(parent.color, 1.2)
  95. border.width: closeBtn.down ? 2 : 0
  96. opacity: closeBtn.down ? 0.5 : 0
  97. Behavior on opacity { NumberAnimation { duration: 100 } }
  98. }
  99. }
  100. // 点击事件
  101. onClicked: {
  102. console.log("关闭操作触发")
  103. fullscreenPopup.close()
  104. // 添加具体关闭逻辑
  105. }
  106. }
  107. }
  108. function showFullscreen(path) {
  109. imgFull.source = "file://" + path
  110. fullscreenPopup.open()
  111. }
  112. SplitView {
  113. anchors.fill: parent
  114. orientation: Qt.Horizontal
  115. // 图片显示区域 (70%)
  116. GridView {
  117. id: imageGridView
  118. SplitView.preferredWidth: parent.width * 0.7
  119. clip: true
  120. cellWidth: 200
  121. cellHeight: 200
  122. model: ListModel { id: imageListModel }
  123. delegate: Item {
  124. width: imageGridView.cellWidth - 5
  125. height: imageGridView.cellHeight - 5
  126. Rectangle {
  127. anchors.fill: parent
  128. anchors.margins: 5
  129. color: "transparent"
  130. border.color: "#eee"
  131. radius: 4
  132. Image {
  133. anchors.fill: parent
  134. anchors.margins: 2
  135. source: "file://" + filePath
  136. asynchronous: true
  137. sourceSize.width: 200
  138. sourceSize.height: 200
  139. fillMode: Image.PreserveAspectFit
  140. cache: true
  141. BusyIndicator {
  142. anchors.centerIn: parent
  143. running: parent.status === Image.Loading
  144. width: 32
  145. height: 32
  146. }
  147. }
  148. MouseArea {
  149. anchors.fill: parent
  150. onClicked: {
  151. // 处理图片点击
  152. console.log("Selected image:", filePath)
  153. // 显示大图
  154. showFullscreen(filePath)
  155. }
  156. }
  157. }
  158. }
  159. }
  160. // 归档树形列表 (30%)
  161. ScrollView {
  162. SplitView.preferredWidth: parent.width * 0.3
  163. SplitView.minimumWidth: 200
  164. clip: true
  165. TreeView {
  166. id: archiveTreeView
  167. model: treeModel
  168. anchors.fill: parent
  169. selectionModel: ItemSelectionModel {} // 处理选择状态
  170. selectionBehavior: TreeView.SelectRows // 整行选择
  171. delegate: Item {
  172. implicitWidth: archiveTreeView.width
  173. implicitHeight: 40
  174. required property TreeView treeView
  175. required property var model
  176. required property bool expanded //是否展开
  177. required property bool isFolder //是否有子节点
  178. required property string name //名字
  179. required property string path //路径
  180. required property int depth //深度层级
  181. required property int row //当前列
  182. required property int column //行
  183. // 自动生成正确的模型索引
  184. // ✅ 获取正确的模型索引
  185. //property var modelIndex: treeView.model.index(row, 0)
  186. // Rectangle {
  187. // visible: model.changed
  188. // width: 8
  189. // height: 8
  190. // radius: 4
  191. // color: "red"
  192. // anchors.right: parent.right
  193. // anchors.verticalCenter: parent.verticalCenter
  194. // SequentialAnimation on opacity {
  195. // loops: Animation.Infinite
  196. // NumberAnimation { from: 1; to: 0.3; duration: 1000 }
  197. // NumberAnimation { from: 0.3; to: 1; duration: 1000 }
  198. // }
  199. // }
  200. Rectangle {
  201. width: parent.width
  202. height: parent.height
  203. //color: mouseArea.containsMouse ? "#f0f0f0" : "transparent"
  204. Row {
  205. spacing: 8
  206. // anchors.verticalCenter: parent.verticalCenter
  207. // anchors.left: parent.left
  208. anchors.leftMargin: 10 + depth * 20
  209. // 展开/折叠指示器
  210. Text {
  211. visible: model.isFolder
  212. text: expanded ? "▼" : "▶"
  213. color: "#666"
  214. anchors.verticalCenter: parent.verticalCenter
  215. //anchors.verticalCenter: parent.verticalCenter
  216. }
  217. TapHandler{
  218. onSingleTapped: {
  219. if(model.isFolder){
  220. let index = treeView.model.index(row, column)
  221. treeModel.loadChildren(index)
  222. treeView.toggleExpanded(row)
  223. }else{
  224. // 选中图片
  225. imageListModel.clear()
  226. imageListModel.append({filePath: model.path})
  227. }
  228. }
  229. onLongPressed: {
  230. if (model.isFolder) {
  231. // 加载文件夹内容到图片区
  232. loadFolderContents(model.path)
  233. }
  234. }
  235. }
  236. // 名称
  237. Text {
  238. text:{
  239. if(model.isFolder){
  240. //const count = treeModel.rowCount(treeView.index(row, column))
  241. return model.name + " (" + model.count + ")"
  242. }
  243. return model.name
  244. }
  245. color: model.isFolder ? "#333" : "#666"
  246. font.bold: model.isFolder
  247. anchors.verticalCenter: parent.verticalCenter
  248. elide: Text.ElideRight
  249. width: archiveTreeView.width - 50 - depth * 20
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256. }
  257. // PhotoArchivePage.qml
  258. function loadFolderContents(folderPath) {
  259. imageListModel.clear()
  260. var stack = [folderPath]
  261. while (stack.length > 0) {
  262. var currentPath = stack.pop()
  263. var dir = Qt.createQmlObject('import QtQuick 2.0; QtObject {}', parent)
  264. var files = treeModel.getFolderContents(currentPath)
  265. for (var i = 0; i < files.length; i++) {
  266. if (files[i].isFolder) {
  267. stack.push(files[i].path)
  268. } else {
  269. imageListModel.append({filePath: files[i].path})
  270. }
  271. }
  272. }
  273. }
  274. function loadRootDirectory() {
  275. if(isLoading) return
  276. isLoading = true
  277. console.log("开始加载根目录...")
  278. // 重置模型
  279. treeModel.resetModel()
  280. // 获取根节点
  281. var rootIndex = treeModel.index(0, 0)
  282. if (rootIndex.valid) {
  283. // 加载子项
  284. treeModel.loadChildren(rootIndex)
  285. // 加载图片
  286. loadFolderContents(treeModel.data(rootIndex, 256))
  287. // 展开根节点
  288. archiveTreeView.expand(0)
  289. }
  290. // 结束加载状态(根据实际加载完成时机调用)
  291. isLoading = false
  292. }
  293. Component.onCompleted: {
  294. // 初始化加载根目录
  295. var rootIndex = treeModel.index(0, 0)
  296. if (rootIndex.valid) {
  297. treeModel.loadChildren(rootIndex)
  298. loadFolderContents(treeModel.data(rootIndex, 256)) // 256对应PathRole
  299. }
  300. }
  301. }