Debian Codegraph @

src/qml/common/VisibilityController.qml

raw
1 /*
2 * This file is part of unity-2d
3 *
4 * Copyright 2012 Canonical Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 import QtQuick 2.0
20 import "utils.js" as Utils
21
22 Item {
23 id: controller
24 property bool shown: true
25 property variant behavior: null
26 property bool forceVisible: false
27 property bool forceHidden: false
28 property variant forceVisibleChangeId
29 property variant forceVisibleStack: ({})
30 property variant forceHiddenStack: ({})
31
32 Binding {
33 target: controller
34 property: "shown"
35 value: (!forceHidden) ? forceVisible || behavior.shown : false
36 when: behavior != null
37 }
38
39 function beginForceVisible(id) {
40 /* We need to copy the property to a JS variable before we can properly interact
41 with it and then copy it back to the QML property when done. This seems to be
42 a limitation of QML that will be fixed in QtQuick 2.0. For more information:
43 https://bugreports.qt.nokia.com/browse/QTBUG-21842
44 */
45 var stack = controller.forceVisibleStack
46 var wasEmpty = Utils.hashEmpty(stack)
47
48 if (forceHidden) console.log("DEBUG: beginForceVisible for id \"" + id +
49 "\" called when forceHidden still true")
50
51 if (stack[id]) stack[id] += 1
52 else stack[id] = 1
53 controller.forceVisibleStack = stack
54
55 if (wasEmpty) {
56 forceVisibleChangeId = id
57 forceVisible = true
58 }
59 }
60
61 function endForceVisible(id) {
62 var stack = controller.forceVisibleStack
63
64 if (stack[id]) {
65 stack[id] -= 1
66 if (stack[id] === 0) delete stack[id]
67 } else console.log("DEBUG: endForceVisible for id \"" + id +
68 "\" called without matching startForceVisible")
69
70 controller.forceVisibleStack = stack
71 if (Utils.hashEmpty(stack)) {
72 forceVisibleChangeId = id
73 forceVisible = false
74 }
75 }
76
77 function beginForceHidden(id) {
78 var stack = controller.forceHiddenStack
79 var wasEmpty = Utils.hashEmpty(stack)
80
81 if (forceVisible) console.log("DEBUG: beginForceHidden for id \"" + id +
82 "\" called when forceVisible still true")
83
84 if (stack[id]) stack[id] += 1
85 else stack[id] = 1
86 controller.forceHiddenStack = stack
87
88 if (wasEmpty) {
89 forceVisibleChangeId = id
90 forceHidden = true
91 }
92 }
93
94 function endForceHidden(id) {
95 var stack = controller.forceHiddenStack
96
97 if (stack[id]) {
98 stack[id] -= 1
99 if (stack[id] === 0) delete stack[id]
100 } else console.log("DEBUG: endForceHidden for id \"" + id +
101 "\" called without matching startForceHidden")
102
103 controller.forceHiddenStack = stack
104 if (Utils.hashEmpty(stack)) {
105 forceVisibleChangeId = id
106 forceHidden = false
107 }
108 }
109 }