Toggle states

This commit is contained in:
Stefan Persson 2011-01-17 12:42:54 +00:00
parent f5032da87d
commit 4887e4e90a
4 changed files with 145 additions and 20 deletions

View file

@ -3,8 +3,16 @@ import Qt 4.7
Rectangle{
id: pointRect
//property variant xposition
property string actionType: "blue"
property string actionTypeColor: "blue" //TODO default value
property int actionType: 1 //TODO default value
property double actionTypeOpacity: 1
property string isPoint: "true"
property variant isLoaded
Component.onCompleted: {
//TODO useless really, still gets Cannot anchor to a null item-warning...
isLoaded = "true"
}
//x: xposition
/*
@ -20,14 +28,12 @@ Rectangle{
border.color: "black"
opacity: 0.8
z: 100
state: "on"
//actionTypeColor: getColor()
MouseArea {
onClicked: {
if(actionType == "red"){
actionType = "blue"
}
else{
actionType = "red"
}
//pointRect.border.color: "red"
//Fungerar inte: for(var child in myListView.children){
// dialog.show("hej?")
@ -40,8 +46,8 @@ Rectangle{
}
*/
//dialog.show("Width: " + Scripts.getBarWidth(pointRect, parent.parent.children));
dialog.show("Nice dialog with possibility to set type of action, exact time, fuzziness, offset etc") //myListView.children[0].children[0].x), parent.x = punktens x, parent.parent.children = siblings... starting from 1
dialog.show(pointRect) //TODO om inte redan i visandes läge....
//dialog.show("Nice dialog with possibility to set type of action, exact time, fuzziness, offset etc") //myListView.children[0].children[0].x), parent.x = punktens x, parent.parent.children = siblings... starting from 1
}
//onPositionChange... maybe emit signal to change in row...
anchors.fill: parent
@ -68,4 +74,63 @@ Rectangle{
source: "/home/stefan/Downloads/11949889941371111141clock_michael_breuer_01.svg.hi.png"
}
}
states: [
State {
name: "on"
PropertyChanges { target: pointRect; actionTypeColor: "blue"; actionTypeOpacity: 1 }
},
State{
name: "off"
PropertyChanges { target: pointRect; actionTypeColor: "red"; actionTypeOpacity: 1 }
},
State{
name: "dim"
PropertyChanges { target: pointRect; actionTypeColor: "green"; actionTypeOpacity: 1 }
//something opacity = dim for example
},
State{
name: "bell"
PropertyChanges { target: pointRect; actionTypeColor: getLastPointColor() }
}
]
function toggleType(){
print(pointRect.state);
if(pointRect.state == "on"){
pointRect.state = "off"
}
else if(pointRect.state == "off"){
pointRect.state = "dim"
}
else if(pointRect.state == "dim"){
pointRect.state = "bell"
}
else if(pointRect.state == "bell"){
pointRect.state = "on"
}
}
function getLastPointColor(){
//get previous point:
var prevPoint = null;
var pointList = pointRect.parent.children;
for(var i=1;i<pointList.length;i++){
if (pointList[i].isPoint != undefined && pointList[i] != pointRect) {
if(pointList[i].x < pointRect.x && (prevPoint == null || pointList[i].x > prevPoint.x)){
prevPoint = pointList[i];
}
}
}
//TODO Binding loop here when moving transperent point over other point
if(prevPoint == null || prevPoint.actionTypeOpacity == 0){
//no point before, no bar after either
actionTypeOpacity = 0
return "papayawhip" //just return a color, will not be used
}
actionTypeOpacity = 1
return prevPoint.actionTypeColor
}
}

View file

@ -2,23 +2,25 @@
Rectangle {
id: container
property ActionPoint actionPoint
function show(text) {
dialogText.text = text;
function show(actionPoint) {
dialogText.text = "Nice dialog with possibility to set type of action, exact time, fuzziness, offset etc"
container.opacity = 1;
container.border.color = "black"
container.border.width = 2
container.actionPoint = actionPoint
}
function hide() {
container.opacity = 0;
container.border.width = 0
}
smooth: true
radius: 5
width: dialogText.width + 120
height: dialogText.height + 120
height: dialogText.height + 220
opacity: 0
Text {
@ -26,9 +28,64 @@
anchors.centerIn: parent
text: ""
}
Rectangle {
id: circleType //TODO only types this device has...
height: 20
width: 100
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenterOffset: 0
MouseArea {
anchors.fill: parent
onClicked: hide();
}
property color buttonColor: "lightgrey"
Text{
text: "Toggle type"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
anchors.margins: 2
}
MouseArea {
id: buttonMouseAreaType
anchors.fill: parent
hoverEnabled: true
//onEntered: parent.border.color = onHoverColor
//onExited: parent.border.color = borderColor
onClicked: {
container.actionPoint.toggleType();
}
}
color: buttonMouseAreaType.pressed ? Qt.darker(buttonColor, 1.5) : buttonColor
}
Rectangle { //TODO create common button-class
id: closeButton
height: 20
width: 100
anchors.horizontalCenter: circleType.right
anchors.horizontalCenterOffset: 30
property color buttonColor: "lightgrey"
Text{
text: "Close"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
anchors.margins: 2
}
MouseArea {
id: buttonMouseAreaClose
anchors.fill: parent
hoverEnabled: true
//onEntered: parent.border.color = onHoverColor
//onExited: parent.border.color = borderColor
onClicked: {
hide();
}
}
color: buttonMouseAreaClose.pressed ? Qt.darker(buttonColor, 1.5) : buttonColor
}
}

View file

@ -104,6 +104,8 @@ import "schedulerscripts.js" as Scripts
var dynamicBar = actionBar.createObject(deviceRow)
dynamicBar.hangOnToPoint = dynamicPoint
dialog.show(dynamicPoint)
//dynamicBar.width = Scripts.getBarWidth(dynamicPoint, deviceRow.children)
//dynamicBar.color = "blue" //TODO dependent of point type
//dynamicBar.anchors.left = dynamicPoint.right
@ -226,12 +228,13 @@ import "schedulerscripts.js" as Scripts
// couldnt get this to work:
// (if it works later on, try to set opacity for actionPoint in this way too)
states: State {
name: "myState"; when: hangOnToPoint != undefined
name: "myState"; when: hangOnToPoint.isLoaded != undefined && hangOnToPoint.verticalCenter != undefined //TODO might aswell use hangOnToPoint != undefined, still get null item warning
PropertyChanges {
target: barRectangle
anchors.verticalCenter: hangOnToPoint.verticalCenter
anchors.left: hangOnToPoint.horizontalCenter
color: hangOnToPoint.actionType
color: hangOnToPoint.actionTypeColor
opacity: hangOnToPoint.actionTypeOpacity
width: Scripts.getBarWidth(actionBar, hangOnToPoint, hangOnToPoint.parent.children)
}
//anchors.verticalCenter: hangOnToPoint.verticalCenter

View file

@ -1,6 +1,6 @@
function getBarWidth(currentBar, currentPointRect, pointList){
var maxWidth = currentPointRect.parent.width;
var nextX = maxWidth
var halfPointWidth = currentPointRect.width / 2