1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtDeclarative module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | import QtQuick 1.0
|
---|
43 | import "../common" as Common
|
---|
44 |
|
---|
45 | Flipable {
|
---|
46 | id: container
|
---|
47 |
|
---|
48 | property alias frontContainer: containerFront
|
---|
49 | property string photoTitle: ""
|
---|
50 | property string photoTags: ""
|
---|
51 | property int photoWidth
|
---|
52 | property int photoHeight
|
---|
53 | property string photoType
|
---|
54 | property string photoAuthor
|
---|
55 | property string photoDate
|
---|
56 | property string photoUrl
|
---|
57 | property int rating: 2
|
---|
58 | property variant prevScale: 1.0
|
---|
59 |
|
---|
60 | signal closed
|
---|
61 |
|
---|
62 | transform: Rotation {
|
---|
63 | id: itemRotation
|
---|
64 | origin.x: container.width / 2;
|
---|
65 | axis.y: 1; axis.z: 0
|
---|
66 | }
|
---|
67 |
|
---|
68 | front: Item {
|
---|
69 | id: containerFront; anchors.fill: container
|
---|
70 |
|
---|
71 | Rectangle {
|
---|
72 | anchors.fill: parent
|
---|
73 | color: "black"; opacity: 0.4
|
---|
74 | }
|
---|
75 |
|
---|
76 | Column {
|
---|
77 | spacing: 10
|
---|
78 | anchors {
|
---|
79 | left: parent.left; leftMargin: 10
|
---|
80 | right: parent.right; rightMargin: 10
|
---|
81 | top: parent.top; topMargin: 120
|
---|
82 | }
|
---|
83 | Text { font.bold: true; color: "white"; elide: Text.ElideRight; text: container.photoTitle; width: parent.width }
|
---|
84 | Text { color: "white"; elide: Text.ElideRight; text: "Size: " + container.photoWidth + 'x' + container.photoHeight; width: parent.width }
|
---|
85 | Text { color: "white"; elide: Text.ElideRight; text: "Type: " + container.photoType; width: parent.width }
|
---|
86 | Text { color: "white"; elide: Text.ElideRight; text: "Author: " + container.photoAuthor; width: parent.width }
|
---|
87 | Text { color: "white"; elide: Text.ElideRight; text: "Published: " + container.photoDate; width: parent.width }
|
---|
88 | Text { color: "white"; elide: Text.ElideRight; text: container.photoTags == "" ? "" : "Tags: "; width: parent.width }
|
---|
89 | Text { color: "white"; elide: Text.ElideRight; text: container.photoTags; width: parent.width }
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | back: Item {
|
---|
94 | anchors.fill: container
|
---|
95 |
|
---|
96 | Rectangle { anchors.fill: parent; color: "black"; opacity: 0.4 }
|
---|
97 |
|
---|
98 | Common.Progress {
|
---|
99 | anchors.centerIn: parent; width: 200; height: 22
|
---|
100 | progress: bigImage.progress; visible: bigImage.status != Image.Ready
|
---|
101 | }
|
---|
102 |
|
---|
103 | Flickable {
|
---|
104 | id: flickable; anchors.fill: parent; clip: true
|
---|
105 | contentWidth: imageContainer.width; contentHeight: imageContainer.height
|
---|
106 |
|
---|
107 | function updateMinimumScale() {
|
---|
108 | if (bigImage.status == Image.Ready && bigImage.width != 0) {
|
---|
109 | slider.minimum = Math.min(flickable.width / bigImage.width, flickable.height / bigImage.height);
|
---|
110 | if (bigImage.width * slider.value > flickable.width) {
|
---|
111 | var xoff = (flickable.width/2 + flickable.contentX) * slider.value / prevScale;
|
---|
112 | flickable.contentX = xoff - flickable.width/2;
|
---|
113 | }
|
---|
114 | if (bigImage.height * slider.value > flickable.height) {
|
---|
115 | var yoff = (flickable.height/2 + flickable.contentY) * slider.value / prevScale;
|
---|
116 | flickable.contentY = yoff - flickable.height/2;
|
---|
117 | }
|
---|
118 | prevScale = slider.value;
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | onWidthChanged: updateMinimumScale()
|
---|
123 | onHeightChanged: updateMinimumScale()
|
---|
124 |
|
---|
125 | Item {
|
---|
126 | id: imageContainer
|
---|
127 | width: Math.max(bigImage.width * bigImage.scale, flickable.width);
|
---|
128 | height: Math.max(bigImage.height * bigImage.scale, flickable.height);
|
---|
129 |
|
---|
130 | Image {
|
---|
131 | id: bigImage; source: container.photoUrl; scale: slider.value
|
---|
132 | anchors.centerIn: parent; smooth: !flickable.movingVertically
|
---|
133 | onStatusChanged : {
|
---|
134 | // Default scale shows the entire image.
|
---|
135 | if (bigImage.status == Image.Ready && bigImage.width != 0) {
|
---|
136 | slider.minimum = Math.min(flickable.width / bigImage.width, flickable.height / bigImage.height);
|
---|
137 | prevScale = Math.min(slider.minimum, 1);
|
---|
138 | slider.value = prevScale;
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | Text {
|
---|
146 | text: "Image Unavailable"
|
---|
147 | visible: bigImage.status == Image.Error
|
---|
148 | anchors.centerIn: parent; color: "white"; font.bold: true
|
---|
149 | }
|
---|
150 |
|
---|
151 | Common.Slider {
|
---|
152 | id: slider; visible: { bigImage.status == Image.Ready && maximum > minimum }
|
---|
153 | anchors {
|
---|
154 | bottom: parent.bottom; bottomMargin: 65
|
---|
155 | left: parent.left; leftMargin: 25
|
---|
156 | right: parent.right; rightMargin: 25
|
---|
157 | }
|
---|
158 | onValueChanged: {
|
---|
159 | if (bigImage.width * value > flickable.width) {
|
---|
160 | var xoff = (flickable.width/2 + flickable.contentX) * value / prevScale;
|
---|
161 | flickable.contentX = xoff - flickable.width/2;
|
---|
162 | }
|
---|
163 | if (bigImage.height * value > flickable.height) {
|
---|
164 | var yoff = (flickable.height/2 + flickable.contentY) * value / prevScale;
|
---|
165 | flickable.contentY = yoff - flickable.height/2;
|
---|
166 | }
|
---|
167 | prevScale = value;
|
---|
168 | }
|
---|
169 | }
|
---|
170 | }
|
---|
171 |
|
---|
172 | states: State {
|
---|
173 | name: "Back"
|
---|
174 | PropertyChanges { target: itemRotation; angle: 180 }
|
---|
175 | PropertyChanges { target: toolBar; button2Visible: false }
|
---|
176 | PropertyChanges { target: toolBar; button1Label: "Back" }
|
---|
177 | }
|
---|
178 |
|
---|
179 | transitions: Transition {
|
---|
180 | SequentialAnimation {
|
---|
181 | PropertyAction { target: bigImage; property: "smooth"; value: false }
|
---|
182 | NumberAnimation { easing.type: Easing.InOutQuad; properties: "angle"; duration: 500 }
|
---|
183 | PropertyAction { target: bigImage; property: "smooth"; value: !flickable.movingVertically }
|
---|
184 | }
|
---|
185 | }
|
---|
186 | }
|
---|