Unity 8
 All Classes Functions
ScreenGrabber.qml
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 QtMultimedia 5.0
19 import ScreenGrabber 0.1
20 
21 Rectangle {
22  id: root
23  enabled: true
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  Audio {
35  id: shutterSound
36  audioRole: MediaPlayer.alert
37  source: "/system/media/audio/ui/camera_click.ogg"
38  }
39 
40  function capture() {
41  if (!enabled)
42  return;
43 
44  visible = true;
45  shutterSound.stop();
46  shutterSound.play();
47  fadeIn.start();
48  }
49 
50  NumberAnimation on opacity {
51  id: fadeIn
52  from: 0.0
53  to: 1.0
54  onStopped: {
55  if (visible) {
56  fadeOut.start();
57  }
58  }
59  }
60 
61  NumberAnimation on opacity {
62  id: fadeOut
63  from: 1.0
64  to: 0.0
65  onStopped: {
66  if (visible) {
67  screenGrabber.captureAndSave();
68  visible = false;
69  }
70  }
71  }
72 }