1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Qt Components project.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
42 import "RectUtils.js" as Utils
47 property alias imageSource: image.source
48 property int editorPos: 0 //character position of the handle in the editor document
50 // the default size of the touch area should come from some style constant
51 property variant touchAreaSize: Qt.size(platformStyle.graphicSizeMedium, platformStyle.graphicSizeMedium)
52 property alias showImage: image.visible
53 property variant viewPortRect: Qt.rect(0, 0, 0, 0) // item's coordinates
54 //parent's coordinate system
55 property variant center: Qt.point(root.x + root.width / 2, root.y + root.height / 2)
57 // Point is in Item's coordinate system
58 function containsPoint(point) {
59 var touchAreaRect = Qt.rect(touchArea.x, touchArea.y, touchArea.width, touchArea.height);
61 if (!Utils.rectContainsRect(viewPortRect, touchAreaRect)
62 && Utils.rectIntersectsRect(viewPortRect, touchAreaRect)) {
63 touchAreaRect.x = Math.max(touchAreaRect.x, viewPortRect.x);
64 touchAreaRect.x = Math.min(touchAreaRect.x, viewPortRect.x + viewPortRect.width - touchAreaRect.width);
65 touchAreaRect.y = Math.max(touchAreaRect.y, viewPortRect.y);
66 touchAreaRect.y = Math.min(touchAreaRect.y, viewPortRect.y + viewPortRect.height - touchAreaRect.height);
69 effectiveTouchArea.x = touchAreaRect.x;
70 effectiveTouchArea.y = touchAreaRect.y;
72 if (Utils.rectContainsPoint(touchAreaRect, point.x, point.y))
78 // Point is in parent's coordinate system
79 function pointDistanceFromCenter(point) {
80 return Utils.manhattan(point, root.center);
83 function updateGeometry() {
84 var rect = root.editor.positionToRectangle(editorPos);
85 var pos = root.editor.mapToItem(root.parent, rect.x, rect.y);
88 root.width = rect.width;
89 root.height = rect.height;
92 onEditorPosChanged: root.updateGeometry()
98 anchors.centerIn: root
99 width: root.touchAreaSize.width
100 height: Math.max(root.touchAreaSize.height, root.height)
104 id: effectiveTouchArea
107 width: root.touchAreaSize.width
108 height: Math.max(root.touchAreaSize.height, root.height)
114 property real tiny: Math.round(platformStyle.borderSizeMedium / 2)
117 left: root.objectName == "SelectionEnd" ? root.right : undefined
118 right: root.objectName == "SelectionBegin" ? root.left : undefined
119 leftMargin: root.objectName == "SelectionEnd" ? -editor.cursorRectangle.width : 0
121 topMargin: -tiny / 2 + 1
123 bottomMargin: -tiny / 2