Debian Codegraph @

src/qml/common/visibilityBehaviors/TimeoutBehavior.qml

raw
1 /*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
16
17
18 import QtQuick 2.0
19
20 /*
21 This behavior will show the target onFocusIn and hide it
22 onFocusOut or after a timeout, regardless of focus.
23
24 If you forward key events to this behavior, the timer will
25 get reset on every Keys.onPress.
26
27 Binding forcedVisible to VisibilityController's forceVisible
28 will prevent the behavior to hide as soon as visibility is
29 unforced
30 */
31
32 BaseBehavior {
33 id: timeout
34
35 property bool forcedVisible: false
36 property alias interval: hideTimer.interval
37
38 function restartTimer() {
39 if (hideTimer.running) hideTimer.restart()
40 }
41
42 Timer {
43 id: hideTimer
44 interval: 3000
45 onTriggered: shown = false
46 }
47
48 Connections {
49 target: timeout.target
50 onActiveFocusChanged: {
51 if (timeout.target.activeFocus) {
52 shown = true
53 hideTimer.restart()
54 } else {
55 shown = false
56 hideTimer.stop()
57 }
58 }
59 }
60
61 onForcedVisibleChanged: {
62 if (forcedVisible) {
63 hideTimer.stop()
64 shown = true
65 } else {
66 hideTimer.restart()
67 }
68 }
69
70 Keys.onPressed: restartTimer()
71 }