| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- import Felgo
- import QtQuick
- import QtQuick.Controls
- import QtQuick.Layouts
- import "../controls"
- import "../common"
- import PhotoViewer 1.0
- AppPage {
- id: photoArchivePage
- navigationBarHidden: true
- backgroundColor: app.theme_backgroundColor
- property bool isLoading: false
- TreeModel {
- id: treeModel
- }
- // 全屏查看组件
- 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
- contentWidth: imgFull.width * imgFull.scale
- contentHeight: imgFull.height * imgFull.scale
- interactive: contentWidth > width || contentHeight > height
- Image {
- id: imgFull
- x: (flick.width - width * scale)/2
- y: (flick.height - height * scale)/2
- sourceSize.width: 4096
- asynchronous: true
- fillMode: Image.PreserveAspectFit
- // 自动计算初始缩放比例
- function calculateScale() {
- const widthScale = flick.width / implicitWidth
- const heightScale = flick.height / implicitHeight
- initScale = Math.min(widthScale, heightScale) * 0.9
- scale = initScale
- }
- onStatusChanged: if(status === Image.Ready) calculateScale()
- }
- // 手势缩放
- PinchArea {
- anchors.fill: parent
- pinch.target: imgFull
- pinch.minimumScale: imgFull.minScale
- pinch.maximumScale: imgFull.maxScale
- onPinchFinished: flick.returnToBounds()
- }
- // 双击缩放
- MouseArea {
- anchors.fill: parent
- onDoubleClicked: {
- if(imgFull.scale === imgFull.initScale) {
- imgFull.scale = imgFull.maxScale
- } else {
- imgFull.scale = imgFull.initScale
- }
- flick.returnToBounds()
- }
- }
- }
- // 关闭按钮
- 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) {
- imgFull.source = "file://" + path
- fullscreenPopup.open()
- }
- 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
- TreeView {
- id: archiveTreeView
- model: treeModel
- anchors.fill: parent
- selectionModel: ItemSelectionModel {} // 处理选择状态
- selectionBehavior: TreeView.SelectRows // 整行选择
- delegate: Item {
- implicitWidth: archiveTreeView.width
- implicitHeight: 40
- required property TreeView treeView
- required property var model
- required property bool expanded //是否展开
- required property bool isFolder //是否有子节点
- required property string name //名字
- required property string path //路径
- required property int depth //深度层级
- required property int row //当前列
- required property int column //行
- // 自动生成正确的模型索引
- // ✅ 获取正确的模型索引
- //property var modelIndex: treeView.model.index(row, 0)
- // Rectangle {
- // visible: model.changed
- // width: 8
- // height: 8
- // radius: 4
- // color: "red"
- // anchors.right: parent.right
- // anchors.verticalCenter: parent.verticalCenter
- // SequentialAnimation on opacity {
- // loops: Animation.Infinite
- // NumberAnimation { from: 1; to: 0.3; duration: 1000 }
- // NumberAnimation { from: 0.3; to: 1; duration: 1000 }
- // }
- // }
- Rectangle {
- width: parent.width
- height: parent.height
- //color: mouseArea.containsMouse ? "#f0f0f0" : "transparent"
- Row {
- spacing: 8
- // anchors.verticalCenter: parent.verticalCenter
- // anchors.left: parent.left
- anchors.leftMargin: 10 + depth * 20
- // 展开/折叠指示器
- Text {
- visible: model.isFolder
- text: expanded ? "▼" : "▶"
- color: "#666"
- anchors.verticalCenter: parent.verticalCenter
- //anchors.verticalCenter: parent.verticalCenter
- }
- TapHandler{
- onSingleTapped: {
- if(model.isFolder){
- let index = treeView.model.index(row, column)
- treeModel.loadChildren(index)
- treeView.toggleExpanded(row)
- }else{
- // 选中图片
- imageListModel.clear()
- imageListModel.append({filePath: model.path})
- }
- }
- onLongPressed: {
- if (model.isFolder) {
- // 加载文件夹内容到图片区
- loadFolderContents(model.path)
- }
- }
- }
- // 名称
- Text {
- text:{
- if(model.isFolder){
- //const count = treeModel.rowCount(treeView.index(row, column))
- return model.name + " (" + model.count + ")"
- }
- return model.name
- }
- color: model.isFolder ? "#333" : "#666"
- font.bold: model.isFolder
- anchors.verticalCenter: parent.verticalCenter
- elide: Text.ElideRight
- width: archiveTreeView.width - 50 - depth * 20
- }
- }
- }
- }
- }
- }
- }
- // 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
- isLoading = true
- console.log("开始加载根目录...")
- // 重置模型
- treeModel.resetModel()
- // 获取根节点
- var rootIndex = treeModel.index(0, 0)
- if (rootIndex.valid) {
- // 加载子项
- treeModel.loadChildren(rootIndex)
- // 加载图片
- loadFolderContents(treeModel.data(rootIndex, 256))
- // 展开根节点
- archiveTreeView.expand(0)
- }
- // 结束加载状态(根据实际加载完成时机调用)
- isLoading = false
- }
- Component.onCompleted: {
- // 初始化加载根目录
- var rootIndex = treeModel.index(0, 0)
- if (rootIndex.valid) {
- treeModel.loadChildren(rootIndex)
- loadFolderContents(treeModel.data(rootIndex, 256)) // 256对应PathRole
- }
- }
- }
|