on xenial help sign in
More signals, waiting for unity scope shell adjustments
528ccefAndrea Cimitan
plugins/Dash/CardCreator.js+2−4
@@ -344,7 +344,7 @@ var kSocialAttributesRowCode = 'CardSocialAttributes { \n\
344 anchors { %1 } \n\
344 anchors { %1 } \n\
345 color: %2; \n\
345 color: %2; \n\
346 model: cardData && cardData["socialAttributes"]; \n\
346 model: cardData && cardData["socialAttributes"]; \n\
347− onClicked: root.clicked(result); \n\
347+ onClicked: root.action(actionId); \n\
348 }\n';
348 }\n';
349
349
350// %1 is used as top anchor of summary
350// %1 is used as top anchor of summary
@@ -436,9 +436,7 @@ function cardString(template, components) {
436 var hasSocialAttributes = hasTitle && components["socialAttributes"] || false;
436 var hasSocialAttributes = hasTitle && components["socialAttributes"] || false;
437 var isAudio = template["quick-preview-type"] === "audio";
437 var isAudio = template["quick-preview-type"] === "audio";
438
438
439− if (hasSocialAttributes) {
440− code += 'signal clicked(var result);\n';
439+ code += 'signal action(var actionId);\n';
441− }
442 if (isAudio) {
440 if (isAudio) {
443 // For now we only support audio cards with [optional] art, title, subtitle
441 // For now we only support audio cards with [optional] art, title, subtitle
444 // in horizontal mode
442 // in horizontal mode
plugins/Dash/CardSocialAttributes.qml+18−12
@@ -22,12 +22,11 @@ import "../../../qml/Components/ListItems" as ListItems
22Column {
22Column {
23 id: socialAttributes
23 id: socialAttributes
24 spacing: units.gu(0.5)
24 spacing: units.gu(0.5)
25− height: divider.height + spacing + grid.height
26
25
27 property alias model: repeater.model
26 property alias model: repeater.model
28 property color color: theme.palette.normal.baseText
27 property color color: theme.palette.normal.baseText
29
28
30− signal clicked(var result)
29+ signal clicked(var actionId)
31
30
32 ListItems.ThinDivider {
31 ListItems.ThinDivider {
33 id: divider
32 id: divider
@@ -35,32 +34,39 @@ Column {
35 anchors { left: parent.left; right: parent.right; }
34 anchors { left: parent.left; right: parent.right; }
36 }
35 }
37
36
38− GridLayout {
37+ Row {
39− id: grid
38+ id: row
40 anchors {
39 anchors {
41 left: parent.left
40 left: parent.left
42 right: parent.right
41 right: parent.right
43 leftMargin: units.gu(1)
42 leftMargin: units.gu(1)
44 rightMargin: units.gu(1)
43 rightMargin: units.gu(1)
45 }
44 }
45+ spacing: units.gu(2)
46+ readonly property int visibleItems: {
46− columns: width > units.gu(12) ? 4 : 2
47+ if (width <= units.gu(12)) // small card
47− rowSpacing: units.gu(2)
48+ return 2;
49+ else if (width <= units.gu(21)) // medium card
50+ return 3;
51+ else // large or horizontal card
52+ return 4;
53+ }
48
54
49 Repeater {
55 Repeater {
50 id: repeater
56 id: repeater
51− delegate: Row {
57+ delegate: Loader {
52− objectName: "delegate" + index
53− spacing: units.gu(0.5)
54 height: units.gu(2)
58 height: units.gu(2)
59+ active: index < row.visibleItems
55− AbstractButton {
60+ sourceComponent: AbstractButton {
61+ objectName: "delegate" + index
56 height: units.gu(2)
62 height: units.gu(2)
57 width: icon.width
63 width: icon.width
58 Icon {
64 Icon {
59 id: icon
65 id: icon
60 objectName: "icon"
66 objectName: "icon"
61
67
62− property url urlIcon: "icon" in modelData && modelData["icon"] || ""
68+ readonly property url urlIcon: "image://theme/ok"
63− property url urlTemporaryIcon: "temporaryIcon" in modelData && modelData["temporaryIcon"] || ""
69+ readonly property url urlTemporaryIcon: "temporaryIcon" in modelData && modelData["temporaryIcon"] || ""
64
70
65 height: units.gu(2)
71 height: units.gu(2)
66 // FIXME Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
72 // FIXME Workaround for bug https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1421293
qml/Dash/CardGrid.qml+3
@@ -34,6 +34,8 @@ DashRenderer {
34 collapsedItemCount: collapsedRows * grid.columns
34 collapsedItemCount: collapsedRows * grid.columns
35 originY: grid.originY
35 originY: grid.originY
36
36
37+ onAction: console.log(index, actionId)
38+
37 function cardPosition(index) {
39 function cardPosition(index) {
38 var pos = {};
40 var pos = {};
39 var row = Math.floor(index / grid.columns);
41 var row = Math.floor(index / grid.columns);
@@ -79,6 +81,7 @@ DashRenderer {
79 target: loader.item
81 target: loader.item
80 onClicked: root.clicked(index, result, loader.item, model)
82 onClicked: root.clicked(index, result, loader.item, model)
81 onPressAndHold: root.pressAndHold(index, result, model)
83 onPressAndHold: root.pressAndHold(index, result, model)
84+ onAction: root.action(index, actionId)
82 }
85 }
83 }
86 }
84 }
87 }
qml/Dash/DashRenderer.qml+5
@@ -57,4 +57,9 @@ Item {
57 /// @param result result model of the clicked item, used for activation
57 /// @param result result model of the clicked item, used for activation
58 /// @param itemModel model of the item
58 /// @param itemModel model of the item
59 signal pressAndHold(int index, var result, var itemModel)
59 signal pressAndHold(int index, var result, var itemModel)
60+
61+ /// Emitted when the user clicked on an item action
62+ /// @param index is the index of the clicked item
63+ /// @param actionId id of the clicked action
64+ signal action(int index, var actionId)
60}
65}
qml/Dash/GenericScopeView.qml+4
@@ -407,6 +407,10 @@ FocusScope {
407 scopeView.itemPressedAndHeld(index, result, target.model, categoryItemCount(), baseItem.category);
407 scopeView.itemPressedAndHeld(index, result, target.model, categoryItemCount(), baseItem.category);
408 }
408 }
409
409
410+ onAction: { // (int index, var actionId)
411+ scopeview.activateAction(index, baseitem.categoryId, actionId);
412+ }
413+
410 function categoryItemCount() {
414 function categoryItemCount() {
411 var categoryItemCount = -1;
415 var categoryItemCount = -1;
412 if (!rendererLoader.expanded && !seeAllLabel.visible && target.collapsedItemCount > 0) {
416 if (!rendererLoader.expanded && !seeAllLabel.visible && target.collapsedItemCount > 0) {
tests/mocks/Unity/fake_categories.cpp+4−1
@@ -88,7 +88,7 @@ Categories::data(const QModelIndex& index, int role) const
88 }
88 }
89 case RoleComponents:
89 case RoleComponents:
90 {
90 {
91− QVariantMap map, artMap, attributeMap;
91+ QVariantMap map, artMap, attributeMap, socialAttributeMap;
92 if (index.row() % 2 != 0) {
92 if (index.row() % 2 != 0) {
93 artMap["aspect-ratio"] = QString("1.%1").arg(index.row());
93 artMap["aspect-ratio"] = QString("1.%1").arg(index.row());
94 } else {
94 } else {
@@ -99,6 +99,9 @@ Categories::data(const QModelIndex& index, int role) const
99 map["title"] = "HOLA";
99 map["title"] = "HOLA";
100 map["subtitle"] = "HOLA";
100 map["subtitle"] = "HOLA";
101 attributeMap["field"] = "attribute";
101 attributeMap["field"] = "attribute";
102+ socialAttributeMap["icon"] = "image://theme/cancel";
103+ socialAttributeMap["id"] = "dislike";
104+ map["socialAttributes"] = socialAttributeMap;
102 map["attributes"] = attributeMap;
105 map["attributes"] = attributeMap;
103 return map;
106 return map;
104 }
107 }
tests/mocks/Unity/fake_resultsmodel.cpp+3−1
@@ -83,8 +83,10 @@ ResultsModel::data(const QModelIndex& index, int role) const
83 return QString("Subtitle.%1.%2").arg(m_categoryId).arg(index.row());
83 return QString("Subtitle.%1.%2").arg(m_categoryId).arg(index.row());
84 case RoleMascot:
84 case RoleMascot:
85 case RoleEmblem:
85 case RoleEmblem:
86− case RoleSummary:
86+
87 default:
87 default:
88 return QVariant();
88 return QVariant();
89+ case RoleSummary:
90+ return QString("Subtitle.%1.%2").arg(m_categoryId).arg(index.row());
89 }
91 }
90}
92}
tests/plugins/Dash/cardcreator/1.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
13 property bool showHeader: true;
13 property bool showHeader: true;
14 implicitWidth: childrenRect.width;
14 implicitWidth: childrenRect.width;
15 enabled: true;
15 enabled: true;
16−
16+signal action(var actionId);
17readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
17readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
18Item {
18Item {
19 id: artShapeHolder;
19 id: artShapeHolder;
tests/plugins/Dash/cardcreator/10.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
13 property bool showHeader: true;
13 property bool showHeader: true;
14 implicitWidth: childrenRect.width;
14 implicitWidth: childrenRect.width;
15 enabled: true;
15 enabled: true;
16−
16+signal action(var actionId);
17Loader {
17Loader {
18 id: backgroundLoader;
18 id: backgroundLoader;
19 objectName: "backgroundLoader";
19 objectName: "backgroundLoader";
tests/plugins/Dash/cardcreator/11.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
13 property bool showHeader: true;
13 property bool showHeader: true;
14 implicitWidth: childrenRect.width;
14 implicitWidth: childrenRect.width;
15 enabled: true;
15 enabled: true;
16−
16+signal action(var actionId);
17Loader {
17Loader {
18 id: backgroundLoader;
18 id: backgroundLoader;
19 objectName: "backgroundLoader";
19 objectName: "backgroundLoader";
tests/plugins/Dash/cardcreator/12.res+2−2
@@ -13,7 +13,7 @@ AbstractButton {
13 property bool showHeader: true;
13 property bool showHeader: true;
14 implicitWidth: childrenRect.width;
14 implicitWidth: childrenRect.width;
15 enabled: true;
15 enabled: true;
16−signal clicked(var result);
16+signal action(var actionId);
17readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
17readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
18Item {
18Item {
19 id: artShapeHolder;
19 id: artShapeHolder;
@@ -133,7 +133,7 @@ CardSocialAttributes {
133 anchors { top: subtitleLabel.bottom; left: parent.left; right: parent.right; topMargin: units.gu(1); }
133 anchors { top: subtitleLabel.bottom; left: parent.left; right: parent.right; topMargin: units.gu(1); }
134 color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
134 color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
135 model: cardData && cardData["socialAttributes"];
135 model: cardData && cardData["socialAttributes"];
136− onClicked: root.clicked(result);
136+ onClicked: root.action(actionId);
137}
137}
138UbuntuShape {
138UbuntuShape {
139 id: touchdown;
139 id: touchdown;
tests/plugins/Dash/cardcreator/2.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
13 property bool showHeader: true;
13 property bool showHeader: true;
14 implicitWidth: childrenRect.width;
14 implicitWidth: childrenRect.width;
15 enabled: true;
15 enabled: true;
16−
16+signal action(var actionId);
17Loader {
17Loader {
18 id: backgroundLoader;
18 id: backgroundLoader;
19 objectName: "backgroundLoader";
19 objectName: "backgroundLoader";
tests/plugins/Dash/cardcreator/3.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
13 property bool showHeader: true;
13 property bool showHeader: true;
14 implicitWidth: childrenRect.width;
14 implicitWidth: childrenRect.width;
15 enabled: true;
15 enabled: true;
16−
16+signal action(var actionId);
17readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
17readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
18Item {
18Item {
19 id: artShapeHolder;
19 id: artShapeHolder;
tests/plugins/Dash/cardcreator/4.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
13 property bool showHeader: true;
13 property bool showHeader: true;
14 implicitWidth: childrenRect.width;
14 implicitWidth: childrenRect.width;
15 enabled: true;
15 enabled: true;
16−
16+signal action(var actionId);
17readonly property size artShapeSize: Qt.size(-1, -1);
17readonly property size artShapeSize: Qt.size(-1, -1);
18readonly property int headerHeight: row.height;
18readonly property int headerHeight: row.height;
19Row {
19Row {
tests/plugins/Dash/cardcreator/5.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
13 property bool showHeader: true;
13 property bool showHeader: true;
14 implicitWidth: childrenRect.width;
14 implicitWidth: childrenRect.width;
15 enabled: false;
15 enabled: false;
16−
16+signal action(var actionId);
17readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
17readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
18Item {
18Item {
19 id: artShapeHolder;
19 id: artShapeHolder;
tests/plugins/Dash/cardcreator/6.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
13 property bool showHeader: true;
13 property bool showHeader: true;
14 implicitWidth: childrenRect.width;
14 implicitWidth: childrenRect.width;
15 enabled: true;
15 enabled: true;
16−
16+signal action(var actionId);
17Loader {
17Loader {
18 id: backgroundLoader;
18 id: backgroundLoader;
19 objectName: "backgroundLoader";
19 objectName: "backgroundLoader";
tests/plugins/Dash/cardcreator/7.res+1
@@ -13,6 +13,7 @@ AbstractButton {
13 property bool showHeader: true;
13 property bool showHeader: true;
14 implicitWidth: childrenRect.width;
14 implicitWidth: childrenRect.width;
15 enabled: true;
15 enabled: true;
16+signal action(var actionId);
16
17
17Loader {
18Loader {
18 id: backgroundLoader;
19 id: backgroundLoader;
tests/plugins/Dash/cardcreator/8.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
13 property bool showHeader: true;
13 property bool showHeader: true;
14 implicitWidth: childrenRect.width;
14 implicitWidth: childrenRect.width;
15 enabled: true;
15 enabled: true;
16−
16+signal action(var actionId);
17Loader {
17Loader {
18 id: backgroundLoader;
18 id: backgroundLoader;
19 objectName: "backgroundLoader";
19 objectName: "backgroundLoader";
tests/plugins/Dash/cardcreator/9.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
13 property bool showHeader: true;
13 property bool showHeader: true;
14 implicitWidth: childrenRect.width;
14 implicitWidth: childrenRect.width;
15 enabled: true;
15 enabled: true;
16−
16+signal action(var actionId);
17readonly property size artShapeSize: Qt.size(-1, -1);
17readonly property size artShapeSize: Qt.size(-1, -1);
18readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + audioProgressBar.height + audioProgressBar.anchors.topMargin;
18readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + audioProgressBar.height + audioProgressBar.anchors.topMargin;
19Label {
19Label {
tests/qmltests/Dash/tst_Card.qml+1−1
@@ -217,7 +217,7 @@ Rectangle {
217
217
218 SignalSpy {
218 SignalSpy {
219 id: signalSpy
219 id: signalSpy
220− signalName: "clicked"
220+ signalName: "action"
221 }
221 }
222
222
223 UT.UnityTestCase {
223 UT.UnityTestCase {