on xenial help sign in
Merge lp:~cimi/unity8/card_touchdown_2.
commitb3cfec77d5b98e9d4feff81bfb84e4400a845280 authorMichał Sawicz <michal.sawicz@canonical.com> dateWed 6 Aug 2014, 00:51 (12 years ago) parentf3347f9a223069
10 files changed+103−6
plugins/Dash/CardCreator.js+21−1 tests/plugins/Dash/cardcreator/1.res+8 tests/plugins/Dash/cardcreator/2.res+8 tests/plugins/Dash/cardcreator/3.res+8 tests/plugins/Dash/cardcreator/4.res+8 tests/plugins/Dash/cardcreator/5.res+8 tests/plugins/Dash/cardcreator/6.res+8 tests/plugins/Dash/cardcreator/7.res+9−1 tests/plugins/Dash/cardcreatortest.cpp+13−4 tests/qmltests/Dash/tst_Card.qml+12
plugins/Dash/CardCreator.js+21−1
@@ -251,6 +251,16 @@ var kTitleLabelCode = 'Label { \n\
251251 horizontalAlignment: root.headerAlignment; \n\
252252 }\n';
253253
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+
254264// %1 is used as anchors of subtitleLabel
255265// %2 is used as color of subtitleLabel
256266var kSubtitleLabelCode = 'Label { \n\
@@ -273,7 +283,7 @@ var kAttributesRowCode = 'CardAttributes { \n\
273283 objectName: "attributesRow"; \n\
274284 anchors { %1 } \n\
275285 color: %2; \n\
276− model: cardData && cardData["attributes"] || undefined; \n\
286+ model: cardData["attributes"]; \n\
277287 }\n';
278288
279289// %1 is used as top anchor of summary
@@ -563,6 +573,16 @@ function cardString(template, components) {
563573 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(color);
564574 }
565575
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+
566586 if (hasSummary) {
567587 code += 'implicitHeight: summary.y + summary.height + (summary.text ? units.gu(1) : 0);\n';
568588 } else if (hasHeaderRow) {
tests/plugins/Dash/cardcreator/1.res+8
@@ -78,5 +78,13 @@ leftMargin: units.gu(1);
7878 font.weight: components && components["subtitle"] ? Font.DemiBold : Font.Normal;
7979 horizontalAlignment: root.headerAlignment;
8080 }
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+}
8189implicitHeight: titleLabel.y + titleLabel.height + units.gu(1);
8290}
tests/plugins/Dash/cardcreator/2.res+8
@@ -116,5 +116,13 @@ left: parent.left;
116116
117117 ]
118118 }
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+}
119127implicitHeight: row.y + row.height + units.gu(1);
120128}
tests/plugins/Dash/cardcreator/3.res+8
@@ -97,5 +97,13 @@ Label {
9797 font.weight: Font.Light;
9898 horizontalAlignment: root.headerAlignment;
9999 }
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+}
100108implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);
101109}
tests/plugins/Dash/cardcreator/4.res+8
@@ -94,5 +94,13 @@ Label {
9494}
9595]
9696}
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+}
97105implicitHeight: row.y + row.height + units.gu(1);
98106}
tests/plugins/Dash/cardcreator/5.res+8
@@ -137,5 +137,13 @@ Label {
137137 font.weight: Font.Light;
138138 horizontalAlignment: root.headerAlignment;
139139 }
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+}
140148implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);
141149}
tests/plugins/Dash/cardcreator/6.res+8
@@ -57,5 +57,13 @@ Item {
5757 }
5858 }
5959readonly 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+}
6068implicitHeight: artShapeHolder.height;
6169}
tests/plugins/Dash/cardcreator/7.res+9−1
@@ -116,7 +116,7 @@ CardAttributes {
116116 objectName: "attributesRow";
117117 anchors { left: parent.left; right: parent.right }
118118 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"];
120120 }
121121
122122 ]
@@ -124,5 +124,13 @@ CardAttributes {
124124
125125 ]
126126 }
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+}
127135implicitHeight: row.y + row.height + units.gu(1);
128136}
tests/plugins/Dash/cardcreatortest.cpp+13−4
@@ -19,6 +19,7 @@
1919#include <QQuickItem>
2020#include <QQuickView>
2121#include <QtTestGui>
22+#include <QDebug>
2223#include <QTemporaryFile>
2324
2425class CardCreatorTest : public QObject
@@ -74,15 +75,23 @@ private Q_SLOTS:
7475 QFile testResultFile(testDirPath + resultFileName);
7576 QVERIFY(testResultFile.open(QIODevice::ReadOnly));
7677 QTextStream ts2(&testResultFile);
77− const QString expectedResult = ts2.readAll();
78− const QString executedResult = cardStringResult.toString();
78+
7979 // Record failed results to /tmp
80+ const QString executedResult = cardStringResult.toString();
8081 QTemporaryFile tmpFile(QDir::tempPath() + QDir::separator() + "testCardCreatorFailedResultXXXXXX");
8182 tmpFile.open();
8283 tmpFile.setAutoRemove(false);
8384 tmpFile.write(executedResult.toUtf8().constData());
84− QCOMPARE(executedResult.simplified(), expectedResult.simplified());
85− tmpFile.setAutoRemove(true); // Remove the result if it passed
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) {
90+ QCOMPARE(cardStringResultLines[i].simplified(), expectedLines[i].simplified());
91+ }
92+
93+ // Remove the result if it passed
94+ tmpFile.setAutoRemove(true);
8695
8796 QVariant createCardComponentResult;
8897 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 {
475475 compare(shape !== null, data.shape);
476476 tryCompare(mascotImage, "visible", !data.shape);
477477 }
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+ }
478490 }
479491}