maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   SailfishOS (https://talk.maemo.org/forumdisplay.php?f=52)
-   -   Help me to code for Sailfish OS (https://talk.maemo.org/showthread.php?t=100817)

bobsikus 2020-01-11 09:41

Re: Help me to code for Sailfish OS
 
mm, related, both, property binding and "onAboutToChange" signal does not actually work completely. Thing is, both react "too soon". I had Assigned Theme.highlightColor to my property, problem is, there is actually "old" stuff in that property, so my property changes to what was there before the change of Ambience. I can bind property highlightColor and on that it reacts better but I suppose it might screw me if I would need to use any other Theme properties.. I need reaction on Ambience already changed, it might be through property binding, but I would need to know, which is "last in list". Or can I get status of changing the ambience?

coderus 2020-01-11 09:46

Re: Help me to code for Sailfish OS
 
in the example above os handling ambience change with 600ms timer: https://github.com/CODeRUS/better-sa...indow.qml#L234

bobsikus 2020-01-11 09:48

Re: Help me to code for Sailfish OS
 
thanks, Timer then, I did not need Timer yet, I will look at it :) I could wrap some animation with it
Code:

    Timer {
        id: ambiencetimer
        interval: 1
        onTriggered: {applyAmbienceThemeColors();}
    }

It actually does not need bigger time, i put only 1ms and it works properly. :)
EDIT: for the record, as "ThemeChanger" property bindind I have used Theme._homeBackgroundImage , because it changes everytime you change the ambience, even if the actual background image is the same picture (tested :) )

Markkyboy 2020-03-16 11:53

Re: Help me to code for Sailfish OS
 
Hi,

I have made a fully functioning UI for my LED RGBW lighting strip (10 rows / 4 buttons per row).

I have used a MouseArea for each button, but this makes the code bulky.

I would like to know how to call each IR code from another page within my app, but I don't really know where to start.

Currently, I have this for each button on my first page;

Code:

    Row { id: row1; ........
        Rectangle { id: brightUp; width: 60; height: 60; radius: 30 .......
            MouseArea {
                anchors.fill: brightUp
                onClicked: {
                    var xmlhttp = new XMLHttpRequest()
                    xmlhttp.onreadystatechange = function() {
                        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
                            console.log("Brightness UP")
                        }
                    }
                    xmlhttp.open("POST", "http://192.168.0.222/lightup")
                    xmlhttp.send()
                }
            }

I was thinking that a matrix of all 40 codes could be listed on the second page, but how would this look?, how do I call each code when a button is clicked on my first page?

Thanks,

Halftux 2020-03-16 12:44

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by Markkyboy (Post 1566086)
I was thinking that a matrix of all 40 codes could be listed on the second page, but how would this look?, how do I call each code when a button is clicked on my first page?

When I get it right, you will also do it with signals:

https://doc-snapshots.qt.io/qt5-5.9/...x-signals.html
https://stackoverflow.com/questions/...qml-to-another
https://forum.qt.io/topic/103891/qml...-another-qml/6

coderus 2020-03-16 20:51

Re: Help me to code for Sailfish OS
 
inside main.qml declare:
Code:

function controlLamp(endpoint) {
  var xmlhttp = new XMLHttpRequest()
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
      console.log(endpoint)
    }
  }
  xmlhttp.open("POST", "http://192.168.0.222/" + endpoint)
  xmlhttp.send()
}

and call anywhere you want like:
Code:

MouseArea {
    anchors.fill: brightUp
    onClicked: {
        controlLamp("lightup")
    }
}


Markkyboy 2020-03-17 00:41

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1566098)
inside main.qml declare:
Code:

function controlLamp(endpoint) {
  var xmlhttp = new XMLHttpRequest()
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
      console.log(endpoint)
    }
  }
  xmlhttp.open("POST", "http://192.168.0.222/" + endpoint)
  xmlhttp.send()
}

and call anywhere you want like:
Code:

MouseArea {
    anchors.fill: brightUp
    onClicked: {
        controlLamp("lightup")
    }
}


Thanks coderus, this works nicely, much appreciated!

I now have only one mouse area per row of 4 buttons, this is much better ;)

Morc 2020-04-12 09:58

Re: Help me to code for Sailfish OS
 
Hi, I've been thinking of adding auto refresh interval to my app and also to add settings for that auto refresh and also for other things. Are there any simple code examples for C++ or JavaScript?

Fuzzillogic 2020-04-12 10:39

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by Morc (Post 1566796)
Hi, I've been thinking of adding auto refresh interval to my app and also to add settings for that auto refresh and also for other things. Are there any simple code examples for C++ or JavaScript?

Guess we'd need a bit more than that. What language(s) is the app? QML has the Timer object, of which you can see an example earlier on this very page.

To store settings, SailishOS has the Configuration API for QML. I must say the documentation isn't very clear and lacking of any examples...

Morc 2020-04-12 11:58

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by Fuzzillogic (Post 1566797)
Guess we'd need a bit more than that. What language(s) is the app? QML has the Timer object, of which you can see an example earlier on this very page.

To store settings, SailishOS has the Configuration API for QML. I must say the documentation isn't very clear and lacking of any examples...

I checked it again, and I actually made it as QML-only without C++ because I was not planning to use any C++ code in the time of making it. It's my mistake that i missed and i haven't seen that Timer object and example, I tried it and it's working flawlessly. So now only to figure out how to make those settings


All times are GMT. The time now is 22:19.

vBulletin® Version 3.8.8