123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import QtQuick 1.0
- import InvMA 1.0
- import "Magnifier.js" as MagnifierPopup
- FocusScope {
- id: root
- property alias font: textEdit.font
- property alias cursorPosition: textEdit.cursorPosition
- property alias text: textEdit.text
- property alias readOnly: textEdit.readOnly
- property alias textFormat: textEdit.textFormat
- property alias wrapMode: textEdit.wrapMode
- signal textChanged
- signal cursorRectangleChanged
- property alias cursorRectangle: textEdit.cursorRectangle
- property alias tx: textEdit.x
- property alias ty: textEdit.y
- function copy() {
- textEdit.copy()
- }
- function paste() {
- textEdit.paste()
- }
- function cut() {
- textEdit.cut()
- }
- function positionAt(x, y) {
- var p = mapToItem(textEdit, x, y);
- return textEdit.positionAt(p.x, p.y)
- }
- onActiveFocusChanged: {
- if (activeFocus && !readOnly) {
- textEdit.openSoftwareInputPanel();
- //repositionTimer.running = true;
- } else if (!activeFocus) {
- if (!readOnly) {
- textEdit.closeSoftwareInputPanel();
- }
- }
- }
- /*Rectangle {
- id: wrapperTE
- //anchors.fill: parent
- anchors.top: parent.top
- anchors.left: parent.left
- width: parent.width
- height: parent.height
- color: "white"
- border.color: "blue"
- radius: 5
- }*/
- TextEdit {
- id: textEdit
- clip: true
- anchors.top: parent.top;
- anchors.left: parent.left; anchors.leftMargin: 5
- width: parent.width - 2*anchors.leftMargin
- height: parent.height
- font.pixelSize: 28
- //FIXME:
- function updateMagnifierPosition(posX, posY) {
- var magnifier = MagnifierPopup.popup;
- var cursorHeight = textEdit.positionToRectangle(0,0).height;
- var mappedPos = mapToItem(magnifier.parent, posX - magnifier.width / 2,
- posY - magnifier.height / 2 - cursorHeight - 70);
- magnifier.xCenter = mapToItem(magnifier.sourceItem, posX, 0).x / magnifier.sourceItem.width;
- magnifier.x = mappedPos.x;
- if (-root.mapFromItem(magnifier.__rootElement(), 0,0).y - (posY - cursorHeight) < (magnifier.height / 1.5)) {
- magnifier.yAdjustment = Math.max(0,(magnifier.height / 1.5) + root.mapFromItem(magnifier.__rootElement(), 0,0).y - (posY - cursorHeight));
- } else {
- magnifier.yAdjustment = 0;
- }
- magnifier.yCenter = 1.0 - ((50 + posY - cursorHeight) / root.height);
- magnifier.y = mappedPos.y + magnifier.yAdjustment;
- }
- onTextChanged: {
- root.textChanged()
- }
- onCursorRectangleChanged: {
- root.cursorRectangleChanged()
- }
- InverseMouseArea {
- anchors.fill: parent
- enabled: root.activeFocus
- onClickedOutside: {
- root.parent.focus = true;
- }
- }
- //FIXME:
- MouseArea {
- anchors.fill: parent
- enabled: root.activeFocus
- onPressAndHold:{
- // possible pre-edit word have to be commited before showing the magnifier
- console.log("MouseArea: onPressAndHold")
- if ((root.text != "") && root.activeFocus) {
- //inputContext.reset()
- //attemptToActivate = false
- //parent.selectByMouse = false
- MagnifierPopup.open(root);
- var magnifier = MagnifierPopup.popup;
- parent.cursorPosition = parent.positionAt(mouse.x,mouse.y)
- parent.updateMagnifierPosition(mouse.x,mouse.y)
- root.z = Number.MAX_VALUE
- }
- }
- }
- }
- }
|