on xenial help sign in
move screenshot animation to its own qml file
commit77bdac279cfc1e9f66fdfdbb6d0873dedca8a3d1 authorAlberto Aguirre <alberto.aguirre@canonical.com> dateFri 26 Sep 2014, 21:19 (12 years ago) parent86331ae
2 files changed+87−66
qml/Components/ScreenGrabber.qml+81 qml/Shell.qml+6−66
qml/Components/ScreenGrabber.qmlnew file+81
@@ -0,0 +1,81 @@
1+/*
2+ * Copyright (C) 2014 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+import QtQuick 2.0
18+import ScreenGrabber 0.1
19+
20+Rectangle {
21+ id: root
22+ enabled: false
23+ visible: false
24+ color: "white"
25+ anchors.fill: parent
26+ opacity: 0.0
27+
28+ QtObject {
29+ id: keyState
30+ property bool volumeUp: false
31+ property bool volumeDown: false
32+ }
33+
34+ ScreenGrabber {
35+ id: screenGrabber
36+ objectName: "screenGrabber"
37+ }
38+
39+ function onKeyPressed(key) {
40+ if (key == Qt.Key_VolumeUp)
41+ keyState.volumeUp = true;
42+ else if (key == Qt.Key_VolumeDown)
43+ keyState.volumeDown = true;
44+ if (keyState.volumeDown && keyState.volumeUp) {
45+ enabled = true;
46+ visible = true;
47+ fadeIn.start();
48+ }
49+ }
50+
51+ function onKeyReleased(key) {
52+ if (key == Qt.Key_VolumeUp)
53+ keyState.volumeUp = false;
54+ else if (key == Qt.Key_VolumeDown)
55+ keyState.volumeDown = false;
56+ }
57+
58+ NumberAnimation on opacity {
59+ id: fadeIn
60+ from: 0.0
61+ to: 1.0
62+ onStopped: {
63+ if (enabled && visible) {
64+ fadeOut.start()
65+ }
66+ }
67+ }
68+
69+ NumberAnimation on opacity {
70+ id: fadeOut
71+ from: 1.0
72+ to: 0.0
73+ onStopped: {
74+ if (enabled && visible) {
75+ screenGrabber.captureAndSave();
76+ enabled = false
77+ visible = false
78+ }
79+ }
80+ }
81+}
qml/Shell.qml+6−66
@@ -30,7 +30,6 @@ import Utils 0.1
3030import LightDM 0.1 as LightDM
3131import Powerd 0.1
3232import SessionBroadcast 0.1
33−import Screenshotter 0.1
3433import "Greeter"
3534import "Launcher"
3635import "Panel"
@@ -128,10 +127,10 @@ Item {
128127 id: dash
129128 objectName: "dashCommunicator"
130129 }
131−
132− Screenshotter {
133− id: screenShotter
134− objectName: "screenShotter"
130+
131+ ScreenGrabber {
132+ id: screenGrabber
133+ z: edgeDemo.z + 10
135134 }
136135
137136 WindowKeysFilter {
@@ -140,7 +139,7 @@ Item {
140139 Keys.onVolumeDownPressed: { volumeControl.volumeDown(); event.accepted = false; }
141140
142141 Keys.onPressed: {
143− screenshotAnimation.onKeyPressed(event.key);
142+ screenGrabber.onKeyPressed(event.key);
144143 if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
145144 dialogs.onPowerKeyPressed();
146145 event.accepted = true;
@@ -150,7 +149,7 @@ Item {
150149 }
151150
152151 Keys.onReleased: {
153− screenshotAnimation.onKeyReleased(event.key);
152+ screenGrabber.onKeyReleased(event.key);
154153 if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
155154 dialogs.onPowerKeyReleased();
156155 event.accepted = true;
@@ -699,65 +698,6 @@ Item {
699698 }
700699 }
701700 }
702− }
703−
704− Rectangle {
705− id: screenshotAnimation
706− z: edgeDemo.z + 10
707− enabled: false
708− visible: false
709− color: "white"
710− anchors.fill: parent
711− opacity: 0.0
712−
713− QtObject {
714− id: state
715− property bool volumeUp: false
716− property bool volumeDown: false
717− }
718−
719− function onKeyPressed(key) {
720− if (key == Qt.Key_VolumeUp)
721− state.volumeUp = true;
722− else if (key == Qt.Key_VolumeDown)
723− state.volumeDown = true;
724− if (state.volumeDown && state.volumeUp) {
725− enabled = true;
726− visible = true;
727− screenshotFadeIn.start();
728− }
729− }
730−
731− function onKeyReleased(key) {
732− if (key == Qt.Key_VolumeUp)
733− state.volumeUp = false;
734− else if (key == Qt.Key_VolumeDown)
735− state.volumeDown = false;
736− }
737−
738− NumberAnimation on opacity {
739− id: screenshotFadeIn
740− from: 0.0
741− to: 1.0
742− onStopped: {
743− if (screenshotAnimation.enabled && screenshotAnimation.visible) {
744− screenshotFadeOut.start()
745− }
746− }
747− }
748−
749− NumberAnimation on opacity {
750− id: screenshotFadeOut
751− from: 1.0
752− to: 0.0
753− onStopped: {
754− if (screenshotAnimation.enabled && screenshotAnimation.visible) {
755− screenShotter.takeScreenshot();
756− screenshotAnimation.enabled = false
757− screenshotAnimation.visible = false
758− }
759− }
760− }
761701 }
762702
763703}