83 lines
2.8 KiB
QML
83 lines
2.8 KiB
QML
import QtQuick
|
|
|
|
// The corner badge shape: a round top corner facing into the screen, and
|
|
// concave curves where the box runs into the screen edges, as if it grows
|
|
// out of the corner. Drawn for the bottom-right corner; leftSide flips it.
|
|
// Only the shape is drawn here; put the content on top of it.
|
|
Item {
|
|
id: root
|
|
|
|
required property Theme theme
|
|
required property color tint
|
|
// Round corner at the top, on the side facing into the screen.
|
|
required property real radius
|
|
// Size of the curves that run into the screen edges. The box itself
|
|
// starts this far in from the left and top of this item.
|
|
required property real flare
|
|
required property bool leftSide
|
|
|
|
// Flip only the drawing, not the text that sits on top of it.
|
|
transform: Scale {
|
|
origin.x: root.width / 2
|
|
xScale: root.leftSide ? -1 : 1
|
|
}
|
|
|
|
Canvas {
|
|
id: shape
|
|
|
|
readonly property color fill: root.tint
|
|
|
|
anchors.fill: parent
|
|
|
|
onWidthChanged: shape.requestPaint()
|
|
onHeightChanged: shape.requestPaint()
|
|
onFillChanged: shape.requestPaint()
|
|
|
|
onPaint: {
|
|
const ctx = shape.getContext("2d");
|
|
ctx.reset();
|
|
const w = shape.width;
|
|
const h = shape.height;
|
|
if (w <= 0 || h <= 0)
|
|
return;
|
|
const f = Math.min(root.flare, w / 2, h / 2);
|
|
const r = Math.min(root.radius, (w - f) / 2, (h - f) / 2);
|
|
|
|
// The edges facing into the screen: from the bottom edge, up the
|
|
// inner side, round the top corner, and across to the right edge.
|
|
function innerEdges() {
|
|
ctx.moveTo(0, h);
|
|
ctx.arcTo(f, h, f, h - f, f);
|
|
ctx.lineTo(f, f + r);
|
|
ctx.arcTo(f, f, f + r, f, r);
|
|
ctx.lineTo(w - f, f);
|
|
ctx.arcTo(w, f, w, 0, f);
|
|
}
|
|
|
|
ctx.beginPath();
|
|
innerEdges();
|
|
ctx.lineTo(w, h);
|
|
ctx.closePath();
|
|
ctx.fillStyle = shape.fill;
|
|
ctx.fill();
|
|
|
|
// Shine over the top half, like light on curved glass.
|
|
const shine = ctx.createLinearGradient(0, f, 0, h);
|
|
shine.addColorStop(0, root.theme.glassShine);
|
|
shine.addColorStop(0.55, "rgba(255, 255, 255, 0)");
|
|
ctx.fillStyle = shine;
|
|
ctx.fill();
|
|
|
|
// The rim, only along the edges facing into the screen.
|
|
const rim = ctx.createLinearGradient(0, 0, 0, h);
|
|
rim.addColorStop(0, root.theme.glassRimTop);
|
|
rim.addColorStop(1, root.theme.glassRimBottom);
|
|
ctx.beginPath();
|
|
innerEdges();
|
|
ctx.strokeStyle = rim;
|
|
ctx.lineWidth = 1;
|
|
ctx.stroke();
|
|
}
|
|
}
|
|
}
|