on xenial help sign in
Privitize internal properties in PhysicalKeysMapper
commitffe76cc5e4c7beec05d7549dc976d79ce84ac212 authorJosh Arenson <joshua.arenson@canonical.com> dateThu 11 Dec 2014, 14:20 (12 years ago) parent64d4212
2 files changed+23−42
qml/Components/PhysicalKeysMapper.qml+23−28 tests/qmltests/Components/tst_PhysicalKeysMapper.qml−14
qml/Components/PhysicalKeysMapper.qml+23−28
@@ -30,63 +30,60 @@ import QtQuick 2.0
3030
3131*/
3232
33−QtObject {
33+Item {
3434 id: root
3535
36− signal bothVolumeKeysPressed();
3736 signal powerKeyLongPress();
3837 signal screenshotPressed();
3938 signal volumeDownPressed();
4039 signal volumeUpPressed();
4140
42− property bool aPowerKeyWasReleased: true
43− property bool powerKeyPressed: false
41+ QtObject {
42+ id: d
4443
45− property bool aVolumeKeyWasReleased: true
46− property bool volumeDownKeyPressed: false
47− property bool volumeUpKeyPressed: false
44+ property bool aPowerKeyWasReleased: true
45+ property bool powerKeyPressed: false
46+
47+ property bool volumeDownKeyPressed: false
48+ property bool volumeUpKeyPressed: false
49+ }
4850
4951 // FIXME: event.isAutoRepeat is always false on Nexus 4.
5052 // So we use powerKeyTimer.running to avoid the PowerOff key repeat
5153 // https://launchpad.net/bugs/1349416
52− property variant pklpt: Timer {
54+ Timer {
5355 id: powerKeyLongPressTimer
5456
5557 interval: 2000
5658 repeat: false
5759 triggeredOnStart: false
58−
5960 onTriggered: powerKeyLongPress();
6061 }
6162
63+
6264 function onKeyPressed(key) {
6365 /* Determine what key was pressed */
6466 if (key == Qt.Key_PowerDown || key == Qt.Key_PowerOff) {
6567 if (!powerKeyLongPressTimer.running) {
6668 powerKeyLongPressTimer.restart();
6769 }
68− powerKeyPressed = true;
70+ d.powerKeyPressed = true;
6971 } else if (key == Qt.Key_VolumeDown) {
70− volumeDownKeyPressed = true;
72+ d.volumeDownKeyPressed = true;
7173 } else if (key == Qt.Key_VolumeUp) {
72− volumeUpKeyPressed = true;
74+ d.volumeUpKeyPressed = true;
7375 }
7476
7577 /* Determine how to handle it */
76− if (volumeDownKeyPressed && volumeUpKeyPressed) {
77− if (aVolumeKeyWasReleased) {
78− bothVolumeKeysPressed();
79− }
80− aVolumeKeyWasReleased = false;
81− } else if (volumeDownKeyPressed) {
82− if (powerKeyPressed && aPowerKeyWasReleased) {
78+ if (d.volumeDownKeyPressed) {
79+ if (d.powerKeyPressed && d.aPowerKeyWasReleased) {
8380 screenshotPressed();
84− aPowerKeyWasReleased = false;
81+ d.aPowerKeyWasReleased = false;
8582 // Don't emit volumeDownPressed if power key is held
86− } else if (aPowerKeyWasReleased){
83+ } else if (d.aPowerKeyWasReleased){
8784 volumeDownPressed();
8885 }
89− } else if (volumeUpKeyPressed) {
86+ } else if (d.volumeUpKeyPressed) {
9087 volumeUpPressed();
9188 }
9289 }
@@ -94,14 +91,12 @@ QtObject {
9491 function onKeyReleased(key) {
9592 if (key == Qt.Key_PowerDown || key == Qt.Key_PowerOff) {
9693 powerKeyLongPressTimer.stop();
97− powerKeyPressed = false;
98− aPowerKeyWasReleased = true;
94+ d.powerKeyPressed = false;
95+ d.aPowerKeyWasReleased = true;
9996 } else if (key == Qt.Key_VolumeDown) {
100− volumeDownKeyPressed = false;
101− aVolumeKeyWasReleased = false;
97+ d.volumeDownKeyPressed = false;
10298 } else if (key == Qt.Key_VolumeUp) {
103− volumeUpKeyPressed = false;
104− aVolumeKeyWasReleased = true;
99+ d.volumeUpKeyPressed = false;
105100 }
106101 }
107102}
tests/qmltests/Components/tst_PhysicalKeysMapper.qml−14
@@ -21,7 +21,6 @@ import "../../../qml/Components"
2121TestCase {
2222 name: "PhysicalKeysMapper"
2323
24− property int onBothVolumeKeysPressedCount: 0
2524 property int onPowerKeyLongPressCount: 0
2625 property int onScreenshotPressedCount: 0
2726 property int onVolumeDownPressedCount: 0
@@ -30,7 +29,6 @@ TestCase {
3029 PhysicalKeysMapper {
3130 id: physicalKeysMapper
3231
33− onBothVolumeKeysPressed: onBothVolumeKeysPressedCount += 1
3432 onPowerKeyLongPress: onPowerKeyLongPressCount += 1
3533 onScreenshotPressed: onScreenshotPressedCount += 1
3634 onVolumeDownPressed: onVolumeDownPressedCount += 1
@@ -43,24 +41,12 @@ TestCase {
4341 physicalKeysMapper.onKeyReleased(Qt.Key_VolumeDown);
4442 physicalKeysMapper.onKeyReleased(Qt.Key_VolumeUp);
4543
46− onBothVolumeKeysPressedCount = 0;
4744 onPowerKeyLongPressCount = 0;
4845 onScreenshotPressedCount = 0;
4946 onVolumeDownPressedCount = 0;
5047 onVolumeUpPressedCount = 0;
5148 }
5249
53− function test_BothVolumeKeysSimultaneously() {
54− physicalKeysMapper.onKeyPressed(Qt.Key_VolumeDown);
55− physicalKeysMapper.onKeyPressed(Qt.Key_VolumeUp);
56−
57− compare(onBothVolumeKeysPressedCount, 1);
58−
59− // Simulate holding the keys down
60− wait(3000);
61− compare(onBothVolumeKeysPressedCount, 1);
62− }
63−
6450 function test_LongPressPowerButton() {
6551 physicalKeysMapper.onKeyPressed(Qt.Key_PowerDown);
6652 wait(3000);