State of added point will depend on already added points state
This commit is contained in:
parent
eb463ca09f
commit
6ca06ca24d
4 changed files with 178 additions and 47 deletions
|
@ -7,6 +7,7 @@ Rectangle{
|
|||
property string actionTypeColor: "blue" //TODO default value
|
||||
property int actionType: 1 //TODO default value
|
||||
property double actionTypeOpacity: 1
|
||||
property string actionTypeImage: "/home/stefan/Projects/tellstick/trunk/telldus-gui/TelldusCenter/images/devices.png"
|
||||
property string isPoint: "true"
|
||||
property variant isLoaded
|
||||
property int xvalue
|
||||
|
@ -80,7 +81,7 @@ Rectangle{
|
|||
//opacity: 1
|
||||
id: actionImage
|
||||
width: 20; height: 20
|
||||
source: "/home/stefan/Projects/tellstick/trunk/telldus-gui/TelldusCenter/images/devices.png"
|
||||
source: pointRect.actionTypeImage
|
||||
}
|
||||
|
||||
Rectangle{
|
||||
|
@ -140,29 +141,29 @@ Rectangle{
|
|||
State {
|
||||
name: "on"
|
||||
PropertyChanges { target: pointRect; actionTypeColor: "blue"; actionTypeOpacity: 1 } //TODO: images!!
|
||||
PropertyChanges { target: actionImage; source: "/home/stefan/Projects/tellstick/trunk/telldus-gui/TelldusCenter/images/devices.png" }
|
||||
PropertyChanges { target: pointRect; actionTypeImage: "/home/stefan/Projects/tellstick/trunk/telldus-gui/TelldusCenter/images/devices.png" }
|
||||
},
|
||||
State{
|
||||
name: "off"
|
||||
PropertyChanges { target: pointRect; actionTypeColor: "gainsboro"; actionTypeOpacity: 0 }
|
||||
PropertyChanges { target: actionImage; source: "/home/stefan/Projects/tellstick/trunk/telldus-gui/TelldusCenter/images/devices-bw.png" }
|
||||
PropertyChanges { target: pointRect; actionTypeImage: "/home/stefan/Projects/tellstick/trunk/telldus-gui/TelldusCenter/images/devices-bw.png" }
|
||||
//PropertyChanges { target: actionImage; source: "/home/stefan/Projects/tellstick/trunk/telldus-gui/TelldusCenter/images/devices-bw.png" }
|
||||
},
|
||||
State{
|
||||
name: "dim"
|
||||
PropertyChanges { target: pointRect; actionTypeColor: "green"; actionTypeOpacity: 1 }
|
||||
PropertyChanges { target: actionImage; source: "/home/stefan/Projects/tellstick/trunk/telldus-gui/TelldusCenter/images/TelldusCenter_128.png" }
|
||||
PropertyChanges { target: pointRect; actionTypeImage: "/home/stefan/Projects/tellstick/trunk/telldus-gui/TelldusCenter/images/TelldusCenter_128.png" }
|
||||
//something opacity = dim for example
|
||||
},
|
||||
State{
|
||||
name: "bell"
|
||||
PropertyChanges { target: pointRect; actionTypeColor: getLastPointColor() }
|
||||
PropertyChanges { target: actionImage; source: "icon.png" }
|
||||
PropertyChanges { target: pointRect; actionTypeImage: "icon.png" }
|
||||
}
|
||||
]
|
||||
|
||||
function toggleType(){ //TODO other kind of selection method
|
||||
var index = 0;
|
||||
|
||||
var activeStates = Scripts.getActiveStates();
|
||||
if(activeStates == undefined || activeStates.length == 0){
|
||||
return;
|
||||
|
@ -197,6 +198,11 @@ Rectangle{
|
|||
*/
|
||||
}
|
||||
|
||||
function setType(name){
|
||||
print("setting state to " + name);
|
||||
pointRect.state = name;
|
||||
}
|
||||
|
||||
function toggleTrigger(){ //TODO other kind of selection method
|
||||
if(trigger.state == "sunrise"){
|
||||
trigger.state = "sunset";
|
||||
|
@ -252,4 +258,44 @@ Rectangle{
|
|||
function addState(state){
|
||||
Scripts.addState(state);
|
||||
}
|
||||
|
||||
function setFirstState(firstState){
|
||||
|
||||
var activeStates = Scripts.getActiveStates();
|
||||
|
||||
if(activeStates == null || activeStates.length == 0){
|
||||
//nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
//state may already be set:
|
||||
if(firstState != undefined && firstState != ""){
|
||||
pointRect.state = firstState;
|
||||
return;
|
||||
}
|
||||
|
||||
//check that device has the "off" state:
|
||||
var exists = false;
|
||||
for(var i=1;i<activeStates.length;i++){
|
||||
if(activeStates[i] == "off"){
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!exists){
|
||||
//no "off", just set state to the first added state
|
||||
pointRect.state = activeStates[0];
|
||||
return;
|
||||
}
|
||||
|
||||
var previousState = Scripts.getPreviousState(pointRect, pointRect.parent.children);
|
||||
if(previousState == "" || previousState == "off"){
|
||||
//nothing on/dimmed at the moment, use first added state
|
||||
pointRect.state = activeStates[0];
|
||||
return;
|
||||
}
|
||||
|
||||
pointRect.state = "off"; //previous point should be "on" or "dim"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,14 +3,19 @@
|
|||
Rectangle {
|
||||
id: container
|
||||
property ActionPoint actionPoint
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
var rootCoordinates = actionPoint.mapToItem(null, actionPoint.x, actionPoint.y);
|
||||
//container.x = rootCoordinates.x + actionPoint.parent.width/2 - container.width/2;
|
||||
container.y = rootCoordinates.y + actionPoint.height + 10;
|
||||
container.width = actionPoint.parent.width;
|
||||
container.x = (actionPoint.parent.parent.width - container.width)/2;
|
||||
}
|
||||
|
||||
function hide() {
|
||||
container.opacity = 0;
|
||||
|
@ -19,22 +24,18 @@
|
|||
|
||||
smooth: true
|
||||
radius: 5
|
||||
width: dialogText.width + 120
|
||||
height: dialogText.height + 220
|
||||
//width: 500 //TODO
|
||||
height: 500 // typelist.height * 2 + 50
|
||||
opacity: 0
|
||||
|
||||
Text {
|
||||
id: dialogText
|
||||
anchors.centerIn: parent
|
||||
text: ""
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: circleType //TODO only types this device has...
|
||||
height: 20
|
||||
width: 100
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.verticalCenterOffset: 0
|
||||
anchors.left: typeList.right
|
||||
anchors.leftMargin: 50
|
||||
|
||||
property color buttonColor: "lightgrey"
|
||||
|
||||
|
@ -126,9 +127,83 @@
|
|||
color: buttonMouseAreaClose.pressed ? Qt.darker(buttonColor, 1.5) : buttonColor
|
||||
}
|
||||
|
||||
Row{
|
||||
ListView{
|
||||
id: typeList
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 20
|
||||
anchors.left: currentType.right
|
||||
anchors.leftMargin: 10
|
||||
width: 100 //TODO relative
|
||||
height: 100 //TODO relative
|
||||
//anchors.fill: parent
|
||||
model: typeSelection
|
||||
delegate: typeSelectionRow
|
||||
highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
|
||||
|
||||
//TODO can these paths be turned into some kind of constants? Import from common file or something?
|
||||
ListModel{
|
||||
id: typeSelection
|
||||
ListElement{
|
||||
name: "on"
|
||||
imagesource: "/home/stefan/Projects/tellstick/trunk/telldus-gui/TelldusCenter/images/devices.png"
|
||||
}
|
||||
ListElement{
|
||||
name: "off"
|
||||
imagesource: "/home/stefan/Projects/tellstick/trunk/telldus-gui/TelldusCenter/images/devices-bw.png"
|
||||
}
|
||||
ListElement{
|
||||
name: "dim"
|
||||
imagesource: "/home/stefan/Projects/tellstick/trunk/telldus-gui/TelldusCenter/images/TelldusCenter_128.png"
|
||||
}
|
||||
ListElement{
|
||||
name: "bell"
|
||||
imagesource: "icon.png"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle{
|
||||
id: currentType
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 20
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 10
|
||||
border.color: "grey"
|
||||
border.width: 1
|
||||
width: 120
|
||||
height: 120
|
||||
Image{
|
||||
anchors.fill: parent
|
||||
source: actionPoint.actionTypeImage //TODO, set only when defined...
|
||||
}
|
||||
}
|
||||
|
||||
Component{
|
||||
id: typeSelectionRow
|
||||
Row{
|
||||
|
||||
Rectangle{
|
||||
border.color: "grey"
|
||||
border.width: 2
|
||||
anchors.leftMargin: 10
|
||||
width: 30; height: 30
|
||||
Image{
|
||||
anchors.fill: parent
|
||||
//anchors.left: typeSelectionText.right
|
||||
//anchors.leftMargin: 10
|
||||
//anchors.centerIn: parent
|
||||
source: imagesource
|
||||
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
//pointRect.focus = true
|
||||
container.actionPoint.setType(name)
|
||||
//typeList.highlight = name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ import "schedulerscripts.js" as Scripts
|
|||
id: main
|
||||
width: 800 //TODO how?
|
||||
height: 600 //TODO how?
|
||||
property variant sunData;
|
||||
property variant sunData
|
||||
property string dimImageSource: "/home/stefan/Projects/tellstick/trunk/telldus-gui/TelldusCenter/images/TelldusCenter_128.png" //TODO use this somehow?
|
||||
|
||||
Component{
|
||||
id: listRow
|
||||
|
@ -17,15 +18,17 @@ import "schedulerscripts.js" as Scripts
|
|||
width: parent.width; //TODO relative
|
||||
height: 50
|
||||
//color: "red"
|
||||
Rectangle { border.color: "red"; width: 100; height:parent.height;
|
||||
Rectangle {
|
||||
border.color: "red"; width: 100; height:parent.height;
|
||||
Text{
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
//text: "Device " + (index + 1) + "Name: " + name
|
||||
|
||||
text: modelData.name + height
|
||||
text: modelData.name
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle { id: "deviceRow"; border.color: "blue"; width: parent.width-100; height:parent.height;
|
||||
|
||||
MouseArea {
|
||||
|
@ -37,29 +40,25 @@ import "schedulerscripts.js" as Scripts
|
|||
//onEntered: parent.border.color = onHoverColor
|
||||
//onExited: parent.border.color = borderColor
|
||||
onClicked: {
|
||||
//ny point här
|
||||
|
||||
|
||||
var component = Qt.createComponent("ActionPoint.qml")
|
||||
var dynamicPoint = component.createObject(deviceRow)
|
||||
//dynamicPoint.x = mouseX (blir inte kvar)
|
||||
//dynamicPoint.
|
||||
dynamicPoint.x = mouseX - dynamicPoint.width/2 //xposition
|
||||
//dynamicPoint.width = mouseX-
|
||||
dynamicPoint.border.color = "blue"
|
||||
|
||||
//TODO different states depending on the device
|
||||
dynamicPoint.addState("on");
|
||||
dynamicPoint.addState("off");
|
||||
dynamicPoint.addState("dim");
|
||||
dynamicPoint.addState("bell");
|
||||
//dynamicPoint.setFirstState("dim"); //when type is a stored value
|
||||
dynamicPoint.setFirstState();
|
||||
|
||||
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
|
||||
//dynamicBar.width = 100 //TODO dependent of this and next point position
|
||||
|
||||
|
||||
//deviceRow.add(point)
|
||||
//TODO destroy? (only to remove them if needed)
|
||||
//TODO komponenter med stor bokstav kanske?
|
||||
|
@ -214,7 +213,7 @@ import "schedulerscripts.js" as Scripts
|
|||
|
||||
Dialog {
|
||||
id: dialog
|
||||
anchors.centerIn: parent
|
||||
//anchors.centerIn: parent
|
||||
z: 150
|
||||
}
|
||||
|
||||
|
@ -287,11 +286,4 @@ import "schedulerscripts.js" as Scripts
|
|||
//kan man liksom göra hela linjen (från en vecka tillbaka) men inte visa den? Om det är vettigt... Då hade man tom kunnat zooma en vacker dag
|
||||
//properties, ställa in dem...
|
||||
//fuzziness
|
||||
/*
|
||||
* Dialog {
|
||||
id: dialog
|
||||
anchors.centerIn: parent
|
||||
z: 100
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -24,14 +24,22 @@ function getBarWidth(currentBar, currentPointRect, pointList){
|
|||
return nextX - (currentPointRect.x + halfPointWidth);
|
||||
}
|
||||
|
||||
function pad(number, length) {
|
||||
|
||||
var str = '' + number;
|
||||
while (str.length < length) {
|
||||
str = '0' + str;
|
||||
}
|
||||
|
||||
return str;
|
||||
function getPreviousState(currentPointRect, pointList){
|
||||
|
||||
var prevPoint = null;
|
||||
for(var i=0;i<pointList.length;i++){
|
||||
if(pointList[i].isPoint != undefined && pointList[i] != currentPointRect){
|
||||
if(pointList[i].x < currentPointRect.x && (prevPoint == null || pointList[i].x > prevPoint.x) && pointList[i].state != "bell"){ //TODO when more than "bell", make dynamic
|
||||
prevPoint = pointList[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(prevPoint == null){
|
||||
return "";
|
||||
}
|
||||
|
||||
return prevPoint.state;
|
||||
}
|
||||
|
||||
function isMidnightDark(){
|
||||
|
@ -49,3 +57,13 @@ function isMidnightDark(){
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function pad(number, length) {
|
||||
|
||||
var str = '' + number;
|
||||
while (str.length < length) {
|
||||
str = '0' + str;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue