on xenial help sign in
Merge refactor-carousel-activation
aa5506cMichał Sawicz
qml/Components/BaseCarouselDelegate.qml+3
@@ -28,6 +28,9 @@ Item {
28 /// True if this item is currently "focused" in the carousel.
28 /// True if this item is currently "focused" in the carousel.
29 property bool explicitlyScaled
29 property bool explicitlyScaled
30
30
31+ /// Model index for this delegate.
32+ property int index
33+
31 /// Model data for this delegate.
34 /// Model data for this delegate.
32 property var model
35 property var model
33
36
qml/Components/Carousel.qml+1−1
@@ -306,8 +306,8 @@ Item {
306 }
306 }
307
307
308 onLoaded: {
308 onLoaded: {
309− item.objectName = Qt.binding(function() { return "carouselDelegate" + index; });
310 item.explicitlyScaled = Qt.binding(function() { return explicitlyScaled; });
309 item.explicitlyScaled = Qt.binding(function() { return explicitlyScaled; });
310+ item.index = Qt.binding(function() { return index; });
311 item.model = Qt.binding(function() { return model; });
311 item.model = Qt.binding(function() { return model; });
312 }
312 }
313
313
qml/Dash/CardCarousel.qml+3−1
@@ -48,14 +48,16 @@ DashRenderer {
48
48
49 property bool explicitlyScaled
49 property bool explicitlyScaled
50 property var model
50 property var model
51+ property int index
51 enabled: false
52 enabled: false
52
53
54+ objectName: "carouselDelegate" + index
55+
53 function clicked() { cardCarousel.clicked(index, model.result) }
56 function clicked() { cardCarousel.clicked(index, model.result) }
54 function pressAndHold() { cardCarousel.pressAndHold(index, model.result) }
57 function pressAndHold() { cardCarousel.pressAndHold(index, model.result) }
55
58
56 sourceComponent: cardTool.cardComponent
59 sourceComponent: cardTool.cardComponent
57 onLoaded: {
60 onLoaded: {
58− item.objectName = "carouselDelegate" + index;
59 item.fixedHeaderHeight = Qt.binding(function() { return carousel.headerHeight; });
61 item.fixedHeaderHeight = Qt.binding(function() { return carousel.headerHeight; });
60 item.height = Qt.binding(function() { return cardTool.cardHeight; });
62 item.height = Qt.binding(function() { return cardTool.cardHeight; });
61 item.cardData = Qt.binding(function() { return model; });
63 item.cardData = Qt.binding(function() { return model; });
tests/qmltests/Components/tst_Carousel.qml+11−17
@@ -31,15 +31,15 @@ Item {
31 property int createdDelegates: 0
31 property int createdDelegates: 0
32 property int destroyedDelegates: 0
32 property int destroyedDelegates: 0
33
33
34− itemComponent: Component {
35− BaseCarouselDelegate {
34+ itemComponent: BaseCarouselDelegate {
35+ objectName: "carouselDelegate" + index
36+
36− Rectangle {
37+ Rectangle {
37− anchors.fill: parent
38+ anchors.fill: parent
38− border.color: "black"
39+ border.color: "black"
39− color: "red"
40+ color: "red"
40− Component.onCompleted: carousel.createdDelegates++
41+ Component.onCompleted: carousel.createdDelegates++
41− Component.onDestruction: carousel.destroyedDelegates++
42+ Component.onDestruction: carousel.destroyedDelegates++
42− }
43 }
43 }
44 }
44 }
45 }
45 }
@@ -266,11 +266,12 @@ Item {
266 verify(Math.abs(x - carouselList.contentX) < 1);
266 verify(Math.abs(x - carouselList.contentX) < 1);
267 }
267 }
268
268
269− function test_click() {
269+ function test_activate() {
270 var carouselList = findChild(carousel, "listView");
270 var carouselList = findChild(carousel, "listView");
271 tryCompareFunction(function() { return findChild(carouselList, "carouselDelegate3") ? true : false; }, true);
271 tryCompareFunction(function() { return findChild(carouselList, "carouselDelegate3") ? true : false; }, true);
272 var carouselItem = findChild(carousel, "carouselDelegate3")
272 var carouselItem = findChild(carousel, "carouselDelegate3")
273 verify(carouselItem, "Could not find delegate");
273 verify(carouselItem, "Could not find delegate");
274+
274 spy.signalName = "clicked";
275 spy.signalName = "clicked";
275 spy.target = carouselItem;
276 spy.target = carouselItem;
276 mouseClick(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
277 mouseClick(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
@@ -278,13 +279,7 @@ Item {
278 tryCompare(carouselItem, "explicitlyScaled", true);
279 tryCompare(carouselItem, "explicitlyScaled", true);
279 mouseClick(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
280 mouseClick(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
280 spy.wait();
281 spy.wait();
281− }
282
282
283− function test_pressAndHold() {
284− var carouselList = findChild(carousel, "listView");
285− tryCompareFunction(function() { return findChild(carouselList, "carouselDelegate3") ? true : false; }, true);
286− var carouselItem = findChild(carousel, "carouselDelegate3")
287− verify(carouselItem, "Could not find delegate");
288 spy.signalName = "pressAndHold";
283 spy.signalName = "pressAndHold";
289 spy.target = carouselItem;
284 spy.target = carouselItem;
290 mouseClick(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
285 mouseClick(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
@@ -294,6 +289,5 @@ Item {
294 spy.wait();
289 spy.wait();
295 mouseRelease(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
290 mouseRelease(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
296 }
291 }
297−
298 }
292 }
299}
293}