summaryrefslogtreecommitdiff
path: root/SDL_Core/src/components/qt_hmi/References/Look/plugins/com/ford/hmiframework/qml/Framework/FStyle.qml
blob: 5f9106f9af0e7acd32c92c949b908da8f511fb77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 2.0
import com.ford.hmiframework 1.0

QtObject {
    id: _style

    Component.onCompleted: {
        FThemeProvider.themeChanged.connect(themeChanged);
    }

    // This property is used to assign a "style" filename to the style. This file loads the style data and updates the properties of the style
    property string styleFile: ""

    property bool themed: false

    onStyleFileChanged: {
        loadStyle(_style);
    }

    function themeChanged() {
        if (themed)
        {
            loadStyle(_style);
        }
    }

    // indicate, that the style has been updated to the attached widgets
    signal styleUpdated

    function loadStyle(style)
    {
        if(styleFile.length > 0) {
            console.log( "Loading style: " + styleFile + " (" + FThemeProvider.theme + ")")
            var xhr = new XMLHttpRequest();
            xhr.open("GET", FThemeProvider.resourcePath + FThemeProvider.getFileSubPath(styleFile + ".qmlstyle") + "/" + styleFile + ".qmlstyle");
            xhr.onreadystatechange = function() {
                if (xhr.readyState === XMLHttpRequest.DONE) {
                    try {
                        var a = JSON.parse(xhr.responseText);
                        for (var b in a) {
                            if (style.hasOwnProperty(b)) {
                                style[b] = a[b];
                            }
                        }
                        styleUpdated();
                    }
                    catch (ex) {
                        console.log("Style exception (" + styleFile + "): " + ex);
                    }
                }
            }
            xhr.send();
        }
    }
}