title: QML button toggling
body: <p>I want to have a button in QML that has 3 states: off, pressed, and on. right now I have the following for code, but it does not work. right now i have a toggle function that sets the new state based on the previous state, but if the previous state is "pressed" then how can I detect the state before it is pressed to toggle the button?</p>
  
  <p>the following is not the whole class, just the relevant function and Mouse Area</p>
  
  <pre><code>    Rectangle {
          id: button1
          function toggle(){
              var tempstate = button1.state
              if (tempstate=="on") {tempstate = "off"; } else { tempstate ="on"}
          }
  
          MouseArea {
              anchors.fill: parent
              onPressed: parent.state = "pressed"
              onReleased: parent.toggle()
          }
  </code></pre>