on xenial help sign in
Fix for tst_Card
commita6678c015278f651fdcb7e29fb68f01689b698d7 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateFri 15 Jan 2016, 11:46 (11 years ago) parent88c6f00
4 files changed+62−7
plugins/Dash/CardCreator.js+50−1 plugins/Dash/qmldir+1 tests/qmltests/Dash/CardHelpers.js+5−3 tests/qmltests/Dash/tst_Card.qml+6−3
plugins/Dash/CardCreator.js+50−1
@@ -294,6 +294,18 @@ var kAttributesRowCode = 'CardAttributes { \n\
294294 model: cardData && cardData["attributes"]; \n\
295295 }\n';
296296
297+// %1 is used as anchors of socialAttributesRow
298+// %2 is used as color of socialAttributesRow
299+var kSocialAttributesRowCode = 'CardSocialAttributes { \n\
300+ id: socialAttributesRow; \n\
301+ objectName: "socialAttributesRow"; \n\
302+ anchors { %1 } \n\
303+ color: %2; \n\
304+ fontScale: root.fontScale; \n\
305+ model: cardData && cardData["socialAttributes"]; \n\
306+ onClicked: root.clicked(result); \n\
307+ }\n';
308+
297309// %1 is used as top anchor of summary
298310// %2 is used as topMargin anchor of summary
299311// %3 is used as color of summary
@@ -352,6 +364,11 @@ function cardString(template, components) {
352364 var hasSubtitle = hasTitle && components["subtitle"] || false;
353365 var hasHeaderRow = hasMascot && hasTitle;
354366 var hasAttributes = hasTitle && components["attributes"]["field"] || false;
367+ var hasSocialAttributes = hasTitle && components["socialAttributes"] || false;
368+
369+ if (hasSocialAttributes) {
370+ code += 'signal clicked(var result);\n';
371+ }
355372
356373 if (hasBackground) {
357374 var templateCardBackground = (template && typeof template["card-background"] === "string") ? template["card-background"] : "";
@@ -657,6 +674,36 @@ function cardString(template, components) {
657674 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(summaryColor);
658675 }
659676
677+ if (hasSocialAttributes) {
678+ var socialAnchors;
679+ var socialTopAnchor;
680+
681+ if (hasSummary) {
682+ socialTopAnchor = 'summary.bottom;';
683+ } else {
684+ if (isHorizontal && hasArt) socialTopAnchor = 'artShapeHolder.bottom;';
685+ else if (headerAsOverlay && hasArt) socialTopAnchor = 'artShapeHolder.bottom;';
686+ else if (hasHeaderRow) socialTopAnchor = 'row.bottom;';
687+ else if (hasTitleContainer) socialTopAnchor = 'headerTitleContainer.bottom;';
688+ else if (hasMascot) socialTopAnchor = 'mascotImage.bottom;';
689+ else if (hasAttributes) socialTopAnchor = 'attributesRow.bottom;';
690+ else if (hasSubtitle) socialTopAnchor = 'subtitleLabel.bottom;';
691+ else if (hasTitle) socialTopAnchor = 'titleLabel.bottom;';
692+ else if (hasArt) socialTopAnchor = 'artShapeHolder.bottom;';
693+ else socialTopAnchor = 'parent.top';
694+ }
695+ socialAnchors = 'top: ' + socialTopAnchor + ' left: parent.left; right: parent.right; topMargin: units.gu(1);'
696+
697+ var socialColor;
698+ if (hasBackground) {
699+ socialColor = summaryColorWithBackground;
700+ } else {
701+ socialColor = 'root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText';
702+ }
703+
704+ code += kSocialAttributesRowCode.arg(socialAnchors).arg(socialColor);
705+ }
706+
660707 var touchdownAnchors;
661708 if (hasBackground) {
662709 touchdownAnchors = 'fill: backgroundLoader';
@@ -668,7 +715,9 @@ function cardString(template, components) {
668715 code += kTouchdownCode.arg(touchdownAnchors);
669716
670717 var implicitHeight = 'implicitHeight: ';
671− if (hasSummary) {
718+ if (hasSocialAttributes) {
719+ implicitHeight += 'socialAttributesRow.y + socialAttributesRow.height + units.gu(1);\n';
720+ } else if (hasSummary) {
672721 implicitHeight += 'summary.y + summary.height + units.gu(1);\n';
673722 } else if (headerAsOverlay) {
674723 implicitHeight += 'artShapeHolder.height;\n';
plugins/Dash/qmldir+1
@@ -4,4 +4,5 @@ typeinfo Dash.qmltypes
44singleton CardCreatorCache 0.1 CardCreatorCache.qml
55ScopeStyle 0.1 ScopeStyle.qml
66CardAttributes 0.1 CardAttributes.qml
7+CardSocialAttributes 0.1 CardSocialAttributes.qml
78CroppedImageMinimumSourceSize 0.1 CroppedImageMinimumSourceSize.qml
tests/qmltests/Dash/CardHelpers.js+5−3
@@ -16,7 +16,7 @@
1616
1717.pragma library
1818
19−var components = ["title", "art", "subtitle", "mascot", "emblem", "summary", "attributes", "overlayColor"]
19+var components = ["title", "art", "subtitle", "mascot", "emblem", "summary", "attributes", "socialAttributes", "overlayColor"]
2020
2121var defaultLayout = ' \
2222{ \
@@ -38,7 +38,8 @@ var defaultLayout = ' \
3838 "mascot": null, \
3939 "emblem": null, \
4040 "summary": null, \
41− "attributes": { "max-count": 2 } \
41+ "attributes": { "max-count": 2 },
42+ "socialAttributes": null \
4243 }, \
4344 "resources": {} \
4445}'
@@ -52,7 +53,8 @@ var fullMapping = ' \
5253 "emblem": "emblem", \
5354 "overlayColor": "overlayColor", \
5455 "summary": "summary", \
55− "attributes": "attributes" \
56+ "attributes": "attributes", \
57+ "socialAttributes": "socialAttributes" \
5658}'
5759
5860
tests/qmltests/Dash/tst_Card.qml+6−3
@@ -35,7 +35,8 @@ Rectangle {
3535 "title": "foo",
3636 "subtitle": "bar",
3737 "summary": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
38− "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}]
38+ "attributes": [{"value":"text1","icon":"image://theme/ok"},{"value":"text2","icon":"image://theme/cancel"}],
39+ "socialAttributes": [{"label":"text1","icon":"image://theme/ok","temporaryIcon":"image://theme/undo"},{"label":"text2","icon":"image://theme/cancel"}]
3940 }'
4041
4142 property var cardsModel: [
@@ -267,9 +268,11 @@ Rectangle {
267268 { tag: "Wide", width: units.gu(18), index: 0 },
268269 { tag: "Horizontal", width: units.gu(38), index: 5 },
269270 // Make sure card ends with header when there's no summary
270− { tag: "NoSummary", height: function() { var cardToolRow = findChild(cardTool, "outerRow");
271+ { tag: "NoSummary", height: function() { var cardToolRow = findChild(cardTool, "socialAttributesRow");
271272 return cardToolRow.y + cardToolRow.height + units.gu(1) }, index: 6 },
272− { tag: "HorizontalNoSummary", height: function() { return headerRow.height + units.gu(2) }, card_layout: "horizontal", index: 6 },
273+ { tag: "HorizontalNoSummary", height: function() { var cardToolRow = findChild(cardTool, "socialAttributesRow");
274+ return cardToolRow.y + cardToolRow.height + units.gu(1) },
275+ card_layout: "horizontal", index: 6 },
273276 ]
274277 }
275278