Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RoundedRectangle.qml « qml « resources - github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3ca05e2125f870773544541c433277f7c4438960 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import QtQuick 2.7

import UM 1.2 as UM

// The rounded rectangle works mostly like a regular rectangle, but provides the option to have rounded corners on only one side of the rectangle.
Item
{
    id: roundedRectangle
    // As per the regular rectangle
    property color color: "transparent"

    // As per regular rectangle
    property int radius: UM.Theme.getSize("default_radius").width

    // On what side should the corners be shown 5 can be used if no radius is needed.
    // 1 is down, 2 is left, 3 is up and 4 is right.
    property int cornerSide: RoundedRectangle.Direction.None

    // Simple object to ensure that border.width and border.color work
    property BorderGroup border: BorderGroup {}

    enum Direction
    {
        None = 0,
        Down = 1,
        Left = 2,
        Up = 3,
        Right = 4,
        All = 5
    }

    Rectangle
    {
        id: background
        anchors.fill: parent
        radius: cornerSide != RoundedRectangle.Direction.None ? parent.radius : 0
        color: parent.color
        border.width: parent.border.width
        border.color: parent.border.color
    }

    // The item that covers 2 of the corners to make them not rounded.
    Rectangle
    {
        visible: cornerSide != RoundedRectangle.Direction.None && cornerSide != RoundedRectangle.Direction.All
        height: cornerSide % 2 ? parent.radius: parent.height
        width: cornerSide % 2 ? parent.width : parent.radius
        color: parent.color
        anchors
        {
            right: cornerSide == RoundedRectangle.Direction.Left ? parent.right: undefined
            bottom: cornerSide == RoundedRectangle.Direction.Up ? parent.bottom: undefined
        }

        border.width: parent.border.width
        border.color: parent.border.color

        Rectangle
        {
            color: roundedRectangle.color
            height: cornerSide % 2 ? roundedRectangle.border.width: roundedRectangle.height - 2 * roundedRectangle.border.width
            width: cornerSide % 2 ? roundedRectangle.width - 2 * roundedRectangle.border.width: roundedRectangle.border.width
            anchors
            {
                right: cornerSide == RoundedRectangle.Direction.Right ? parent.right : undefined
                bottom: cornerSide  == RoundedRectangle.Direction.Down ? parent.bottom: undefined
                horizontalCenter: cornerSide % 2 ? parent.horizontalCenter: undefined
                verticalCenter: cornerSide % 2 ? undefined: parent.verticalCenter
            }
        }
    }
}