diff --git a/qml/Key.qml b/qml/Key.qml index 19f6cb4..cabb918 100644 --- a/qml/Key.qml +++ b/qml/Key.qml @@ -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 @@ -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; @@ -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) { @@ -208,6 +197,11 @@ Rectangle { } } + Timer { + id: keyPressHighlight + interval: keyboard.feedbackDuration + } + function setStickiness(val) { if(sticky) { diff --git a/qml/Keyboard.qml b/qml/Keyboard.qml index c84c2af..c72246b 100644 --- a/qml/Keyboard.qml +++ b/qml/Keyboard.qml @@ -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 @@ -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 @@ -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() + } } } diff --git a/qml/Main.qml b/qml/Main.qml index 7c2332b..3e4b919 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -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