Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[fingerterm] Add a minimal delay between key press and release.
  • Loading branch information
dcaliste committed Jun 14, 2017
1 parent 851c577 commit d72c296
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
24 changes: 9 additions & 15 deletions qml/Key.qml
Expand Up @@ -34,15 +34,12 @@ Rectangle {
property real labelOpacity: keyboard.active ? 1.0 : 0.3

// mouse input handling
property int clickThreshold: 20
property bool isClick
property int pressMouseY
property int pressMouseX
property bool shiftActive: (keyboard.keyModifiers & Qt.ShiftModifier) && !sticky

width: window.width/12 // some default
height: window.height/8 < 55*window.pixelRatio ? window.height/8 : 55*window.pixelRatio
color: label=="" ? "transparent" : keyboard.keyBgColor
color: label=="" ? "transparent" : (isClick || keyPressHighlight.running ? keyboard.keyHilightBgColor : keyboard.keyBgColor)
border.color: label=="" ? "transparent" : keyboard.keyBorderColor
border.width: 1
radius: window.radiusSmall
Expand Down Expand Up @@ -118,14 +115,12 @@ Rectangle {

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

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

keyRepeatStarter.start();
keyPressHighlight.restart()

if (sticky) {
keyboard.keyModifiers |= code;
Expand All @@ -147,20 +142,14 @@ Rectangle {
return false;
}

if (key.isClick) {
if (Math.abs(x - key.pressMouseX) > key.clickThreshold
|| Math.abs(y - key.pressMouseY) > key.clickThreshold) {
key.isClick = false
}
}

return true;
}

function handleRelease(touchArea, x, y) {
key.isClick = false
keyRepeatStarter.stop();
keyRepeatTimer.stop();
key.color = keyboard.keyBgColor;

keyboard.currentKeyPressed = null;

if (sticky && !becomesSticky) {
Expand Down Expand Up @@ -208,6 +197,11 @@ Rectangle {
}
}

Timer {
id: keyPressHighlight
interval: keyboard.feedbackDuration
}

function setStickiness(val)
{
if(sticky) {
Expand Down
49 changes: 37 additions & 12 deletions qml/Keyboard.qml
Expand Up @@ -32,6 +32,8 @@ Item {
property string keyHilightBgColor: "#ffffff"
property string keyBorderColor: "#303030"

property int feedbackDuration: 150

property bool active

property int outmargins: util.keyboardMargins
Expand All @@ -40,7 +42,7 @@ Item {
property real keywidth: (keyboard.width - keyspacing*keysPerRow - outmargins*2)/keysPerRow;

width: parent.width
height: childrenRect.height + outmargins
height: keyboardLoader.height + outmargins

Component {
id: keyboardContents
Expand Down Expand Up @@ -85,17 +87,40 @@ Item {
keyboardLoader.sourceComponent = keyboardContents;
}

onCurrentKeyPressedChanged: {
if(currentKeyPressed && currentKeyPressed.currentLabel.length === 1 && currentKeyPressed.currentLabel !== " ") {
visualKeyFeedbackRect.label = currentKeyPressed.currentLabel
visualKeyFeedbackRect.width = currentKeyPressed.width*1.5
visualKeyFeedbackRect.height = currentKeyPressed.height*1.5
var mappedCoord = window.mapFromItem(currentKeyPressed, 0, 0);
visualKeyFeedbackRect.x = mappedCoord.x - (visualKeyFeedbackRect.width-currentKeyPressed.width)/2
visualKeyFeedbackRect.y = mappedCoord.y - currentKeyPressed.height*1.5
visualKeyFeedbackRect.visible = true;
} else {
visualKeyFeedbackRect.visible = false;
Rectangle {
// visual key press feedback...
id: visualKeyFeedbackRect

property alias label: label.text
property var _key: (currentKeyPressed
&& currentKeyPressed.currentLabel.length === 1
&& currentKeyPressed.currentLabel !== " ")
? currentKeyPressed : null

visible: _key || visualFeedbackDelay.running
radius: window.radiusSmall
color: keyFgColor

Text {
id: label
color: keyBgColor
font.pointSize: 34*window.pixelRatio
anchors.centerIn: parent
}
Timer {
id: visualFeedbackDelay
interval: feedbackDuration
}
on_KeyChanged: {
if (_key) {
visualKeyFeedbackRect.label = _key.currentLabel
visualKeyFeedbackRect.width = _key.width * 1.5
visualKeyFeedbackRect.height = _key.height * 1.5
var mappedCoord = keyboard.mapFromItem(_key, 0, 0);
visualKeyFeedbackRect.x = mappedCoord.x - (visualKeyFeedbackRect.width-_key.width)/2
visualKeyFeedbackRect.y = mappedCoord.y - _key.height*1.5
visualFeedbackDelay.restart()
}
}
}

Expand Down
19 changes: 0 additions & 19 deletions qml/Main.qml
Expand Up @@ -272,25 +272,6 @@ Item {
}
}

Rectangle {
// visual key press feedback...
// easier to work with the coordinates if it's here and not under keyboard element
id: visualKeyFeedbackRect

property string label

visible: false
radius: window.radiusSmall
color: "#ffffff"

Text {
color: "#000000"
font.pointSize: 34*window.pixelRatio
anchors.centerIn: parent
text: visualKeyFeedbackRect.label
}
}

NotifyWin {
id: aboutDialog

Expand Down

0 comments on commit d72c296

Please sign in to comment.