Unity 8
ScreenGrabber.qml
1 /*
2  * Copyright (C) 2014-2015 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.4
18 import ScreenGrabber 0.1
19 import GlobalShortcut 1.0
20 
21 Rectangle {
22  id: root
23  visible: false
24  color: "white"
25  anchors.fill: parent
26  opacity: 0.0
27 
28  // to be set from outside
29  property int rotationAngle: 0
30 
31  ScreenGrabber {
32  id: screenGrabber
33  objectName: "screenGrabber"
34  }
35 
36  GlobalShortcut {
37  id: screenshotShortcut
38  shortcut: Qt.Key_Print
39  onTriggered: capture()
40  }
41 
42  NotificationAudio {
43  id: shutterSound
44  source: "/system/media/audio/ui/camera_click.ogg"
45  }
46 
47  function capture() {
48  visible = true;
49  shutterSound.stop();
50  shutterSound.play();
51  fadeIn.start();
52  }
53 
54  NumberAnimation on opacity {
55  id: fadeIn
56  from: 0.0
57  to: 1.0
58  onStopped: {
59  if (visible) {
60  fadeOut.start();
61  }
62  }
63  }
64 
65  NumberAnimation on opacity {
66  id: fadeOut
67  from: 1.0
68  to: 0.0
69  onStopped: {
70  if (visible) {
71  screenGrabber.captureAndSave(root.rotationAngle);
72  visible = false;
73  }
74  }
75  }
76 }