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