yubioath-flutter/qml/ArrowKeysSelecter.qml
Dag Heyman ffb55773f3
Refactor out selected
The variables for selected credentials
was treated as global variables,
so it makes more sense to bind it to appWindow.
2017-03-30 10:23:04 +02:00

39 lines
1.0 KiB
QML

import QtQuick 2.5
Item {
focus: true
property var credRepeater
property int nCreds: credRepeater.model.length
property bool nothingSelected: selectedIndex === null
property var firstCred: credRepeater.model[0]
property var lastCred: credRepeater.model[nCreds - 1]
property bool lastCredSelected: selectedIndex === nCreds - 1
property bool firstCredSeleced: selectedIndex === 0
Keys.onDownPressed: {
flickable.flick(0, -300)
if (nothingSelected) {
selected = firstCred
selectedIndex = 0
} else if (!lastCredSelected) {
selected = credRepeater.model[selectedIndex + 1]
selectedIndex = selectedIndex + 1
}
}
Keys.onUpPressed: {
flickable.flick(0, 300)
if (nothingSelected) {
selected = lastCred
selectedIndex = nCreds - 1
} else if (!firstCredSeleced) {
selected = credRepeater.model[selectedIndex - 1]
selectedIndex = selectedIndex - 1
}
}
}