blob: 0edb0a227808566a20b9052a9eeead24523af548 (
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
|
import Qt 4.6
Item {
id: togglebutton
width: imgItem.width + txtItem.width + gui.width/24; height: imgItem.height
property string stOn: "false"
property string text: "Toggle button"
property string icon: "Icon.png"
signal changed
function toggle() {
if (togglebutton.state == "on")
togglebutton.state = "off";
else
togglebutton.state = "on";
}
function startup () {
if (togglebutton.stOn == "1" )
togglebutton.stOn = "true";
else
togglebutton.stOn = "false";
if (togglebutton.stOn == "true")
togglebutton.state = "on";
else
togglebutton.state = "off";
}
Component.onCompleted: startup();
MouseRegion { id: mr; anchors.fill: parent; onReleased: toggle() }
Image {
id: imgItem; source: gui.iconPath+togglebutton.icon; anchors.top: togglebutton.top; anchors.horizontalCenter: togglebutton.horizontalCenter;
width: gui.height/32; height: gui.height/32
}
Text {
id: txtItem; text: togglebutton.text; anchors.top: imgItem.bottom; anchors.horizontalCenter: togglebutton.horizontalCenter;
color: "White"; font.pointSize: gui.height/64; horizontalAlignment: Qt.AlignHCenter
}
states: [
State {
name: "on"
PropertyChanges { target: imgItem; opacity: 1 }
PropertyChanges { target: txtItem; opacity: 1 }
PropertyChanges { target: togglebutton; stOn: "true" }
StateChangeScript { script: togglebutton.changed(); }
},
State {
name: "off"
PropertyChanges { target: imgItem; opacity: 0.3 }
PropertyChanges { target: txtItem; opacity: 0.3 }
PropertyChanges { target: togglebutton; stOn: "false" }
StateChangeScript { script: togglebutton.changed(); }
}
]
transitions: Transition {
NumberAnimation { matchProperties: "scale"; easing: "easeOutExpo"; duration: 200 }
NumberAnimation { matchProperties: "opacity"; easing: "easeInQuad"; duration: 200 }
}
}
|