Skip to content

Commit

Permalink
Create3Widget toggle options
Browse files Browse the repository at this point in the history
  • Loading branch information
erinharrington-12 committed Jan 24, 2024
1 parent 7ec1606 commit d0d6be7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
Binary file added left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions rc/qml/Switch.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import QtQuick 2.0

Item {
id: toggleswitch
width: background.width; height: background.height

property bool on: false

function toggle() {
if (toggleswitch.state == "on")
toggleswitch.state = "off";
else
toggleswitch.state = "on";
}

function releaseSwitch() {
if (knob.x == 1) {
if (toggleswitch.state == "off") return;
}
if (knob.x == 78) {
if (toggleswitch.state == "on") return;
}
toggle();
}

Image {
id: background
source: "background.png"
MouseArea { anchors.fill: parent; onClicked: toggle() }
}

Image {
id: knob
x: 1; y: 2
source: "knob.png"

MouseArea {
anchors.fill: parent
drag.target: knob; drag.axis: Drag.XAxis; drag.minimumX: 1; drag.maximumX: 78
onClicked: toggle()
onReleased: releaseSwitch()
}
}

states: [
State {
name: "on"
PropertyChanges { target: knob; x: 78 }
PropertyChanges { target: toggleswitch; on: true }
},
State {
name: "off"
PropertyChanges { target: knob; x: 1 }
PropertyChanges { target: toggleswitch; on: false }
}
]

transitions: Transition {
NumberAnimation { properties: "x"; easing.type: Easing.InOutQuad; duration: 200 }
}
}
Binary file added right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d0d6be7

Please sign in to comment.