| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- 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
- // 全屏查看组件
- 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: "transparent"
- border.color: "#eee"
- 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
- }
- }
- MouseArea {
- anchors.fill: parent
- onClicked: {
- // 处理图片点击
- console.log("Selected image:", filePath)
- // 显示大图
- showFullscreen(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
- 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===5){
- 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)
- // 若未展开且有子节点,则加载并展开
- treeModel.loadChildren(index); // 同步加载子节点(阻塞直到完成)
- treeView.toggleExpanded(row); // 显式展开(确保视图刷新)
- }
- console.log("root.type:", root.type)
- }
- onLongPressed: {
- console.log("长按:", root.type)
- if (model.type===4) {
- // 加载文件夹内容到图片区
- loadFolderContents(model.path)
- }
- }
- }
- // 名称
- Text {
- text: {
- if(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) ? "#333" : "#666"
- font.bold: root.type===0 || root.type === 1 || root.type===2 || root.type===3 || root.type===4
- 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})
- }
- }
- }
- }
- function loadRootDirectory() {
- if(isLoading) return
- rootExpanded = false
- console.log("开始加载根目录...")
- // 触发 C++ 里的 resetModel(),异步加载年份目录
- treeModel.resetModel()
- }
- Component.onCompleted: {
- loadRootDirectory()
- }
- }
|