summaryrefslogtreecommitdiffstats
path: root/examples/declarative/slideswitch/Switch.qml
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/slideswitch/Switch.qml')
-rw-r--r--examples/declarative/slideswitch/Switch.qml104
1 files changed, 72 insertions, 32 deletions
diff --git a/examples/declarative/slideswitch/Switch.qml b/examples/declarative/slideswitch/Switch.qml
index 90e6e64..f62e4b6 100644
--- a/examples/declarative/slideswitch/Switch.qml
+++ b/examples/declarative/slideswitch/Switch.qml
@@ -1,6 +1,12 @@
-<Item id="Switch" width="{Groove.width}" height="{Groove.height}">
- <properties><Property name="on"/></properties>
- <Script>
+Item {
+ id: Switch
+ width: Groove.width
+ height: Groove.height
+ properties: Property {
+ name: "on"
+ }
+ Script {
+
function toggle() {
if(Switch.state == "On")
Switch.state = "Off";
@@ -21,32 +27,66 @@
toggle();
}
- </Script>
- <Image id="Groove" src="background.svg"/>
- <MouseRegion anchors.fill="{Groove}" onClicked="toggle()"/>
- <Image id="Knob" src="knob.svg" x="1" y="2"/>
- <MouseRegion anchors.fill="{Knob}"
- onClicked="toggle()"
- onReleased="if (!isClick) dorelease()"
- drag.target="{Knob}"
- drag.axis="x"
- drag.xmin="1"
- drag.xmax="78"/>
-
- <states>
- <State name="On">
- <SetProperty target="{Knob}" property="x" value="78" />
- <SetProperty target="{Switch}" property="on" value="true" />
- </State>
- <State name="Off">
- <SetProperty target="{Knob}" property="x" value="1" />
- <SetProperty target="{Switch}" property="on" value="false" />
- </State>
- </states>
-
- <transitions>
- <Transition>
- <NumericAnimation properties="x" easing="easeInOutQuad" duration="200"/>
- </Transition>
- </transitions>
-</Item>
+
+ }
+ Image {
+ id: Groove
+ src: "background.svg"
+ }
+ MouseRegion {
+ anchors.fill: Groove
+ onClicked: { toggle() }
+ }
+ Image {
+ id: Knob
+ src: "knob.svg"
+ x: 1
+ y: 2
+ }
+ MouseRegion {
+ anchors.fill: Knob
+ onClicked: { toggle() }
+ onReleased: { if (!isClick) dorelease() }
+ drag.target: Knob
+ drag.axis: "x"
+ drag.xmin: 1
+ drag.xmax: 78
+ }
+ states: [
+ State {
+ name: "On"
+ SetProperty {
+ target: Knob
+ property: "x"
+ value: 78
+ }
+ SetProperty {
+ target: Switch
+ property: "on"
+ value: true
+ }
+ },
+ State {
+ name: "Off"
+ SetProperty {
+ target: Knob
+ property: "x"
+ value: 1
+ }
+ SetProperty {
+ target: Switch
+ property: "on"
+ value: false
+ }
+ }
+ ]
+ transitions: [
+ Transition {
+ NumericAnimation {
+ properties: "x"
+ easing: "easeInOutQuad"
+ duration: 200
+ }
+ }
+ ]
+}