Commit 5a9eb9c3 authored by Sebastian Gottfried's avatar Sebastian Gottfried
Browse files

training screen: allow multiple highlighted keys for the next character

Based on a patch by Peter Feigl <craven@gmx.net>

This useful for training on chorded keyboards where one has to press
multiple keys at the same time to produce a character.

BUG: 315448
FIXED-IN: 4.11.0
parent a5b5a587
/*
* Copyright 2012 Sebastian Gottfried <sebastiangottfried@web.de>
* Copyright 2013 Sebastian Gottfried <sebastiangottfried@web.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -29,40 +29,49 @@ Item {
function keyItems() {
var items = []
for (var i = 0; i < keys.count; i++)
for (var i = 0; i < keys.count; i++) {
items.push(keys.itemAt(i))
}
return items
}
function findKeyItem(keyChar) {
function findKeyItems(keyChar) {
var matchingKeys = []
for (var i = 0; i < keys.count; i++) {
var key = keys.itemAt(i);
if (key.match(keyChar))
return key
matchingKeys.push(key)
}
return null
return matchingKeys
}
function findModifierKeyItem(modifierId) {
for (var i = 0; i < keys.count; i++) {
var key = keys.itemAt(i);
if (key.key.keyType() == "specialKey" && key.key.modifierId == modifierId)
if (key.key.keyType() === "specialKey" && key.key.modifierId === modifierId)
return key
}
return null
}
function handleKeyPress(event) {
var key = findKeyItem(event)
if (key)
key.pressed = true
var eventKeys = findKeyItems(event)
for (var i = 0; i < eventKeys.length; i++) {
eventKeys[i].pressed = true
}
}
function handleKeyRelease(event) {
var key = findKeyItem(event)
if (key)
key.pressed = false
var eventKeys = findKeyItems(event)
for (var i = 0; i < eventKeys.length; i++) {
eventKeys[i].pressed = false
}
}
Item {
......
/*
* Copyright 2012 Sebastian Gottfried <sebastiangottfried@web.de>
* Copyright 2013 Sebastian Gottfried <sebastiangottfried@web.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -199,27 +199,30 @@ FocusScope {
function highlightKey(which) {
for (var i = 0; i < highlightedKeys.length; i++)
highlightedKeys[i].isHighlighted = false
var key = findKeyItem(which)
if (key) {
var newHighlightedKeys = []
key.isHighlighted = true
newHighlightedKeys.push(key)
if (typeof which == "string") {
var code = which.charCodeAt(0)
for (var i = 0; i < key.key.keyCharCount; i++) {
var keyChar = key.key.keyChar(i)
if (keyChar.value == code && keyChar.modifier != "") {
var modifier = findModifierKeyItem(keyChar.modifier)
if (modifier) {
modifier.isHighlighted = true
newHighlightedKeys.push(modifier)
var keys = findKeyItems(which)
var newHighlightedKeys = []
for (var index = 0; index < keys.length ; index++) {
var key = keys[index]
if (key) {
key.isHighlighted = true
newHighlightedKeys.push(key)
if (typeof which == "string") {
var code = which.charCodeAt(0)
for (var i = 0; i < key.key.keyCharCount; i++) {
var keyChar = key.key.keyChar(i)
if (keyChar.value == code && keyChar.modifier != "") {
var modifier = findModifierKeyItem(keyChar.modifier)
if (modifier) {
modifier.isHighlighted = true
newHighlightedKeys.push(modifier)
}
break
}
break
}
}
}
highlightedKeys = newHighlightedKeys
}
highlightedKeys = newHighlightedKeys
}
function updateKeyHighlighting() {
......
Supports Markdown
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