Skip to content

Commit

Permalink
[vkb] Basic multi-touch support (no modifiers yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Perl committed Sep 20, 2013
1 parent 317a17a commit 48f73a7
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 70 deletions.
61 changes: 45 additions & 16 deletions qml/Key.qml
Expand Up @@ -30,6 +30,12 @@ Rectangle {
property bool sticky: false // can key be stickied?
property int stickiness: 0 // current stickiness status

// mouse input handling
property int clickThreshold: 20
property bool isClick: false
property int pressMouseY: 0
property int pressMouseX: 0

width: window.width/12 // some default
height: window.height/8 < 55 ? window.height/8 : 55
color: label=="" ? "transparent" : keyboard.keyBgColor
Expand Down Expand Up @@ -94,36 +100,59 @@ Rectangle {
anchors.topMargin: key.height/2
}

function handlePress() {
function handlePress(touchArea, x, y) {
isClick = true;
pressMouseX = x;
pressMouseY = y;

key.color = keyboard.keyHilightBgColor
keyboard.currentKeyPressed = key;
util.keyPressFeedback();

keyRepeatStarter.start();
}

function handleRelease() {
util.keyReleaseFeedback();

keyRepeatStarter.stop();
keyRepeatTimer.stop();

key.color = keyboard.keyBgColor

setStickiness(-1)
window.vkbKeypress(currentCode, keyboard.keyModifiers);
function handleMove(touchArea, x, y) {
var mappedPoint = key.mapFromItem(touchArea, x, y)
if (!key.contains(Qt.point(mappedPoint.x, mappedPoint.y))) {
key.handleRelease(touchArea, x, y);
return false;
}

if( !sticky && keyboard.resetSticky != 0 && keyboard.resetSticky !== key ) {
resetSticky.setStickiness(0);
if (key.isClick) {
if (Math.abs(x - key.pressMouseX) > key.clickThreshold ||
Math.abs(y - key.pressMouseY) > key.clickThreshold )
key.isClick = false
}

return true;
}

function handleExit() {
function handleRelease(touchArea, x, y) {
keyRepeatStarter.stop();
keyRepeatTimer.stop();

key.color = keyboard.keyBgColor
key.color = keyboard.keyBgColor;
keyboard.currentKeyPressed = 0;

// Wake up the keyboard if the user has tapped/clicked on it and we're not in select mode
//(or it would be hard to select text)
if (y < vkb.y && key.pressMouseY < vkb.y && util.settingsValue("ui/dragMode") !== "select") {
if (vkb.active)
window.sleepVKB();
else
window.wakeVKB();
}

if (vkb.keyAt(x, y) == key) {
util.keyReleaseFeedback();

setStickiness(-1);
window.vkbKeypress(currentCode, keyboard.keyModifiers);

if( !sticky && keyboard.resetSticky != 0 && keyboard.resetSticky !== key ) {
resetSticky.setStickiness(0);
}
}
}

Timer {
Expand Down
98 changes: 44 additions & 54 deletions qml/Main.qml
Expand Up @@ -116,70 +116,60 @@ PageStackWindow {
visible: windowHasFocus && visibleSetting
}

//area that handles gestures/select/scroll modes and vkb-keypresses
MouseArea {
id: touchArea
objectName: "touchArea"
// area that handles gestures/select/scroll modes and vkb-keypresses
MultiPointTouchArea {
id: multiTouchArea
anchors.fill: parent
property int pressMouseY: 0
property int pressMouseX: 0
property int clickThreshold: 20
property alias pressedKey: vkb.currentKeyPressed
//We define a click as a mouse-press followed by a mouse-release
//Morover, we only consider it a click if the mouse hasn't moved too much
//between press and release events
property bool isClick: false

property int firstTouchId: -1
property var pressedKeys: ({})

onPressed: {
isClick = true
pressMouseY = mouse.y
pressMouseX = mouse.x
var key = vkb.keyAt(mouse.x, mouse.y)
if (key != null) {
pressedKey = key
pressedKey.handlePress()
}
//gestures c++ handler
util.mousePress(mouse.x, mouse.y)
touchPoints.forEach(function (touchPoint) {
if (multiTouchArea.firstTouchId == -1) {
multiTouchArea.firstTouchId = touchPoint.pointId;

//gestures c++ handler
util.mousePress(touchPoint.x, touchPoint.y);
}

var key = vkb.keyAt(touchPoint.x, touchPoint.y);
if (key != null) {
key.handlePress(multiTouchArea, touchPoint.x, touchPoint.y);
}
multiTouchArea.pressedKeys[touchPoint.pointId] = key;
});
}
onPositionChanged: {
//if the finger exits key's area
if (pressedKey != null && pressedKey != 0) {
var mappedPoint = pressedKey.mapFromItem(touchArea, mouse.x, mouse.y)
if (!pressedKey.contains(Qt.point(mappedPoint.x, mappedPoint.y))) {
pressedKey.handleExit()
onUpdated: {
touchPoints.forEach(function (touchPoint) {
if (multiTouchArea.firstTouchId == touchPoint.pointId) {
//gestures c++ handler
util.mouseMove(touchPoint.x, touchPoint.y);
}
}

if (isClick) {
if (Math.abs(mouse.x - pressMouseX) > clickThreshold ||
Math.abs(mouse.y - pressMouseY) > clickThreshold )
isClick = false
}
//gestures c++ handler
util.mouseMove(mouse.x, mouse.y)
var key = multiTouchArea.pressedKeys[touchPoint.pointId];
if (key != null) {
if (!key.handleMove(multiTouchArea, touchPoint.x, touchPoint.y)) {
delete multiTouchArea.pressedKeys[touchPoint.pointId];
}
}
});
}
onReleased: {
if (pressedKey != null && pressedKey != 0) {
if (vkb.keyAt(mouse.x, mouse.y) == pressedKey) {
pressedKey.handleRelease()
touchPoints.forEach(function (touchPoint) {
if (multiTouchArea.firstTouchId == touchPoint.pointId) {
//gestures c++ handler
util.mouseRelease(touchPoint.x, touchPoint.y);
multiTouchArea.firstTouchId = -1;
}
pressedKey.handleExit()
}

//gestures c++ handler
util.mouseRelease(mouse.x, mouse.y)

// Wake up the keyboard if the user has tapped/clicked on it and we're not in select mode
//(or it would be hard to select text)
if (mouse.y < vkb.y && pressMouseY < vkb.y && isClick && util.settingsValue("ui/dragMode") !== "select") {
if (vkb.active)
window.sleepVKB();
else
window.wakeVKB();
}
var key = multiTouchArea.pressedKeys[touchPoint.pointId];
if (key != null) {
key.handleRelease(multiTouchArea, touchPoint.x, touchPoint.y);
}
delete multiTouchArea.pressedKeys[touchPoint.pointId];
});
}


}

Rectangle {
Expand Down

0 comments on commit 48f73a7

Please sign in to comment.