AicsKnowledgeBase_client/AicsKnowledgeBase/qml/component/TransferListPopup.qml

164 lines
6.7 KiB
QML
Raw Normal View History

2023-07-02 15:58:02 +08:00
import QtQuick
import QtQuick.Controls
import QtQuick.Window
import QtQuick.Layouts
2023-07-05 21:14:33 +08:00
import Qt5Compat.GraphicalEffects
2023-07-02 15:58:02 +08:00
import FluentUI
2023-07-05 21:14:33 +08:00
import AicsKB.FileTransferManager
2023-07-07 00:48:58 +08:00
import "qrc:///AicsKnowledgeBase/qml/global"
2023-07-02 15:58:02 +08:00
Popup {
id: transfer_popup
x: parent ? (parent.width - implicitWidth) / 2 : 0
y: parent ? parent.height : 0
background: FluArea {
implicitWidth: 300
implicitHeight: 200
color: "#f8f8f8"
radius: 5
FluShadow {}
}
2023-07-07 00:48:58 +08:00
Connections {
target: FileTransferManager
onTransferComplete: (download, fileId, fileName) => {
console.log("onTransferComplete")
UserData.downloadedFiles.push(fileId)
console.log(UserData.downloadedFiles)
}
}
2023-07-03 17:13:47 +08:00
contentItem: FluScrollablePage {
anchors.fill: parent
anchors.topMargin: 10
ColumnLayout {
Layout.fillWidth: true
2023-07-05 21:14:33 +08:00
spacing: 0
2023-07-03 17:13:47 +08:00
Repeater {
model: FileTransferListModel
2023-07-05 21:14:33 +08:00
delegate: Item {
Layout.fillWidth: true
height: 50
2023-07-07 00:48:58 +08:00
Item {
2023-07-05 21:14:33 +08:00
anchors.fill: parent
2023-07-07 00:48:58 +08:00
anchors.topMargin: 5
anchors.bottomMargin: 5
anchors.leftMargin: 0
Image {
id: icon
anchors.verticalCenter: parent.verticalCenter
width: 32
height: 32
source: download ? "qrc:/AicsKnowledgeBase/res/download.png" : "qrc:/AicsKnowledgeBase/res/upload.png"
2023-07-05 21:14:33 +08:00
}
2023-07-07 00:48:58 +08:00
ColumnLayout {
anchors.left: icon.right
anchors.right: parent.right
anchors.leftMargin: 5
spacing: 2
Text {
text: name
}
Text {
visible: completedSize >= totalSize
text: "已完成"
color: FluColors.Grey130
}
FluProgressBar {
Layout.fillWidth: true
progress: completedSize / totalSize
indeterminate: false
visible: completedSize < totalSize
}
2023-07-05 21:14:33 +08:00
2023-07-07 00:48:58 +08:00
Text {
visible: completedSize < totalSize
color: FluColors.Grey130
text: formatSize(speed) + "/s - " + formatSize(
completedSize) + "/" + formatSize(
totalSize)
2023-07-05 21:14:33 +08:00
2023-07-07 00:48:58 +08:00
/**
* ,
* @param {Number} size
* @param {Number} [pointLength=1]
* @param {Array} [units=[ 'B', 'K', 'M', 'G', 'TB' ]]
* K()M, K.
*/
function formatSize(size, pointLength, units) {
var unit
units = units
|| ['B', 'KB', 'MB', 'GB', 'TB']
while ((unit = units.shift())
&& size > 1024) {
size = size / 1024
}
return (unit === 'B' ? size : size.toFixed(
pointLength === undefined ? 1 : pointLength)) + ' ' + unit
2023-07-05 21:14:33 +08:00
}
}
}
2023-07-03 17:13:47 +08:00
}
2023-07-05 21:14:33 +08:00
MouseArea {
anchors.fill: parent
hoverEnabled: true
2023-07-07 00:48:58 +08:00
onEntered: {
if (completedSize < totalSize)
file_buttons.visible = true
}
2023-07-05 21:14:33 +08:00
onExited: file_buttons.visible = false
LinearGradient {
anchors.fill: file_buttons
visible: file_buttons.visible
start: Qt.point(0, 0)
end: Qt.point(20, 0)
gradient: Gradient {
GradientStop {
position: 0.0
color: "transparent"
}
GradientStop {
position: 1.0
color: "#f8f8f8"
}
}
}
RowLayout {
id: file_buttons
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
layoutDirection: Qt.RightToLeft
visible: false
FluIconButton {
iconSource: FluentIcons.Cancel
}
FluIconButton {
Layout.leftMargin: 20
iconSource: paused ? FluentIcons.Play : FluentIcons.Pause
onClicked: {
if (!paused) {
console.log("pause")
FileTransferManager.pause(fileId)
2023-07-06 15:58:23 +08:00
} else {
FileTransferManager.download(fileId,
name, true)
2023-07-05 21:14:33 +08:00
}
}
}
}
2023-07-03 17:13:47 +08:00
}
2023-07-02 15:58:02 +08:00
}
}
}
}
}