examples/declarative/ui-components/slideswitch/content/Switch.qml
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    51 
    51 
    52 //![2]
    52 //![2]
    53     function toggle() {
    53     function toggle() {
    54         if (toggleswitch.state == "on")
    54         if (toggleswitch.state == "on")
    55             toggleswitch.state = "off";
    55             toggleswitch.state = "off";
    56         else toggleswitch.state = "on";
    56         else 
       
    57             toggleswitch.state = "on";
    57     }
    58     }
    58 //![2]
    59 //![2]
    59 
    60 
    60 //![3]
    61 //![3]
    61     function dorelease() {
    62     function releaseSwitch() {
    62         if (knob.x == 1) {
    63         if (knob.x == 1) {
    63             if (toggleswitch.state == "off") return;
    64             if (toggleswitch.state == "off") return;
    64         }
    65         }
    65         if (knob.x == 78) {
    66         if (knob.x == 78) {
    66             if (toggleswitch.state == "on") return;
    67             if (toggleswitch.state == "on") return;
    85 
    86 
    86         MouseArea {
    87         MouseArea {
    87             anchors.fill: parent
    88             anchors.fill: parent
    88             drag.target: knob; drag.axis: Drag.XAxis; drag.minimumX: 1; drag.maximumX: 78
    89             drag.target: knob; drag.axis: Drag.XAxis; drag.minimumX: 1; drag.maximumX: 78
    89             onClicked: toggle()
    90             onClicked: toggle()
    90             onReleased: dorelease()
    91             onReleased: releaseSwitch()
    91         }
    92         }
    92     }
    93     }
    93 //![5]
    94 //![5]
    94 
    95 
    95 //![6]
    96 //![6]