on xenial help sign in
Update animations on open/close
commite6c8496edc0575ae699b98c429299b84821eeb64 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateWed 22 Oct 2014, 16:08 (12 years ago) parent3188f32
4 files changed+48−18
qml/Dash/Previews/PreviewImageGallery.qml+22−8 qml/Dash/Previews/PreviewZoomableImage.qml+22−8 tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+2−1 tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+2−1
qml/Dash/Previews/PreviewImageGallery.qml+22−8
@@ -67,9 +67,9 @@ PreviewWidget {
6767 anchors.fill: parent
6868 onClicked: {
6969 slideShowListView.currentIndex = index;
70− slideShow.initialX = rootItem.mapFromItem(parent, 0, 0).x
71− slideShow.initialY = rootItem.mapFromItem(parent, 0, 0).y
72− slideShow.visible = true;
70+ slideShow.initialX = rootItem.mapFromItem(parent, 0, 0).x;
71+ slideShow.initialY = rootItem.mapFromItem(parent, 0, 0).y;
72+ slideShow.open();
7373 }
7474 }
7575 }
@@ -83,13 +83,15 @@ PreviewWidget {
8383 readonly property real scaleProgress: (scale - initialScale) / (1.0 - initialScale)
8484 property real initialX: 0
8585 property real initialY: 0
86+ property bool opened: false
87+ property bool opening: false
8688
8789 parent: rootItem
8890 width: parent.width
8991 height: parent.height
90− visible: false
92+ visible: scale > initialScale
9193 clip: visible && scale < 1.0
92− scale: visible ? 1.0 : initialScale
94+ scale: opened ? 1.0 : initialScale
9395 transformOrigin: Item.TopLeft
9496 transform: Translate {
9597 x: slideShow.initialX - slideShow.initialX * slideShow.scaleProgress
@@ -98,9 +100,21 @@ PreviewWidget {
98100 color: "black"
99101 radius: units.gu(1) - units.gu(1) * slideShow.scaleProgress
100102
103+ function open() {
104+ opening = true;
105+ opened = true;
106+ }
107+
108+ function close() {
109+ opening = false;
110+ opened = false;
111+ }
112+
101113 Behavior on scale {
102− enabled: !slideShow.visible
103− UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration }
114+ UbuntuNumberAnimation {
115+ duration: slideShow.opening ? UbuntuAnimation.FastDuration :
116+ UbuntuAnimation.FastDuration / 3
117+ }
104118 }
105119
106120 Flickables.ListView {
@@ -160,7 +174,7 @@ PreviewWidget {
160174 width: units.gu(8)
161175 height: width
162176
163− onClicked: slideShow.visible = false
177+ onClicked: slideShow.close()
164178
165179 Rectangle {
166180 anchors.fill: parent
qml/Dash/Previews/PreviewZoomableImage.qml+22−8
@@ -46,9 +46,9 @@ PreviewWidget {
4646 id: mouseArea
4747 anchors.fill: parent
4848 onClicked: {
49− zoomableImageContainer.initialX = rootItem.mapFromItem(parent, 0, 0).x
50− zoomableImageContainer.initialY = rootItem.mapFromItem(parent, 0, 0).y
51− zoomableImageContainer.visible = true;
49+ zoomableImageContainer.initialX = rootItem.mapFromItem(parent, 0, 0).x;
50+ zoomableImageContainer.initialY = rootItem.mapFromItem(parent, 0, 0).y;
51+ zoomableImageContainer.open();
5252 }
5353 }
5454 }
@@ -61,13 +61,15 @@ PreviewWidget {
6161 readonly property real scaleProgress: (scale - initialScale) / (1.0 - initialScale)
6262 property real initialX: 0
6363 property real initialY: 0
64+ property bool opened: false
65+ property bool opening: false
6466
6567 parent: rootItem
6668 width: parent.width
6769 height: parent.height
68− visible: false
70+ visible: scale > initialScale
6971 clip: visible && scale < 1.0
70− scale: visible ? 1.0 : initialScale
72+ scale: opened ? 1.0 : initialScale
7173 transformOrigin: Item.TopLeft
7274 transform: Translate {
7375 x: zoomableImageContainer.initialX - zoomableImageContainer.initialX * zoomableImageContainer.scaleProgress
@@ -76,9 +78,21 @@ PreviewWidget {
7678 color: "black"
7779 radius: units.gu(1) - units.gu(1) * zoomableImageContainer.scaleProgress
7880
81+ function open() {
82+ opening = true;
83+ opened = true;
84+ }
85+
86+ function close() {
87+ opening = false;
88+ opened = false;
89+ }
90+
7991 Behavior on scale {
80− enabled: !zoomableImageContainer.visible
81− UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration }
92+ UbuntuNumberAnimation {
93+ duration: zoomableImageContainer.opening ? UbuntuAnimation.FastDuration :
94+ UbuntuAnimation.FastDuration / 3
95+ }
8296 }
8397
8498 ZoomableImage {
@@ -114,7 +128,7 @@ PreviewWidget {
114128 width: units.gu(8)
115129 height: width
116130
117− onClicked: zoomableImageContainer.visible = false
131+ onClicked: zoomableImageContainer.close()
118132
119133 Rectangle {
120134 anchors.fill: parent
tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+2−1
@@ -53,7 +53,8 @@ Rectangle {
5353 property Item slideShowListView: findChild(slideShow, "slideShowListView")
5454
5555 function cleanup() {
56− slideShow.visible = false;
56+ slideShow.close();
57+ tryCompare(slideShow, "visible", false);
5758 imageGallery.widgetData = sourcesModel1;
5859 waitForRendering(imageGallery);
5960 }
tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+2−1
@@ -53,7 +53,8 @@ Rectangle {
5353 }
5454
5555 function cleanup() {
56− zoomableImageContainer.visible = false;
56+ zoomableImageContainer.close();
57+ tryCompare(zoomableImageContainer, "visible", false);
5758 zoomableImage.widgetData = widgetData0;
5859 }
5960