[SailfishDevel] App own C++ plugin equivalent to Silica Theme

Andrea Bernabei and.bernabei at gmail.com
Tue Jan 28 23:41:43 UTC 2014


The sane way to have the Theme element exported is via
qmlRegisterSingletonType() so I think that's what sailors are doing :)

About the import, they probably just registered the singleton type using
the Sailfish.Silica import URI, so you don't have to import another module
to be able to access the Theme element ;)


2014-01-28 <christopher.lamb at thurweb.ch>

> 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.perl at gmail.com>:
>
>
>  On 2014-01-28 10:59, christopher.lamb at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20140129/ef042b6f/attachment.html>


More information about the Devel mailing list