Browse Source

- 修复文字时钟的边缘色差

master
mashiros 2 years ago
parent
commit
fee59b2811
  1. 55
      qml/TopUI.qml

55
qml/TopUI.qml

@ -15,14 +15,14 @@ T.Widget {
property real thour: 0
property real t12hour: 0
property real tmin: 0
property real tmin: -1
editing: styleDialog.active
readonly property var fonts: Qt.fontFamilies()
readonly property var fontweight: [Font.Light, Font.Normal, Font.Bold]
readonly property var sfontweight: [qsTr("Light"), qsTr("Normal"), qsTr("Bold")]
readonly property var fontweight: ["normal", "bold"]
readonly property var sfontweight: [qsTr("Normal"), qsTr("Bold")]
readonly property var configs: widget.settings.styles ? widget.settings.styles : {"Circle Color":"#fffcf9","Line Color":"#fffcf9","Line Width":38,"Shadow Color":"#e0e0e0","Shadow Size":0.5,"Battle UI":false,"Clock Visible":true,"Full Clock":true,"Font Color":"#f5f5f5","Font Size":44,"Font Name":fonts.length-1,"Font Weight":0,"Text Vertical Offset":16}
readonly property var configs: widget.settings.styles ? widget.settings.styles : {"Circle Color":"#fffcf9","Line Color":"#fffcf9","Line Width":38,"Shadow Color":"#e0e0e0","Shadow Size":0.5,"Battle UI":false,"Clock Visible":true,"Full Clock":true,"Font Color":"#f5f5f5","Font Size":60,"Font Name":fonts.length-1,"Font Weight":0,"Text Vertical Offset":-30}
property string circle_color: configs["Circle Color"]
property string line_color: configs["Line Color"]
@ -36,28 +36,40 @@ T.Widget {
Timer {
interval: 250
running: text_clock.visible
repeat: true
onTriggered: {
var now = new Date();
tmin = now.getMinutes();
thour = now.getHours();
if (!configs["Full Clock"])
t12hour = thour > 12 ? thour - 12 : thour;
if (tmin !== now.getMinutes()) {
tmin = now.getMinutes();
thour = now.getHours();
if (!configs["Full Clock"])
t12hour = thour > 12 ? thour - 12 : thour;
text_clock.requestPaint();
}
}
}
Text {
Canvas{
id: text_clock
width: widget.width
height: widget.height
anchors.top: parent.top
anchors.topMargin: widget.height/200*configs["Text Vertical Offset"]
anchors.horizontalCenter: parent.horizontalCenter
color: configs["Font Color"]
text: configs["Full Clock"] ? ("0"+thour).slice(-2) + ":" + ("0"+tmin).slice(-2) : ("0"+t12hour).slice(-2) + ":" + ("0"+tmin).slice(-2)
font.pointSize: widget.height/200*configs["Font Size"]
font.family: fonts[configs["Font Name"]]
font.weight: fontweight[configs["Font Weight"]]
contextType: "2d"
visible: widget.NVG.View.exposed && !configs["Battle UI"] && configs["Clock Visible"]
onPaint: {
context.clearRect(0,0,width,height);
context.fillStyle = configs["Font Color"];
context.font = "normal normal " + ["normal", "bold"][configs["Font Weight"]] + " " + widget.height/200*configs["Font Size"] + "px " + fonts[configs["Font Name"]];
context.textAlign = 'center';
context.beginPath();
context.fillText(configs["Full Clock"] ? ("0"+thour).slice(-2) + ":" + ("0"+tmin).slice(-2) : ("0"+t12hour).slice(-2) + ":" + ("0"+tmin).slice(-2), width/2, height/2);
context.fill();
}
}
Item {
@ -268,18 +280,18 @@ T.Widget {
context.clearRect(0,0,width,height);
context.shadowBlur = shadowBlur;
context.shadowColor = shadowColor;
context.lineWidth = Math.max(0.08*configs["Line Width"] - shadowBlur, 0.1);
context.lineWidth = Math.max(0.08*configs["Line Width"], 0.1);
context.strokeStyle = line_color;
let deg = Math.asin(w/2/r)*0.95;
context.beginPath();
if (circle.visible) {
context.arc(w/2, -r+h/2, r-shadowBlur/2, deg+Math.PI/2, Math.PI/2+circle.scale*size/1.22/r, true);
context.arc(w/2, -r+h/2, r, deg+Math.PI/2, Math.PI/2+circle.scale*size/1.22/r, true);
context.stroke();
context.beginPath();
context.arc(w/2, -r+h/2, r-shadowBlur/2, -deg+Math.PI/2, Math.PI/2-circle.scale*size/1.22/r, false);
context.arc(w/2, -r+h/2, r, -deg+Math.PI/2, Math.PI/2-circle.scale*size/1.22/r, false);
context.stroke();
} else {
context.arc(w/2, -r+h/2, r-shadowBlur/2, deg+Math.PI/2, -deg+Math.PI/2, true);
context.arc(w/2, -r+h/2, r, deg+Math.PI/2, -deg+Math.PI/2, true);
context.stroke();
}
}
@ -334,6 +346,7 @@ T.Widget {
c3.requestPaint();
c4.requestPaint();
c5.requestPaint();
text_clock.requestPaint();
}
}
@ -370,6 +383,7 @@ T.Widget {
c3.requestPaint();
c4.requestPaint();
c5.requestPaint();
text_clock.requestPaint();
}
P.ColorPreference {
@ -454,7 +468,7 @@ T.Widget {
from: 1
to: 100
stepSize: 1
defaultValue: 44
defaultValue: 60
displayValue: value + "%"
}
@ -486,7 +500,7 @@ T.Widget {
from: -100
to: 100
stepSize: 1
defaultValue: 16
defaultValue: -30
displayValue: value + "%"
}
@ -514,6 +528,7 @@ T.Widget {
c3.requestPaint();
c4.requestPaint();
c5.requestPaint();
text_clock.requestPaint();
}
}
}

Loading…
Cancel
Save