on xenial help sign in
Add preview image slideshow Fixes: 1351537

Approved by: Albert Astals Cid

commitdb0f253dcc49bc8b60ee782875b1017cdf94b82b authorAndrea Cimitan <andrea.cimitan@gmail.com> dateMon 6 Oct 2014, 08:01 (12 years ago) parent82a82b47dd4d4b
3 files changed+173−19
qml/Components/LazyImage.qml+1 qml/Dash/Previews/PreviewImageGallery.qml+121−18 tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+51−1
qml/Components/LazyImage.qml+1
@@ -37,6 +37,7 @@ Item {
3737 property alias horizontalAlignment: image.horizontalAlignment
3838 property alias verticalAlignment: image.verticalAlignment
3939 property alias sourceImage: image
40+ property alias borderSource: shape.borderSource
4041
4142 state: "default"
4243
qml/Dash/Previews/PreviewImageGallery.qml+121−18
@@ -26,8 +26,11 @@ PreviewWidget {
2626 id: root
2727 implicitHeight: units.gu(22)
2828
29+ property Item rootItem: QuickUtils.rootItem(root)
30+
2931 ListView {
3032 id: previewImageListView
33+ objectName: "previewImageListView"
3134 spacing: units.gu(1)
3235 anchors.fill: parent
3336 orientation: ListView.Horizontal
@@ -35,24 +38,6 @@ PreviewWidget {
3538 model: root.widgetData["sources"]
3639 clip: true
3740
38− // FIXME: Because of ListViews inside ListViews inside Flickables inside ListViews (and some more)
39− // we finally reached the point where this ListView doesn't correctly get swipe input any more but
40− // instead the parent ListView is the one that is swiped. This MouseArea sort of creates a blocking
41− // layer to make sure this ListView can be swiped, regardless of what's behind it.
42− MouseArea {
43− anchors.fill: parent
44− enabled: parent.contentWidth > parent.width
45− }
46−
47− // FIXME: Because of ListViews inside ListViews inside Flickables inside ListViews (and some more)
48− // we finally reached the point where this ListView doesn't correctly get swipe input any more but
49− // instead the parent ListView is the one that is swiped. This MouseArea sort of creates a blocking
50− // layer to make sure this ListView can be swiped, regardless of what's behind it.
51− MouseArea {
52− anchors.fill: parent
53− enabled: parent.contentWidth > parent.width
54− }
55−
5641 LazyImage {
5742 objectName: "placeholderScreenshot"
5843 anchors {
@@ -66,6 +51,7 @@ PreviewWidget {
6651 }
6752
6853 delegate: LazyImage {
54+ objectName: "previewImage" + index
6955 anchors {
7056 top: parent.top
7157 bottom: parent.bottom
@@ -73,6 +59,123 @@ PreviewWidget {
7359 source: modelData ? modelData : ""
7460 scaleTo: "height"
7561 initialWidth: units.gu(13)
62+ borderSource: mouseArea.pressed ? "radius_pressed.sci" : "radius_idle.sci"
63+
64+ MouseArea {
65+ id: mouseArea
66+ anchors.fill: parent
67+ onClicked: {
68+ slideShowListView.currentIndex = index;
69+ slideShow.initialX = rootItem.mapFromItem(parent, 0, 0).x
70+ slideShow.initialY = rootItem.mapFromItem(parent, 0, 0).y
71+ slideShow.visible = true;
72+ }
73+ }
74+ }
75+ }
76+
77+ Rectangle {
78+ id: slideShow
79+ objectName: "slideShow"
80+
81+ readonly property real initialScale: previewImageListView.height / rootItem.height
82+ readonly property real scaleProgress: (scale - initialScale) / (1.0 - initialScale)
83+ property real initialX: 0
84+ property real initialY: 0
85+
86+ parent: rootItem
87+ width: parent.width
88+ height: parent.height
89+ visible: false
90+ clip: visible && scale < 1.0
91+ scale: visible ? 1.0 : initialScale
92+ transformOrigin: Item.TopLeft
93+ transform: Translate {
94+ x: slideShow.initialX - slideShow.initialX * slideShow.scaleProgress
95+ y: slideShow.initialY - slideShow.initialY * slideShow.scaleProgress
96+ }
97+ color: "black"
98+ radius: units.gu(1) - units.gu(1) * slideShow.scaleProgress
99+
100+ Behavior on scale {
101+ enabled: !slideShow.visible
102+ UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration }
103+ }
104+
105+ ListView {
106+ id: slideShowListView
107+ objectName: "slideShowListView"
108+ anchors.fill: parent
109+ orientation: ListView.Horizontal
110+ highlightRangeMode: ListView.StrictlyEnforceRange
111+ highlightMoveDuration: 0
112+ snapMode: ListView.SnapOneItem
113+ boundsBehavior: Flickable.DragAndOvershootBounds
114+ model: root.widgetData["sources"]
115+
116+ delegate: Image {
117+ id: screenshot
118+ anchors {
119+ top: parent.top
120+ bottom: parent.bottom
121+ }
122+ width: slideShow.width
123+ source: modelData ? modelData : ""
124+ fillMode: Image.PreserveAspectFit
125+ sourceSize { width: screenshot.width; height: screenshot.height }
126+ }
127+
128+ MouseArea {
129+ anchors.fill: parent
130+ onClicked: slideShowHeader.shown = !slideShowHeader.shown
131+ }
132+ }
133+
134+ Rectangle {
135+ id: slideShowHeader
136+
137+ property bool shown: true
138+
139+ anchors {
140+ left: parent.left
141+ right: parent.right
142+ }
143+ height: units.gu(7)
144+ visible: opacity > 0
145+ opacity: slideShow.scaleProgress > 0.6 && shown ? 0.8 : 0
146+ color: "black"
147+
148+ Behavior on opacity {
149+ UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration }
150+ }
151+
152+ AbstractButton {
153+ id: slideShowCloseButton
154+ objectName: "slideShowCloseButton"
155+ anchors {
156+ top: parent.top
157+ bottom: parent.bottom
158+ }
159+ width: units.gu(8)
160+ height: width
161+
162+ onClicked: slideShow.visible = false
163+
164+ Rectangle {
165+ anchors.fill: parent
166+ color: Qt.rgba(1.0, 1.0, 1.0, 0.3)
167+ visible: slideShowCloseButton.pressed
168+ }
169+
170+ Icon {
171+ id: icon
172+ anchors.centerIn: parent
173+ width: units.gu(2.5)
174+ height: width
175+ color: Theme.palette.normal.foregroundText
176+ name: "close"
177+ }
178+ }
76179 }
77180 }
78181}
tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+51−1
@@ -21,7 +21,7 @@ import Unity.Test 0.1 as UT
2121
2222Rectangle {
2323 id: root
24− width: units.gu(60)
24+ width: units.gu(80)
2525 height: units.gu(80)
2626 color: "lightgrey"
2727
@@ -44,13 +44,63 @@ Rectangle {
4444 }
4545
4646 UT.UnityTestCase {
47+ id: testCase
4748 name: "PreviewImageGalleryTest"
4849 when: windowShown
4950
51+ property Item slideShow: findChild(imageGallery.rootItem, "slideShow")
52+ property Item slideShowCloseButton: findChild(slideShow, "slideShowCloseButton")
53+ property Item slideShowListView: findChild(slideShow, "slideShowListView")
54+
55+ function cleanup() {
56+ slideShow.visible = false;
57+ imageGallery.widgetData = sourcesModel1;
58+ waitForRendering(imageGallery);
59+ }
60+
5061 function test_changeEmptyModel() {
5162 imageGallery.widgetData = sourcesModel0;
5263 var placeholderScreenshot = findChild(imageGallery, "placeholderScreenshot");
5364 compare(placeholderScreenshot.visible, true);
5465 }
66+
67+ function test_slideShowOpenClose() {
68+ var image0 = findChild(imageGallery, "previewImage0");
69+ mouseClick(image0, image0.width / 2, image0.height / 2);
70+ tryCompare(slideShow, "visible", true);
71+ tryCompare(slideShow, "scale", 1.0);
72+ tryCompare(slideShowCloseButton, "visible", true);
73+ mouseClick(slideShowCloseButton, slideShowCloseButton.width / 2, slideShowCloseButton.height / 2);
74+ tryCompare(slideShow, "visible", false);
75+ }
76+
77+ function test_slideShowShowHideHeader() {
78+ var image0 = findChild(imageGallery, "previewImage0");
79+ mouseClick(image0, image0.width / 2, image0.height / 2);
80+ tryCompare(slideShow, "visible", true);
81+ tryCompare(slideShow, "scale", 1.0);
82+ tryCompare(slideShowCloseButton, "visible", true);
83+ mouseClick(slideShow, slideShow.width / 2, slideShow.height / 2);
84+ tryCompare(slideShowCloseButton, "visible", false);
85+ mouseClick(slideShow, slideShow.width / 2, slideShow.height / 2);
86+ tryCompare(slideShowCloseButton, "visible", true);
87+ }
88+
89+ function test_slideShowOpenCorrectImage_data() {
90+ return [
91+ { tag: "Image 0", index: 0 },
92+ { tag: "Image 1", index: 1 },
93+ { tag: "Image 2", index: 2 },
94+ ];
95+ }
96+
97+ function test_slideShowOpenCorrectImage(data) {
98+ var image = findChild(imageGallery, "previewImage" + data.index);
99+ mouseClick(image, image.width / 2, image.height / 2);
100+ tryCompare(slideShow, "visible", true);
101+ tryCompare(slideShow, "scale", 1.0);
102+ tryCompare(slideShowListView, "currentIndex", data.index);
103+ verify(image.source === slideShowListView.currentItem.source);
104+ }
55105 }
56106}