on xenial help sign in
Use binding instead of function call to enable/disable screenshotting according to screen power status.
81298c9Alberto Aguirre
qml/Components/ScreenGrabber.qml+5−7
@@ -20,17 +20,17 @@ import ScreenGrabber 0.1
20
20
21Rectangle {
21Rectangle {
22 id: root
22 id: root
23− enabled: false
23+ enabled: true
24 visible: false
24 visible: false
25 color: "white"
25 color: "white"
26 anchors.fill: parent
26 anchors.fill: parent
27 opacity: 0.0
27 opacity: 0.0
28
28
29+
29 QtObject {
30 QtObject {
30 id: keyState
31 id: keyState
31 property bool volumeUpPressed: false
32 property bool volumeUpPressed: false
32 property bool volumeDownPressed: false
33 property bool volumeDownPressed: false
33− property bool ignoreKeyPresses: false
34 property bool ignoreKeyRepeats: false
34 property bool ignoreKeyRepeats: false
35 }
35 }
36
36
@@ -46,7 +46,7 @@ Rectangle {
46 }
46 }
47
47
48 function onKeyPressed(key) {
48 function onKeyPressed(key) {
49− if (keyState.ignoreKeyPresses || keyState.ignoreKeyRepeats)
49+ if (!enabled || keyState.ignoreKeyRepeats)
50 return;
50 return;
51
51
52 if (key == Qt.Key_VolumeUp)
52 if (key == Qt.Key_VolumeUp)
@@ -57,7 +57,6 @@ Rectangle {
57 if (keyState.volumeDownPressed && keyState.volumeUpPressed) {
57 if (keyState.volumeDownPressed && keyState.volumeUpPressed) {
58 // Only take one screenshot if both keys are held
58 // Only take one screenshot if both keys are held
59 keyState.ignoreKeyRepeats = true;
59 keyState.ignoreKeyRepeats = true;
60− enabled = true;
61 visible = true;
60 visible = true;
62 shutterSound.stop();
61 shutterSound.stop();
63 shutterSound.play();
62 shutterSound.play();
@@ -80,7 +79,7 @@ Rectangle {
80 from: 0.0
79 from: 0.0
81 to: 1.0
80 to: 1.0
82 onStopped: {
81 onStopped: {
83− if (enabled && visible) {
82+ if (visible) {
84 fadeOut.start();
83 fadeOut.start();
85 }
84 }
86 }
85 }
@@ -91,9 +90,8 @@ Rectangle {
91 from: 1.0
90 from: 1.0
92 to: 0.0
91 to: 0.0
93 onStopped: {
92 onStopped: {
94− if (enabled && visible) {
93+ if (visible) {
95 screenGrabber.captureAndSave();
94 screenGrabber.captureAndSave();
96− enabled = false;
97 visible = false;
95 visible = false;
98 }
96 }
99 }
97 }
qml/Shell.qml+1−6
@@ -135,12 +135,7 @@ Item {
135 ScreenGrabber {
135 ScreenGrabber {
136 id: screenGrabber
136 id: screenGrabber
137 z: edgeDemo.z + 10
137 z: edgeDemo.z + 10
138− }
139−
140− Binding {
141− target: screenGrabber
142− property: keyState.ignoreKeyPresses
143− value: Powerd.status === Powerd.Off
138+ enabled: Powerd.status === Powerd.On
144 }
139 }
145
140
146 Binding {
141 Binding {