Commit 15ed1170 authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

applets/calculator: move focus to the corresponding button when pressing keys

This allows the button to get focus so a screen reader can read the
text.
parent 8b918d58
......@@ -48,35 +48,40 @@ QQC2.Control {
// When calculating 1/3 the answer is
// 18 characters long.
Keys.onDigit0Pressed: { digitClicked(0); }
Keys.onDigit1Pressed: { digitClicked(1); }
Keys.onDigit2Pressed: { digitClicked(2); }
Keys.onDigit3Pressed: { digitClicked(3); }
Keys.onDigit4Pressed: { digitClicked(4); }
Keys.onDigit5Pressed: { digitClicked(5); }
Keys.onDigit6Pressed: { digitClicked(6); }
Keys.onDigit7Pressed: { digitClicked(7); }
Keys.onDigit8Pressed: { digitClicked(8); }
Keys.onDigit9Pressed: { digitClicked(9); }
Keys.onEscapePressed: { allClearClicked(); }
Keys.onDeletePressed: { clearClicked(); }
Keys.onDigit0Pressed: { digitClicked(0); zeroButton.forceActiveFocus(); }
Keys.onDigit1Pressed: { digitClicked(1); oneButton.forceActiveFocus(); }
Keys.onDigit2Pressed: { digitClicked(2); twoButton.forceActiveFocus(); }
Keys.onDigit3Pressed: { digitClicked(3); threeButton.forceActiveFocus(); }
Keys.onDigit4Pressed: { digitClicked(4); fourButton.forceActiveFocus(); }
Keys.onDigit5Pressed: { digitClicked(5); fiveButton.forceActiveFocus(); }
Keys.onDigit6Pressed: { digitClicked(6); sixButton.forceActiveFocus(); }
Keys.onDigit7Pressed: { digitClicked(7); sevenButton.forceActiveFocus(); }
Keys.onDigit8Pressed: { digitClicked(8); eightButton.forceActiveFocus(); }
Keys.onDigit9Pressed: { digitClicked(9); nineButton.forceActiveFocus(); }
Keys.onEscapePressed: { allClearClicked(); allClearButton.forceActiveFocus(); }
Keys.onDeletePressed: { clearClicked(); clearButton.forceActiveFocus(); }
Keys.onPressed: {
switch (event.key) {
case Qt.Key_Plus:
setOperator("+");
plusButton.forceActiveFocus();
break;
case Qt.Key_Minus:
setOperator("-");
minusButton.forceActiveFocus();
break;
case Qt.Key_Asterisk:
setOperator("*");
multiplyButton.forceActiveFocus();
break;
case Qt.Key_Slash:
setOperator("/");
divideButton.forceActiveFocus();
break;
case Qt.Key_Comma:
case Qt.Key_Period:
decimalClicked();
decimalButton.forceActiveFocus();
break;
case Qt.Key_Equal:
case Qt.Key_Return:
......@@ -283,6 +288,8 @@ QQC2.Control {
Layout.fillHeight: true
PlasmaComponents.Button {
id: clearButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -292,6 +299,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: divideButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -300,6 +309,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: multiplyButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -308,6 +319,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: allClearButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -317,6 +330,8 @@ QQC2.Control {
PlasmaComponents.Button {
id: sevenButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -325,6 +340,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: eightButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -333,6 +350,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: nineButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -341,6 +360,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: minusButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -350,6 +371,8 @@ QQC2.Control {
PlasmaComponents.Button {
id: fourButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -358,6 +381,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: fiveButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -367,6 +392,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: sixButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -375,6 +402,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: plusButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -384,6 +413,8 @@ QQC2.Control {
PlasmaComponents.Button {
id: oneButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -392,6 +423,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: twoButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -400,6 +433,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: threeButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -408,7 +443,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: ansButton;
id: ansButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -418,6 +454,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: zeroButton
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -427,6 +465,8 @@ QQC2.Control {
}
PlasmaComponents.Button {
id: decimalButton
Layout.fillWidth: true
Layout.fillHeight: true
......
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