on xenial help sign in
* Add overlay to card.

* Fix implicit card height.

commit4301b32863707bfcc568759a525ffd06c217ebf0 authorMichał Sawicz <michal.sawicz@canonical.com> dateFri 7 Feb 2014, 10:46 (13 years ago) parent62e07dd9fb61f5
4 files changed+85−4
qml/Dash/Card.qml+64−3 qml/Dash/CardHeader.qml+8−1 qml/Dash/CardTool.qml+5 tests/qmltests/Dash/tst_Card.qml+8
qml/Dash/Card.qml+64−3
@@ -23,8 +23,13 @@ Item {
2323 property var components
2424 property var cardData
2525
26+ property alias fontScale: header.fontScale
27+ readonly property alias headerHeight: header.height
28+
29+ property bool showHeader: true
30+
2631 implicitWidth: childrenRect.width
27− implicitHeight: childrenRect.height
32+ implicitHeight: summary.y + summary.height
2833
2934 UbuntuShape {
3035 id: artShape
@@ -58,21 +63,77 @@ Item {
5863 }
5964 }
6065
66+ ShaderEffect {
67+ id: overlay
68+ anchors {
69+ left: artShape.left
70+ right: artShape.right
71+ bottom: artShape.bottom
72+ }
73+
74+ height: header.height
75+ opacity: header.opacity * 0.6
76+ visible: template && template["overlay"] && artShape.visible && artShape.image.status === Image.Ready || false
77+
78+ property var source: ShaderEffectSource {
79+ id: shaderSource
80+ sourceItem: artShape
81+ onVisibleChanged: if (visible) scheduleUpdate()
82+ live: false
83+ sourceRect: Qt.rect(0, artShape.height - overlay.height, artShape.width, overlay.height)
84+ }
85+
86+ vertexShader: "
87+ uniform highp mat4 qt_Matrix;
88+ attribute highp vec4 qt_Vertex;
89+ attribute highp vec2 qt_MultiTexCoord0;
90+ varying highp vec2 coord;
91+ void main() {
92+ coord = qt_MultiTexCoord0;
93+ gl_Position = qt_Matrix * qt_Vertex;
94+ }"
95+
96+ fragmentShader: "
97+ varying highp vec2 coord;
98+ uniform sampler2D source;
99+ uniform lowp float qt_Opacity;
100+ void main() {
101+ lowp vec4 tex = texture2D(source, coord);
102+ gl_FragColor = vec4(0, 0, 0, tex.a) * qt_Opacity;
103+ }"
104+ }
105+
61106 CardHeader {
62107 id: header
63108 objectName: "cardHeader"
64109 anchors {
65− top: template && template["card-layout"] === "horizontal" ? artShape.top : artShape.bottom
66− left: template && template["card-layout"] === "horizontal" ? artShape.right : parent.left
110+ top: {
111+ if (template) {
112+ if (template["overlay"]) return overlay.top;
113+ if (template["card-layout"] === "horizontal") return artShape.top;
114+ }
115+ return artShape.bottom;
116+ }
117+ left: {
118+ if (template) {
119+ if (!template["overlay"] && template["card-layout"] === "horizontal") return artShape.right;
120+ }
121+ return parent.left;
122+ }
67123 right: parent.right
68124 }
69125
70126 mascot: cardData && cardData["mascot"] || ""
71127 title: cardData && cardData["title"] || ""
72128 subtitle: cardData && cardData["subtitle"] || ""
129+
130+ opacity: showHeader ? 1 : 0
131+
132+ Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.SnapDuration } }
73133 }
74134
75135 Label {
136+ id: summary
76137 objectName: "summaryLabel"
77138 anchors { top: header.visible ? header.bottom : artShape.bottom; left: parent.left; right: parent.right }
78139 wrapMode: Text.Wrap
qml/Dash/CardHeader.qml+8−1
@@ -26,6 +26,9 @@ Item {
2626 property alias oldPrice: oldPriceLabel.text
2727 property alias altPrice: altPriceLabel.text
2828
29+ // FIXME: Saviq, used to scale fonts down in Carousel
30+ property real fontScale: 1.0
31+
2932 visible: mascotImage.status === Image.Ready || title || price
3033 height: row.height > 0 ? row.height + row.margins * 2 : 0
3134
@@ -41,7 +44,7 @@ Item {
4144 leftMargin: spacing
4245 rightMargin: spacing
4346 }
44− spacing: mascotShape.visible ? margins : 0
47+ spacing: mascotShape.visible || (template && template["overlay"]) ? margins : 0
4548
4649 UbuntuShape {
4750 id: mascotShape
@@ -77,6 +80,8 @@ Item {
7780 wrapMode: Text.Wrap
7881 maximumLineCount: 2
7982 fontSize: "small"
83+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
84+ color: template["overlay"] === true ? "white" : Theme.palette.selected.backgroundText
8085 }
8186
8287 Label {
@@ -87,6 +92,8 @@ Item {
8792 font.weight: Font.Light
8893 visible: titleLabel.text && text
8994 fontSize: "x-small"
95+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
96+ color: template["overlay"] === true ? "white" : Theme.palette.selected.backgroundText
9097 }
9198
9299 Row {
qml/Dash/CardTool.qml+5
@@ -100,6 +100,11 @@ Item {
100100 }
101101 }
102102
103+ /*!
104+ type:real \brief Height of the card's header.
105+ */
106+ readonly property alias headerHeight: card.headerHeight
107+
103108 Card {
104109 id: card
105110 objectName: "card"
tests/qmltests/Dash/tst_Card.qml+8
@@ -74,6 +74,11 @@ Rectangle {
7474 "name": "Header title only",
7575 "layout": { "components": { "title": "title" } }
7676 },
77+ {
78+ "name": "Art, header, summary - overlaid",
79+ "layout": { "template": { "overlay": true },
80+ "components": JSON.parse(Helpers.fullMapping) }
81+ },
7782 ]
7883
7984 CardTool {
@@ -224,6 +229,7 @@ Rectangle {
224229 }
225230
226231 function test_card_size(data) {
232+ waitForRendering(card);
227233 selector.selectedIndex = data.index;
228234
229235 if (data.hasOwnProperty("size")) {
@@ -314,6 +320,8 @@ Rectangle {
314320 left: function() { return art.x }, index: 0 },
315321 { tag: "Horizontal", top: function() { return art.y },
316322 left: function() { return art.x + art.width }, index: 5 },
323+ { tag: "Overlay", top: function() { return art.y + art.height - header.height },
324+ left: function() { return art.x }, index: 9 },
317325 ]
318326 }
319327