forked from rh-lab-q/confla-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhotoDetailPage.qml
149 lines (116 loc) · 4.68 KB
/
PhotoDetailPage.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import QtQuick 2.0
import "functions.js" as F
Page {
id: page
// allowedOrientations: Orientation.All
property alias addr: imageItem.source
// BusyIndicator {
// anchors.centerIn: parent;
// visible: (imageItem.status !== Image.Ready)
// running: visible;
// }
Flickable {
id: imageFlickable
anchors.fill: parent;
clip: true;
contentWidth: imageContainer.width; contentHeight: imageContainer.height
onHeightChanged: {
if (imageItem.status === Image.Ready) {
imageItem.fitToScreen()
}
}
Item {
id: imageContainer
width: Math.max(imageItem.width * imageItem.scale, imageFlickable.width)
height: Math.max(imageItem.height * imageItem.scale, imageFlickable.height)
AnimatedImage {
id: imageItem
property real prevScale
function fitToScreen() {
scale = Math.min(imageFlickable.width / width, imageFlickable.height / height, 1)
pinchArea.minScale = scale
prevScale = scale
}
anchors.centerIn: parent
asynchronous: true
smooth: !imageFlickable.moving
cache: false
fillMode: Image.PreserveAspectFit
// pause the animation when app is in background
paused: !Qt.application.active
// paused: (page.status !== PageStatus.Active) || !Qt.application.active
onScaleChanged: {
if ((width * scale) > imageFlickable.width) {
var xoff = (imageFlickable.width / 2 + imageFlickable.contentX) * scale / prevScale;
imageFlickable.contentX = xoff - imageFlickable.width / 2
}
if ((height * scale) > imageFlickable.height) {
var yoff = (imageFlickable.height / 2 + imageFlickable.contentY) * scale / prevScale;
imageFlickable.contentY = yoff - imageFlickable.height / 2
}
prevScale = scale
}
onStatusChanged: {
if ((status === Image.Ready) && (imageItem.width !== 0)) { // The width is 0 when Image.Ready ? Why?
fitToScreen()
loadedAnimation.start()
}
}
onWidthChanged: {
if ((status === Image.Ready) && (imageItem.width !== 0)) {
fitToScreen()
loadedAnimation.start()
}
}
onSourceChanged: {
console.log("GET: " + source)
}
NumberAnimation {
id: loadedAnimation
target: imageItem
property: "opacity"
duration: 250
from: 0; to: 1
easing.type: Easing.InOutQuad
}
}
}
PinchArea {
id: pinchArea
property real minScale: 1.0
property real maxScale: 3.0
anchors.fill: parent
enabled: true; // (imageItem.status === Image.Ready)
pinch.target: imageItem
pinch.minimumScale: minScale * 0.5 // This is to create "bounce back effect"
pinch.maximumScale: maxScale * 1.5 // when over zoomed
onPinchFinished: {
imageFlickable.returnToBounds()
if (imageItem.scale < pinchArea.minScale) {
bounceBackAnimation.to = pinchArea.minScale
bounceBackAnimation.start()
}
else if (imageItem.scale > pinchArea.maxScale) {
bounceBackAnimation.to = pinchArea.maxScale
bounceBackAnimation.start()
}
}
NumberAnimation {
id: bounceBackAnimation
target: imageItem
duration: 250
property: "scale"
from: imageItem.scale
}
MouseArea {
anchors.fill: parent;
onClicked: {
var targetScale = 0.5*(pinchArea.maxScale-pinchArea.minScale) + pinchArea.minScale
bounceBackAnimation.to = (( imageItem.scale-pinchArea.minScale) > 0.5) ? pinchArea.minScale : targetScale;
bounceBackAnimation.start()
imageFlickable.returnToBounds()
}
}
}
}
}