How can I achieve 26 touch points
-
How can I modify my code such that I have 26 touch points instead of 17 while keeping the format:
A • D • G • J • M • P • S • V • Z
. The•
is supposed to represent the missing letters(indices). For example, If I was to click or drag betweenA • D
. My expected results should either outputB 1 or C 2
.Currently, if you run the code as is, clicking or dragging between
A • D
, depending on the placement of your mouse index the output would beA 0 or D 1
.import QtQuick 2.15 import QtQuick.Window 2.15 import QtQml 2.15 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Rectangle { id: root visible: true property string letters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ" function newLetters(index) { if(index % 2 === 0){ if(index === 16) return root.letters[25] else return root.letters[index/2 * 3] } else return "•" } Repeater { model: 17 Text { property double angle: 1.08 * (index + 2) * Math.PI / 21 - Math.PI/2 x: 515 + 90 * Math.cos(angle) y: 205 + 150 * Math.sin(angle) text: root.newLetters(index) objectName: root.newLetters(index) property int idx: index } } } MouseArea { id: mouseArea anchors.fill: parent onPressed: processTap(Qt.point(mouse.x, mouse.y)) onPositionChanged: processTap(Qt.point(mouse.x, mouse.y)) function processTap(pos) { var closestActiveLetter; var closestDistance = Infinity; var closestIdx = -1; for(var i = 0; i < root.children.length; i++) { var item = root.children[i]; if(!item.objectName || item.objectName === "•") { continue; } pos = mapToItem(root, pos) var disx = pos.x - item.x var disy = pos.y - item.y var distance = Math.sqrt(disx * disx + disy * disy ); if(distance < closestDistance) { closestDistance = distance; closestActiveLetter = item.objectName; closestIdx = item.idx; } } if(closestActiveLetter) { console.log(closestActiveLetter, closestIdx); } } } }
-
Hi,
Might be a silly idea (and I currently don't know the performance hit for that one) but why not have one mouse area per Text object ?