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