~aacid/unity8/dash_overview

« back to all changes in this revision

Viewing changes to plugins/Dash/CardCreator.js

  • Committer: Albert Astals
  • Date: 2014-08-07 15:27:32 UTC
  • mfrom: (1155.1.29 do_merged)
  • Revision ID: albert.astals@canonical.com-20140807152732-0zf22298f1lsxrz8
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
                                    visible: image.status == Image.Ready; \n\
72
72
                                    readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1; \n\
73
73
                                    readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1; \n\
74
 
                                    readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect; \n\
75
74
                                    Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; } \n\
76
 
                                    onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings(); \n\
77
75
                                    Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
78
76
                                    function updateWidthHeightBindings() { \n\
79
77
                                        if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) { \n\
80
78
                                            width = root.fixedArtShapeSize.width; \n\
81
79
                                            height = root.fixedArtShapeSize.height; \n\
82
 
                                        } else if (aspectSmallerThanImageAspect) { \n\
 
80
                                        } else { \n\
83
81
                                            width = Qt.binding(function() { return !visible ? 0 : image.width }); \n\
84
 
                                            height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect }); \n\
85
 
                                        } else { \n\
86
 
                                            width = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.width : height * image.aspect }); \n\
87
82
                                            height = Qt.binding(function() { return !visible ? 0 : image.height }); \n\
88
83
                                        } \n\
89
84
                                    } \n\
92
87
                                        source: cardData && cardData["art"] || ""; \n\
93
88
                                        cache: true; \n\
94
89
                                        asynchronous: root.asynchronous; \n\
95
 
                                        fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop; \n\
96
 
                                        readonly property real aspect: implicitWidth / implicitHeight; \n\
 
90
                                        fillMode: Image.PreserveAspectCrop; \n\
97
91
                                        width: %2; \n\
98
92
                                        height: %3; \n\
99
93
                                    } \n\
114
108
                            sourceComponent: ShaderEffect { \n\
115
109
                                id: overlay; \n\
116
110
                                height: (fixedHeaderHeight > 0 ? fixedHeaderHeight : headerHeight) + units.gu(2); \n\
117
 
                                opacity: 0.6; \n\
 
111
                                property real luminance: 0.2126 * overlayColor.r + 0.7152 * overlayColor.g + 0.0722 * overlayColor.b; \n\
 
112
                                property color overlayColor: cardData && cardData["overlayColor"] || "#99000000"; \n\
118
113
                                property var source: ShaderEffectSource { \n\
119
114
                                    id: shaderSource; \n\
120
115
                                    sourceItem: artShapeLoader.item; \n\
135
130
                                    varying highp vec2 coord; \n\
136
131
                                    uniform sampler2D source; \n\
137
132
                                    uniform lowp float qt_Opacity; \n\
 
133
                                    uniform highp vec4 overlayColor; \n\
138
134
                                    void main() { \n\
139
135
                                        lowp vec4 tex = texture2D(source, coord); \n\
140
 
                                        gl_FragColor = vec4(0, 0, 0, tex.a) * qt_Opacity; \n\
 
136
                                        gl_FragColor = vec4(overlayColor.r, overlayColor.g, overlayColor.b, 1) * qt_Opacity * overlayColor.a * tex.a; \n\
141
137
                                    }"; \n\
142
138
                            } \n\
143
139
                        }\n';
257
253
                        horizontalAlignment: root.headerAlignment; \n\
258
254
                    }\n';
259
255
 
 
256
// %1 is used as anchors of touchdown effect
 
257
var kTouchdownCode = 'UbuntuShape { \n\
 
258
                        id: touchdown; \n\
 
259
                        objectName: "touchdown"; \n\
 
260
                        anchors { %1 } \n\
 
261
                        visible: root.pressed; \n\
 
262
                        radius: "medium"; \n\
 
263
                        borderSource: "radius_pressed.sci" \n\
 
264
                    }\n';
 
265
 
260
266
// %1 is used as anchors of subtitleLabel
261
267
// %2 is used as color of subtitleLabel
262
268
var kSubtitleLabelCode = 'Label { \n\
279
285
                            objectName: "attributesRow"; \n\
280
286
                            anchors { %1 } \n\
281
287
                            color: %2; \n\
282
 
                            model: cardData && cardData["attributes"] || undefined; \n\
 
288
                            model: cardData["attributes"]; \n\
283
289
                          }\n';
284
290
 
285
291
// %1 is used as top anchor of summary
447
453
    if (hasTitle) {
448
454
        var color;
449
455
        if (headerAsOverlay) {
450
 
            color = '"white"';
 
456
            color = 'overlayLoader.item.luminance < (root.scopeStyle ? root.scopeStyle.threshold : 0.7) ? (root.scopeStyle ? root.scopeStyle.light : "white") : (root.scopeStyle ? root.scopeStyle.dark : "grey")';
451
457
        } else if (hasSummary) {
452
458
            color = 'summary.color';
453
459
        } else if (hasBackground) {
569
575
        code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(color);
570
576
    }
571
577
 
 
578
    var touchdownAnchors;
 
579
    if (hasBackground) {
 
580
        touchdownAnchors = 'fill: backgroundLoader';
 
581
    } else if (hasArt && !hasMascot && !hasSummary) {
 
582
        touchdownAnchors = 'fill: artShapeHolder';
 
583
    } else {
 
584
        touchdownAnchors = 'fill: root'
 
585
    }
 
586
    code += kTouchdownCode.arg(touchdownAnchors);
 
587
 
572
588
    if (hasSummary) {
573
589
        code += 'implicitHeight: summary.y + summary.height + (summary.text ? units.gu(1) : 0);\n';
574
590
    } else if (hasHeaderRow) {
593
609
function createCardComponent(parent, template, components) {
594
610
    var imports = 'import QtQuick 2.2; \n\
595
611
                   import Ubuntu.Components 0.1; \n\
596
 
                   import Ubuntu.Thumbnailer 0.1;\n\
597
612
                   import Dash 0.1;\n';
598
613
    var card = cardString(template, components);
599
614
    var code = imports + 'Component {\n' + card + '}\n';