Skip to content

Commit

Permalink
Merge pull request #164 from dobey/simplify-extended-swipe
Browse files Browse the repository at this point in the history
qml: Simplify extended keys swipe logic, and move to selector component
  • Loading branch information
dobey authored Mar 13, 2024
2 parents 9846f24 + 9803bab commit 0ea21b3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 38 deletions.
39 changes: 1 addition & 38 deletions qml/keys/CharKey.qml
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ Item {
property bool allowPreeditHandler: false
property var preeditHandler: null

// Don't detect swipe changes until the swipeTimer has expired to prevent
// accidentally selecting something other than the default extended key
property bool swipeReady: false

signal pressed()
signal released()
Expand Down Expand Up @@ -246,8 +243,6 @@ Item {
if (activeExtendedModel != undefined) {
Feedback.startPressEffect();

swipeReady = false;
swipeTimer.restart();
magnifier.shown = false
extendedKeysSelector.enabled = true
extendedKeysSelector.extendedKeysModel = activeExtendedModel
Expand Down Expand Up @@ -347,40 +342,8 @@ Item {
}
}

// Determine which extended key we're underneath when swiping,
// highlight it and set it as the currentExtendedKey (to be committed
// when press is released)
function evaluateSelectorSwipe() {
if (extendedKeysSelector.enabled && swipeReady) {
var extendedKeys = extendedKeysSelector.keys;
currentExtendedKey = null;
var keyMapping = extendedKeysSelector.mapToItem(key, extendedKeysSelector.rowX, extendedKeysSelector.rowY);
var mx = mouseX - keyMapping.x;
var my = mouseY - keyMapping.y;
for(var i = 0; i < extendedKeys.length; i++) {
var posX = extendedKeys[i].x;
var posY = extendedKeys[i].y;
if(mx > posX && mx < (posX + extendedKeys[i].width * 1.25 )
&& my > posY && my < (posY + extendedKeys[i].height * (extendedKeysSelector.multirow ? 1.3 : 2.5))) {
if(!extendedKeys[i].highlight) {
Feedback.startPressEffect();
}
extendedKeys[i].highlight = true;
currentExtendedKey = extendedKeys[i];
} else if('highlight' in extendedKeys[i]) {
extendedKeys[i].highlight = false;
}
}
}
}
}

Timer {
id: swipeTimer
interval: 750
onTriggered: {
swipeReady = true;
keyMouseArea.evaluateSelectorSwipe();
currentExtendedKey = extendedKeysSelector.evaluateSelectorSwipe(mouseX, mouseY);
}
}

Expand Down
27 changes: 27 additions & 0 deletions qml/keys/ExtendedKeysSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,33 @@ KeyPopover {
}
}

// Determine which extended key we're underneath when swiping,
// highlight it and set it as the currentExtendedKey (to be committed
// when press is released)
function evaluateSelectorSwipe(mouseX, mouseY) {
let currentExtendedKey = null;
if (enabled && currentlyAssignedKey != null) {
var keyMapping = mapToItem(currentlyAssignedKey, rowX, rowY);
var mx = mouseX - keyMapping.x;
var my = mouseY - keyMapping.y;
for (var i = 0; i < keys.length; i++) {
var posX = keys[i].x;
var posY = keys[i].y;
if (mx > posX && mx < (posX + keys[i].width)
&& my > posY && my < (posY + (keys[i].height * (posY == rowOfKeys.height - panel.keyHeight ? 2 : 1)))) {
if (!keys[i].highlight) {
Feedback.startPressEffect();
}
keys[i].highlight = true;
currentExtendedKey = keys[i];
} else if('highlight' in keys[i]) {
keys[i].highlight = false;
}
}
}
return currentExtendedKey;
}

function __restoreAssignedKey()
{
currentlyAssignedKey.state = "NORMAL"
Expand Down

0 comments on commit 0ea21b3

Please sign in to comment.