Code cleanup and small fixes: *Sun data is updated when browsing between days (dark/light areas, point positions), *More efficient reuse of sun data, *Moving points with keys only available in state 'absolute', *Removing timers from jobs loaded from storage correctly

This commit is contained in:
Stefan Persson 2011-02-16 11:09:38 +00:00
parent 84d6008dee
commit f808e3b079
5 changed files with 207 additions and 447 deletions

View file

@ -22,6 +22,7 @@ Rectangle{
property variant lastRun: 0;
//property int parentPointAbsoluteHour //TEST changed from int, want "undefined"
property alias deviceRow: pointRect.parent
property variant selectedDate: (deviceRow == null || deviceRow == undefined) ? new Date() : deviceRow.selectedDate
Component.onCompleted: {
//TODO useless really, still gets Cannot anchor to a null item-warning...
@ -41,27 +42,10 @@ Rectangle{
z: 100
state: "on"
focus: true
//actionTypeColor: getColor()
//TODO make this work:
/*Keys.onLeftPressed: {
pointRect.x = pointRect.x - 1
}
Keys.onRightPressed: {
pointRect.x = pointRect.x + 1
}
Text {
//focus: true
text: pointRect.activeFocus ? "I HAVE active focus!" : "I do NOT have active focus"
}
*/
//reflect changes on parent/siblings:
onAbsoluteHourChanged: {
updateChanges();
//print("ABSOLUTE HOUR CHANGED");
}
onAbsoluteMinuteChanged: {
@ -167,14 +151,14 @@ Rectangle{
PropertyChanges { target: triggerImage; source: imageTriggerSunrise; opacity: 1 }
PropertyChanges { target: triggerTime; opacity: 0 }
PropertyChanges { target: pointRectMouseArea; drag.target: undefined }
PropertyChanges { target: pointRect; x: getSunRiseTime.callWith(pointRect.parent.width, pointRect.width) + minutesToTimelineUnits(pointRect.offset) } //TODO se nedan
PropertyChanges { target: pointRect; x: getSunRiseTime.callWith(pointRect.parent.width, pointRect.width, pointRect.selectedDate) + minutesToTimelineUnits(pointRect.offset) } //TODO se nedan
},
State {
name: "sunset"
PropertyChanges { target: triggerImage; source: imageTriggerSunset; opacity: 1 }
PropertyChanges { target: triggerTime; opacity: 0 }
PropertyChanges { target: pointRectMouseArea; drag.target: undefined }
PropertyChanges { target: pointRect; x: getSunSetTime.callWith(pointRect.parent.width, pointRect.width) + minutesToTimelineUnits(pointRect.offset) } //TODO räkna om till tidsunits
PropertyChanges { target: pointRect; x: getSunSetTime.callWith(pointRect.parent.width, pointRect.width, pointRect.selectedDate) + minutesToTimelineUnits(pointRect.offset) } //TODO räkna om till tidsunits
},
State {
name: "absolute"; when: !pointRectMouseArea.drag.active
@ -272,8 +256,8 @@ Rectangle{
//print("Different x");
point = pointRect.parentPoint;
}
//print("ABSOLUTE X-value: " + (point.absoluteHour * hourSize + hourSize * (point.absoluteMinute/60) - point.width/2));
//print("AbsoluteHour: " +point.absoluteHour+ " hourSize: " + hourSize + " AbsoluteMinute: " + point.absoluteMinute + " Width: " + point.width);
print("ABSOLUTE X-value: " + (point.absoluteHour * hourSize + hourSize * (point.absoluteMinute/60) - point.width/2));
print("AbsoluteHour: " +point.absoluteHour+ " hourSize: " + hourSize + " AbsoluteMinute: " + point.absoluteMinute + " Width: " + point.width);
return point.absoluteHour * hourSize + hourSize * (point.absoluteMinute/60) - point.width/2;
}

View file

@ -11,12 +11,9 @@
focus: true
Keys.onPressed: {
tryme(event, "container");
var hours = 0;
var minutes = 0;
if (event.key == Qt.Key_Left) {
//actionPoint.x = actionPoint.x - 1
if (event.key == Qt.Key_Left && actionPoint.triggerstate == "absolute") { //step left, 1 min
var minutes = parseInt(inputAbsoluteMinuteText.text, 10);
var hours = parseInt(inputAbsoluteHourText.text, 10);
if(minutes == 0){
@ -31,8 +28,7 @@
}
event.accepted = true;
}
else if (event.key == Qt.Key_Right) {
//actionPoint.x = actionPoint.x + 1
else if (event.key == Qt.Key_Right && actionPoint.triggerstate == "absolute") { //step right, 1 min
var minutes = parseInt(inputAbsoluteMinuteText.text, 10);
var hours = parseInt(inputAbsoluteHourText.text, 10);
if(minutes == 59){
@ -49,9 +45,7 @@
}
else if( event.key == Qt.Key_Delete){
//TODO warning?
print("DELETING");
container.actionPoint.remove();
}
else{
return;
@ -69,7 +63,7 @@
//create default actionPoint, to avoid null values and binding errors
var component = Qt.createComponent("ActionPoint.qml")
var dynamicPoint = component.createObject(container)
dynamicPoint.opacity = 0 //TODO why not use "visible"? Test that...
dynamicPoint.opacity = 0
dynamicPoint.width = 0
dynamicPoint.height = 0
container.actionPoint = dynamicPoint
@ -88,7 +82,7 @@
container.actionPoint = actionPoint
var rootCoordinates = actionPoint.mapToItem(null, actionPoint.x, actionPoint.y);
container.y = rootCoordinates.y + actionPoint.height + 10;
container.y = rootCoordinates.y + actionPoint.height + 10; //TODO poistion in other way, too far down in some cases now
container.width = actionPoint.parent.width;
container.x = (actionPoint.parent.parent.width - container.width)/2;
container.opacity = 1;
@ -104,8 +98,7 @@
smooth: true
radius: 5
//width: 500 //TODO
height: 500 // typelist.height * 2 + 50
height: 500
opacity: 0
Button{
@ -118,11 +111,6 @@
onClicked: {
container.actionPoint.toggleType();
}
Keys.onLeftPressed: {
debug("Left pressed"); //TODO make it work
}
}
Button{
@ -559,13 +547,10 @@
width: weekColumn.width
Column{
id: "weekColumn"
//anchors.verticalCenter: parent.verticalCenter
//anchors.fill: parent
spacing: 2
Repeater{
id: weekRepeater
model: 7 //actionPoint.daysOfWeek
//delegate: weekDayDelegate
model: 7 //7 days, one week...
Rectangle{
width: 30
height: 30
@ -582,13 +567,11 @@
anchors.fill: parent
onClicked: {
actionPoint.toggleTickedWeekDay(index)
print("Just toggled, now update image: " + actionPoint);
tickBox.source = actionPoint.getTickedImageSource(index)
}
}
}
Text{
//anchors.fill: parent
anchors.left: tickBox.right
anchors.leftMargin: 10
text: Scripts.getOffsetWeekdayName(index)
@ -611,9 +594,7 @@
id: closeButton
text: "Close"
anchors.top: weekDayPanel.bottom
anchors.horizontalCenter: weekDayPanel.right //horizontalCenter
//y: circleTrigger.y + 30
//x: parent.x + 30
anchors.horizontalCenter: weekDayPanel.right
onClicked: {
hide();
}
@ -625,20 +606,19 @@
anchors.topMargin: 20
anchors.left: currentType.right
anchors.leftMargin: 10
width: 100 //TODO relative
height: 100 //TODO relative
width: 100
height: 100
model: typeSelection
delegate: typeSelectionRow
highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
snapMode: ListView.SnapToItem
interactive: false
//TODO can these paths be turned into some kind of constants? Import from common file or something?
ListModel{
id: typeSelection
ListElement{
name: "on"
imagesource: "on.png" //TODO cannot use javascript properties here... do in some other way, maybe a list with names here?
imagesource: "on.png"
}
ListElement{
name: "off"
@ -683,17 +663,12 @@
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
}
}
}
@ -701,10 +676,6 @@
}
}
function tryme(event, origin){
print("KEY: " + event.key + " Från: " + origin);
}
function getMinimumOffset(state){
//TODO this will not work if a value is set to the highest limit, then not reentering scheduler until the sunrise/set has changed so much that the device will be hidden anyway... Not common though
var minutes = 0;
@ -735,6 +706,6 @@
return 0 ;
}
return 24 * 60 - (parseInt(time[0], 10) * 60 + parseInt(time[1], 10));
return 24 * 60 - (parseInt(time[0], 10) * 60 + parseInt(time[1], 10));
}
}

View file

@ -8,10 +8,11 @@ __postInit__ = function() {
com.telldus.schedulersimplegui = function() {
var deviceList;
var view;
var restoredJobsTimerKeys;
var sunData;
function init() {
view = new com.telldus.qml.view({
addDevice: addDevice,
addJobsToSchedule: addJobsToSchedule,
getJob: getJob,
getMethodFromState: getMethodFromState,
@ -21,7 +22,8 @@ com.telldus.schedulersimplegui = function() {
getSunData: getSunData,
getTypeFromTriggerstate: getTypeFromTriggerstate,
getTriggerstateFromType: getTriggerstateFromType,
restoreJobs: restoreJobs
restoreJobs: restoreJobs,
updateSunData: updateSunData
});
//devices:
@ -37,9 +39,8 @@ com.telldus.schedulersimplegui = function() {
//Listen for device-change
com.telldus.core.deviceChange.connect(deviceChange);
//var storedPoints = loadJobs();
//view.setProperty('storedPoints', storedPoints);
updateSunData(new Date()); //default
//set images:
view.setProperty("imageTriggerSunrise", "sunrise.png");
view.setProperty("imageTriggerSunset", "sunset.png");
@ -55,16 +56,14 @@ com.telldus.schedulersimplegui = function() {
view.setProperty("constDeviceRowHeight", 50);
view.setProperty("constDeviceRowWidth", 600);
view.setProperty("constPointWidth", 30);
view.setProperty("mainHeight", 700); //TODO get this from somewhere
view.setProperty("mainWidth", 800); //TODO get this from somewhere
view.load("main.qml");
application.addWidget("scheduler.simple", "icon.png", view);
}
function addDevice() {
deviceList.push({name:'Stallet istallet'});
}
function deviceChange( deviceId, eventType ) {
if (eventType == com.telldus.core.TELLSTICK_DEVICE_ADDED) {
var item = com.telldus.core.deviceList.getDevice(deviceId);
@ -81,6 +80,13 @@ com.telldus.schedulersimplegui = function() {
com.telldus.scheduler.removeJob(deviceTimerKeys[i]);
}
}
if(restoredJobsTimerKeys != undefined && restoredJobsTimerKeys[deviceId] != undefined){
for(var i=0;i<restoredJobsTimerKeys[deviceId].length;i++){
var waitForMore = (i == restoredJobsTimerKeys[deviceId].length-1) ? "true" : undefined;
com.telldus.scheduler.removeJob(restoredJobsTimerKeys[deviceId][i]);
}
restoredJobsTimerKeys[deviceId] = undefined;
}
//add new schedules:
var jobs = new Array();
@ -88,9 +94,7 @@ com.telldus.schedulersimplegui = function() {
var jobtemp = getJob(points[i], callbackFunc);
jobs.push(jobtemp);
}
print("Adding some jobs " + jobs.length);
saveJobs(deviceId, jobs);
//return [];
return com.telldus.scheduler.addJobs(jobs);
}
@ -108,13 +112,14 @@ com.telldus.schedulersimplegui = function() {
function loadJobs(updateLastRun){
var settings = new com.telldus.settings();
var storedJobs = settings.value("jobs", "");
restoreJobsToSchedule(storedJobs, updateLastRun); //Start timers here
restoredJobsTimerKeys = restoreJobsToSchedule(storedJobs, updateLastRun); //Start timers here, save keys so they can be removed if jobs are updated
return storedJobs;
}
function restoreJobsToSchedule(storedJobs, updateLastRun){
var jobs = new Array();
var deviceTimerKeys = {};
for(var devicekey in storedJobs){
var jobs = new Array();
for(var i=0;i<storedJobs[devicekey].length;i++){
if(storedJobs[devicekey][i] == undefined){
continue;
@ -122,8 +127,11 @@ com.telldus.schedulersimplegui = function() {
var jobtemp = restoreJob(storedJobs[devicekey][i], updateLastRun);
jobs.push(jobtemp);
}
if(jobs.length > 0){
deviceTimerKeys[devicekey] = com.telldus.scheduler.addJobs(jobs); //have to do this per device, so that the timerkeys are stored for each device
}
}
return com.telldus.scheduler.addJobs(jobs)
return deviceTimerKeys;
}
function restoreJob(storedJob, updateLastRunInGUI){
@ -141,7 +149,6 @@ com.telldus.schedulersimplegui = function() {
function getJob(pointArray, updateLastRunInGUI){ //deviceId, pointName, startdate, lastrun, pointMethod, pointDimValue, pointTime, pointType, pointFuzzinessBefore, pointFuzzinessAfter, pointOffset, pointDays
//updateLastRunInGUI: deviceId, day of week, id
var execFunc = function(job){ print("Custom execute function running"); print("Job: " + job.v.name); var lastRun = new Date().getTime(); updateLastRun(job, lastRun); updateLastRunInGUI(job.v.device, job.v.events[job.v.id + "_0"].d.value, job.v.id, lastRun); return job.executeDefault();};
print("POINTARRAY3: " + pointArray[3]);
var job = new com.telldus.scheduler.JobRecurringWeek({id: pointArray[13], executeFunc: execFunc, name: pointArray[1], type: com.telldus.scheduler.JOBTYPE_RECURRING_WEEK, startdate: pointArray[2], lastRun: pointArray[3], device: pointArray[0], method: pointArray[4], value: pointArray[5], absoluteTime: pointArray[12]});
var event = {};
var pointFuzzinessBefore = (pointArray[8]*60);
@ -160,20 +167,13 @@ com.telldus.schedulersimplegui = function() {
return job;
}
//Update last run for this job from storage, then store it again
function updateLastRun(job, lastRun){
//TODO uppdatera både storage och värdet i pointen...
var settings = new com.telldus.settings();
var storedjobs = settings.value("jobs", "");
//settings.setValue("test", "TESTAR");
print("UPDATING LAST RUN 3 " + storedjobs);
for(var devicekey in storedjobs){
print("Key: " + devicekey);
if(devicekey == job.v.device){
print("En bra bit");
for(var i=0;i<storedjobs[devicekey].length;i++){
print("GREJ 2: " + storedjobs[devicekey][i].v.id);
print("JMF: " + job.v.id);
if(storedjobs[devicekey][i].v.id == job.v.id){
storedjobs[devicekey][i].v.lastRun = lastRun;
break;
@ -184,10 +184,6 @@ com.telldus.schedulersimplegui = function() {
}
settings.setValue("jobs", storedjobs);
print("saveD");
//för alla points denna... device och dag (parentpointens dag, dvs det som är lagrat i job)
//gå igenom punkterna, hitta punkt med korrekt id, uppdatera last run för den...
}
function getMethodFromState(state){
@ -224,9 +220,14 @@ com.telldus.schedulersimplegui = function() {
return state;
}
function updateSunData(date){
sunData = com.telldus.suncalculator.riseset(date);
return sunData;
}
function getSun(riseset, rowWidth, pointWidth){
var date = new Date();
var timevalues = com.telldus.suncalculator.riseset(date);
var timevalues = sunData;
var hourminute;
if(riseset == "rise"){
hourminute = timevalues[0].split(':');
@ -239,13 +240,12 @@ com.telldus.schedulersimplegui = function() {
}
//Raw sun data
function getSunData(){
var date = new Date;
function getSunData(date){
print("GET SUN DATA - can be made more efficient if called often...");
return com.telldus.suncalculator.riseset(date);
}
function getSunRiseTime(rowWidth, pointWidth){
return getSun("rise", rowWidth, pointWidth);
}

View file

@ -1,32 +1,32 @@
//import QtQuick 1.0 TODO not until 4.7.1
import Qt 4.7
import "schedulerscripts.js" as Scripts
import "mainscripts.js" as MainScripts
Item{
id: main
width: 800 //TODO how?
height: 700 //TODO how?
property variant sunData
width: mainWidth
height: mainHeight
property int dayListHeaderHeight: 15
property variant selectedDate: Scripts.getCurrentDate(); //Maybe just today
property variant sunData: MainScripts.getSunData();
Component.onCompleted: {
var dynamicDay = 0;
var previousDayEndsWithPoint = null; //previous day, nothing to begin with
var startday = new Date();
startday.setDate(startday.getDate() - 6);
for(var i=0;i<7;i++){ //One week, TODO dynamic
for(var i=0;i<7;i++){ //One week
dynamicDay = dayListViewComponent.createObject(mainContent)
dynamicDay.state = "hiddenLeft";
var currentDay = new Date(startday);
currentDay.setDate(startday.getDate() + i);
dynamicDay.daydate = currentDay;
//TODO previousDayEndsWith =
Scripts.addDay(dynamicDay);
Scripts.updateDeviceIndex(); //TODO, don't run in every iteration
}
dynamicDay.state = "visible" //set last one as visible
dynamicDay.state = "visible" //set last day (today) as visible
weekDayText.text = Scripts.getCurrentDayName()
//Scripts.updateDeviceIndex();
Scripts.updateDeviceIndex();
Scripts.setLoading();
var updateLastRunFunc = updateLastRun;
restoreJobs.callWith(updateLastRunFunc);
@ -41,61 +41,26 @@ import "schedulerscripts.js" as Scripts
width: parent.width
anchors.top: parent.top
anchors.left: parent.left
Rectangle{
NavButton{
id: leftarrow
anchors.right: weekDayText.left
anchors.verticalCenter: weekDayText.verticalCenter
height: 20
width: 20
border.color: "red"
Text{
anchors.centerIn: parent
text: "<-"
}
MouseArea{
anchors.fill: parent
onClicked: {
//step to prev weekday
dialog.hide()
Scripts.updateEndsWith()
Scripts.decrementCurrentDay()
weekDayText.text = Scripts.getCurrentDayName()
//mainListView.positionViewAtIndex(mainListView.currentIndex, ListView.Center)
//mainListView.currentIndex = mainListView.currentIndex - 1
}
arrowText: "<-"
onClicked: {
Scripts.decrementCurrentDay();
}
}
Text{
id: weekDayText
anchors.centerIn: parent
//text: ""
/*states: State{
name: "loaded";
PropertyChanges{ target: weekDayText; text: Scripts.getCurrentDay().dayName }
}
*/
}
Rectangle{
NavButton{
id: rightarrow
anchors.left: weekDayText.right
anchors.verticalCenter: weekDayText.verticalCenter
height: 20
width: 20
border.color: "red"
Text{
anchors.centerIn: parent
text: "->"
}
MouseArea{
anchors.fill: parent
onClicked: {
//step to next weekday
dialog.hide()
Scripts.updateEndsWith() //mainListView)
Scripts.incrementCurrentDay()
weekDayText.text = Scripts.getCurrentDayName()
//mainListView.positionViewAtIndex(mainListView.currentIndex, ListView.Center)
//mainListView.currentIndex = mainListView.currentIndex + 1
}
arrowText: "->"
onClicked: {
Scripts.incrementCurrentDay();
}
}
}
@ -108,9 +73,6 @@ import "schedulerscripts.js" as Scripts
Column{
id: mainHeader
//anchors.left: parent.left
//anchors.top: parent.top
//anchors.topMargin: dayListHeaderHeight
width: main.width - constDeviceRowWidth
spacing: 0
@ -148,6 +110,7 @@ import "schedulerscripts.js" as Scripts
//TODO implement setProperty if this is to be stored... or do something else... modelData.setProperty(index, isEnabled, modelData.isEnabled == "enabled" ? "disabled" : "enabled");
//TODO also implement disabled/enabled for all (deviceEnabled=false on all) and per point (set isPoint=false and opacity=0.4)...
//take that value into consideration when saving and sending jobs for execution
//else, remove this button
deviceNameRect.isEnabled = deviceNameRect.isEnabled == "enabled" ? "disabled" : "enabled"
Scripts.deviceEnabled(modelData.id, deviceNameRect.isEnabled);
}
@ -159,10 +122,8 @@ import "schedulerscripts.js" as Scripts
Rectangle{
id: mainContent
height: 700 //TODO
width: constDeviceRowWidth //TODO
//anchors.top: parent.top
//anchors.left: mainListViewHeaderColumn.right
height: mainHeight
width: constDeviceRowWidth
clip: true
z: 50
}
@ -175,200 +136,173 @@ import "schedulerscripts.js" as Scripts
id: dayListView
property date daydate
width: constDeviceRowWidth
height: 700 //TODO
height: mainHeight
//anchors.fill: parent
model: deviceModel
delegate: listRow
//focus: true
//footer: addButtonComponent //TODO move...
header: timeline
snapMode: ListView.SnapToItem
interactive: false //no scroll between devices at the moment
//anchors.top: parent.top;
//state: "hidden" //default
states: [
State {
name: "hiddenRight"; //when: parent.left != null
name: "hiddenRight";
AnchorChanges { target: dayListView; anchors.left: parent.right; anchors.right: undefined }
//PropertyChanges { target: dayListView; opacity: 0 }
},
State {
name: "hiddenLeft"; //when: parent.left != null
name: "hiddenLeft";
AnchorChanges { target: dayListView; anchors.left: undefined; anchors.right: parent.left }
//PropertyChanges { target: dayListView; opacity: 0 }
},
State {
name: "visible"; //when: parent.left != null
name: "visible";
PropertyChanges { target: dayListView; opacity: 1 }
AnchorChanges { target: dayListView; anchors.right: undefined; anchors.left: parent.left }
}
]
onChildrenChanged: {
//TODO REMOVE
print("-------------- CHILDREN CHANGED ----------------");
}
transitions: [
Transition {
from: "hiddenLeft"
to: "visible"
AnchorAnimation { easing.type: Easing.InOutQuad; duration: 1000 } //PropertyAnimation { properties: "x"; duration: 1000; easing.type: Easing.InOutQuad }
AnchorAnimation { easing.type: Easing.InOutQuad; duration: 1000 }
},
Transition {
from: "visible"
to: "hiddenRight"
AnchorAnimation { easing.type: Easing.InOutQuad; duration: 1000 } //PropertyAnimation { properties: "x"; duration: 1000; easing.type: Easing.InOutQuad }
AnchorAnimation { easing.type: Easing.InOutQuad; duration: 1000 }
},
Transition {
from: "visible"
to: "hiddenLeft"
AnchorAnimation { easing.type: Easing.InOutQuad; duration: 1000 } //PropertyAnimation { properties: "x"; duration: 1000; easing.type: Easing.InOutQuad }
AnchorAnimation { easing.type: Easing.InOutQuad; duration: 1000 }
},
Transition {
from: "hiddenRight"
to: "visible"
AnchorAnimation { easing.type: Easing.InOutQuad; duration: 1000 } //PropertyAnimation { properties: "x"; duration: 1000; easing.type: Easing.InOutQuad }
AnchorAnimation { easing.type: Easing.InOutQuad; duration: 1000 }
}
]
//TODO transition between state, animation
}
}
Component{
id: listRow
/*
Row{
id: mainRow
Rectangle { id: "deviceRow"; border.color: "blue"; width: constDeviceRowWidth; height: constDeviceRowHeight;
clip: true
property variant endPoint: undefined
property int deviceId: modelData.id;
property alias continuingBar: continuingBar
property variant selectedDate: main.selectedDate
state: "enabled"
width: constDeviceRowWidth //parent.width; //TODO relative
height: constDeviceRowHeight
/*
Rectangle {
border.color: "red"; width: 100; height:parent.height;
Text{
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
text: modelData.name
states: [
State{
name: "enabled"
PropertyChanges{ target: deviceRow; opacity: 1 }
},
State{
name: "disabled"
PropertyChanges{ target: deviceRow; opacity: 0.4 }
}
}
*/
Rectangle { id: "deviceRow"; border.color: "blue"; width: constDeviceRowWidth; height: constDeviceRowHeight;
clip: true
property variant endPoint: undefined //: Scripts.getEndsWith(deviceRow.children, index, modelData.id);
property int deviceId: modelData.id;
property alias continuingBar: continuingBar
state: "enabled"
states: [
State{
name: "enabled"
PropertyChanges{ target: deviceRow; opacity: 1 }
},
State{
name: "disabled"
PropertyChanges{ target: deviceRow; opacity: 0.4 }
}
]
MouseArea {
id: deviceMouseArea
anchors.fill: parent
//hoverEnabled: true
//TODO ändra muspekaren kanske?
//onEntered: parent.border.color = onHoverColor
//onExited: parent.border.color = borderColor
onClicked: {
//Scripts.debugPrintDeviceIndex();
Scripts.setChanged(deviceId, true);
Scripts.updateDeviceIndex(); //TODO why is this needed here? (but it is, adding points to empty device will get wrong state otherwise)
//print("Mainrow: " + mainRow.parent.children[0].height);
var component = Qt.createComponent("ActionPoint.qml")
var dynamicPoint = component.createObject(deviceRow)
//dynamicPoint.x = mouseX - dynamicPoint.width/2 //xposition
var hourMinute = dynamicPoint.getTimeFromPosition(mouse.x)
dynamicPoint.absoluteHour = hourMinute[0]
dynamicPoint.absoluteMinute = hourMinute[1]
dynamicPoint.x = dynamicPoint.getAbsoluteXValue();
dynamicPoint.border.color = "blue"
//TODO different states depending on the device
dynamicPoint.addActiveState("on");
dynamicPoint.addActiveState("off");
dynamicPoint.addActiveState("dim");
dynamicPoint.addActiveState("bell");
//dynamicPoint.setFirstState("dim"); //when type is a stored value
dynamicPoint.setFirstState();
dynamicPoint.pointId = new Date().getTime(); //just needed for storage update
deviceRow.updateContinuingBars();
dialog.show(dynamicPoint)
}
}
ActionBar{
id: "continuingBar"
hangOnToPoint: deviceRow
firstBar: "true"
state: "continuing"
}
ListView.onAdd: SequentialAnimation {
PropertyAction { target: mainRow; property: "height"; value: 0 }
NumberAnimation { target: mainRow; property: "height"; to: 50; duration: 250; easing.type: Easing.InOutQuad }
}
function hasPoints(){
return Scripts.hasBarChangingPoints(deviceRow.children);
}
function updateContinuingBars(){
Scripts.updateEndsWith();
}
function getDeviceRow(dayIndex, deviceId){
print("CALLING getDeviceRow");
return Scripts.getDeviceRow(dayIndex, deviceId);
}
function createChildPoint(index, pointRect, deviceId){
print("CREATING child point");
return Scripts.createChildPoint(index, pointRect, deviceId);
}
function setChanged(){
]
MouseArea {
id: deviceMouseArea
anchors.fill: parent
onClicked: {
Scripts.setChanged(deviceId, true);
}
function isLoading(){
return Scripts.isLoading();
//TODO really needed? Scripts.updateDeviceIndex(); //needed here, adding points to empty device will get wrong state otherwise
var component = Qt.createComponent("ActionPoint.qml")
var dynamicPoint = component.createObject(deviceRow)
var hourMinute = dynamicPoint.getTimeFromPosition(mouse.x)
dynamicPoint.absoluteHour = hourMinute[0]
dynamicPoint.absoluteMinute = hourMinute[1]
dynamicPoint.x = dynamicPoint.getAbsoluteXValue();
dynamicPoint.border.color = "blue"
//TODO different states depending on the device
dynamicPoint.addActiveState("on");
dynamicPoint.addActiveState("off");
dynamicPoint.addActiveState("dim");
dynamicPoint.addActiveState("bell");
dynamicPoint.setFirstState();
dynamicPoint.pointId = new Date().getTime(); //just needed for storage update
deviceRow.updateContinuingBars();
dialog.show(dynamicPoint)
}
}
//}
ActionBar{
id: "continuingBar"
hangOnToPoint: deviceRow
firstBar: "true"
state: "continuing"
}
ListView.onAdd: SequentialAnimation {
PropertyAction { target: mainRow; property: "height"; value: 0 }
NumberAnimation { target: mainRow; property: "height"; to: 50; duration: 250; easing.type: Easing.InOutQuad }
}
//device functions:
function createChildPoint(index, pointRect, deviceId){
return Scripts.createChildPoint(index, pointRect, deviceId);
}
function getDeviceRow(dayIndex, deviceId){
return Scripts.getDeviceRow(dayIndex, deviceId);
}
function hasPoints(){
return Scripts.hasBarChangingPoints(deviceRow.children);
}
function isLoading(){
return Scripts.isLoading();
}
function setChanged(){
Scripts.setChanged(deviceId, true);
}
function updateContinuingBars(){
Scripts.updateEndsWith();
}
}
}
Component{
id: timeline
Item{
width: constDeviceRowWidth //TODO parent.width
id: timelinerange
width: constDeviceRowWidth
height: dayListHeaderHeight
property int morningDarkWidth: MainScripts.getMorningDarkWidth()
property double morningDarkStart: MainScripts.getMorningDarkStart()
property int eveningDarkWidth: MainScripts.getEveningDarkWidth()
property double eveningDarkStart: MainScripts.getEveningDarkStart()
property variant currentDate: main.selectedDate;
onCurrentDateChanged: {
//update values
timelinerange.morningDarkWidth = MainScripts.getMorningDarkWidth()
timelinerange.morningDarkStart = MainScripts.getMorningDarkStart()
timelinerange.eveningDarkWidth = MainScripts.getEveningDarkWidth()
timelinerange.eveningDarkStart = MainScripts.getEveningDarkStart()
}
Rectangle{
id: morningDark
color: "black"
height: parent.height
border.width: 0
width: getMorningDarkWidth()
width: timelinerange.morningDarkWidth
opacity: 0.1
x: getMorningDarkStart()
x: timelinerange.morningDarkStart
}
Rectangle{
@ -376,9 +310,9 @@ import "schedulerscripts.js" as Scripts
color: "black"
height: parent.height
border.width: 0
width: getEveningDarkWidth()
width: timelinerange.eveningDarkWidth
opacity: 0.1
x: getEveningDarkStart()
x: timelinerange.eveningDarkStart
}
Rectangle{
@ -386,13 +320,12 @@ import "schedulerscripts.js" as Scripts
border.color: "red"
Row{
//x: 100
anchors.horizontalCenter: parent.horizontalCenter
anchors.horizontalCenterOffset: parent.width/24
width: parent.width //listRow.width
width: parent.width
height: parent.height
spacing: (parent.width-24)/24 //before: -124
spacing: (parent.width-24)/24
Repeater{
model:24
Rectangle{
@ -418,116 +351,20 @@ import "schedulerscripts.js" as Scripts
}
}
/* Not in use, adding all devices always instead
Component{
id: addButtonComponent
Row {
id: addButton
Rectangle {
height: 20
width: 100
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenterOffset: 30
property color buttonColor: "lightgrey"
Text{
text: "Add an item"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
anchors.margins: 2
}
MouseArea {
id: buttonMouseArea
anchors.fill: parent
onClicked: {
addDevice.call()
}
}
color: buttonMouseArea.pressed ? Qt.darker(buttonColor, 1.5) : buttonColor
}
}
}
*/
Dialog {
id: dialog
z: 150
}
//TODO move functions, and test odd cases:
function getEveningDarkStart(){
if(!willSunSet){
return 0;
}
if(Scripts.isMidnightDark()){
return sunToTimeUnits(main.sunData[1]); // + 100;
}
else{
return 0;
}
function mainGetMethodFromState(state){
return getMethodFromState.callWith(state);
}
function getMorningDarkStart(){
//TODO the day of the year when the sun "begins" not to set, will it work then?
if(!willSunSet){
return 0;
}
if(Scripts.isMidnightDark()){
return 0; //100; //TODO constants
}
else{
return sunToTimeUnits(main.sunData[1]); // + 100; //TODO constants
}
function mainGetTypeFromTriggerstate(triggerstate){
return getTypeFromTriggerstate.callWith(triggerstate);
}
function getEveningDarkWidth(){
if(!willSunSet){
return 0;
}
if(Scripts.isMidnightDark()){
return constDeviceRowWidth - sunToTimeUnits(main.sunData[1]); //(main.width - 100) - sunToTimeUnits(main.sunData[1]); //TODO constant or something
}
else{
return 0;
}
}
function getMorningDarkWidth(){
if(!willSunSet){
return 0;
}
if(Scripts.isMidnightDark()){
return sunToTimeUnits(main.sunData[0]);
}
else{
return sunToTimeUnits(main.sunData[1]) - sunToTimeUnits(main.sunData[0]);
}
}
function willSunSet(){
if(main.sunData == undefined){
main.sunData = getSunData.call();
}
return !(main.sunData[2] && main.sunData[2] != "")
}
function sunToTimeUnits(suntime){
suntime = suntime.split(':');
var hourSize = constDeviceRowWidth/24; //(main.width - 100)/24; //TODO constant or something?
return hourSize * suntime[0] + hourSize * suntime[1]/60;
}
function saveAll(){
print("Save all and reset jobs");
//var jobs = new Array();
//var points = new Array();
var days = Scripts.getDays();
if(dialog.dialogOpacity == 1){
Scripts.setChanged(dialog.actionPoint.deviceRow.deviceId, true); //set the devicerow that the currently visible dialog is connected to as dirty
@ -537,20 +374,17 @@ import "schedulerscripts.js" as Scripts
var deviceId = deviceModel.get(i).id;
if(!Scripts.hasChanged(deviceId)){
//no point has been updated, removed or added, ignore this device
print("Not updated: " + deviceId);
continue;
}
Scripts.setChanged(deviceId, false); //reset hasChanged-status
print("Updated: " + deviceId);
if(Scripts.deviceIsEnabled(deviceId)){ //if device is disabled, don't add any points to schedule (but remove current)
print("Device is enabled: " + deviceId);
for(var j=0;j<days.length;j++){
var row = Scripts.getDeviceRow(days[j].daydate.getDay(), deviceId);
for(var k=0;k<row.children.length;k++){
var point = row.children[k];
if(point.isPoint && point.parentPoint == undefined){ //and not disabled
points.push(pointToArray(point));
points.push(MainScripts.pointToArray(point));
}
}
}
@ -563,45 +397,18 @@ import "schedulerscripts.js" as Scripts
}
}
function updateLastRun(deviceId, day, pointId, lastRun){
print("deviceid: " + deviceId);
print("day: " + day);
print("pointid: " + pointId);
Scripts.updateLastRun(deviceId, day, pointId, lastRun);
function updateCurrentDay(){
main.selectedDate = Scripts.getCurrentDate();
main.sunData = updateSunData.callWith(main.selectedDate);
MainScripts.updateSunData(main.sunData);
weekDayText.text = Scripts.getCurrentDayName();
}
function pointToArray(point){ //TODO another way than using arrays...
var deviceId = point.deviceRow.deviceId; //not really in use yet
var pointName = "Job_" + deviceId;
var startdate = new Date(); //startdate, not in use, always "now"
var pointDimValue = point.dimvalue * (255/100);
var pointMethod = getMethodFromState.callWith(point.state);
var pointId = point.pointId;
var lastRun = point.lastRun;
print("LASTRUN pointToArray: " + lastRun);
var pointTime = point.absoluteHour * 3600 + point.absoluteMinute * 60;
var absolutePointTime = pointTime;
var pointType = getTypeFromTriggerstate.callWith(point.triggerstate);
if(point.triggerstate == "sunrise"){
var suntime = main.sunData[0].split(':');
pointTime = suntime[0] * 3600 + suntime[1] * 60;
}
else if(point.triggerstate == "sunset"){
var suntime = main.sunData[1].split(':');
pointTime = suntime[0] * 3600 + suntime[1] * 60;
}
var pointFuzzinessBefore = point.fuzzyBefore;
var pointFuzzinessAfter = point.fuzzyAfter;
var pointOffset = point.triggerstate == "absolute" ? 0 : point.offset;
var pointDays = new Array();
pointDays.push(point.deviceRow.parent.parent.daydate.getDay());
var childPoints = point.getChildPoints();
for(var child in childPoints){
pointDays.push(childPoints[child].deviceRow.parent.parent.daydate.getDay()); //different per event
print("GOT DAY " + childPoints[child].deviceRow.parent.parent.daydate.getDay());
}
return new Array(deviceId, pointName, startdate, lastRun, pointMethod, pointDimValue, pointTime, pointType, pointFuzzinessBefore, pointFuzzinessAfter, pointOffset, pointDays, absolutePointTime, pointId);
function updateEndsWith(){
Scripts.updateEndsWith();
}
function updateLastRun(deviceId, day, pointId, lastRun){
Scripts.updateLastRun(deviceId, day, pointId, lastRun);
}
}

View file

@ -55,6 +55,7 @@ function addDay(day){
}
function decrementCurrentDay(){
print("Currentdayindex: " + currentDayIndex);
days[currentDayIndex].state = "hiddenRight";
var workDate = days[currentDayIndex].daydate;
workDate.setDate(workDate.getDate() - 7);
@ -73,6 +74,15 @@ function getCurrentDay(){
return days[currentDayIndex];
}
function getCurrentDate(){
if(days.length < 7){
//not initiated yet
return new Date(); //now
}
var date = new Date(days[currentDayIndex].daydate);
return date;
}
function getCurrentDayName(){
var day = getCurrentDay().daydate;
return weekday_name_array[day.getDay()] + " " + day.getDate();
@ -186,19 +196,7 @@ function getPreviousState(currentPointRect){
return prevPoint.state;
}
function isMidnightDark(){
if(main.sunData == undefined){
main.sunData = getSunData.call();
}
var sunrise = main.sunData[0].split(':');;
var sunset = main.sunData[1].split(':');
if(sunset[0] < sunrise[0] || (sunset[0] == sunrise[0] && sunset[1] < sunrise[1])){
return false;
}
return true;
}
function pad(number, length) {
@ -596,11 +594,11 @@ function createChildPoint(index, pointRect, deviceId){
dynamicPoint.fuzzyBefore = pointRect.fuzzyBefore;
dynamicPoint.fuzzyAfter = pointRect.fuzzyAfter;
dynamicPoint.offset = pointRect.offset;
dynamicPoint.triggerstate = pointRect.triggerstate;
dynamicPoint.dimvalue = pointRect.dimvalue;
dynamicPoint.parentPoint = pointRect
dynamicPoint.x = dynamicPoint.getAbsoluteXValue();
dynamicPoint.triggerstate = pointRect.triggerstate;
dynamicPoint.border.color = "blue"
dynamicPoint.setActiveStates(pointRect.getActiveStates());