Browse Source

- 修复Text控件边缘色差

- TopUI.qml
  - 新增[曲线]选项
  - 新增[切换UI]挂件动作
- BottomUI.qml
  - 新增[曲线]选项
master
mashiros 2 years ago
parent
commit
252effc514
  1. 51
      qml/BottomUI.qml
  2. 186
      qml/TopUI.qml

51
qml/BottomUI.qml

@ -18,7 +18,9 @@ T.Widget {
property real tmin: 0 property real tmin: 0
editing: styleDialog.active editing: styleDialog.active
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":0,"Font Weight":0,"Text Vertical Offset":16} readonly property var defaultValues: {"Curve":true,"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":0,"Font Weight":0,"Text Vertical Offset":16}
readonly property var configs: widget.settings.styles
property string line_color: configs["Line Color"] property string line_color: configs["Line Color"]
property string shadowColor: configs["Shadow Color"] property string shadowColor: configs["Shadow Color"]
@ -28,21 +30,24 @@ T.Widget {
readonly property real w: widget.width readonly property real w: widget.width
readonly property real r: (w**2+4*h**2)/2/h readonly property real r: (w**2+4*h**2)/2/h
property real triangle_size: 24 onConfigsChanged: {
line.requestPaint();
triangle.requestPaint();
}
Canvas { Canvas {
id: triangle id: triangle
anchors.centerIn: parent anchors.centerIn: parent
anchors.verticalCenterOffset: height/2 anchors.verticalCenterOffset: height/2
width: triangle_size width: 0.4*h
height: triangle_size*Math.sin(Math.PI/6) height: 0.4*h*Math.sin(Math.PI/6)
contextType: "2d" contextType: "2d"
onPaint: { onPaint: {
context.reset(); context.reset();
context.clearRect(0,0,width,height); context.clearRect(0,0,width,height);
context.shadowBlur = shadowBlur; context.shadowBlur = shadowBlur;
context.shadowColor = shadowColor; 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; context.strokeStyle = line_color;
context.beginPath(); context.beginPath();
context.moveTo(0,0); context.moveTo(0,0);
@ -65,11 +70,17 @@ T.Widget {
context.clearRect(0,0,width,height); context.clearRect(0,0,width,height);
context.shadowBlur = shadowBlur; context.shadowBlur = shadowBlur;
context.shadowColor = shadowColor; 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; context.strokeStyle = line_color;
let deg = Math.asin(w/2/r)*0.95; if (configs["Curve"]) {
context.beginPath(); let deg = Math.asin(w/2/r)*0.95;
context.arc(w/2, r+h/2, r-shadowBlur/2, deg+Math.PI*3/2, -deg+Math.PI*3/2, true); context.beginPath();
context.arc(w/2, r+h/2, r, deg+Math.PI*3/2, -deg+Math.PI*3/2, true);
} else {
context.beginPath();
context.moveTo(0, height/2);
context.lineTo(width, height/2);
}
context.stroke(); context.stroke();
} }
} }
@ -147,14 +158,18 @@ T.Widget {
onPreferenceEdited: { onPreferenceEdited: {
widget.settings.styles = rootPreference.save(); widget.settings.styles = rootPreference.save();
line.requestPaint(); }
triangle.requestPaint();
P.SwitchPreference {
name: "Curve"
label: qsTr("Curve")
defaultValue: defaultValues["Curve"]
} }
P.ColorPreference { P.ColorPreference {
name: "Line Color" name: "Line Color"
label: qsTr("Line Color") label: qsTr("Line Color")
defaultValue: "#fffcf9" defaultValue: defaultValues["Line Color"]
} }
P.SliderPreference { P.SliderPreference {
@ -163,14 +178,14 @@ T.Widget {
from: 1 from: 1
to: 100 to: 100
stepSize: 1 stepSize: 1
defaultValue: 38 defaultValue: defaultValues["Line Width"]
displayValue: value + "%" displayValue: value + "%"
} }
P.ColorPreference { P.ColorPreference {
name: "Shadow Color" name: "Shadow Color"
label: qsTr("Shadow Color") label: qsTr("Shadow Color")
defaultValue: "#e0e0e0" defaultValue: defaultValues["Shadow Color"]
} }
P.SliderPreference { P.SliderPreference {
@ -179,7 +194,7 @@ T.Widget {
from: 0 from: 0
to: 3 to: 3
stepSize: 0.1 stepSize: 0.1
defaultValue: 0.5 defaultValue: defaultValues["Shadow Size"]
displayValue: Math.round(value*10)/10 + "px" displayValue: Math.round(value*10)/10 + "px"
} }
@ -200,9 +215,11 @@ T.Widget {
onClosing: { onClosing: {
widget.settings.styles = configuration; widget.settings.styles = configuration;
styleDialog.active = false; styleDialog.active = false;
line.requestPaint();
triangle.requestPaint();
} }
} }
} }
Component.onCompleted: {
widget.settings.styles = widget.settings.styles ?? defaultValues;
}
} }

186
qml/TopUI.qml

@ -19,10 +19,27 @@ T.Widget {
editing: styleDialog.active editing: styleDialog.active
readonly property var fonts: Qt.fontFamilies() readonly property var fonts: Qt.fontFamilies()
readonly property var fontweight: ["normal", "bold"] readonly property var fontweight: [Font.Light, Font.Normal, Font.Bold]
readonly property var sfontweight: [qsTr("Normal"), qsTr("Bold")] readonly property var sfontweight: [qsTr("Light"), qsTr("Normal"), qsTr("Bold")]
readonly property var defaultValues: {
"Curve": "true",
"Line Color": "#fffcf9",
"Line Width": 38,
"Shadow Color": "#e0e0e0",
"Shadow Size": 0.5,
"Battle UI": false,
"Circle Color": "#fffcf9",
"Clock Visible": true,
"Full Clock": true,
"Font Color": "#f5f5f5",
"Font Size": 44,
"Font Name": 0,
"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} readonly property var configs: widget.settings.styles
property string circle_color: configs["Circle Color"] property string circle_color: configs["Circle Color"]
property string line_color: configs["Line Color"] property string line_color: configs["Line Color"]
@ -34,6 +51,42 @@ T.Widget {
readonly property real w: widget.width readonly property real w: widget.width
readonly property real r: (w**2+h**2)/4/h readonly property real r: (w**2+h**2)/4/h
onConfigsChanged: {
line.requestPaint();
c0.requestPaint();
c1.requestPaint();
c2.requestPaint();
c3.requestPaint();
c4.requestPaint();
c5.requestPaint();
}
action: T.Action {
id: thiz
title: qsTr("Top Line Action")
description: title
execute: function () {
return new Promise(function (resolve, reject) {
if (!styleDialog.active) {
let cfg = widget.settings.styles;
cfg["Battle UI"] = !cfg["Battle UI"];
widget.settings.styles = cfg;
}
resolve();
});
}
preference: P.SelectPreference {
label: qsTr("Command")
model: [ qsTr("Toggle UI") ]
defaultValue: 0
load: function () {}
save: function () {}
}
}
Timer { Timer {
interval: 250 interval: 250
@ -44,32 +97,26 @@ T.Widget {
if (tmin !== now.getMinutes()) { if (tmin !== now.getMinutes()) {
tmin = now.getMinutes(); tmin = now.getMinutes();
thour = now.getHours(); thour = now.getHours();
if (!configs["Full Clock"]) t12hour = thour > 12 ? thour - 12 : thour;
t12hour = thour > 12 ? thour - 12 : thour;
text_clock.requestPaint();
} }
} }
} }
Canvas{ Text {
id: text_clock id: text_clock
width: widget.width
height: widget.height
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: widget.height/200*configs["Text Vertical Offset"] anchors.topMargin: widget.height/200*configs["Text Vertical Offset"]
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
contextType: "2d"
visible: widget.NVG.View.exposed && !configs["Battle UI"] && configs["Clock Visible"]
onPaint: { style: Text.Outline
context.clearRect(0,0,width,height); styleColor: "transparent"
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"]]; color: configs["Font Color"]
context.textAlign = 'center'; text: configs["Full Clock"] ? ("0"+thour).slice(-2) + ":" + ("0"+tmin).slice(-2) : ("0"+t12hour).slice(-2) + ":" + ("0"+tmin).slice(-2)
context.beginPath(); font.pointSize: widget.height/200*configs["Font Size"]
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); font.family: fonts[configs["Font Name"]]
context.fill(); font.weight: fontweight[configs["Font Weight"]]
} visible: widget.NVG.View.exposed && !configs["Battle UI"] && configs["Clock Visible"]
} }
Item { Item {
@ -284,15 +331,31 @@ T.Widget {
context.strokeStyle = line_color; context.strokeStyle = line_color;
let deg = Math.asin(w/2/r)*0.95; let deg = Math.asin(w/2/r)*0.95;
context.beginPath(); context.beginPath();
if (circle.visible) { if (configs["Curve"]) {
context.arc(w/2, -r+h/2, r, deg+Math.PI/2, Math.PI/2+circle.scale*size/1.22/r, true); if (circle.visible) {
context.stroke(); context.arc(w/2, -r+h/2, r, deg+Math.PI/2, Math.PI/2+circle.scale*size/1.22/r, true);
context.beginPath(); context.stroke();
context.arc(w/2, -r+h/2, r, -deg+Math.PI/2, Math.PI/2-circle.scale*size/1.22/r, false); context.beginPath();
context.stroke(); 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, deg+Math.PI/2, -deg+Math.PI/2, true);
context.stroke();
}
} else { } else {
context.arc(w/2, -r+h/2, r, deg+Math.PI/2, -deg+Math.PI/2, true); if (circle.visible) {
context.stroke(); context.moveTo(0, height/2);
context.lineTo(width/2-circle.scale*size/1.22, height/2);
context.stroke();
context.beginPath();
context.moveTo(width/2+circle.scale*size/1.22, height/2);
context.lineTo(width, height/2);
context.stroke();
} else {
context.moveTo(0, height/2);
context.lineTo(width, height/2);
context.stroke();
}
} }
} }
} }
@ -339,14 +402,6 @@ T.Widget {
rootPreference.load(); rootPreference.load();
let cfg = rootPreference.save(); let cfg = rootPreference.save();
widget.settings.styles = cfg; widget.settings.styles = cfg;
line.requestPaint();
c0.requestPaint();
c1.requestPaint();
c2.requestPaint();
c3.requestPaint();
c4.requestPaint();
c5.requestPaint();
text_clock.requestPaint();
} }
} }
@ -376,26 +431,18 @@ T.Widget {
onPreferenceEdited: { onPreferenceEdited: {
widget.settings.styles = rootPreference.save(); widget.settings.styles = rootPreference.save();
line.requestPaint();
c0.requestPaint();
c1.requestPaint();
c2.requestPaint();
c3.requestPaint();
c4.requestPaint();
c5.requestPaint();
text_clock.requestPaint();
} }
P.ColorPreference { P.SwitchPreference {
name: "Circle Color" name: "Curve"
label: qsTr("Circle Color") label: qsTr("Curve")
defaultValue: "#fffcf9" defaultValue: defaultValues["Curve"]
} }
P.ColorPreference { P.ColorPreference {
name: "Line Color" name: "Line Color"
label: qsTr("Line Color") label: qsTr("Line Color")
defaultValue: "#fffcf9" defaultValue: defaultValues["Line Color"]
} }
P.SliderPreference { P.SliderPreference {
@ -404,14 +451,14 @@ T.Widget {
from: 1 from: 1
to: 100 to: 100
stepSize: 1 stepSize: 1
defaultValue: 38 defaultValue: defaultValues["Line Width"]
displayValue: value + "%" displayValue: value + "%"
} }
P.ColorPreference { P.ColorPreference {
name: "Shadow Color" name: "Shadow Color"
label: qsTr("Shadow Color") label: qsTr("Shadow Color")
defaultValue: "#e0e0e0" defaultValue: defaultValues["Shadow Color"]
} }
P.SliderPreference { P.SliderPreference {
@ -420,7 +467,7 @@ T.Widget {
from: 0 from: 0
to: 3 to: 3
stepSize: 0.1 stepSize: 0.1
defaultValue: 0.5 defaultValue: defaultValues["Shadow Size"]
displayValue: Math.round(value*10)/10 + "px" displayValue: Math.round(value*10)/10 + "px"
} }
@ -430,7 +477,14 @@ T.Widget {
id: _cfg_battle_ui id: _cfg_battle_ui
name: "Battle UI" name: "Battle UI"
label: qsTr("Battle UI") label: qsTr("Battle UI")
defaultValue: false defaultValue: defaultValues["Battle UI"]
}
P.ColorPreference {
name: "Circle Color"
label: qsTr("Circle Color")
visible: _cfg_battle_ui.value
defaultValue: defaultValues["Circle Color"]
} }
P.Separator {} P.Separator {}
@ -441,7 +495,7 @@ T.Widget {
label: qsTr("Clock Visible") label: qsTr("Clock Visible")
visible: !_cfg_battle_ui.value visible: !_cfg_battle_ui.value
enabled: visible enabled: visible
defaultValue: true defaultValue: defaultValues["Clock Visible"]
} }
P.SwitchPreference { P.SwitchPreference {
@ -449,7 +503,7 @@ T.Widget {
label: qsTr("24 Hour Clock") label: qsTr("24 Hour Clock")
visible: !_cfg_battle_ui.value visible: !_cfg_battle_ui.value
enabled: visible && _cfg_clock_visible.value enabled: visible && _cfg_clock_visible.value
defaultValue: true defaultValue: defaultValues["Full Clock"]
} }
P.ColorPreference { P.ColorPreference {
@ -457,7 +511,7 @@ T.Widget {
label: qsTr("Font Color") label: qsTr("Font Color")
visible: !_cfg_battle_ui.value visible: !_cfg_battle_ui.value
enabled: visible && _cfg_clock_visible.value enabled: visible && _cfg_clock_visible.value
defaultValue: "#f5f5f5" defaultValue: defaultValues["Font Color"]
} }
P.SliderPreference { P.SliderPreference {
@ -468,7 +522,7 @@ T.Widget {
from: 1 from: 1
to: 100 to: 100
stepSize: 1 stepSize: 1
defaultValue: 60 defaultValue: defaultValues["Font Size"]
displayValue: value + "%" displayValue: value + "%"
} }
@ -478,7 +532,7 @@ T.Widget {
visible: !_cfg_battle_ui.value visible: !_cfg_battle_ui.value
enabled: visible && _cfg_clock_visible.value enabled: visible && _cfg_clock_visible.value
icon.name: "solid:\uf1fc" icon.name: "solid:\uf1fc"
defaultValue: fonts.length-1 defaultValue: defaultValues["Font Name"]
model: fonts model: fonts
} }
@ -488,7 +542,7 @@ T.Widget {
visible: !_cfg_battle_ui.value visible: !_cfg_battle_ui.value
enabled: visible && _cfg_clock_visible.value enabled: visible && _cfg_clock_visible.value
icon.name: "solid:\uf1fc" icon.name: "solid:\uf1fc"
defaultValue: 0 defaultValue: defaultValues["Font Weight"]
model: sfontweight model: sfontweight
} }
@ -500,7 +554,7 @@ T.Widget {
from: -100 from: -100
to: 100 to: 100
stepSize: 1 stepSize: 1
defaultValue: -30 defaultValue: defaultValues["Text Vertical Offset"]
displayValue: value + "%" displayValue: value + "%"
} }
@ -521,15 +575,11 @@ T.Widget {
onClosing: { onClosing: {
widget.settings.styles = configuration; widget.settings.styles = configuration;
styleDialog.active = false; styleDialog.active = false;
line.requestPaint();
c0.requestPaint();
c1.requestPaint();
c2.requestPaint();
c3.requestPaint();
c4.requestPaint();
c5.requestPaint();
text_clock.requestPaint();
} }
} }
} }
Component.onCompleted: {
widget.settings.styles = widget.settings.styles ?? defaultValues;
}
} }

Loading…
Cancel
Save