on xenial help sign in
Remove unused Carousel component.
commit5018704c512f822cad8c7e24daa5a5ce00766b60 authorRodney Dawes <dobey.pwns@gmail.com> dateMon 15 Apr 2019, 20:00 (8 years ago) parent5d5cc7f
4 files changed−670
qml/Components/BaseCarouselDelegate.qml−42 qml/Components/Carousel.qml−335 tests/qmltests/CMakeLists.txt−1 tests/qmltests/Components/tst_Carousel.qml−292
qml/Components/BaseCarouselDelegate.qmldeleted−42
@@ -1,42 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.4
18−import Ubuntu.Components 1.3
19−
20−/*!
21− \brief Base delegate for use with the Carousel component
22−
23− Use this as the base of your component in a Carousel, the properties
24− will get updated and signals emitted accordingly.
25−*/
26−
27−Item {
28− /// True if this item is currently "focused" in the carousel.
29− property bool explicitlyScaled
30−
31− /// Model index for this delegate.
32− property int index
33−
34− /// Model data for this delegate.
35− property var model
36−
37− /// Will be emitted when the item is tapped.
38− signal clicked
39−
40− /// Will be emitted when the item is long-pressed.
41− signal pressAndHold
42−}
qml/Components/Carousel.qmldeleted−335
@@ -1,335 +0,0 @@
1−/*
2− * Copyright (C) 2013-2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.4
18−import Ubuntu.Components 1.3
19−import "carousel.js" as CarouselJS
20−import "."
21−
22−/*! The Carousel component presents the items of a model in a carousel view. It's similar to a
23− cover flow. But it stops at it's boundaries (therefore no PathView is used).
24− */
25−Item {
26− id: carousel
27−
28− clip: true // Don't leak horizontally to other dashes
29−
30− /// The component to be used as delegate. This component has to be derived from BaseCarouselDelegate
31− property Component itemComponent
32− /// Model for the Carousel, which has to be a model usable by a ListView
33− property alias model: listView.model
34− /// A minimal width of a tile can be set here. Per default a best fit will be calculated
35− property alias minimumTileWidth: listView.minimumTileWidth
36− /// Sets the number of tiles that are visible
37− property alias pathItemCount: listView.pathItemCount
38− /// Aspect ratio of the tiles width/height
39− property alias tileAspectRatio: listView.tileAspectRatio
40− /// Used to cache some delegates for performance reasons. See the ListView documentation for details
41− property alias cacheBuffer: listView.cacheBuffer
42− property alias displayMarginBeginning: listView.displayMarginBeginning
43− property alias displayMarginEnd: listView.displayMarginEnd
44− /// Width of the "draw buffer" in pixel. The drawBuffer is an additional area at start/end where
45− /// items drawn, even if it is not in the visible area.
46− /// cacheBuffer controls only the to retain delegates outside the visible area (and is used on top of the drawBuffer)
47− /// see https://bugreports.qt-project.org/browse/QTBUG-29173
48− property int drawBuffer: width / pathItemCount // an "ok" value - but values used from the listView cause loops
49− /// The selected item can be shown in a different size controlled by selectedItemScaleFactor
50− property real selectedItemScaleFactor: 1.1
51− /// The extra margin at the bottom
52− property real extraBottomMargin: 0
53− /// The index of the item that should be highlighted
54− property alias highlightIndex: listView.highlightIndex
55− /// exposes the delegate of the currentItem
56− readonly property alias currentItem: listView.currentItem
57− /// exposes the distance to the next row (only one row in carousel, so it's the topMargins)
58− readonly property alias verticalSpacing: listView.verticalMargin
59− /// the width of the internal list
60− readonly property alias innerWidth: listView.width
61−
62− implicitHeight: listView.tileHeight * selectedItemScaleFactor
63− opacity: listView.highlightIndex === -1 ? 1 : 0.6
64−
65− /* Basic idea behind the carousel effect is to move the items of the delegates (compacting /stuffing them).
66− One drawback is, that more delegates have to be drawn than usually. As some items are moved from the
67− invisible to the visible area. Setting the cacheBuffer does not fix this.
68− See https://bugreports.qt-project.org/browse/QTBUG-29173
69− Therefore the ListView has negative left and right anchors margins, and in addition a header
70− and footer item to compensate that.
71−
72− The scaling of the items is controlled by the variable continuousIndex, described below. */
73− ListView {
74− id: listView
75− objectName: "listView"
76−
77− property int highlightIndex: -1
78− property real minimumTileWidth: 0
79− property real newContentX: disabledNewContentX
80− property real pathItemCount: referenceWidth / referenceTileWidth
81− property real tileAspectRatio: 1
82−
83− /* The positioning and scaling of the items in the carousel is based on the variable
84− 'continuousIndex', a continuous real variable between [0, 'carousel.model.count'],
85− roughly representing the index of the item that is prioritised over the others.
86− 'continuousIndex' is not linear, but is weighted depending on if it is close
87− to the beginning of the content (beginning phase), in the middle (middle phase)
88− or at the end (end phase).
89− Each tile is scaled and transformed in proportion to the difference between
90− its own index and continuousIndex.
91− To efficiently calculate continuousIndex, we have these values:
92− - 'gapToMiddlePhase' gap in pixels between beginning and middle phase
93− - 'gapToEndPhase' gap in pixels between middle and end phase
94− - 'kGapEnd' constant used to calculate 'continuousIndex' in end phase
95− - 'kMiddleIndex' constant used to calculate 'continuousIndex' in middle phase
96− - 'kXBeginningEnd' constant used to calculate 'continuousIndex' in beginning and end phase
97− - 'realContentWidth' the width of all the delegates only (without header/footer)
98− - 'realContentX' the 'contentX' of the listview ignoring the 'drawBuffer'
99− - 'realWidth' the 'width' of the listview, as it is used as component. */
100−
101− readonly property real gapToMiddlePhase: Math.min(realWidth / 2 - tileWidth / 2, (realContentWidth - realWidth) / 2)
102− readonly property real gapToEndPhase: realContentWidth - realWidth - gapToMiddlePhase
103− readonly property real kGapEnd: kMiddleIndex * (1 - gapToEndPhase / gapToMiddlePhase)
104− readonly property real kMiddleIndex: (realWidth / 2) / tileWidth - 0.5
105− readonly property real kXBeginningEnd: 1 / tileWidth + kMiddleIndex / gapToMiddlePhase
106− readonly property real maximumItemTranslation: (listView.tileWidth * 3) / listView.scaleFactor
107− readonly property real disabledNewContentX: -carousel.drawBuffer - 1
108− readonly property real realContentWidth: contentWidth - 2 * carousel.drawBuffer
109− readonly property real realContentX: contentX + carousel.drawBuffer
110− readonly property real realPathItemCount: Math.min(realWidth / tileWidth, pathItemCount)
111− readonly property real realWidth: carousel.width
112− readonly property real referenceGapToMiddlePhase: realWidth / 2 - tileWidth / 2
113− readonly property real referencePathItemCount: referenceWidth / referenceTileWidth
114− readonly property real referenceWidth: 848
115− readonly property real referenceTileWidth: 175
116− readonly property real scaleFactor: tileWidth / referenceTileWidth
117− readonly property real tileWidth: Math.max(realWidth / pathItemCount, minimumTileWidth)
118− readonly property real tileHeight: tileWidth / tileAspectRatio
119− readonly property real translationXViewFactor: 0.2 * (referenceGapToMiddlePhase / gapToMiddlePhase)
120− readonly property real verticalMargin: (parent.height - tileHeight - carousel.extraBottomMargin) / 2
121− readonly property real visibleTilesScaleFactor: realPathItemCount / referencePathItemCount
122−
123− anchors {
124− fill: parent
125− topMargin: verticalMargin
126− bottomMargin: verticalMargin + carousel.extraBottomMargin
127− // extending the "drawing area"
128− leftMargin: -carousel.drawBuffer
129− rightMargin: -carousel.drawBuffer
130− }
131−
132− /* The header and footer help to "extend" the area, the listview draws items.
133− This together with anchors.leftMargin and anchors.rightMargin. */
134− header: Item {
135− width: carousel.drawBuffer
136− height: listView.tileHeight
137− }
138− footer: Item {
139− width: carousel.drawBuffer
140− height: listView.tileHeight
141− }
142−
143− boundsBehavior: Flickable.DragOverBounds
144− cacheBuffer: carousel.cacheBuffer
145− orientation: ListView.Horizontal
146−
147− function getXFromContinuousIndex(index) {
148− return CarouselJS.getXFromContinuousIndex(index,
149− realWidth,
150− footerItem.x,
151− tileWidth,
152− gapToMiddlePhase,
153− gapToEndPhase,
154− carousel.drawBuffer)
155− }
156−
157− function itemClicked(index, delegateItem) {
158− listView.currentIndex = index
159− var x = getXFromContinuousIndex(index);
160−
161− if (Math.abs(x - contentX) < 1 && delegateItem !== undefined) {
162− /* We're clicking the selected item and
163− we're in the neighbourhood of radius 1 pixel from it.
164− Let's emit the clicked signal. */
165− delegateItem.clicked()
166− return
167− }
168−
169− stepAnimation.stop()
170− newContentXAnimation.stop()
171−
172− newContentX = x
173− newContentXAnimation.start()
174− }
175−
176− function itemPressAndHold(index, delegateItem) {
177− var x = getXFromContinuousIndex(index);
178−
179− if (Math.abs(x - contentX) < 1 && delegateItem !== undefined) {
180− /* We're pressAndHold the selected item and
181− we're in the neighbourhood of radius 1 pixel from it.
182− Let's emit the pressAndHold signal. */
183− delegateItem.pressAndHold();
184− return;
185− }
186−
187− stepAnimation.stop();
188− newContentXAnimation.stop();
189−
190− newContentX = x;
191− newContentXAnimation.start();
192− }
193−
194− onHighlightIndexChanged: {
195− if (highlightIndex != -1) {
196− itemClicked(highlightIndex)
197− }
198− }
199−
200− onMovementStarted: {
201− stepAnimation.stop()
202− newContentXAnimation.stop()
203− newContentX = disabledNewContentX
204− }
205− onMovementEnded: {
206− if (realContentX > 0)
207− stepAnimation.start()
208− }
209−
210− SmoothedAnimation {
211− id: stepAnimation
212− objectName: "stepAnimation"
213−
214− target: listView
215− property: "contentX"
216− to: listView.getXFromContinuousIndex(listView.selectedIndex)
217− duration: 450
218− velocity: 200
219− easing.type: Easing.InOutQuad
220− }
221−
222− SequentialAnimation {
223− id: newContentXAnimation
224−
225− NumberAnimation {
226− target: listView
227− property: "contentX"
228− from: listView.contentX
229− to: listView.newContentX
230− duration: 300
231− easing.type: Easing.InOutQuad
232− }
233− ScriptAction {
234− script: listView.newContentX = listView.disabledNewContentX
235− }
236− }
237−
238− readonly property int selectedIndex: Math.round(continuousIndex)
239− readonly property real continuousIndex: CarouselJS.getContinuousIndex(listView.realContentX,
240− listView.tileWidth,
241− listView.gapToMiddlePhase,
242− listView.gapToEndPhase,
243− listView.kGapEnd,
244− listView.kMiddleIndex,
245− listView.kXBeginningEnd)
246−
247− property real viewTranslation: CarouselJS.getViewTranslation(listView.realContentX,
248− listView.tileWidth,
249− listView.gapToMiddlePhase,
250− listView.gapToEndPhase,
251− listView.translationXViewFactor)
252−
253− delegate: tileWidth > 0 && tileHeight > 0 ? loaderComponent : null
254−
255− Component {
256− id: loaderComponent
257−
258− Loader {
259− property bool explicitlyScaled: explicitScaleFactor == carousel.selectedItemScaleFactor
260− property real explicitScaleFactor: explicitScale ? carousel.selectedItemScaleFactor : 1.0
261− readonly property bool explicitScale: (!listView.moving ||
262− listView.realContentX <= 0 ||
263− listView.realContentX >= listView.realContentWidth - listView.realWidth) &&
264− listView.newContentX === listView.disabledNewContentX &&
265− index === listView.selectedIndex
266− readonly property real cachedTiles: listView.realPathItemCount + carousel.drawBuffer / listView.tileWidth
267− readonly property real distance: listView.continuousIndex - index
268− readonly property real itemTranslationScale: CarouselJS.getItemScale(0.5,
269− (index + 0.5), // good approximation of scale while changing selected item
270− listView.count,
271− listView.visibleTilesScaleFactor)
272− readonly property real itemScale: CarouselJS.getItemScale(distance,
273− listView.continuousIndex,
274− listView.count,
275− listView.visibleTilesScaleFactor)
276− readonly property real translationX: CarouselJS.getItemTranslation(index,
277− listView.selectedIndex,
278− distance,
279− itemScale,
280− itemTranslationScale,
281− listView.maximumItemTranslation)
282−
283− readonly property real xTransform: listView.viewTranslation + translationX * listView.scaleFactor
284− readonly property real center: x - listView.contentX + xTransform - drawBuffer + (width/2)
285−
286− width: listView.tileWidth
287− height: listView.tileHeight
288− scale: itemScale * explicitScaleFactor
289− sourceComponent: itemComponent
290− z: cachedTiles - Math.abs(index - listView.selectedIndex)
291−
292− transform: Translate {
293− x: xTransform
294− }
295−
296− Behavior on explicitScaleFactor {
297− SequentialAnimation {
298− ScriptAction {
299− script: if (!explicitScale)
300− explicitlyScaled = false
301− }
302− NumberAnimation {
303− duration: explicitScaleFactor === 1.0 ? 250 : 150
304− easing.type: Easing.InOutQuad
305− }
306− ScriptAction {
307− script: if (explicitScale)
308− explicitlyScaled = true
309− }
310− }
311− }
312−
313− onLoaded: {
314− item.explicitlyScaled = Qt.binding(function() { return explicitlyScaled; });
315− item.index = Qt.binding(function() { return index; });
316− item.model = Qt.binding(function() { return model; });
317− }
318−
319− MouseArea {
320− id: mouseArea
321−
322− anchors.fill: parent
323−
324− onClicked: {
325− listView.itemClicked(index, item)
326− }
327−
328− onPressAndHold: {
329− listView.itemPressAndHold(index, item)
330− }
331− }
332− }
333− }
334− }
335−}
tests/qmltests/CMakeLists.txt−1
@@ -11,7 +11,6 @@ add_unity8_qmltest_data(. ApplicationMenuDataLoader)
1111add_unity8_qmltest(ApplicationMenus MenuBar)
1212add_unity8_qmltest(ApplicationMenus MenuPopup)
1313add_unity8_qmltest(Components Background)
14−add_unity8_qmltest(Components Carousel)
1514add_unity8_qmltest(Components Dialogs)
1615add_unity8_qmltest(Components DraggingArea)
1716add_unity8_qmltest(Components LazyImage)
tests/qmltests/Components/tst_Carousel.qmldeleted−292
@@ -1,292 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.4
18−import QtTest 1.0
19−import "../../../qml/Components/"
20−import "../../../qml/Components/carousel.js" as Carousel
21−import Unity.Test 0.1 as UT
22−
23−Item {
24− width: 700
25− height: 400
26−
27− Carousel {
28− anchors.fill: parent
29− id: carousel
30−
31− property int createdDelegates: 0
32− property int destroyedDelegates: 0
33−
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++
43− }
44− }
45− }
46−
47− SignalSpy {
48− id: spy
49− }
50−
51− UT.UnityTestCase {
52− id: root
53− name: "Carousel"
54− when: windowShown
55−
56− property real carouselWidth
57− property int itemCount
58− property real tileWidth
59−
60− property Item listView: findChild(carousel, "listView")
61−
62− property real contentWidth: itemCount * tileWidth
63− // following variables are copied from Carousel.qml
64− // I'm not using the variables directly from there, as then tileWidth and others would be affected as well
65− property real gapToMiddlePhase: Math.min(carouselWidth / 2 - tileWidth / 2, (contentWidth - carouselWidth) / 2)
66− property real gapToEndPhase: contentWidth - carouselWidth - gapToMiddlePhase
67− property real kMiddleIndex: (carouselWidth / 2) / tileWidth - 0.5
68− property real kGapEnd: kMiddleIndex * (1 - gapToEndPhase / gapToMiddlePhase)
69− property real kXBeginningEnd: 1 / tileWidth + kMiddleIndex / gapToMiddlePhase
70−
71− function init() {
72− carousel.model = 40;
73− waitForRendering(carousel)
74− listView.positionViewAtBeginning();
75− }
76−
77− function cleanup() {
78− carousel.model = 0;
79− carousel.createdDelegates = 0;
80− carousel.destroyedDelegates = 0;
81− spy.target = null;
82− spy.signalName = "";
83− }
84−
85− // This test needs to run first since it tests a corner case condition
86− // to where the carousel is just being created
87− // That is why it has a 1 in the name
88− function test_1onlyNeededItemsCreated() {
89− tryCompare(carousel, "createdDelegates", 9);
90− compare(carousel.destroyedDelegates, 0);
91− }
92−
93− // test for the getContinuousIndex() function
94− function test_getContinuousIndex_data() {
95− // testing for 10 items of size 100 pixel
96− return [ {tag:"at start",
97− x: 0, carouselWidth:400, tileWidth:100, itemCount:10, result: 0},
98− {tag:"in startup",
99− x: 100, carouselWidth:400, tileWidth:100, itemCount:10, result: 2},
100− {tag:"in the middle",
101− x: 350, carouselWidth:400, tileWidth:100, itemCount:10, result: 5},
102− {tag:"at end",
103− x: 600, carouselWidth:400, tileWidth:100, itemCount:10, result: 9},
104− ]
105− }
106−
107− function test_getContinuousIndex(data) {
108− root.carouselWidth = data.carouselWidth
109− root.tileWidth = data.tileWidth
110− root.itemCount = data.itemCount
111−
112− var index = Carousel.getContinuousIndex(data.x,
113− data.tileWidth,
114− gapToMiddlePhase,
115− gapToEndPhase,
116− kGapEnd,
117− kMiddleIndex,
118− kXBeginningEnd)
119− compare(index, data.result)
120− }
121−
122− // test for the getXFromContinuousIndex() function
123− function test_getXFromContinuousIndex_data() {
124− return [ {tag:"at start",
125− index: 0, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 0},
126− {tag:"in startup",
127− index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 100},
128− {tag:"in startup with drawBuffer",
129− index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 0},
130− {tag:"in the middle",
131− index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 350},
132− {tag:"in the middle with drawBuffer",
133− index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 250},
134− {tag:"at end",
135− index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 600},
136− {tag:"at end with drawBuffer",
137− index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 500},
138− ]
139− }
140−
141− function test_getXFromContinuousIndex(data) {
142− root.carouselWidth = data.carouselWidth
143− root.tileWidth = data.tileWidth
144− root.itemCount = data.itemCount
145−
146− var x = Carousel.getXFromContinuousIndex(data.index,
147− data.carouselWidth,
148− contentWidth,
149− data.tileWidth,
150− gapToMiddlePhase,
151− gapToEndPhase,
152− data.drawBuffer)
153− compare(x, data.result)
154− }
155−
156− // test for the getViewTranslation() function
157− function test_getViewTranslation_data() {
158− return [ {tag:"at start - viewfactor 1",
159− x: 0, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 150},
160− {tag:"at start - viewfactor 2",
161− x: 0, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:2, result: 300},
162− {tag:"in startup",
163− x: 100, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 50},
164− {tag:"in the middle",
165− x: 350, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 0},
166− {tag:"at end",
167− x: 600, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: -150},
168− ]
169− }
170−
171− function test_getViewTranslation(data) {
172− root.carouselWidth = data.carouselWidth
173− root.tileWidth = data.tileWidth
174− root.itemCount = data.itemCount
175−
176− var x = Carousel.getViewTranslation(data.x,
177− data.tileWidth,
178− root.gapToMiddlePhase,
179− root.gapToEndPhase,
180− data.translationXViewFactor)
181− compare(x, data.result)
182− }
183−
184− // test for the getItemScale() function
185− function test_getItemScale_data() {
186− return [ // tests for distance
187− {distance: 0, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 1},
188− {distance: 9, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
189− {distance: 999, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
190− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
191− {distance: 3, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.688230855}, // = 1 - (3^2.5 / 50)
192− // tests for continuousIndex
193− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
194− {distance: 1, continuousIndex: 97, numberOfItems: 100, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
195− // tests for numberOfItems
196− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
197− {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
198− // tests for scaleFactor
199− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
200− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 2, result: 0.99}, // = 1 - (1 / 100)
201− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 0.5, result: 0.96}, // = 1 - (1 / 25)
202− {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
203− {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 2, result: 0.996666666}, // = 1 - (1 / 300) - distanceToBounds is used
204− ]
205− }
206−
207− function test_getItemScale(data) {
208− var scale = Carousel.getItemScale(data.distance,
209− data.continuousIndex,
210− data.numberOfItems,
211− data.scaleFactor)
212− compare(scale, data.result)
213− }
214−
215− // test for the getItemTranslation() function
216− function test_getItemTranslation_data() {
217− return [ // tests for index and selectedIndex
218− {index: 1, selectedIndex: 1, distance: 1, scale: 1, maxScale: 1, maxTranslation: 10, result: 0},
219− // tests if distance only affects the sign
220− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
221− {index: 1, selectedIndex: 2, distance: 99, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
222− {index: 1, selectedIndex: 2, distance: -1, scale: 0, maxScale: 1, maxTranslation: 10, result: -10},
223− {index: 1, selectedIndex: 2, distance: -99, scale: 0, maxScale: 1, maxTranslation: 10, result: -10},
224− // tests for the scale
225− {index: 1, selectedIndex: 2, distance: 1, scale: 1, maxScale: 1, maxTranslation: 10, result: 0},
226− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
227− {index: 1, selectedIndex: 2, distance: 1, scale: 0.5, maxScale: 1, maxTranslation: 10, result: 5},
228− // tests for maxScale
229− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 0.98, maxTranslation: 10, result: 9.8},
230− {index: 1, selectedIndex: 2, distance: 1, scale: 0.5, maxScale: 0.95, maxTranslation: 10, result: 4.5},
231− {index: 1, selectedIndex: 2, distance: 1, scale: 0.8, maxScale: 0.93, maxTranslation: 10, result: 1.3},
232− // test for maxTranslation
233− {index: 1, selectedIndex: 2, distance: 1, scale: 1, maxScale: 1, maxTranslation: 1, result: 0},
234− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 1, result: 1},
235− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
236− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 0, result: 0},
237− ]
238− }
239−
240− function test_getItemTranslation(data) {
241− var scale = Carousel.getItemTranslation(data.index,
242− data.selectedIndex,
243− data.distance,
244− data.scale,
245− data.maxScale,
246− data.maxTranslation)
247− compare(scale, data.result)
248− }
249−
250− function test_lastItemXPosition() {
251− var carouselList = findChild(carousel, "listView");
252− var stepAnimation = findInvisibleChild(carouselList, "stepAnimation");
253− var stepDiff = 0;
254− stepAnimation.onRunningChanged.connect(function() { if (stepAnimation.running) stepDiff = Math.abs(carouselList.contentX - stepAnimation.to); })
255− var overshootOnce = false;
256− while (!overshootOnce) {
257− overshootOnce = carouselList.realContentX > carouselList.realContentWidth - carouselList.realWidth;
258− mouseFlick(carousel, carousel.width - units.gu(1),
259− carousel.height / 2,
260− units.gu(2),
261− carousel.height / 2);
262− tryCompare(carouselList, "moving", false);
263− }
264− verify(stepDiff < 1);
265− var x = carouselList.getXFromContinuousIndex(carousel.model - 1);
266− verify(Math.abs(x - carouselList.contentX) < 1);
267− }
268−
269− function test_activate() {
270− var carouselList = findChild(carousel, "listView");
271− var carouselItem = findChild(carousel, "carouselDelegate3")
272− verify(carouselItem, "Could not find delegate");
273−
274− spy.signalName = "clicked";
275− spy.target = carouselItem;
276− mouseClick(carouselItem);
277− tryCompare(carouselList, "moving", false);
278− tryCompare(carouselItem, "explicitlyScaled", true);
279− mouseClick(carouselItem);
280− spy.wait();
281−
282− spy.signalName = "pressAndHold";
283− spy.target = carouselItem;
284− mouseClick(carouselItem);
285− tryCompare(carouselList, "moving", false);
286− tryCompare(carouselItem, "explicitlyScaled", true);
287− mousePress(carouselItem);
288− spy.wait();
289− mouseRelease(carouselItem);
290− }
291− }
292−}