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)

Markkyboy 2019-11-12 20:37

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by Ancelad (Post 1561893)
Code:

import QtFeedback 5.0

HapticsEffect {
        id: activeEffect
        duration: 500 // in ms
        intensity: 0.2 // from 0 to 1 with 0.1 step-size
        running: button.pressed
}
Button {
        id: button
        width: text.width
        text: "Test"                                       
        anchors.horizontalCenter: parent.horizontalCenter
        onClicked: activeEffect.start()         
}


Excellent!, just what I needed and with a little jigger-pokery I now have 29 buttons with short feedback and will be inserting this into other "remote-control" app projects.

Thanks very much!

Regards,

rob_kouw 2019-11-16 19:46

Re: Help me to code for Sailfish OS
 
I hardly dare to ask... Today I decided to try and create an app. But first: install the SDK on Windows 10. It refuses to even start. The installer says:

Git not installed: Please ensure Git is installed and in PATH...

GitHub Desktop was already installed, maybe as an app (as I cannot find it under C:\Programs). So I downloaded and installed Git from
https://git-scm.com/download/win
and this did not help at all. Is there a secret Git to be downloaded?

Thanks!
Rob

coderus 2019-11-16 19:47

Re: Help me to code for Sailfish OS
 
looks like a thread for TJC

BGK 2019-11-18 18:10

How to create "advanced" GUI?
 
How do you create "advanced" GUI for SFOS apps?

Simple (text centered) designs can be created via IDE in text mode, but how do you create apps which are more "graphical" oriented?

As design mode isn't available in Sailfish IDE, is there another way to create QML-page designs in a more graphic way?

coderus 2019-11-18 18:54

Re: Help me to code for Sailfish OS
 
if you not aware of qml you can practice with desktop qt creator to learn qml basics

BGK 2019-11-18 20:42

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1562224)
if you not aware of qml you can practice with desktop qt creator to learn qml basics

Well, it's one way placing UI-elements in colums and rows by defining their width (and other properties) like in HTML/CSS - another would be building UI-design like in graphic software.

The latter I'm looking for... :)

coderus 2019-11-18 20:51

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by BGK (Post 1562227)
Well, it's one way placing UI-elements in colums and rows by defining their width (and other properties) like in HTML/CSS - another would be building UI-design like in graphic software.

The latter I'm looking for... :)

main goal is making fluid software ui which will be looking good on any device resolution and screen orientation. show me how to do this in graphic software :)

rob_kouw 2019-11-23 12:09

Re: Help me to code for Sailfish OS
 
All right coderus, the SDK is up and running. I started with a new QtQuick/Sailfish project. It contains an empty Cover Page and two empty Pages.

I find working with a new environment not easy: where to start? What examples to use? More or less similar would be Daily Comics, but they use python code. I've done some python, but incorporating it into QtQuick seems another hurdle to me.

Now, what I want to do:
1. download the webpage of https://nos.nl/ as a text file
2. zoom in on the <section class="news-in-pictures">
3. take the details from all the (10) <figure>: url, caption, text
4. download the images (each 100 kB, write the files or keep in memory?)
5. display them, optionally with caption and text

I found filedownloader https://wiki.qt.io/Download_Data_from_URL#Usage but the first instruction
Code:

private slots:
 void loadImage();

already gives an error in the IDE. So... maybe not the best start. Any ideas?

coderus 2019-11-23 12:15

Re: Help me to code for Sailfish OS
 
You can always start with component gallery example project, not with dummy one.

rob_kouw 2019-11-23 13:35

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1562505)
You can always start with component gallery example project, not with dummy one.

Right, I found that one too. I was going for that after I solved all the downloading.

The QtQuick examples I found on web pages are aiming to show the url directly in a browser. Do you know a way to download that url as a text?

Maybe QWebDownloadItem? Maybe QNetworkAccessManager with a get method? It's so hard finding an example...

coderus 2019-11-23 18:13

Re: Help me to code for Sailfish OS
 
QNetworkRequest for network stuff, and QRegExp for parsing reply

bauidch 2019-11-25 13:24

Multiple TexFields
 
In the People App(Called "Kontakte" in german) you can add multipe Numbers. I'm guessing this phone number filed is a TextFiled in QML.

Now I would like to do this also in my app.

Does anyone have an idea where I can find it in the SailfishOS code? Or have someone an example to handel this?

See the orginal Question: https://together.jolla.com/question/...comment-217726

bauidch 2019-11-25 14:27

Re: Help me to code for Sailfish OS
 
Hey Guys

I want to add dynamic TextFields to my app, like the people app for Jolla.

Does anyone have an idea where I can find it in the SailfishOS code? Or have someone an example to handel this?

See the orginal Question here: https://together.jolla.com/question/...le-textfields/

rob_kouw 2019-11-26 16:33

Re: Help me to code for Sailfish OS
 
You're not a man of many words, are you? [:D] But thanks, I think I found the way to start thanks to your guidance.

I would like to find out how to store files, probably in .local. With that I think it will be easier to debug. At least now I don't know how to check whether my RegExps lead anywhere.

Then I think I will make a QJsonArray of 10 QJsonObjects filled with information of the photo (jpg, title, caption, source). This QJsonArray would be handed to the QML page. If so, how. If not, what then?

My GitHub repo, still very premature: https://github.com/cow-n-berg/harbour-news-photos

coderus 2019-11-26 17:31

Re: Help me to code for Sailfish OS
 
I'd like to teach to code, not write code instead)

QJsonArray/QJsonObject can be handled natively as Object in QML

