Hi Thomas
I was hoping you would answer 8-)
The .js route did occur to me, but I initially decided to make that "Plan B".
As the list of UX constants will be used by most of the QML files in
my project, a shared js script (i.e. defined as .pragma library) would
seem to be the way to go. But I was put off by an earlier thread that
implied that .pragma js scripts could not access QML elements.
If that thread was correct, then I could not use a .pragma js script
to access Sailfish Theme constants. This implies that if I want the UX
list to be able to access Sailfish Theme, it cannot be shared.
However, I guess that the true hit on memory use is in making such a
library non-shared may not be so important, but I need to do some more
reflecting on that.
In the Qt Project link that your provided, there is a cryptic comment
that I find interesting:
"
In particular, this may be useful in order to access functionality
provided via a singleton type; see qmlRegisterSingletonType() for more
information.
"
How is the Sailfish Theme registered?
I am also intrigued by the fact that in the early SDK Alphas we had to
import Sailfish.Silica.theme in every qml file using Theme properties,
but now Theme has become globally available without any need for an
explicit import. How is that achieved?
GrĂ¼sse
Chris
Zitat von "Thomas Perl" <th.p...@gmail.com>:
On 2014-01-28 10:59, christopher.l...@thurweb.ch wrote:
I would like to create a C++ plugin for my app to export common UX
settings as constants to the QML side (Things like font sizes,
margin sizes that reoccur throughout the app.)
In essence I want something very similar to the functionality
offered by by the Silica Theme.
After some experimentation I have hit on a solution that both
compiles and works. This is pasted at the bottom of this mail.
I have 2 questions:
1) Is there a more elegant solution to achieve the same goal?
Not sure if it's more elegant, but back in the Harmattan days with
gPodder, I just collected all constants in a "config.js" file and
imported that in QML:
https://github.com/gpodder/gpodder/blob/master/share/gpodder/ui/qml/config.js
From QML (assuming it's in the same folder), you can then do:
import "config.js" as Config
And if you have "var blubb = 123" in your config.js file, and you
have imported it like above, you can then use "Config.blubb" to
access that value.
2) From the C++ side, can I access the Silica them UX constants?
e.g to set some of my constants based on Silica constants?
If you go with the JavaScript solution, you can import the Silica
Theme class and use it in your JS, you can do this with something
like:
http://qt-project.org/doc/qt-5.0/qtqml/qtqml-javascript-imports.html#importing-a-qml-module-from-a-javascript-resource
HTH :)
Thomas
_______________________________________________
SailfishOS.org Devel mailing list
_______________________________________________
SailfishOS.org Devel mailing list