on xenial help sign in
More signals, waiting for unity scope shell adjustments
commit528ccef43acda536cc4663afbd6402aabda77ed4 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateTue 16 Feb 2016, 11:27 (11 years ago) parent7b78ca7
20 files changed+53−31
plugins/Dash/CardCreator.js+2−4 plugins/Dash/CardSocialAttributes.qml+18−12 qml/Dash/CardGrid.qml+3 qml/Dash/DashRenderer.qml+5 qml/Dash/GenericScopeView.qml+4 tests/mocks/Unity/fake_categories.cpp+4−1 tests/mocks/Unity/fake_resultsmodel.cpp+3−1 tests/plugins/Dash/cardcreator/1.res+1−1 tests/plugins/Dash/cardcreator/10.res+1−1 tests/plugins/Dash/cardcreator/11.res+1−1 tests/plugins/Dash/cardcreator/12.res+2−2 tests/plugins/Dash/cardcreator/2.res+1−1 tests/plugins/Dash/cardcreator/3.res+1−1 tests/plugins/Dash/cardcreator/4.res+1−1 tests/plugins/Dash/cardcreator/5.res+1−1 tests/plugins/Dash/cardcreator/6.res+1−1 tests/plugins/Dash/cardcreator/7.res+1 tests/plugins/Dash/cardcreator/8.res+1−1 tests/plugins/Dash/cardcreator/9.res+1−1 tests/qmltests/Dash/tst_Card.qml+1−1
plugins/Dash/CardCreator.js+2−4
@@ -344,7 +344,7 @@ var kSocialAttributesRowCode = 'CardSocialAttributes { \n\
344344 anchors { %1 } \n\
345345 color: %2; \n\
346346 model: cardData && cardData["socialAttributes"]; \n\
347− onClicked: root.clicked(result); \n\
347+ onClicked: root.action(actionId); \n\
348348 }\n';
349349
350350// %1 is used as top anchor of summary
@@ -436,9 +436,7 @@ function cardString(template, components) {
436436 var hasSocialAttributes = hasTitle && components["socialAttributes"] || false;
437437 var isAudio = template["quick-preview-type"] === "audio";
438438
439− if (hasSocialAttributes) {
440− code += 'signal clicked(var result);\n';
441− }
439+ code += 'signal action(var actionId);\n';
442440 if (isAudio) {
443441 // For now we only support audio cards with [optional] art, title, subtitle
444442 // in horizontal mode
plugins/Dash/CardSocialAttributes.qml+18−12
@@ -22,12 +22,11 @@ import "../../../qml/Components/ListItems" as ListItems
2222Column {
2323 id: socialAttributes
2424 spacing: units.gu(0.5)
25− height: divider.height + spacing + grid.height
2625
2726 property alias model: repeater.model
2827 property color color: theme.palette.normal.baseText
2928
30− signal clicked(var result)
29+ signal clicked(var actionId)
3130
3231 ListItems.ThinDivider {
3332 id: divider
@@ -35,32 +34,39 @@ Column {
3534 anchors { left: parent.left; right: parent.right; }
3635 }
3736
38− GridLayout {
39− id: grid
37+ Row {
38+ id: row
4039 anchors {
4140 left: parent.left
4241 right: parent.right
4342 leftMargin: units.gu(1)
4443 rightMargin: units.gu(1)
4544 }
46− columns: width > units.gu(12) ? 4 : 2
47− rowSpacing: units.gu(2)
45+ spacing: units.gu(2)
46+ readonly property int visibleItems: {
47+ if (width <= units.gu(12)) // small card
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+ }
4854
4955 Repeater {
5056 id: repeater
51− delegate: Row {
52− objectName: "delegate" + index
53− spacing: units.gu(0.5)
57+ delegate: Loader {
5458 height: units.gu(2)
55− AbstractButton {
59+ active: index < row.visibleItems
60+ sourceComponent: AbstractButton {
61+ objectName: "delegate" + index
5662 height: units.gu(2)
5763 width: icon.width
5864 Icon {
5965 id: icon
6066 objectName: "icon"
6167
62− property url urlIcon: "icon" in modelData && modelData["icon"] || ""
63− property url urlTemporaryIcon: "temporaryIcon" in modelData && modelData["temporaryIcon"] || ""
68+ readonly property url urlIcon: "image://theme/ok"
69+ readonly property url urlTemporaryIcon: "temporaryIcon" in modelData && modelData["temporaryIcon"] || ""
6470
6571 height: units.gu(2)
6672 // 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 {
3434 collapsedItemCount: collapsedRows * grid.columns
3535 originY: grid.originY
3636
37+ onAction: console.log(index, actionId)
38+
3739 function cardPosition(index) {
3840 var pos = {};
3941 var row = Math.floor(index / grid.columns);
@@ -79,6 +81,7 @@ DashRenderer {
7981 target: loader.item
8082 onClicked: root.clicked(index, result, loader.item, model)
8183 onPressAndHold: root.pressAndHold(index, result, model)
84+ onAction: root.action(index, actionId)
8285 }
8386 }
8487 }
qml/Dash/DashRenderer.qml+5
@@ -57,4 +57,9 @@ Item {
5757 /// @param result result model of the clicked item, used for activation
5858 /// @param itemModel model of the item
5959 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)
6065}
qml/Dash/GenericScopeView.qml+4
@@ -407,6 +407,10 @@ FocusScope {
407407 scopeView.itemPressedAndHeld(index, result, target.model, categoryItemCount(), baseItem.category);
408408 }
409409
410+ onAction: { // (int index, var actionId)
411+ scopeview.activateAction(index, baseitem.categoryId, actionId);
412+ }
413+
410414 function categoryItemCount() {
411415 var categoryItemCount = -1;
412416 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
8888 }
8989 case RoleComponents:
9090 {
91− QVariantMap map, artMap, attributeMap;
91+ QVariantMap map, artMap, attributeMap, socialAttributeMap;
9292 if (index.row() % 2 != 0) {
9393 artMap["aspect-ratio"] = QString("1.%1").arg(index.row());
9494 } else {
@@ -99,6 +99,9 @@ Categories::data(const QModelIndex& index, int role) const
9999 map["title"] = "HOLA";
100100 map["subtitle"] = "HOLA";
101101 attributeMap["field"] = "attribute";
102+ socialAttributeMap["icon"] = "image://theme/cancel";
103+ socialAttributeMap["id"] = "dislike";
104+ map["socialAttributes"] = socialAttributeMap;
102105 map["attributes"] = attributeMap;
103106 return map;
104107 }
tests/mocks/Unity/fake_resultsmodel.cpp+3−1
@@ -83,8 +83,10 @@ ResultsModel::data(const QModelIndex& index, int role) const
8383 return QString("Subtitle.%1.%2").arg(m_categoryId).arg(index.row());
8484 case RoleMascot:
8585 case RoleEmblem:
86− case RoleSummary:
86+
8787 default:
8888 return QVariant();
89+ case RoleSummary:
90+ return QString("Subtitle.%1.%2").arg(m_categoryId).arg(index.row());
8991 }
9092}
tests/plugins/Dash/cardcreator/1.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
1313 property bool showHeader: true;
1414 implicitWidth: childrenRect.width;
1515 enabled: true;
16−
16+signal action(var actionId);
1717readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
1818Item {
1919 id: artShapeHolder;
tests/plugins/Dash/cardcreator/10.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
1313 property bool showHeader: true;
1414 implicitWidth: childrenRect.width;
1515 enabled: true;
16−
16+signal action(var actionId);
1717Loader {
1818 id: backgroundLoader;
1919 objectName: "backgroundLoader";
tests/plugins/Dash/cardcreator/11.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
1313 property bool showHeader: true;
1414 implicitWidth: childrenRect.width;
1515 enabled: true;
16−
16+signal action(var actionId);
1717Loader {
1818 id: backgroundLoader;
1919 objectName: "backgroundLoader";
tests/plugins/Dash/cardcreator/12.res+2−2
@@ -13,7 +13,7 @@ AbstractButton {
1313 property bool showHeader: true;
1414 implicitWidth: childrenRect.width;
1515 enabled: true;
16−signal clicked(var result);
16+signal action(var actionId);
1717readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
1818Item {
1919 id: artShapeHolder;
@@ -133,7 +133,7 @@ CardSocialAttributes {
133133 anchors { top: subtitleLabel.bottom; left: parent.left; right: parent.right; topMargin: units.gu(1); }
134134 color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
135135 model: cardData && cardData["socialAttributes"];
136− onClicked: root.clicked(result);
136+ onClicked: root.action(actionId);
137137}
138138UbuntuShape {
139139 id: touchdown;
tests/plugins/Dash/cardcreator/2.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
1313 property bool showHeader: true;
1414 implicitWidth: childrenRect.width;
1515 enabled: true;
16−
16+signal action(var actionId);
1717Loader {
1818 id: backgroundLoader;
1919 objectName: "backgroundLoader";
tests/plugins/Dash/cardcreator/3.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
1313 property bool showHeader: true;
1414 implicitWidth: childrenRect.width;
1515 enabled: true;
16−
16+signal action(var actionId);
1717readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
1818Item {
1919 id: artShapeHolder;
tests/plugins/Dash/cardcreator/4.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
1313 property bool showHeader: true;
1414 implicitWidth: childrenRect.width;
1515 enabled: true;
16−
16+signal action(var actionId);
1717readonly property size artShapeSize: Qt.size(-1, -1);
1818readonly property int headerHeight: row.height;
1919Row {
tests/plugins/Dash/cardcreator/5.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
1313 property bool showHeader: true;
1414 implicitWidth: childrenRect.width;
1515 enabled: false;
16−
16+signal action(var actionId);
1717readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
1818Item {
1919 id: artShapeHolder;
tests/plugins/Dash/cardcreator/6.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
1313 property bool showHeader: true;
1414 implicitWidth: childrenRect.width;
1515 enabled: true;
16−
16+signal action(var actionId);
1717Loader {
1818 id: backgroundLoader;
1919 objectName: "backgroundLoader";
tests/plugins/Dash/cardcreator/7.res+1
@@ -13,6 +13,7 @@ AbstractButton {
1313 property bool showHeader: true;
1414 implicitWidth: childrenRect.width;
1515 enabled: true;
16+signal action(var actionId);
1617
1718Loader {
1819 id: backgroundLoader;
tests/plugins/Dash/cardcreator/8.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
1313 property bool showHeader: true;
1414 implicitWidth: childrenRect.width;
1515 enabled: true;
16−
16+signal action(var actionId);
1717Loader {
1818 id: backgroundLoader;
1919 objectName: "backgroundLoader";
tests/plugins/Dash/cardcreator/9.res+1−1
@@ -13,7 +13,7 @@ AbstractButton {
1313 property bool showHeader: true;
1414 implicitWidth: childrenRect.width;
1515 enabled: true;
16−
16+signal action(var actionId);
1717readonly property size artShapeSize: Qt.size(-1, -1);
1818readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + audioProgressBar.height + audioProgressBar.anchors.topMargin;
1919Label {
tests/qmltests/Dash/tst_Card.qml+1−1
@@ -217,7 +217,7 @@ Rectangle {
217217
218218 SignalSpy {
219219 id: signalSpy
220− signalName: "clicked"
220+ signalName: "action"
221221 }
222222
223223 UT.UnityTestCase {