C

Qt Quick Ultralite shapes Example

// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial

import QtQuick 2.15
import QtQuick.Shapes 1.0

ShapesEntry {
    id: root
    text: "Join styles"

    Rectangle {
        color: "lightGray"
        anchors.top: parent.top
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.margins: root.contentMargins
        width: root.contentHeight
        height: root.contentHeight

        Shape {
            anchors.centerIn: parent
            width: 120
            height: 120

            scale: root.shapeScale

            ShapePath {
                id: joinTest

                strokeColor: "black"
                strokeWidth: 16
                fillColor: "transparent"
                capStyle: ShapePath.RoundCap

                property int joinStyleIdx: 0
                joinStyle: style(joinStyleIdx)

                startX: 30
                startY: 30
                PathLine { x: 100; y: 100 }
                PathLine { x: 30; y: 100 }
            }
        }

        Text {
            anchors.top: parent.top
            anchors.right: parent.right
            anchors.margins: 2
            font.pixelSize: 10
            text: styleText(joinTest.joinStyleIdx)
        }
    }

    function styleText(index: int) : string
    {
        if (index == 0)
            return "BevelJoin";
        else if (index == 1)
            return "MiterJoin";
        else
            return "RoundJoin";
    }

    function style(index: int) : ShapePath.JoinStyle
    {
        if (index == 0)
            return ShapePath.BevelJoin;
        else if (index == 1)
            return ShapePath.MiterJoin;
        else
            return ShapePath.RoundJoin;
    }

    Timer {
        interval: 1000
        repeat: true
        running: true
        onTriggered: joinTest.joinStyleIdx = (joinTest.joinStyleIdx + 1) % 3
    }
}