DPS_Manage/Component/DownloadItemDelegate.qml

162 lines
4.7 KiB
QML

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtMultimedia 5.15
import HuskarUI.Basic 1.0
import QmlTool 1.0
import "../MyGlobals" 1.0
import "../Component" 1.0
Item {
id: delegate
height: 60
property string timestr: ""
Timer {
id: timer
interval: 10 // 1 秒
running: true
repeat: true
onTriggered: {
if(modelData.status === 3){
if(!modelData.error)timestr = "已完成";
if(modelData.error)timestr = "失败!";
return;
}
if(modelData.remainingTime === 0){
timestr = "";
return;
}
var timeDifference = (Math.floor(Date.now() / 1000) - modelData.remainingTime)
var seconds = timeDifference
var minutes = Math.floor(seconds / 60)
var hours = Math.floor(seconds / 60)
timestr = hours + ":" + minutes + ":" + seconds
}
}
HusRectangle {
anchors.fill: parent
color: {
if(!HusTheme.isDark)return index % 2 === 0 ? "#eeeeee" : "#dddddd"
else return index % 2 === 0 ? "#333333" : "#444444"
}
//只有第一个任务上方有圆角
topLeftRadius: index === 0 ? 8 : 0
topRightRadius: index === 0 ? 8 : 0
clip: true
HusRectangle{
id:progress_color
width: {
if(modelData.status === 3)return parent.width
else return Math.min(parent.width * (modelData.progress / 100.0),parent.width)
}
height: parent.height
color: {
if(modelData.error)return "#ff3d38"
return modelData.status === 3 ? "#54a334" : "#1677ff"
}
//只有第一个任务上方有圆角
topLeftRadius: index === 0 ? 8 : 0
topRightRadius: index === 0 ? 8 : 0
// 添加宽度变化的动画行为
Behavior on width {
NumberAnimation {
duration: 300 // 动画持续时间(毫秒)
easing.type: Easing.OutQuad // 缓动曲线(先快后慢)
}
}
}
RowLayout {
anchors.fill: parent
anchors.margins: 5
spacing: 15
// 文件图标
HusIconText {
iconSource: HusIcon.CopyOutlined
iconSize: 32
}
// 文件名
HusText {
text: modelData.fileName
elide: Text.ElideMiddle
font.bold: true
font {
pixelSize: 14
family: HusTheme.Primary.fontPrimaryFamily
}
color: HusTheme.Primary.colorTextBase
}
// 下载时间
HusText {
text: timestr
elide: Text.ElideMiddle
font.bold: true
font {
pixelSize: 14
family: HusTheme.Primary.fontPrimaryFamily
}
color: HusTheme.Primary.colorTextBase
}
// 占位项,用于将状态和进度文本推到右边
Item {
Layout.fillWidth: true
}
// 进度百分比文本
HusText {
visible: modelData.status === 3 ? false : true
Layout.margins: 10 // 设置右边距
text: Math.min(modelData.progress,100) + "%"
elide: Text.ElideMiddle
font.bold: true
font {
pixelSize: 14
family: HusTheme.Primary.fontPrimaryFamily
}
color: HusTheme.Primary.colorTextBase
Layout.alignment: Qt.AlignRight
}
// 状态
HusText {
Layout.margins: 10 // 设置右边距
text: {
switch(modelData.status){
case 0 : return "等待中"
case 1 : return "下载中"
case 2 : return "上传中"
case 3 : return ""
default: return ""
}
}
elide: Text.ElideMiddle
font.bold: true
font {
pixelSize: 14
family: HusTheme.Primary.fontPrimaryFamily
}
color: HusTheme.Primary.colorTextBase
Layout.alignment: Qt.AlignRight
}
}
}
}