Commit 68a3449d authored by Jimmy HUGUET's avatar Jimmy HUGUET

Automatically replace succession of two character by another one, used for...

Automatically replace succession of two character by another one, used for acmaking cent (ed character
parent 97be392a
/****************************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Contact: Pekka Vuorela <pekka.vuorela@jollamobile.com>
** All rights reserved.
**
** You may use this file under the terms of BSD license as follows:
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the Jolla Ltd nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
****************************************************************************************/
import QtQuick 2.0
import com.meego.maliitquick 1.0
import com.jolla.keyboard 1.0
import Sailfish.Silica 1.0 as Silica
Item {
property Item pressedKey
property Component topItem
property Component verticalItem
property bool active
Timer {
id: autorepeatTimer
repeat: true
onTriggered: {
interval = 80
if (pressedKey !== null) {
_handleKeyClick(pressedKey)
} else {
stop()
}
}
}
Multitap {
id: multitap
}
function _handleKeyPress(key) {
pressedKey = key
autorepeatTimer.stop()
if (handleKeyPress())
return
if (pressedKey.repeat) {
autorepeatTimer.interval = 500
autorepeatTimer.start()
}
}
function _handleKeyRelease() {
pressedKey = null
if (handleKeyRelease())
return
autorepeatTimer.stop()
}
function _handleKeyClick(key) {
pressedKey = key
if (key.keyType === KeyType.CharacterKey || key.keyType === KeyType.PopupKey) {
keyboard.characterKeyCounter++
}
if (handleKeyClick())
return
if (pressedKey.key === Qt.Key_Multi_key) {
multitap.apply(pressedKey.text)
return
} else {
multitap.flush()
}
var resetShift = !keyboard.isShiftLocked
if (pressedKey.key === Qt.Key_Shift) {
resetShift = false
}
if (pressedKey.text.length) {
if (pressedKey.text in layout.accentMap) {
var previousChar = MInputMethodQuick.surroundingText.charAt(MInputMethodQuick.surroundingText.length - 1)
if (previousChar in layout.accentMap[pressedKey.text]) {
var merge = layout.accentMap[pressedKey.text][previousChar]
layout.lastAccentMerge = previousChar + pressedKey.text
MInputMethodQuick.sendKey(Qt.Key_Backspace, 0, "\b", Maliit.KeyClick)
MInputMethodQuick.sendCommit(merge)
} else {
MInputMethodQuick.sendCommit(pressedKey.text)
layout.lastAccentMerge = ""
}
} else {
MInputMethodQuick.sendCommit(pressedKey.text)
layout.lastAccentMerge = ""
}
} else if (pressedKey.key === Qt.Key_Return) {
MInputMethodQuick.activateActionKey()
} else if (pressedKey.key === Qt.Key_Backspace) {
if (layout.lastAccentMerge !== "") {
MInputMethodQuick.sendKey(Qt.Key_Backspace, 0, "\b", Maliit.KeyClick)
MInputMethodQuick.sendCommit(layout.lastAccentMerge)
layout.lastAccentMerge = ""
} else {
if (MInputMethodQuick.surroundingTextValid && MInputMethodQuick.cursorPosition == 0) {
resetShift = false
}
MInputMethodQuick.sendKey(Qt.Key_Backspace, 0, "\b", Maliit.KeyClick)
}
} else if (pressedKey.key === Qt.Key_Paste) {
MInputMethodQuick.sendCommit(Silica.Clipboard.text)
} else {
resetShift = false
}
if (resetShift)
keyboard.resetShift()
}
function _reset() {
autorepeatTimer.stop()
multitap.flush()
reset()
}
// called when button gets down. can be reimplemented to handle input. return true input is consumed
function handleKeyPress() {
return false
}
// called when button click was fully done or on autorepeat. can be reimplemented to handle input.
// return true input was consumed.
function handleKeyClick() {
return false
}
// called when button got up either by moving out of the button or after click was done.
// can be reimplemented. return true if input was consumed.
function handleKeyRelease() {
return false
}
// called when input state needs to be reset
function reset() {
}
}
......@@ -50,8 +50,10 @@ Item {
|| shiftState === ShiftState.LatchedShift
|| shiftState === ShiftState.LockedShift
|| (shiftState === ShiftState.AutoShift && autocaps
&& (typeof inputHandler.preedit !== "string"
|| inputHandler.preedit.length === 0))
&& (typeof layout.isEase !== 'undefined' ? (typeof inputEaseHandler.preedit !== "string"
|| inputEaseHandler.preedit.length === 0)
:(typeof inputHandler.preedit !== "string"
|| inputHandler.preedit.length === 0)))
readonly property bool isShiftLocked: shiftState === ShiftState.LockedShift
property bool inSymView
......@@ -79,6 +81,9 @@ Item {
property Item inputHandler: InputHandler {
}
property Item inputEaseHandler: InputEaseHandler {
}
height: layout ? layout.height : 0
onLayoutChanged: if (layout) layout.parent = keyboard
onPortraitModeChanged: cancelAllTouchPoints()
......@@ -143,7 +148,11 @@ Item {
}
}
onInputMethodReset: {
inputHandler._reset()
if (typeof layout.isEase !== 'undefined') {
inputEaseHandler._reset()
} else {
inputHandler._reset()
}
}
}
......@@ -219,7 +228,11 @@ Item {
// swiped down to close keyboard
MInputMethodQuick.userHide()
if (point.pressedKey) {
inputHandler._handleKeyRelease()
if (typeof layout.isEase !== 'undefined') {
inputEaseHandler._handleKeyRelease()
} else {
inputHandler._handleKeyRelease()
}
point.pressedKey.pressed = false
}
lastPressedKey = null
......@@ -294,7 +307,11 @@ Item {
}
if (point.pressedKey !== null) {
inputHandler._handleKeyRelease()
if (typeof layout.isEase !== 'undefined') {
inputEaseHandler._handleKeyRelease()
} else {
inputHandler._handleKeyRelease()
}
point.pressedKey.pressed = false
}
......@@ -312,7 +329,11 @@ Item {
// on that case, trigger input from previous character
releasePreviousCharacterKey(point)
point.pressedKey.pressed = true
inputHandler._handleKeyPress(point.pressedKey)
if (typeof layout.isEase !== 'undefined') {
inputEaseHandler._handleKeyPress(point.pressedKey)
} else {
inputHandler._handleKeyPress(point.pressedKey)
}
if (point.pressedKey.key === Qt.Key_Space && layoutChangeAllowed)
languageSwitchTimer.start()
}
......@@ -405,7 +426,11 @@ Item {
return
if (point.pressedKey) {
inputHandler._handleKeyRelease()
if (typeof layout.isEase !== 'undefined') {
inputEaseHandler._handleKeyRelease()
} else {
inputHandler._handleKeyRelease()
}
point.pressedKey.pressed = false
if (lastPressedKey === point.pressedKey) {
lastPressedKey = null
......@@ -434,7 +459,11 @@ Item {
inSymView2 = false
resetShift()
inputHandler._reset()
if (typeof layout.isEase !== 'undefined') {
inputEaseHandler._reset()
} else {
inputHandler._reset()
}
lastPressedKey = null
lastInitialKey = null
......@@ -527,10 +556,18 @@ Item {
function triggerKey(key) {
if (key.keyType !== KeyType.DeadKey) {
inputHandler._handleKeyClick(key)
if (typeof layout.isEase !== 'undefined') {
inputEaseHandler._handleKeyClick(key)
} else {
inputHandler._handleKeyClick(key)
}
}
key.clicked()
inputHandler._handleKeyRelease()
if (typeof layout.isEase !== 'undefined') {
inputEaseHandler._handleKeyRelease()
} else {
inputHandler._handleKeyRelease()
}
quickPick.handleInput(key)
key.pressed = false
}
......
......@@ -25,6 +25,8 @@ Column {
property bool capsLockSupported: true
property bool isEase: true
property var accentMap: ({})
property string lastAccentMerge: ""
Component.onCompleted: updateSizes()
onWidthChanged: updateSizes()
......
......@@ -32,15 +32,25 @@ import ".."
import Sailfish.Silica 1.0
KeyboardEaseLayout {
accentMap: {
"´": {"e": "é", "E": "É", "a": "á", "A": "Á", "o": "ó", "O": "Ó", "i": "í", "I": "Í", "u": "ú", "U": "Ú", "y": "ý", "Y": "Ý" },
"^": {"e": "ê", "E": "Ê", "a": "â", "A": "Â", "o": "ô", "O": "Ô", "i": "î", "I": "Î", "u": "û", "U": "Û" },
"¨": {"e": "ë", "E": "Ë", "a": "ä", "A": "Ä", "o": "ö", "O": "Ö", "i": "ï", "I": "Ï", "u": "ü", "U": "Ü", "y": "ÿ", "Y": "Ϋ" },
"`": {"e": "è", "E": "È", "a": "à", "A": "À", "o": "ò", "O": "Ò", "i": "ì", "I": "Ì", "u": "ù", "U": "Ù" },
"°": { "a": "å", "A": "Å" },
"~": { "a": "ã", "A": "Ã", "o": "õ", "O": "Õ" , "n": "ñ", "N": "Ñ"},
"¸": {"c": "ç", "C": "Ç"}
}
KeyboardRow {
CharacterEaseKey {
caption: "a"; swipeCaption: ["", "", "", "", "", "", "", "v"]; swipeSpecial: ["", "", "", "", "-", "", "", ""];
captionShifted: "A"; swipeCaptionShifted: ["", "", "", "", "", "", "", "V"]; symView: "1"; symView2: caption }
CharacterEaseKey {
caption: "n"; swipeCaption: ["", "", "", "", "", "", "l", ""]; swipeSpecial: ["`", "^", "", "+", "!", "/", "", "\\"];
caption: "n"; swipeCaption: ["", "", "", "", "", "", "l", ""]; swipeSpecial: ["`", "^", "´", "+", "!", "/", "", "\\"];
captionShifted: "N"; swipeCaptionShifted: ["", "", "", "", "", "", "L", ""]; symView: "2"; symView2: caption }
CharacterEaseKey {
caption: "i"; swipeCaption: ["", "", "", "", "", "x", "", ""]; swipeSpecial: ["", "", "", "?", "", "", "=", "£"];
caption: "i"; swipeCaption: ["", "", "", "", "", "x", "", ""]; swipeSpecial: ["¨", "°", "¸", "?", "", "", "=", "£"];
captionShifted: "I"; swipeCaptionShifted: ["", "", "", "", "", "X", "", ""]; symView: "3"; symView2: caption }
BackspaceKey {implicitWidth: symbol.width}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment