on xenial help sign in
Move files a bit, to share code
3d06ffcAndrea Cimitan
qml/Dash/Previews/PreviewImageGallery.qml+13−94
@@ -66,60 +66,26 @@ PreviewWidget {
66 id: mouseArea
66 id: mouseArea
67 anchors.fill: parent
67 anchors.fill: parent
68 onClicked: {
68 onClicked: {
69− slideShowListView.currentIndex = index;
69+ overlay.delegateItem.currentIndex = index;
70− slideShow.initialX = rootItem.mapFromItem(parent, 0, 0).x;
70+ overlay.initialX = rootItem.mapFromItem(parent, 0, 0).x;
71− slideShow.initialY = rootItem.mapFromItem(parent, 0, 0).y;
71+ overlay.initialY = rootItem.mapFromItem(parent, 0, 0).y;
72− slideShow.open();
72+ overlay.show();
73 }
73 }
74 }
74 }
75 }
75 }
76 }
76 }
77
77
78− Rectangle {
78+ PreviewOverlay {
79− id: slideShow
79+ id: overlay
80− objectName: "slideShow"
80+ objectName: "overlay"
81−
82− readonly property real initialScale: previewImageListView.height / rootItem.height
83− readonly property real scaleProgress: (scale - initialScale) / (1.0 - initialScale)
84− property real initialX: 0
85− property real initialY: 0
86− property bool opened: false
87− property bool opening: false
88−
89 parent: rootItem
81 parent: rootItem
90 width: parent.width
82 width: parent.width
91 height: parent.height
83 height: parent.height
92− visible: scale > initialScale
84+ initialScale: previewImageListView.height / rootItem.height
93− clip: visible && scale < 1.0
94− scale: opened ? 1.0 : initialScale
95− transformOrigin: Item.TopLeft
96− transform: Translate {
97− x: slideShow.initialX - slideShow.initialX * slideShow.scaleProgress
98− y: slideShow.initialY - slideShow.initialY * slideShow.scaleProgress
99− }
100− color: Qt.rgba(0, 0, 0, scaleProgress)
101− radius: units.gu(1) - units.gu(1) * scaleProgress
102−
103− function open() {
104− opening = true;
105− opened = true;
106− }
107−
108− function close() {
109− opening = false;
110− opened = false;
111− }
112
85
113− Behavior on scale {
114− UbuntuNumberAnimation {
115− duration: slideShow.opening ? UbuntuAnimation.FastDuration :
116− UbuntuAnimation.FastDuration / 2
117− }
118− }
119−
120− Flickables.ListView {
86+ delegate: Flickables.ListView {
121− id: slideShowListView
87+ id: overlayListView
122− objectName: "slideShowListView"
88+ objectName: "overlayListView"
123 anchors.fill: parent
89 anchors.fill: parent
124 orientation: ListView.Horizontal
90 orientation: ListView.Horizontal
125 highlightRangeMode: ListView.StrictlyEnforceRange
91 highlightRangeMode: ListView.StrictlyEnforceRange
@@ -134,7 +100,7 @@ PreviewWidget {
134 top: parent.top
100 top: parent.top
135 bottom: parent.bottom
101 bottom: parent.bottom
136 }
102 }
137− width: slideShow.width
103+ width: overlay.width
138 source: modelData ? modelData : ""
104 source: modelData ? modelData : ""
139 fillMode: Image.PreserveAspectFit
105 fillMode: Image.PreserveAspectFit
140 sourceSize { width: screenshot.width; height: screenshot.height }
106 sourceSize { width: screenshot.width; height: screenshot.height }
@@ -142,54 +108,7 @@ PreviewWidget {
142
108
143 MouseArea {
109 MouseArea {
144 anchors.fill: parent
110 anchors.fill: parent
145− onClicked: slideShowHeader.shown = !slideShowHeader.shown
111+ onClicked: overlay.headerShown = !overlay.headerShown
146− }
147− }
148−
149− Rectangle {
150− id: slideShowHeader
151−
152− property bool shown: true
153−
154− anchors {
155− left: parent.left
156− right: parent.right
157− }
158− height: units.gu(7)
159− visible: opacity > 0
160− opacity: slideShow.scaleProgress > 0.6 && shown ? 0.8 : 0
161− color: "black"
162−
163− Behavior on opacity {
164− UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration }
165− }
166−
167− AbstractButton {
168− id: slideShowCloseButton
169− objectName: "slideShowCloseButton"
170− anchors {
171− top: parent.top
172− bottom: parent.bottom
173− }
174− width: units.gu(8)
175− height: width
176−
177− onClicked: slideShow.close()
178−
179− Rectangle {
180− anchors.fill: parent
181− color: Qt.rgba(1.0, 1.0, 1.0, 0.3)
182− visible: slideShowCloseButton.pressed
183− }
184−
185− Icon {
186− id: icon
187− anchors.centerIn: parent
188− width: units.gu(2.5)
189− height: width
190− color: Theme.palette.normal.foregroundText
191− name: "close"
192− }
193 }
112 }
194 }
113 }
195 }
114 }
qml/Dash/Previews/PreviewZoomableImage.qml+8−88
@@ -47,105 +47,25 @@ PreviewWidget {
47 id: mouseArea
47 id: mouseArea
48 anchors.fill: parent
48 anchors.fill: parent
49 onClicked: {
49 onClicked: {
50− zoomableImageContainer.initialX = rootItem.mapFromItem(parent, 0, 0).x;
50+ overlay.initialX = rootItem.mapFromItem(parent, 0, 0).x;
51− zoomableImageContainer.initialY = rootItem.mapFromItem(parent, 0, 0).y;
51+ overlay.initialY = rootItem.mapFromItem(parent, 0, 0).y;
52− zoomableImageContainer.open();
52+ overlay.show();
53 }
53 }
54 }
54 }
55 }
55 }
56
56
57− Rectangle {
57+ PreviewOverlay {
58− id: zoomableImageContainer
58+ id: overlay
59− objectName: "zoomableImageContainer"
59+ objectName: "overlay"
60−
61− readonly property real initialScale: lazyImage.height / rootItem.height
62− readonly property real scaleProgress: (scale - initialScale) / (1.0 - initialScale)
63− property real initialX: 0
64− property real initialY: 0
65− property bool opened: false
66− property bool opening: false
67−
68 parent: rootItem
60 parent: rootItem
69 width: parent.width
61 width: parent.width
70 height: parent.height
62 height: parent.height
71− visible: scale > initialScale
63+ initialScale: lazyImage.height / rootItem.height
72− clip: visible && scale < 1.0
73− scale: opened ? 1.0 : initialScale
74− transformOrigin: Item.TopLeft
75− transform: Translate {
76− x: zoomableImageContainer.initialX - zoomableImageContainer.initialX * zoomableImageContainer.scaleProgress
77− y: zoomableImageContainer.initialY - zoomableImageContainer.initialY * zoomableImageContainer.scaleProgress
78− }
79− color: Qt.rgba(0, 0, 0, scaleProgress)
80− radius: units.gu(1) - units.gu(1) * scaleProgress
81
64
82− function open() {
83− opening = true;
84− opened = true;
85− }
86−
87− function close() {
88− opening = false;
89− opened = false;
90− }
91−
92− Behavior on scale {
93− UbuntuNumberAnimation {
94− duration: zoomableImageContainer.opening ? UbuntuAnimation.FastDuration :
95− UbuntuAnimation.FastDuration / 2
96− }
97− }
98−
99− ZoomableImage {
65+ delegate: ZoomableImage {
100− id: screenshot
101 anchors.fill: parent
66 anchors.fill: parent
102 source: widgetData["source"]
67 source: widgetData["source"]
103 zoomable: widgetData["zoomable"] ? widgetData["zoomable"] : false
68 zoomable: widgetData["zoomable"] ? widgetData["zoomable"] : false
104 }
69 }
105−
106− Rectangle {
107− id: zoomableImageHeader
108−
109− anchors {
110− left: parent.left
111− right: parent.right
112− }
113− height: units.gu(7)
114− visible: opacity > 0
115− opacity: zoomableImageContainer.scaleProgress > 0.6 ? 0.8 : 0
116− color: "black"
117−
118− Behavior on opacity {
119− UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration }
120− }
121−
122− AbstractButton {
123− id: zoomableImageCloseButton
124− objectName: "zoomableImageCloseButton"
125− anchors {
126− top: parent.top
127− bottom: parent.bottom
128− }
129− width: units.gu(8)
130− height: width
131−
132− onClicked: zoomableImageContainer.close()
133−
134− Rectangle {
135− anchors.fill: parent
136− color: Qt.rgba(1.0, 1.0, 1.0, 0.3)
137− visible: zoomableImageCloseButton.pressed
138− }
139−
140− Icon {
141− id: icon
142− anchors.centerIn: parent
143− width: units.gu(2.5)
144− height: width
145− color: Theme.palette.normal.foregroundText
146− name: "close"
147− }
148− }
149− }
150 }
70 }
151}
71}
tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+25−25
@@ -48,13 +48,13 @@ Rectangle {
48 name: "PreviewImageGalleryTest"
48 name: "PreviewImageGalleryTest"
49 when: windowShown
49 when: windowShown
50
50
51− property Item slideShow: findChild(imageGallery.rootItem, "slideShow")
51+ property Item overlay: findChild(imageGallery.rootItem, "overlay")
52− property Item slideShowCloseButton: findChild(slideShow, "slideShowCloseButton")
52+ property Item overlayCloseButton: findChild(overlay, "overlayCloseButton")
53− property Item slideShowListView: findChild(slideShow, "slideShowListView")
53+ property Item overlayListView: findChild(overlay, "overlayListView")
54
54
55 function cleanup() {
55 function cleanup() {
56− slideShow.close();
56+ overlay.hide();
57− tryCompare(slideShow, "visible", false);
57+ tryCompare(overlay, "visible", false);
58 imageGallery.widgetData = sourcesModel1;
58 imageGallery.widgetData = sourcesModel1;
59 waitForRendering(imageGallery);
59 waitForRendering(imageGallery);
60 }
60 }
@@ -65,29 +65,29 @@ Rectangle {
65 compare(placeholderScreenshot.visible, true);
65 compare(placeholderScreenshot.visible, true);
66 }
66 }
67
67
68− function test_slideShowOpenClose() {
68+ function test_overlayOpenClose() {
69 var image0 = findChild(imageGallery, "previewImage0");
69 var image0 = findChild(imageGallery, "previewImage0");
70 mouseClick(image0, image0.width / 2, image0.height / 2);
70 mouseClick(image0, image0.width / 2, image0.height / 2);
71− tryCompare(slideShow, "visible", true);
71+ tryCompare(overlay, "visible", true);
72− tryCompare(slideShow, "scale", 1.0);
72+ tryCompare(overlay, "scale", 1.0);
73− tryCompare(slideShowCloseButton, "visible", true);
73+ tryCompare(overlayCloseButton, "visible", true);
74− mouseClick(slideShowCloseButton, slideShowCloseButton.width / 2, slideShowCloseButton.height / 2);
74+ mouseClick(overlayCloseButton, overlayCloseButton.width / 2, overlayCloseButton.height / 2);
75− tryCompare(slideShow, "visible", false);
75+ tryCompare(overlay, "visible", false);
76 }
76 }
77
77
78− function test_slideShowShowHideHeader() {
78+ function test_overlayShowHideHeader() {
79 var image0 = findChild(imageGallery, "previewImage0");
79 var image0 = findChild(imageGallery, "previewImage0");
80 mouseClick(image0, image0.width / 2, image0.height / 2);
80 mouseClick(image0, image0.width / 2, image0.height / 2);
81− tryCompare(slideShow, "visible", true);
81+ tryCompare(overlay, "visible", true);
82− tryCompare(slideShow, "scale", 1.0);
82+ tryCompare(overlay, "scale", 1.0);
83− tryCompare(slideShowCloseButton, "visible", true);
83+ tryCompare(overlayCloseButton, "visible", true);
84− mouseClick(slideShow, slideShow.width / 2, slideShow.height / 2);
84+ mouseClick(overlay, overlay.width / 2, overlay.height / 2);
85− tryCompare(slideShowCloseButton, "visible", false);
85+ tryCompare(overlayCloseButton, "visible", false);
86− mouseClick(slideShow, slideShow.width / 2, slideShow.height / 2);
86+ mouseClick(overlay, overlay.width / 2, overlay.height / 2);
87− tryCompare(slideShowCloseButton, "visible", true);
87+ tryCompare(overlayCloseButton, "visible", true);
88 }
88 }
89
89
90− function test_slideShowOpenCorrectImage_data() {
90+ function test_overlayOpenCorrectImage_data() {
91 return [
91 return [
92 { tag: "Image 0", index: 0 },
92 { tag: "Image 0", index: 0 },
93 { tag: "Image 1", index: 1 },
93 { tag: "Image 1", index: 1 },
@@ -95,13 +95,13 @@ Rectangle {
95 ];
95 ];
96 }
96 }
97
97
98− function test_slideShowOpenCorrectImage(data) {
98+ function test_overlayOpenCorrectImage(data) {
99 var image = findChild(imageGallery, "previewImage" + data.index);
99 var image = findChild(imageGallery, "previewImage" + data.index);
100 mouseClick(image, image.width / 2, image.height / 2);
100 mouseClick(image, image.width / 2, image.height / 2);
101− tryCompare(slideShow, "visible", true);
101+ tryCompare(overlay, "visible", true);
102− tryCompare(slideShow, "scale", 1.0);
102+ tryCompare(overlay, "scale", 1.0);
103− tryCompare(slideShowListView, "currentIndex", data.index);
103+ tryCompare(overlayListView, "currentIndex", data.index);
104− verify(image.source === slideShowListView.currentItem.source);
104+ verify(image.source === overlayListView.currentItem.source);
105 }
105 }
106 }
106 }
107}
107}
tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+10−10
@@ -45,16 +45,16 @@ Rectangle {
45 when: windowShown
45 when: windowShown
46
46
47 property Item lazyImage: findChild(zoomableImage, "lazyImage");
47 property Item lazyImage: findChild(zoomableImage, "lazyImage");
48− property Item zoomableImageContainer: findChild(zoomableImage.rootItem, "zoomableImageContainer");
48+ property Item overlay: findChild(zoomableImage.rootItem, "overlay");
49
49
50 function init() {
50 function init() {
51 waitForRendering(zoomableImage);
51 waitForRendering(zoomableImage);
52− waitForRendering(zoomableImageContainer);
52+ waitForRendering(overlay);
53 }
53 }
54
54
55 function cleanup() {
55 function cleanup() {
56− zoomableImageContainer.close();
56+ overlay.hide();
57− tryCompare(zoomableImageContainer, "visible", false);
57+ tryCompare(overlay, "visible", false);
58 zoomableImage.widgetData = widgetData0;
58 zoomableImage.widgetData = widgetData0;
59 }
59 }
60
60
@@ -71,13 +71,13 @@ Rectangle {
71 }
71 }
72
72
73 function test_zoomableImageOpenClose() {
73 function test_zoomableImageOpenClose() {
74− var zoomableImageCloseButton = findChild(zoomableImageContainer, "zoomableImageCloseButton");
74+ var overlayCloseButton = findChild(overlay, "overlayCloseButton");
75 mouseClick(lazyImage, lazyImage.width / 2, lazyImage.height / 2);
75 mouseClick(lazyImage, lazyImage.width / 2, lazyImage.height / 2);
76− tryCompare(zoomableImageContainer, "visible", true);
76+ tryCompare(overlay, "visible", true);
77− tryCompare(zoomableImageContainer, "scale", 1.0);
77+ tryCompare(overlay, "scale", 1.0);
78− tryCompare(zoomableImageCloseButton, "visible", true);
78+ tryCompare(overlayCloseButton, "visible", true);
79− mouseClick(zoomableImageCloseButton, zoomableImageCloseButton.width / 2, zoomableImageCloseButton.height / 2);
79+ mouseClick(overlayCloseButton, overlayCloseButton.width / 2, overlayCloseButton.height / 2);
80− tryCompare(zoomableImageContainer, "visible", false);
80+ tryCompare(overlay, "visible", false);
81 }
81 }
82 }
82 }
83}
83}