on xenial help sign in
Merge lp:~cimi/unity8/card_touchdown_2.
b3cfec7Michał Sawicz
plugins/Dash/CardCreator.js+21−1
@@ -251,6 +251,16 @@ var kTitleLabelCode = 'Label { \n\
251 horizontalAlignment: root.headerAlignment; \n\
251 horizontalAlignment: root.headerAlignment; \n\
252 }\n';
252 }\n';
253
253
254+// %1 is used as anchors of touchdown effect
255+var kTouchdownCode = 'UbuntuShape { \n\
256+ id: touchdown; \n\
257+ objectName: "touchdown"; \n\
258+ anchors { %1 } \n\
259+ visible: root.pressed; \n\
260+ radius: "medium"; \n\
261+ borderSource: "radius_pressed.sci" \n\
262+ }\n';
263+
254// %1 is used as anchors of subtitleLabel
264// %1 is used as anchors of subtitleLabel
255// %2 is used as color of subtitleLabel
265// %2 is used as color of subtitleLabel
256var kSubtitleLabelCode = 'Label { \n\
266var kSubtitleLabelCode = 'Label { \n\
@@ -273,7 +283,7 @@ var kAttributesRowCode = 'CardAttributes { \n\
273 objectName: "attributesRow"; \n\
283 objectName: "attributesRow"; \n\
274 anchors { %1 } \n\
284 anchors { %1 } \n\
275 color: %2; \n\
285 color: %2; \n\
276− model: cardData && cardData["attributes"] || undefined; \n\
286+ model: cardData["attributes"]; \n\
277 }\n';
287 }\n';
278
288
279// %1 is used as top anchor of summary
289// %1 is used as top anchor of summary
@@ -563,6 +573,16 @@ function cardString(template, components) {
563 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(color);
573 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(color);
564 }
574 }
565
575
576+ var touchdownAnchors;
577+ if (hasBackground) {
578+ touchdownAnchors = 'fill: backgroundLoader';
579+ } else if (hasArt && !hasMascot && !hasSummary) {
580+ touchdownAnchors = 'fill: artShapeHolder';
581+ } else {
582+ touchdownAnchors = 'fill: root'
583+ }
584+ code += kTouchdownCode.arg(touchdownAnchors);
585+
566 if (hasSummary) {
586 if (hasSummary) {
567 code += 'implicitHeight: summary.y + summary.height + (summary.text ? units.gu(1) : 0);\n';
587 code += 'implicitHeight: summary.y + summary.height + (summary.text ? units.gu(1) : 0);\n';
568 } else if (hasHeaderRow) {
588 } else if (hasHeaderRow) {
tests/plugins/Dash/cardcreator/1.res+8
@@ -78,5 +78,13 @@ leftMargin: units.gu(1);
78 font.weight: components && components["subtitle"] ? Font.DemiBold : Font.Normal;
78 font.weight: components && components["subtitle"] ? Font.DemiBold : Font.Normal;
79 horizontalAlignment: root.headerAlignment;
79 horizontalAlignment: root.headerAlignment;
80 }
80 }
81+UbuntuShape {
82+ id: touchdown;
83+ objectName: "touchdown";
84+ anchors { fill: artShapeHolder }
85+ visible: root.pressed;
86+ radius: "medium";
87+ borderSource: "radius_pressed.sci"
88+}
81implicitHeight: titleLabel.y + titleLabel.height + units.gu(1);
89implicitHeight: titleLabel.y + titleLabel.height + units.gu(1);
82}
90}
tests/plugins/Dash/cardcreator/2.res+8
@@ -116,5 +116,13 @@ left: parent.left;
116
116
117 ]
117 ]
118 }
118 }
119+UbuntuShape {
120+ id: touchdown;
121+ objectName: "touchdown";
122+ anchors { fill: backgroundLoader }
123+ visible: root.pressed;
124+ radius: "medium";
125+ borderSource: "radius_pressed.sci"
126+}
119implicitHeight: row.y + row.height + units.gu(1);
127implicitHeight: row.y + row.height + units.gu(1);
120}
128}
tests/plugins/Dash/cardcreator/3.res+8
@@ -97,5 +97,13 @@ Label {
97 font.weight: Font.Light;
97 font.weight: Font.Light;
98 horizontalAlignment: root.headerAlignment;
98 horizontalAlignment: root.headerAlignment;
99 }
99 }
100+UbuntuShape {
101+ id: touchdown;
102+ objectName: "touchdown";
103+ anchors { fill: artShapeHolder }
104+ visible: root.pressed;
105+ radius: "medium";
106+ borderSource: "radius_pressed.sci"
107+}
100implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);
108implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);
101}
109}
tests/plugins/Dash/cardcreator/4.res+8
@@ -94,5 +94,13 @@ Label {
94}
94}
95]
95]
96}
96}
97+UbuntuShape {
98+ id: touchdown;
99+ objectName: "touchdown";
100+ anchors { fill: root }
101+ visible: root.pressed;
102+ radius: "medium";
103+ borderSource: "radius_pressed.sci"
104+}
97implicitHeight: row.y + row.height + units.gu(1);
105implicitHeight: row.y + row.height + units.gu(1);
98}
106}
tests/plugins/Dash/cardcreator/5.res+8
@@ -137,5 +137,13 @@ Label {
137 font.weight: Font.Light;
137 font.weight: Font.Light;
138 horizontalAlignment: root.headerAlignment;
138 horizontalAlignment: root.headerAlignment;
139 }
139 }
140+UbuntuShape {
141+ id: touchdown;
142+ objectName: "touchdown";
143+ anchors { fill: artShapeHolder }
144+ visible: root.pressed;
145+ radius: "medium";
146+ borderSource: "radius_pressed.sci"
147+}
140implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);
148implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);
141}
149}
tests/plugins/Dash/cardcreator/6.res+8
@@ -57,5 +57,13 @@ Item {
57 }
57 }
58 }
58 }
59readonly property int headerHeight: 0;
59readonly property int headerHeight: 0;
60+UbuntuShape {
61+ id: touchdown;
62+ objectName: "touchdown";
63+ anchors { fill: artShapeHolder }
64+ visible: root.pressed;
65+ radius: "medium";
66+ borderSource: "radius_pressed.sci"
67+}
60implicitHeight: artShapeHolder.height;
68implicitHeight: artShapeHolder.height;
61}
69}
tests/plugins/Dash/cardcreator/7.res+9−1
@@ -116,7 +116,7 @@ CardAttributes {
116 objectName: "attributesRow";
116 objectName: "attributesRow";
117 anchors { left: parent.left; right: parent.right }
117 anchors { left: parent.left; right: parent.right }
118 color: backgroundLoader.active && backgroundLoader.item && backgroundLoader.item.luminance < 0.7 ? "white" : (root.scopeStyle ? root.scopeStyle.foreground : "grey");
118 color: backgroundLoader.active && backgroundLoader.item && backgroundLoader.item.luminance < 0.7 ? "white" : (root.scopeStyle ? root.scopeStyle.foreground : "grey");
119− model: cardData && cardData["attributes"] || undefined;
119+ model: cardData["attributes"];
120 }
120 }
121
121
122 ]
122 ]
@@ -124,5 +124,13 @@ CardAttributes {
124
124
125 ]
125 ]
126 }
126 }
127+UbuntuShape {
128+ id: touchdown;
129+ objectName: "touchdown";
130+ anchors { fill: backgroundLoader }
131+ visible: root.pressed;
132+ radius: "medium";
133+ borderSource: "radius_pressed.sci"
134+}
127implicitHeight: row.y + row.height + units.gu(1);
135implicitHeight: row.y + row.height + units.gu(1);
128}
136}
tests/plugins/Dash/cardcreatortest.cpp+13−4
@@ -19,6 +19,7 @@
19#include <QQuickItem>
19#include <QQuickItem>
20#include <QQuickView>
20#include <QQuickView>
21#include <QtTestGui>
21#include <QtTestGui>
22+#include <QDebug>
22#include <QTemporaryFile>
23#include <QTemporaryFile>
23
24
24class CardCreatorTest : public QObject
25class CardCreatorTest : public QObject
@@ -74,15 +75,23 @@ private Q_SLOTS:
74 QFile testResultFile(testDirPath + resultFileName);
75 QFile testResultFile(testDirPath + resultFileName);
75 QVERIFY(testResultFile.open(QIODevice::ReadOnly));
76 QVERIFY(testResultFile.open(QIODevice::ReadOnly));
76 QTextStream ts2(&testResultFile);
77 QTextStream ts2(&testResultFile);
77− const QString expectedResult = ts2.readAll();
78+
78− const QString executedResult = cardStringResult.toString();
79 // Record failed results to /tmp
79 // Record failed results to /tmp
80+ const QString executedResult = cardStringResult.toString();
80 QTemporaryFile tmpFile(QDir::tempPath() + QDir::separator() + "testCardCreatorFailedResultXXXXXX");
81 QTemporaryFile tmpFile(QDir::tempPath() + QDir::separator() + "testCardCreatorFailedResultXXXXXX");
81 tmpFile.open();
82 tmpFile.open();
82 tmpFile.setAutoRemove(false);
83 tmpFile.setAutoRemove(false);
83 tmpFile.write(executedResult.toUtf8().constData());
84 tmpFile.write(executedResult.toUtf8().constData());
85+
86+ // Line by line comparison
87+ const QStringList expectedLines = ts2.readAll().trimmed().replace(QRegExp("\n\\s*\n"),"\n").split("\n");
88+ const QStringList cardStringResultLines = cardStringResult.toString().trimmed().replace(QRegExp("\n\\s*\n"),"\n").split("\n");
89+ for (int i = 0; i < expectedLines.size(); ++i) {
84− QCOMPARE(executedResult.simplified(), expectedResult.simplified());
90+ QCOMPARE(cardStringResultLines[i].simplified(), expectedLines[i].simplified());
91+ }
92+
85− tmpFile.setAutoRemove(true); // Remove the result if it passed
93+ // Remove the result if it passed
94+ tmpFile.setAutoRemove(true);
86
95
87 QVariant createCardComponentResult;
96 QVariant createCardComponentResult;
88 QMetaObject::invokeMethod(view->rootObject(), "createCardComponent", Q_RETURN_ARG(QVariant, createCardComponentResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON));
97 QMetaObject::invokeMethod(view->rootObject(), "createCardComponent", Q_RETURN_ARG(QVariant, createCardComponentResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON));
tests/qmltests/Dash/tst_Card.qml+12
@@ -475,5 +475,17 @@ Rectangle {
475 compare(shape !== null, data.shape);
475 compare(shape !== null, data.shape);
476 tryCompare(mascotImage, "visible", !data.shape);
476 tryCompare(mascotImage, "visible", !data.shape);
477 }
477 }
478+
479+ function test_touchdown_visibility() {
480+ selector.selectedIndex = 0;
481+
482+ var touchdown = findChild(card, "touchdown");
483+
484+ compare(touchdown.visible, false);
485+ mousePress(card, card.width/2, card.height/2);
486+ compare(touchdown.visible, true);
487+ mouseRelease(card, card.width/2, card.height/2);
488+ compare(touchdown.visible, false);
489+ }
478 }
490 }
479}
491}