import QtQuick 2.0 import Label 2.0 import "../com/neusoft/auto/widgets" /* * Copyright (C) 2013 by Neusoft * Author : Zhaozhicheng * */ /** * A Switcher . */ import QtQuick 2.0 Rectangle { id: toggleBackground width: 123 height: 41 color: "#08417B" border.color: "white" /*******************************External Interface************************/ /** * type:bool * This property holds the togglePoint's x when the component is completed. * if you specify it false,the Switcher's switch will be off. * The default is true */ property bool completePos: true /** * type:bool * This property set the FlickButton's switch. * For example,when button is clicked,if you specify it false,the Switcher's switch will be off. */ property bool setSwitch /** * type:bool * This property set the diaplay of the Switcher's label. * For example,when showlabel si true,the Switcher's label will be always diplayed. * The default value is false */ property bool showlabel: false /** * type:bool * This property holds the togglePoint's switch. * Read-Only property */ property bool buttonSwitch/*:togglePointer.x == 0 ?false:true*/ /** * type:string * This property holds the source url for the Switcher's background image. * * The default value is an empty url, which displays no background image. */ // property alias backgroundImg: toggleBackground.source /** * type:string * This property holds the source url for the FlickButton's pointer image. * * The default value is an empty url, which displays no pointer image. */ // property alias pointerImg: togglePointer.source /** * type:string * This property holds the leftLabel's text of the Switcher. */ property alias leftLabelText: toggleLeftLabel.text /** * type:string * This property holds the leftLabel's color of the Switcher. */ property alias leftLabelColor: toggleLeftLabel.color /** * type:string * This property holds the text's pointSize of the leftLabel of the Switcher. */ property alias leftLabelSize: toggleLeftLabel.font.pixelSize /** * type:string * This property holds the rightLabel's text of the Switcher. */ property alias rightLabelText: toggleRightLabel.text /** * type:string * This property holds the rightLabel's color of the Switcher. */ property alias rightLabelColor: toggleRightLabel.color /** * type:string * This property holds the text's pointSize of the rightLabel of the Switcher. */ property alias rightLabelSize: toggleRightLabel.font.pixelSize /*******************************Internal Interface************************/ /** * type:real * This property holds the pointer's x of the starting position of the animation. */ property real state1x /** * type:real * This property holds the pointer's x of the target position of the animation. */ property real state2x /** * type:bool * This property holds the leftlabel's text will be diaplayed or not. */ property bool showLText: togglePointer.x>togglePointer.width / 2?true:false /** * type:bool * This property holds the rightlabel's text will be diaplayed or not. */ property bool showRText: togglePointer.x toggleBackground.width - togglePointer.width) { buttonSwitch = true numanimation.stop() if(!dragarea.drag.active) { state1x = togglePointer.x state2x = toggleBackground.width-togglePointer.width numanimation.start() } } } } Rectangle { id: togglePointer width: 59 height: 41 color: "gray" border.color: "white" //color: "#E0E0E0" HMIMouseArea{ id: dragarea anchors.fill: parent drag.target: togglePointer drag.axis: "XAxis" drag.minimumX: 0 drag.maximumX: toggleBackground.width-togglePointer.width onPressed: { numanimation.stop() } onReleased: { toggleBackground.focus = true if(togglePointer.x + togglePointer.width/2 < toggleBackground.width - togglePointer.width) { buttonSwitch = false numanimation.stop() state1x = togglePointer.x state2x = 0 numanimation.start() } else if(togglePointer.x + togglePointer.width/2 > toggleBackground.width - togglePointer.width) { buttonSwitch = true numanimation.stop() state1x = togglePointer.x state2x = toggleBackground.width-togglePointer.width numanimation.start() } } } } onSetSwitchChanged: { toggleBackground.focus = true numanimation.stop() if(!dragarea.drag.active) { if(setSwitch == true) { buttonSwitch = true state1x = togglePointer.x state2x = toggleBackground.width-togglePointer.width numanimation.start() } else { buttonSwitch = false state1x = togglePointer.x state2x = 0 numanimation.start() } } } NumberAnimation { id: numanimation target: togglePointer property: "x" from: state1x to: state2x duration: 400 } }