2
* Copyright (C) 2012 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Charles Lindsay <chaz@yorba.org>
18
* Lucas Beeler <lucas@yorba.org>
22
import Ubuntu.Components 1.1
23
import "GraphicsRoutines.js" as GraphicsRoutines
29
objectName: "cropInteractor"
33
property alias targetPhoto: original.source
35
property string matteColor: "black"
36
property real matteOpacity: 0.6
38
// Note: each element of the cropped rect will be in the range [0,1], since
39
// in the UI we aren't using direct photo pixel values.
40
signal cropped(variant rect)
43
function computeRectSet() {
44
var actualImage = Qt.rect(
45
(original.width - original.paintedWidth) / 2.0,
46
(original.height - original.paintedHeight) / 2.0,
47
original.paintedWidth,
48
original.paintedHeight
50
var photoPreview = GraphicsRoutines.fitRect(viewport, actualImage);
52
var unfitCrop = Qt.rect(0, 0, photoPreview.width, photoPreview.height);
53
var cropFrame = GraphicsRoutines.fitRect(viewport, unfitCrop);
55
var photoExtent = Qt.rect(cropFrame.x, cropFrame.y,
56
cropFrame.scaleFactor * photoPreview.width,
57
cropFrame.scaleFactor * photoPreview.height);
60
photoPreview: photoPreview,
62
photoExtent: photoExtent,
63
photoExtentScale: cropFrame.scaleFactor
71
anchors.margins: units.gu(6)
77
objectName: "cropOverlay"
79
property real minSize: units.gu(4)
87
matteColor: cropInteractor.matteColor
88
matteOpacity: cropInteractor.matteOpacity
92
onMatteRegionPressed: {
93
cropInteractor.canceled();
96
onCropButtonPressed: {
97
original.visible = false;
98
overlay.visible = false;
100
var r = overlay.getRelativeFrameRect()
101
cropInteractor.cropped(overlay.getRelativeFrameRect());
110
width: viewport.width
111
height: viewport.height
112
transformOrigin: Item.TopLeft
113
fillMode: Image.PreserveAspectFit
116
width: original.width
117
height: original.height
121
if (status == Image.Ready) {
122
var rects = computeRectSet();
124
overlay.initialFrameX = rects.cropFrame.x;
125
overlay.initialFrameY = rects.cropFrame.y;
126
overlay.initialFrameWidth = rects.cropFrame.width;
127
overlay.initialFrameHeight = rects.cropFrame.height;
129
overlay.resetFor(rects);
130
overlay.visible = true;
132
x = rects.photoExtent.x;
133
y = rects.photoExtent.y;
134
width = rects.photoPreview.width;
135
height = rects.photoPreview.height;
136
scale = rects.photoExtentScale;