on xenial help sign in
Merge card overlay.
commite9d4b51e16bdb46bea035796ed87249d1f25c45c authorMichał Sawicz <michal.sawicz@canonical.com> dateTue 4 Feb 2014, 23:38 (13 years ago) parentcaeabdf75c2b5e
3 files changed+66−3
qml/Dash/Card.qml+60−3 qml/Dash/CardHeader.qml+5 tests/qmltests/Dash/tst_Card.qml+1
qml/Dash/Card.qml+60−3
@@ -23,8 +23,10 @@ AbstractButton {
2323 property var components
2424 property var cardData
2525
26+ property alias fontScale: header.fontScale
27+
2628 implicitWidth: childrenRect.width
27− implicitHeight: childrenRect.height
29+ implicitHeight: summary.y + summary.height
2830
2931 UbuntuShape {
3032 id: artShape
@@ -58,13 +60,67 @@ AbstractButton {
5860 }
5961 }
6062
63+ ShaderEffect {
64+ id: overlay
65+ anchors {
66+ left: artShape.left
67+ right: artShape.right
68+ bottom: artShape.bottom
69+ }
70+
71+ height: units.gu(8)
72+ opacity: 0.6
73+ visible: template && template["overlay"] && artShape.visible && artShape.image.status === Image.Ready || false
74+
75+ property var source: ShaderEffectSource {
76+ id: shaderSource
77+ sourceItem: artShape
78+ onVisibleChanged: if (visible) scheduleUpdate()
79+ live: false
80+ sourceRect: Qt.rect(0, artShape.height - overlay.height, artShape.width, overlay.height)
81+ }
82+
83+ vertexShader: "
84+ uniform highp mat4 qt_Matrix;
85+ attribute highp vec4 qt_Vertex;
86+ attribute highp vec2 qt_MultiTexCoord0;
87+ varying highp vec2 coord;
88+ void main() {
89+ coord = qt_MultiTexCoord0;
90+ gl_Position = qt_Matrix * qt_Vertex;
91+ }"
92+
93+ fragmentShader: "
94+ varying highp vec2 coord;
95+ uniform sampler2D source;
96+ uniform lowp float qt_Opacity;
97+ void main() {
98+ lowp vec4 tex = texture2D(source, coord);
99+ gl_FragColor = vec4(0, 0, 0, tex.a) * qt_Opacity;
100+ }"
101+
102+ }
103+
61104 CardHeader {
62105 id: header
63106 objectName: "cardHeader"
64107 anchors {
65− top: template && template["card-layout"] === "horizontal" ? artShape.top : artShape.bottom
66− left: template && template["card-layout"] === "horizontal" ? artShape.right : parent.left
108+ top: {
109+ if (template) {
110+ if (template["overlay"]) return overlay.top;
111+ if (template["card-layout"] === "horizontal") return artShape.top;
112+ }
113+ return artShape.bottom;
114+ }
115+ left: {
116+ if (template) {
117+ if (!template["overlay"] && template["card-layout"] === "horizontal") return artShape.right;
118+ }
119+ return parent.left;
120+ }
67121 right: parent.right
122+ margins: template && template["overlay"] ? units.gu(1) : 0
123+ topMargin: 0
68124 }
69125
70126 mascot: cardData && cardData["mascot"] || ""
@@ -73,6 +129,7 @@ AbstractButton {
73129 }
74130
75131 Label {
132+ id: summary
76133 objectName: "summaryLabel"
77134 anchors { top: header.visible ? header.bottom : artShape.bottom; left: parent.left; right: parent.right }
78135 wrapMode: Text.Wrap
qml/Dash/CardHeader.qml+5
@@ -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
@@ -77,6 +80,7 @@ Item {
7780 wrapMode: Text.Wrap
7881 maximumLineCount: 2
7982 fontSize: "small"
83+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
8084 }
8185
8286 Label {
@@ -87,6 +91,7 @@ Item {
8791 font.weight: Font.Light
8892 visible: titleLabel.text && text
8993 fontSize: "x-small"
94+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
9095 }
9196
9297 Row {
tests/qmltests/Dash/tst_Card.qml+1
@@ -224,6 +224,7 @@ Rectangle {
224224 }
225225
226226 function test_card_size(data) {
227+ waitForRendering(card);
227228 selector.selectedIndex = data.index;
228229
229230 if (data.hasOwnProperty("size")) {