on xenial help sign in
Merge trunk header-alignment.
commit5c77bf16538e478a89fed59accfd5cfad438939e authorMichał Sawicz <michal.sawicz@canonical.com> dateFri 7 Feb 2014, 12:08 (13 years ago) parent4bb3ca0383bfc2
5 files changed+96−8
qml/Dash/Card.qml+63−3 qml/Dash/CardHeader.qml+8−1 qml/Dash/CardTool.qml+10−3 tests/qmltests/Dash/tst_Card.qml+8 tests/qmltests/Dash/tst_CardTool.qml+7−1
qml/Dash/Card.qml+63−3
@@ -23,10 +23,14 @@ AbstractButton {
2323 property var components
2424 property var cardData
2525
26+ property alias fontScale: header.fontScale
2627 property alias headerAlignment: header.headerAlignment
28+ readonly property alias headerHeight: header.height
29+
30+ property bool showHeader: true
2731
2832 implicitWidth: childrenRect.width
29− implicitHeight: childrenRect.height
33+ implicitHeight: summary.y + summary.height
3034
3135 UbuntuShape {
3236 id: artShape
@@ -60,21 +64,77 @@ AbstractButton {
6064 }
6165 }
6266
67+ ShaderEffect {
68+ id: overlay
69+ anchors {
70+ left: artShape.left
71+ right: artShape.right
72+ bottom: artShape.bottom
73+ }
74+
75+ height: header.height
76+ opacity: header.opacity * 0.6
77+ visible: template && template["overlay"] && artShape.visible && artShape.image.status === Image.Ready || false
78+
79+ property var source: ShaderEffectSource {
80+ id: shaderSource
81+ sourceItem: artShape
82+ onVisibleChanged: if (visible) scheduleUpdate()
83+ live: false
84+ sourceRect: Qt.rect(0, artShape.height - overlay.height, artShape.width, overlay.height)
85+ }
86+
87+ vertexShader: "
88+ uniform highp mat4 qt_Matrix;
89+ attribute highp vec4 qt_Vertex;
90+ attribute highp vec2 qt_MultiTexCoord0;
91+ varying highp vec2 coord;
92+ void main() {
93+ coord = qt_MultiTexCoord0;
94+ gl_Position = qt_Matrix * qt_Vertex;
95+ }"
96+
97+ fragmentShader: "
98+ varying highp vec2 coord;
99+ uniform sampler2D source;
100+ uniform lowp float qt_Opacity;
101+ void main() {
102+ lowp vec4 tex = texture2D(source, coord);
103+ gl_FragColor = vec4(0, 0, 0, tex.a) * qt_Opacity;
104+ }"
105+ }
106+
63107 CardHeader {
64108 id: header
65109 objectName: "cardHeader"
66110 anchors {
67− top: template && template["card-layout"] === "horizontal" ? artShape.top : artShape.bottom
68− left: template && template["card-layout"] === "horizontal" ? artShape.right : parent.left
111+ top: {
112+ if (template) {
113+ if (template["overlay"]) return overlay.top;
114+ if (template["card-layout"] === "horizontal") return artShape.top;
115+ }
116+ return artShape.bottom;
117+ }
118+ left: {
119+ if (template) {
120+ if (!template["overlay"] && template["card-layout"] === "horizontal") return artShape.right;
121+ }
122+ return parent.left;
123+ }
69124 right: parent.right
70125 }
71126
72127 mascot: cardData && cardData["mascot"] || ""
73128 title: cardData && cardData["title"] || ""
74129 subtitle: cardData && cardData["subtitle"] || ""
130+
131+ opacity: showHeader ? 1 : 0
132+
133+ Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.SnapDuration } }
75134 }
76135
77136 Label {
137+ id: summary
78138 objectName: "summaryLabel"
79139 anchors { top: header.visible ? header.bottom : artShape.bottom; left: parent.left; right: parent.right }
80140 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 property alias headerAlignment: titleLabel.horizontalAlignment
3033
3134 visible: mascotImage.status === Image.Ready || title || price
@@ -43,7 +46,7 @@ Item {
4346 leftMargin: spacing
4447 rightMargin: spacing
4548 }
46− spacing: mascotShape.visible ? margins : 0
49+ spacing: mascotShape.visible || (template && template["overlay"]) ? margins : 0
4750
4851 UbuntuShape {
4952 id: mascotShape
@@ -79,6 +82,8 @@ Item {
7982 wrapMode: Text.Wrap
8083 maximumLineCount: 2
8184 fontSize: "small"
85+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
86+ color: template["overlay"] === true ? "white" : Theme.palette.selected.backgroundText
8287 }
8388
8489 Label {
@@ -89,6 +94,8 @@ Item {
8994 font.weight: Font.Light
9095 visible: titleLabel.text && text
9196 fontSize: "x-small"
97+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
98+ color: template["overlay"] === true ? "white" : Theme.palette.selected.backgroundText
9299 }
93100
94101 Row {
qml/Dash/CardTool.qml+10−3
@@ -100,7 +100,15 @@ Item {
100100 }
101101 }
102102
103− readonly property var headerAlignment: {
103+ /*!
104+ type:real \brief Height of the card's header.
105+ */
106+ readonly property alias headerHeight: card.headerHeight
107+
108+ /*!
109+ \brief Desired alignment of header components.
110+ */
111+ readonly property int headerAlignment: {
104112 var subtitle = components["subtitle"];
105113 var price = components["price"];
106114 var summary = components["summary"];
@@ -115,10 +123,9 @@ Item {
115123 return (template["card-layout"] === "horizontal") ? Text.AlignHCenter : Text.AlignLeft;
116124 }
117125
118− readonly property QtObject priv: card
119−
120126 Card {
121127 id: card
128+ objectName: "card"
122129 template: cardTool.template
123130 components: cardTool.components
124131
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
tests/qmltests/Dash/tst_CardTool.qml+7−1
@@ -226,7 +226,7 @@ Rectangle {
226226 id: dataArea
227227 anchors { left: parent.left; right: parent.right }
228228 height: units.gu(25)
229− text: JSON.stringify(cardTool.priv.cardData, undefined, 2)
229+ text: JSON.stringify(testCase.internalCard.cardData, undefined, 2)
230230 }
231231
232232 Label {
@@ -256,8 +256,14 @@ Rectangle {
256256 id: testCase
257257 name: "Card"
258258
259+ property Card internalCard: findChild(cardTool, "card")
260+
259261 when: windowShown
260262
263+ function init() {
264+ verify(typeof testCase.internalCard === "object", "Couldn't find internal card object.");
265+ }
266+
261267 function cleanup() {
262268 selector.selectedIndex = -1;
263269 layoutSelector.selectedIndex = -1;