Toggle states
This commit is contained in:
parent
f5032da87d
commit
4887e4e90a
4 changed files with 145 additions and 20 deletions
|
@ -3,8 +3,16 @@ import Qt 4.7
|
||||||
Rectangle{
|
Rectangle{
|
||||||
id: pointRect
|
id: pointRect
|
||||||
//property variant xposition
|
//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 string isPoint: "true"
|
||||||
|
property variant isLoaded
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
//TODO useless really, still gets Cannot anchor to a null item-warning...
|
||||||
|
isLoaded = "true"
|
||||||
|
}
|
||||||
//x: xposition
|
//x: xposition
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -20,14 +28,12 @@ Rectangle{
|
||||||
border.color: "black"
|
border.color: "black"
|
||||||
opacity: 0.8
|
opacity: 0.8
|
||||||
z: 100
|
z: 100
|
||||||
|
state: "on"
|
||||||
|
//actionTypeColor: getColor()
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if(actionType == "red"){
|
|
||||||
actionType = "blue"
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
actionType = "red"
|
|
||||||
}
|
|
||||||
//pointRect.border.color: "red"
|
//pointRect.border.color: "red"
|
||||||
//Fungerar inte: for(var child in myListView.children){
|
//Fungerar inte: for(var child in myListView.children){
|
||||||
// dialog.show("hej?")
|
// dialog.show("hej?")
|
||||||
|
@ -40,8 +46,8 @@ Rectangle{
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
//dialog.show("Width: " + Scripts.getBarWidth(pointRect, parent.parent.children));
|
//dialog.show("Width: " + Scripts.getBarWidth(pointRect, parent.parent.children));
|
||||||
|
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
|
//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...
|
//onPositionChange... maybe emit signal to change in row...
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
@ -68,4 +74,63 @@ Rectangle{
|
||||||
source: "/home/stefan/Downloads/11949889941371111141clock_michael_breuer_01.svg.hi.png"
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,23 +2,25 @@
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: container
|
id: container
|
||||||
|
property ActionPoint actionPoint
|
||||||
|
|
||||||
function show(text) {
|
function show(actionPoint) {
|
||||||
dialogText.text = text;
|
dialogText.text = "Nice dialog with possibility to set type of action, exact time, fuzziness, offset etc"
|
||||||
container.opacity = 1;
|
container.opacity = 1;
|
||||||
container.border.color = "black"
|
container.border.color = "black"
|
||||||
container.border.width = 2
|
container.border.width = 2
|
||||||
|
container.actionPoint = actionPoint
|
||||||
}
|
}
|
||||||
|
|
||||||
function hide() {
|
function hide() {
|
||||||
container.opacity = 0;
|
container.opacity = 0;
|
||||||
container.border.width = 0
|
container.border.width = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
smooth: true
|
smooth: true
|
||||||
radius: 5
|
radius: 5
|
||||||
width: dialogText.width + 120
|
width: dialogText.width + 120
|
||||||
height: dialogText.height + 120
|
height: dialogText.height + 220
|
||||||
opacity: 0
|
opacity: 0
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
|
@ -26,9 +28,64 @@
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
text: ""
|
text: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: circleType //TODO only types this device has...
|
||||||
|
height: 20
|
||||||
|
width: 100
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
anchors.verticalCenterOffset: 0
|
||||||
|
|
||||||
MouseArea {
|
property color buttonColor: "lightgrey"
|
||||||
anchors.fill: parent
|
|
||||||
onClicked: hide();
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,8 @@ import "schedulerscripts.js" as Scripts
|
||||||
|
|
||||||
var dynamicBar = actionBar.createObject(deviceRow)
|
var dynamicBar = actionBar.createObject(deviceRow)
|
||||||
dynamicBar.hangOnToPoint = dynamicPoint
|
dynamicBar.hangOnToPoint = dynamicPoint
|
||||||
|
|
||||||
|
dialog.show(dynamicPoint)
|
||||||
//dynamicBar.width = Scripts.getBarWidth(dynamicPoint, deviceRow.children)
|
//dynamicBar.width = Scripts.getBarWidth(dynamicPoint, deviceRow.children)
|
||||||
//dynamicBar.color = "blue" //TODO dependent of point type
|
//dynamicBar.color = "blue" //TODO dependent of point type
|
||||||
//dynamicBar.anchors.left = dynamicPoint.right
|
//dynamicBar.anchors.left = dynamicPoint.right
|
||||||
|
@ -226,12 +228,13 @@ import "schedulerscripts.js" as Scripts
|
||||||
// couldnt get this to work:
|
// couldnt get this to work:
|
||||||
// (if it works later on, try to set opacity for actionPoint in this way too)
|
// (if it works later on, try to set opacity for actionPoint in this way too)
|
||||||
states: State {
|
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 {
|
PropertyChanges {
|
||||||
target: barRectangle
|
target: barRectangle
|
||||||
anchors.verticalCenter: hangOnToPoint.verticalCenter
|
anchors.verticalCenter: hangOnToPoint.verticalCenter
|
||||||
anchors.left: hangOnToPoint.horizontalCenter
|
anchors.left: hangOnToPoint.horizontalCenter
|
||||||
color: hangOnToPoint.actionType
|
color: hangOnToPoint.actionTypeColor
|
||||||
|
opacity: hangOnToPoint.actionTypeOpacity
|
||||||
width: Scripts.getBarWidth(actionBar, hangOnToPoint, hangOnToPoint.parent.children)
|
width: Scripts.getBarWidth(actionBar, hangOnToPoint, hangOnToPoint.parent.children)
|
||||||
}
|
}
|
||||||
//anchors.verticalCenter: hangOnToPoint.verticalCenter
|
//anchors.verticalCenter: hangOnToPoint.verticalCenter
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
function getBarWidth(currentBar, currentPointRect, pointList){
|
function getBarWidth(currentBar, currentPointRect, pointList){
|
||||||
|
|
||||||
var maxWidth = currentPointRect.parent.width;
|
var maxWidth = currentPointRect.parent.width;
|
||||||
var nextX = maxWidth
|
var nextX = maxWidth
|
||||||
var halfPointWidth = currentPointRect.width / 2
|
var halfPointWidth = currentPointRect.width / 2
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue