FluentUI/src/controls/FluRectangle.qml

68 lines
1.9 KiB
QML
Raw Normal View History

2023-03-30 21:52:55 +08:00
import QtQuick
import QtQuick.Controls
import Qt5Compat.GraphicalEffects
2023-02-27 18:46:39 +08:00
2023-02-28 18:29:00 +08:00
Item{
2023-03-27 18:24:35 +08:00
id:control
2023-02-28 18:29:00 +08:00
property var radius:[0,0,0,0]
property color color : "#FFFFFF"
2023-03-03 18:19:48 +08:00
property bool shadow: true
2023-03-15 14:49:33 +08:00
default property alias contentItem: container.data
2023-02-28 18:29:00 +08:00
Rectangle{
id:container
2023-03-27 18:24:35 +08:00
width: control.width
height: control.height
2023-03-02 23:58:50 +08:00
opacity: 0
2023-03-27 18:24:35 +08:00
color:control.color
2023-02-28 18:29:00 +08:00
}
2023-03-03 18:19:48 +08:00
FluShadow{
anchors.fill: container
2023-03-27 18:24:35 +08:00
radius: control.radius[0]
2023-03-03 18:19:48 +08:00
visible: {
2023-03-27 18:24:35 +08:00
if(control.radius[0] === control.radius[1] && control.radius[0] === control.radius[2] && control.radius[0] === control.radius[3] && control.shadow){
2023-03-03 18:19:48 +08:00
return true
}
return false
}
}
2023-03-01 11:58:30 +08:00
Canvas {
id: canvas
anchors.fill: parent
2023-02-28 18:29:00 +08:00
visible: false
2023-03-01 11:58:30 +08:00
onPaint: {
var ctx = getContext("2d");
var x = 0;
var y = 0;
2023-03-27 18:24:35 +08:00
var w = control.width;
var h = control.height;
2023-03-01 11:58:30 +08:00
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.save();
ctx.beginPath();
ctx.moveTo(x + radius[0], y);
ctx.lineTo(x + w - radius[1], y);
ctx.arcTo(x + w, y, x + w, y + radius[1], radius[1]);
ctx.lineTo(x + w, y + h - radius[2]);
ctx.arcTo(x + w, y + h, x + w - radius[2], y + h, radius[2]);
ctx.lineTo(x + radius[3], y + h);
ctx.arcTo(x, y + h, x, y + h - radius[3], radius[3]);
ctx.lineTo(x, y + radius[0]);
ctx.arcTo(x, y, x + radius[0], y, radius[0]);
ctx.closePath();
2023-03-27 18:24:35 +08:00
ctx.fillStyle = control.color;
2023-03-01 11:58:30 +08:00
ctx.fill();
ctx.restore();
2023-02-28 18:29:00 +08:00
}
}
OpacityMask {
anchors.fill: container
source: container
2023-03-01 11:58:30 +08:00
maskSource: canvas
2023-02-28 18:29:00 +08:00
}
2023-02-27 18:46:39 +08:00
}