For storing location check QStandardPaths class

BGK 2019-11-30 11:37

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1562660)
I'd like to teach to code, not write code instead

:D ... :cool: ...

rob_kouw 2019-12-06 09:00

Re: Help me to code for Sailfish OS
 
Do you have an example on how to initialize a QJsonArray in the QML code, so I can fill it up with QJsonObjects in the C++ code?

coderus 2019-12-06 09:30

Re: Help me to code for Sailfish OS
 
why to initialize from one place and fill with data from another?

rob_kouw 2019-12-06 09:42

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1563060)
why to initialize from one place and fill with data from another?

I have no clue how to get the data from the Downloader to the QML window that will show the photo, and that will handle all the UI.

coderus 2019-12-06 09:55

Re: Help me to code for Sailfish OS
 
Save downloaded data as file and pass path to this file to qml

rob_kouw 2019-12-26 19:37

Re: Help me to code for Sailfish OS
 
Unfortunately, I couldn't manage to bind the C++ and QML properly. In the end, I did all the RegExp work in php, and made it available at a web server. So then I could just work with QML-only code. I'm happy I got something working, and submitted it to Harbour just before Christmas.
Thanks for the help!

rob_kouw 2020-01-05 20:59

Re: Help me to code for Sailfish OS
 
I am struggling with some icons, shown in the PhotoDelegate. Do you have experience with the behaviour of icons in light Ambiences vs. dark Ambiences?

Thanks, Rob

Below: the problem.

Bottom layer is a rectangle. With a light Ambience, the rectangle must be darker to show a nice photo. Works properly.
Code:

    Rectangle {
        id: photoRect
        anchors {
            fill: parent
        }
        color: "black"
        opacity: Theme.colorScheme == 0  ? 0.65 : 0.9
    }

On top of this rectangle is the photo, works fine too.

Then in the upper right corner I show the logo of the broadcasting company as an IconButton. For dark Ambiences, it works fine. But for light Ambiences, something strange happens. Basically, I want to show the same logo. But a svg file with a white image, 0.40 opacity, will be shown as very dark grey, so like the inverse of the normal svg.

Code:

        IconButton {
            id: showBroadcast
            icon.source: (site === "NOS")
                            ? ( Theme.colorScheme == 0  ? Qt.resolvedUrl("images/icon-nos.svg") : Qt.resolvedUrl("images/icon-nos-light.svg") )
                            : ( Theme.colorScheme == 0  ? Qt.resolvedUrl("images/icon-the-guardian.svg") : Qt.resolvedUrl("images/icon-the-guardian-light.svg") )
            anchors {
                top: parent.top
                right: parent.right
            }

            onClicked: ExternalLinks.browse(link)
        }

Other tests performed: a logo of black with 1.0 opacity goes black. A logo of white with 1.0 opacity goes black. A logo with some red in it will show as grey.

As a workaround I could work with rectangle, mousearea and image, I guess...

coderus 2020-01-05 21:03

Re: Help me to code for Sailfish OS
 
Nowadays Icon* stuff in sfos using HighlightImage magic underneath to properly adjust monochrome icons for dark/light ambiences. Try using just monochrome white image and check if it magically convert to black in light ambience?

bobsikus 2020-01-09 20:27

Re: Help me to code for Sailfish OS
 
hello guys, maybe stupid question, maybe I did not judt find it.. is there proper reaction/signal on change of the OS's ambience?

rob_kouw 2020-01-09 21:41

Re: Help me to code for Sailfish OS
 
Might be somewhere in Theme...
Theme.colorScheme == 0 stands for a dark Ambience.

coderus 2020-01-09 21:45

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by rob_kouw (Post 1564259)
Might be somewhere in Theme...
Theme.colorScheme == 0 stands for a dark Ambience.

there are constants available:
Code:

Theme.LightOnDark
Theme.DarkOnLight

https://github.com/CODeRUS/better-sa...qmltypes#L1472

But if initial question was about actual ambience change, there is an example in sailfish code: https://github.com/CODeRUS/better-sa...indow.qml#L225

bobsikus 2020-01-10 07:37

Re: Help me to code for Sailfish OS
 
coderus: yes exactly, I have found that colorScheme is defined, only the reaction to that I had not found. Thanks a lot, I will look at it :)

EDIT: Thanks a lot, works :)

Code:

    import Sailfish.Silica.private 1.0

    ThemeTransaction {
        onAmbienceAboutToChange: doStuff() ;
    }


coderus 2020-01-10 09:14

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by bobsikus (Post 1564266)
coderus: yes exactly, I have found that colorScheme is defined, only the reaction to that I had not found. Thanks a lot, I will look at it :)

if you want to detect color scheme change then bind it to property and watch onPropertyChanged

bobsikus 2020-01-10 09:33

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1564270)
if you want to detect color scheme change then bind it to property and watch onPropertyChanged

I needed reaction of ambience change to do stuff I need it to do (change some colors based on if the ambience is actually dark or light, because buttons and text to buttons were based on that), If I will do it by binding, it would probably be a little bit less needy for system resources (don't do it everytime, do it only if this changes), so good point :)

EDIT: works!
Code:

    property real themeType: Theme.colorScheme

    onThemeTypeChanged: console.log ("AmbienceChange");


rob_kouw 2020-01-10 13:19

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1564260)
there are constants available:
Code:

Theme.LightOnDark
Theme.DarkOnLight

https://github.com/CODeRUS/better-sa...qmltypes#L1472

Ooh, nice. Thanks, it will clarify my code some more.

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 15:22.

vBulletin® Version 3.8.8