on xenial help sign in
Merge refactor-carousel-activation
commitaa5506c57ba640ebeb2345a07e1528eea0f9b062 authorMichał Sawicz <michal.sawicz@canonical.com> dateTue 8 Jul 2014, 22:50 (12 years ago) parentf16e991741c4fc
4 files changed+18−19
qml/Components/BaseCarouselDelegate.qml+3 qml/Components/Carousel.qml+1−1 qml/Dash/CardCarousel.qml+3−1 tests/qmltests/Components/tst_Carousel.qml+11−17
qml/Components/BaseCarouselDelegate.qml+3
@@ -28,6 +28,9 @@ Item {
2828 /// True if this item is currently "focused" in the carousel.
2929 property bool explicitlyScaled
3030
31+ /// Model index for this delegate.
32+ property int index
33+
3134 /// Model data for this delegate.
3235 property var model
3336
qml/Components/Carousel.qml+1−1
@@ -306,8 +306,8 @@ Item {
306306 }
307307
308308 onLoaded: {
309− item.objectName = Qt.binding(function() { return "carouselDelegate" + index; });
310309 item.explicitlyScaled = Qt.binding(function() { return explicitlyScaled; });
310+ item.index = Qt.binding(function() { return index; });
311311 item.model = Qt.binding(function() { return model; });
312312 }
313313
qml/Dash/CardCarousel.qml+3−1
@@ -48,14 +48,16 @@ DashRenderer {
4848
4949 property bool explicitlyScaled
5050 property var model
51+ property int index
5152 enabled: false
5253
54+ objectName: "carouselDelegate" + index
55+
5356 function clicked() { cardCarousel.clicked(index, model.result) }
5457 function pressAndHold() { cardCarousel.pressAndHold(index, model.result) }
5558
5659 sourceComponent: cardTool.cardComponent
5760 onLoaded: {
58− item.objectName = "carouselDelegate" + index;
5961 item.fixedHeaderHeight = Qt.binding(function() { return carousel.headerHeight; });
6062 item.height = Qt.binding(function() { return cardTool.cardHeight; });
6163 item.cardData = Qt.binding(function() { return model; });
tests/qmltests/Components/tst_Carousel.qml+11−17
@@ -31,15 +31,15 @@ Item {
3131 property int createdDelegates: 0
3232 property int destroyedDelegates: 0
3333
34− itemComponent: Component {
35− BaseCarouselDelegate {
36− Rectangle {
37− anchors.fill: parent
38− border.color: "black"
39− color: "red"
40− Component.onCompleted: carousel.createdDelegates++
41− Component.onDestruction: carousel.destroyedDelegates++
42− }
34+ itemComponent: BaseCarouselDelegate {
35+ objectName: "carouselDelegate" + index
36+
37+ Rectangle {
38+ anchors.fill: parent
39+ border.color: "black"
40+ color: "red"
41+ Component.onCompleted: carousel.createdDelegates++
42+ Component.onDestruction: carousel.destroyedDelegates++
4343 }
4444 }
4545 }
@@ -266,11 +266,12 @@ Item {
266266 verify(Math.abs(x - carouselList.contentX) < 1);
267267 }
268268
269− function test_click() {
269+ function test_activate() {
270270 var carouselList = findChild(carousel, "listView");
271271 tryCompareFunction(function() { return findChild(carouselList, "carouselDelegate3") ? true : false; }, true);
272272 var carouselItem = findChild(carousel, "carouselDelegate3")
273273 verify(carouselItem, "Could not find delegate");
274+
274275 spy.signalName = "clicked";
275276 spy.target = carouselItem;
276277 mouseClick(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
@@ -278,13 +279,7 @@ Item {
278279 tryCompare(carouselItem, "explicitlyScaled", true);
279280 mouseClick(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
280281 spy.wait();
281− }
282282
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");
288283 spy.signalName = "pressAndHold";
289284 spy.target = carouselItem;
290285 mouseClick(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
@@ -294,6 +289,5 @@ Item {
294289 spy.wait();
295290 mouseRelease(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
296291 }
297−
298292 }
299293}