summaryrefslogtreecommitdiffstats
path: root/examples/painting/painting.qml
blob: d691834bfe537e776f1b58d0140943a4b059f33b (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import "../../Canvas"
import Qt 4.7

Rectangle {
    id:root
    width:500
    height:300
    color:"#333"
    anchors.margins: 4

    Rectangle {
        width:300
        height:260
        color:"#222"
        x:8
        y:8

        Drawing {
            id:canvas
            width:parent.width
            height:parent.height
            anchors.margins:-2
            x:-3
            y:-3
        }
    }

    ListModel {
        id:model
    }

    Rectangle {
        color:"#222"
        anchors.right: parent.right
        height:parent.height
        width:180
        ListView {
            id:view
            anchors.fill: parent
            delegate: idelegate
            model: model
        }
    }

    Component {
        id:idelegate
        Item {
            id:root
            width:120
            height:142
            anchors.horizontalCenter: parent.horizontalCenter
            Image {
                smooth:true
                width:140
                fillMode: Image.PreserveAspectFit
                anchors.centerIn: parent
                source: src
            }
            ListView.onAdd:NumberAnimation{target: root; property: "opacity" ; from:0; to:1; duration:500}
        }
    }

    FocusScope {
        id: colorpicker
        anchors.bottom: parent.bottom
        anchors.left: parent.left
        anchors.margins: 8
        width:200
        height:22
        focus:true
        Row {
            id:row
            anchors.fill: parent
            spacing: 8
            Repeater {
                model: ["black","firebrick", "orange", "gold", "purple", "steelblue", "seagreen"]
                ColorButton { color: modelData }
            }
        }
    }

    Rectangle {
        id:savebutton
        width:80
        height:22
        color:"gray"
        radius: 4
        border.color: "#222"
        anchors.bottom: parent.bottom
        anchors.right: clearbutton.left
        anchors.leftMargin: 32
        anchors.margins: 8
        Text { text: "Save" ; anchors.centerIn: parent}
        MouseArea {
            anchors.fill:parent
            onClicked: {
                var name = "canvas" + canvas.count++ +".png";
                canvas.save("examples/painting/"+name);
                model.append({src:name});
                view.currentIndex = model.count-1
            }
        }
    }

    Rectangle {
        id:clearbutton
        width:80
        height:22
        color:"gray"
        border.color: "#222"
        radius: 4
        anchors.bottom: parent.bottom
        anchors.right: parent.right
        anchors.margins: 8
        Text { text: "Clear" ; anchors.centerIn: parent}
        MouseArea {
            anchors.fill:parent
            onClicked: canvas.clear();
        }
    }
}