Compare commits
2
Commits
9b8f6367e9
...
d1b7e083eb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1b7e083eb | ||
|
|
72c1f1e702 |
+59
-4
@@ -77,6 +77,23 @@ AppletItem {
|
||||
}
|
||||
}
|
||||
|
||||
// 拆分速度字符串为整数部分:formatSpeedShort("194.07K") -> "194"
|
||||
// 用于任务栏双行数值小数点对齐:整数部分右对齐,小数部分左对齐,
|
||||
// 整数位数不同时小数点仍垂直对齐
|
||||
function formatSpeedIntPart(bytesPerSec) {
|
||||
var str = formatSpeedShort(bytesPerSec)
|
||||
var idx = str.indexOf('.')
|
||||
return idx < 0 ? str : str.substring(0, idx)
|
||||
}
|
||||
|
||||
// 拆分速度字符串为小数+单位部分:formatSpeedShort("194.07K") -> ".07K"
|
||||
// 与 formatSpeedIntPart 配合,分别渲染实现小数点对齐
|
||||
function formatSpeedDecimalPart(bytesPerSec) {
|
||||
var str = formatSpeedShort(bytesPerSec)
|
||||
var idx = str.indexOf('.')
|
||||
return idx < 0 ? "" : str.substring(idx)
|
||||
}
|
||||
|
||||
// 带单位的速度/总量格式化函数(formatSpeed / formatTotal)已移至 NetCommon,
|
||||
// 本文件未直接使用;弹窗与图表窗口经 common.formatSpeed / common.formatTotal 调用
|
||||
|
||||
@@ -99,17 +116,31 @@ AppletItem {
|
||||
// 用户主动选色后覆盖,空串回退到 primaryText 保持自适应
|
||||
readonly property color speedTextColor: (applet && applet.textColor.length > 0) ? applet.textColor : primaryText
|
||||
|
||||
// 任务栏图标区:双行紧凑数值,箭头与数值紧贴、左对齐
|
||||
// 设计原因:箭头与数值作为一组固定在左侧,数值左对齐紧贴箭头;
|
||||
// 任务栏图标区:双行紧凑数值,箭头与数值紧贴
|
||||
// 设计原因:箭头与数值作为一组固定在左侧;
|
||||
// 不给每行固定高度,让 RowLayout 按内容自然高度排列,
|
||||
// 整组垂直居中于 dock 区域,避免两行间出现过大间隙
|
||||
// 小数点对齐:整数部分右对齐到两行最大整数宽度,小数部分左对齐,
|
||||
// 整数位数不同时小数点仍垂直对齐;箭头与数值间距固定不随位数变化
|
||||
Column {
|
||||
id: horizontalSpeed
|
||||
visible: !root.isVerticalDock
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 4
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 4
|
||||
spacing: 0
|
||||
|
||||
// 两行整数部分的最大字符数:动态计算,整数短的行补占位到此宽度
|
||||
property int maxIntDigits: Math.max(
|
||||
root.formatSpeedIntPart(root.downloadSpeed).length,
|
||||
root.formatSpeedIntPart(root.uploadSpeed).length
|
||||
)
|
||||
// 整数部分固定宽度:按最大字符数 × 单字符宽度估算
|
||||
// 单字符宽度约为 dockSize * 0.14(数值字号的 ~55%)
|
||||
property real intPartWidth: maxIntDigits * root.dockSize * 0.14
|
||||
|
||||
// 下载速度行
|
||||
RowLayout {
|
||||
spacing: 2
|
||||
@@ -121,8 +152,20 @@ AppletItem {
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
}
|
||||
|
||||
// 整数部分:右对齐到两行最大整数宽度,短的补占位
|
||||
Text {
|
||||
text: root.formatSpeedShort(root.downloadSpeed)
|
||||
text: root.formatSpeedIntPart(root.downloadSpeed)
|
||||
font.pixelSize: root.dockSize * 0.25
|
||||
font.weight: Font.Medium
|
||||
color: root.speedTextColor
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
Layout.preferredWidth: horizontalSpeed.intPartWidth
|
||||
horizontalAlignment: Text.AlignRight
|
||||
}
|
||||
|
||||
// 小数+单位部分:左对齐,紧跟整数部分
|
||||
Text {
|
||||
text: root.formatSpeedDecimalPart(root.downloadSpeed)
|
||||
font.pixelSize: root.dockSize * 0.25
|
||||
font.weight: Font.Medium
|
||||
color: root.speedTextColor
|
||||
@@ -142,8 +185,20 @@ AppletItem {
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
}
|
||||
|
||||
// 整数部分:右对齐到两行最大整数宽度,短的补占位
|
||||
Text {
|
||||
text: root.formatSpeedShort(root.uploadSpeed)
|
||||
text: root.formatSpeedIntPart(root.uploadSpeed)
|
||||
font.pixelSize: root.dockSize * 0.25
|
||||
font.weight: Font.Medium
|
||||
color: root.speedTextColor
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
Layout.preferredWidth: horizontalSpeed.intPartWidth
|
||||
horizontalAlignment: Text.AlignRight
|
||||
}
|
||||
|
||||
// 小数+单位部分:左对齐,紧跟整数部分
|
||||
Text {
|
||||
text: root.formatSpeedDecimalPart(root.uploadSpeed)
|
||||
font.pixelSize: root.dockSize * 0.25
|
||||
font.weight: Font.Medium
|
||||
color: root.speedTextColor
|
||||
|
||||
Reference in New Issue
Block a user