2 * Copyright (C) 2014 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 \brief A filter for volume keys
21 A filter which treats volume keys as single tri-state key with the states:
22 VolumeUp Pressed, VolumeDown Pressed or Volume Up+Down pressed
27 signal volumeUpPressed()
28 signal volumeDownPressed()
29 signal bothVolumeKeysPressed()
31 property bool volumeUpKeyPressed: false
32 property bool volumeDownKeyPressed: false
33 property bool aVolumeKeyWasReleased: true
35 function onKeyPressed(key) {
36 if (key == Qt.Key_VolumeUp)
37 volumeUpKeyPressed = true;
38 else if (key == Qt.Key_VolumeDown)
39 volumeDownKeyPressed = true;
41 if (volumeDownKeyPressed && volumeUpKeyPressed) {
42 //avoids sending a signal repeatedly if both keys are held
43 //instead one of the keys must have been previously released
44 if (aVolumeKeyWasReleased)
45 bothVolumeKeysPressed();
46 aVolumeKeyWasReleased = false;
47 } else if (volumeDownKeyPressed) {
49 } else if (volumeUpKeyPressed) {
54 function onKeyReleased(key) {
55 if (key == Qt.Key_VolumeUp) {
56 volumeUpKeyPressed = false;
57 aVolumeKeyWasReleased = true;
58 } else if (key == Qt.Key_VolumeDown) {
59 volumeDownKeyPressed = false;
60 aVolumeKeyWasReleased = true;