import QtQuick 2.12 import QtGraphicalEffects 1.12 import NERvGear.Preferences 1.0 as P import "../../qml/api" AdvpStyleTemplate { style: Rectangle { id: main width: widget.width; height: widget.height; property bool gradientEnable property bool centerLineFlag property string center_color property real center_width property int linePosition property bool vertical_flag property real _y_dy LinearGradient { id: gradient_mask anchors.fill: parent visible: gradientEnable gradient: Gradient { GradientStop { id: p_start; position: 0.0 } GradientStop { id: p_middle; position: 0.5 } GradientStop { id: p_end; position: 1.0 } } } Canvas { id: centerLine anchors.fill: parent contextType: "2d" renderTarget: Canvas.FramebufferObject renderStrategy: Canvas.Cooperative visible: centerLineFlag && !gradientEnable onPaint: { context.clearRect(0, 0, width+32, height+32); context.fillStyle = center_color; if (vertical_flag) { if (linePosition) { let _y = width/2 + width/2*(3-2*linePosition)*Boolean(linePosition); context.fillRect(_y+(linePosition-2)*center_width, 0, center_width, height); } else { context.fillRect(width/2-_y_dy-center_width/2, 0, center_width, width); } } else { if (linePosition) { let _y = height/2 + height/2*(3-2*linePosition)*Boolean(linePosition); context.fillRect(0, _y+(linePosition-2)*center_width, width, center_width); } else { context.fillRect(0, height/2-_y_dy-center_width/2, width, center_width); } } } } layer.enabled: true layer.effect: OpacityMask{ maskSource: AdvpCanvasTemplate { readonly property var audioData: new Array(128) readonly property string line_color: configs["Line Color"] readonly property int uDataLen: Math.pow(2, configs["Data Length"]); readonly property int dataLength: 64/uDataLen readonly property int channel: configs["Channel"] readonly property bool centerRotateFlag: configs["Rotate Settings"]["Center Enable"] readonly property real centerRotateAngleTangent: centerRotateFlag*Math.tan(configs["Rotate Settings"]["Center Angle"]*Math.PI/180) readonly property bool lineRotateFlag: configs["Rotate Settings"]["Line Enable"] readonly property real lineRotateAngleTangent: lineRotateFlag*Math.tan(configs["Rotate Settings"]["Line Angle"]*Math.PI/180) readonly property bool autoNormalizing: configs["Data Settings"]["Auto Normalizing"] readonly property real amplitude: 400.0/configs["Data Settings"]["Amplitude"] readonly property int unitStyle: configs["Data Settings"]["Unit Style"] readonly property real xOffset: configs["Rotate Settings"]["X Offset"]/100 readonly property real yOffset: configs["Rotate Settings"]["Y Offset"]/100 readonly property real xScale: configs["Rotate Settings"]["X Scale"]/100 readonly property real yScale: configs["Rotate Settings"]["Y Scale"]/100 readonly property real halfWidth: vertical_flag ? height/2 : width/2 readonly property real halfHeight: vertical_flag ? width/2 : height/2 readonly property int l_start: (channel===1)*dataLength readonly property int r_stop: dataLength+dataLength*(channel!==0) readonly property int total: r_stop-l_start readonly property real _ux: halfWidth*2/(r_stop-l_start) readonly property real _dx: Math.round(_ux/2) onWidthChanged: { if (gradientEnable) { gradient_mask.end = Qt.point(width*(configs["Gradient Direction"]!==1), height*(configs["Gradient Direction"]%2)); } centerLine.requestPaint(); } onHeightChanged: { if (gradientEnable) { gradient_mask.start = Qt.point(0, height*(configs["Gradient Direction"]===2)); gradient_mask.end = Qt.point(width*(configs["Gradient Direction"]!==1), height*(configs["Gradient Direction"]%2)); } centerLine.requestPaint(); } onConfigsUpdated: { //尽量不要使用绑定configs的属性以免造成竞争,若一定要使用推荐使用Qt.callLater(()=>{}) centerLineFlag = configs["Center Line"]; center_color = configs["Center Color"]; center_width = configs["Center Width"]/10; linePosition = configs["Line Position"]; vertical_flag = configs["Direction"]; gradientEnable = configs["Enable Gradient"]; context.lineWidth = configs["Line Width"]; main.color = configs["Line Color"]; _y_dy = configs["Rotate Settings"]["Center Enable"]*Math.tan(configs["Rotate Settings"]["Center Angle"]*Math.PI/180)*(vertical_flag ? height/2 : width/2); if (gradientEnable) { gradient_mask.start = Qt.point(0, height*(configs["Gradient Direction"]===2)); gradient_mask.end = Qt.point(width*(configs["Gradient Direction"]!==1), height*(configs["Gradient Direction"]%2)); p_start.color = configs["Start Position Color"]; p_middle.color = configs["Middle Position Color"]; p_end.color = configs["End Position Color"]; } centerLine.requestPaint(); } onAudioDataUpdeted: { let normalizing_ratio = autoNormalizing ? data[128] : amplitude; if (unitStyle) { //对数化显示 for(let i=l_start; i