Overte C++ Documentation
Snapshot.h
1 //
2 // Snapshot.h
3 // interface/src/ui
4 //
5 // Created by Stojce Slavkovski on 1/26/14.
6 // Copyright 2014 High Fidelity, Inc.
7 // Copyright 2022 Overte e.V.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 //
12 
13 #ifndef hifi_Snapshot_h
14 #define hifi_Snapshot_h
15 
16 #include <glm/glm.hpp>
17 
18 #include <QString>
19 #include <QStandardPaths>
20 #include <QUrl>
21 #include <QTimer>
22 #include <QtGui/QImage>
23 
24 #include <SettingHandle.h>
25 #include <DependencyManager.h>
26 
27 class QFile;
28 class QTemporaryFile;
29 
30 class SnapshotMetaData {
31 public:
32 
33  QUrl getURL() { return _URL; }
34  void setURL(QUrl URL) { _URL = URL; }
35 
36 private:
37  QUrl _URL;
38 };
39 
40 
41 /*@jsdoc
42  * The <code>Snapshot</code> API provides access to the path that snapshots are saved to. This path is that provided in
43  * Settings &gt; General &gt; Snapshots. Snapshots may be taken using <code>Window</code> API functions such as
44  * {@link Window.takeSnapshot}.
45  *
46  * @namespace Snapshot
47  *
48  * @hifi-interface
49  * @hifi-client-entity
50  * @hifi-avatar
51  */
52 
53 class Snapshot : public QObject, public Dependency {
54  Q_OBJECT
55  SINGLETON_DEPENDENCY
56 public:
57  Snapshot();
58  QString saveSnapshot(QImage image, const QString& filename, const QString& pathname = QString());
59  void save360Snapshot(const glm::vec3& cameraPosition,
60  const bool& cubemapOutputFormat,
61  const bool& notify,
62  const QString& filename);
63  QTemporaryFile* saveTempSnapshot(QImage image);
64  SnapshotMetaData* parseSnapshotData(QString snapshotPath);
65 
66  Setting::Handle<QString> _snapshotsLocation{ "snapshotsLocation" };
67  Setting::Handle<bool> _snapshotNotifications{ "snapshotNotifications", true };
68  Setting::Handle<QString> _snapshotFormat{ "snapshotFormat" };
69  Setting::Handle<QString> _animatedSnapshotFormat{ "animatedSnapshotFormat" };
70  void uploadSnapshot(const QString& filename, const QUrl& href = QUrl(""));
71 
72 signals:
73 
74  /*@jsdoc
75  * Triggered when the path that snapshots are saved to is changed.
76  * @function Snapshot.snapshotLocationSet
77  * @param {string} location - The new snapshots location.
78  * @returns {Signal}
79  * @example <caption>Report when the snapshots location is changed.</caption>
80  * // Run this script then change the snapshots location in Settings > General > Snapshots.
81  * Snapshot.snapshotLocationSet.connect(function (path) {
82  * print("New snapshot location: " + path);
83  * });
84  */
85  void snapshotLocationSet(const QString& value);
86 
87 public slots:
88 
89  /*@jsdoc
90  * Gets the path that snapshots are saved to.
91  * @function Snapshot.getSnapshotsLocation
92  * @returns {string} The path to save snapshots to.
93  */
94  Q_INVOKABLE QString getSnapshotsLocation();
95 
96  /*@jsdoc
97  * Sets the path that snapshots are saved to.
98  * @function Snapshot.setSnapshotsLocation
99  * @param {String} location - The path to save snapshots to.
100  */
101  Q_INVOKABLE void setSnapshotsLocation(const QString& location);
102 
103  /*@jsdoc
104  * Gets the currently selected snapshot format.
105  * @function Snapshot.getSnapshotFormat
106  * @returns {string} Currently selected snapshot format.
107  */
108  Q_INVOKABLE QString getSnapshotFormat();
109 
110  /*@jsdoc
111  * Sets the snapshot format.
112  * @function Snapshot.setSnapshotFormat
113  * @param {String} format - one of the format names returned by Snapshot.getAvailableSnapshotFormats().
114  */
115  Q_INVOKABLE void setSnapshotFormat(const QString& format);
116 
117  /*@jsdoc
118  * Gets the currently selected animated snapshot format.
119  * @function Snapshot.getAnimatedSnapshotFormat
120  * @returns {Array.<string>} Currently selected snapshot format.
121  */
122  Q_INVOKABLE QString getAnimatedSnapshotFormat();
123 
124  /*@jsdoc
125  * Sets the snapshot format.
126  * @function Snapshot.setAnimatedSnapshotFormat
127  * @param {String} format - one of the format names returned by Snapshot.getAvailableSnapshotFormats().
128  */
129  Q_INVOKABLE void setAnimatedSnapshotFormat(const QString& format);
130 
131  /*@jsdoc
132  * Returns a list of supported snapshot formats.
133  * @function Snapshot.getAvailableSnapshotFormats
134  * @returns {Array.<string>} List of supported snapshot formats.
135  */
136  Q_INVOKABLE QStringList getAvailableSnapshotFormats();
137 
138  /*@jsdoc
139  * Returns a list of supported snapshot formats with short descriptions.
140  * @function Snapshot.getAvailableSnapshotFormatsWithDescriptions
141  * @returns {Array.<string>} List of supported snapshot formats with short descriptions.
142  */
143  Q_INVOKABLE QStringList getAvailableSnapshotFormatsWithDescriptions();
144 
145  /*@jsdoc
146  * Returns a list of supported animated snapshot formats.
147  * @function Snapshot.getAvailableAnimatedSnapshotFormats
148  * @returns {Array.<string>} List of supported animated snapshot formats.
149  */
150  Q_INVOKABLE QStringList getAvailableAnimatedSnapshotFormats();
151 
152  /*@jsdoc
153  * Returns a list of supported animated snapshot formats with short descriptions.
154  * @function Snapshot.getAvailableAnimatedSnapshotFormatsWithDescriptions
155  * @returns {Array.<string>} List of supported animated snapshot formats with short descriptions.
156  */
157  Q_INVOKABLE QStringList getAvailableAnimatedSnapshotFormatsWithDescriptions();
158 
159 
160 
161 private slots:
162  void takeNextSnapshot();
163 
164 private:
165  QFile* savedFileForSnapshot(QImage& image,
166  bool isTemporary,
167  const QString& userSelectedFilename = QString(),
168  const QString& userSelectedPathname = QString());
169  QString _snapshotFilename;
170  bool _notify360;
171  bool _cubemapOutputFormat;
172  QTimer _snapshotTimer;
173  qint16 _snapshotIndex;
174  bool _waitingOnSnapshot { false };
175  bool _taking360Snapshot { false };
176  bool _oldEnabled;
177  QVariant _oldAttachedEntityId;
178  QVariant _oldOrientation;
179  QVariant _oldvFoV;
180  QVariant _oldNearClipPlaneDistance;
181  QVariant _oldFarClipPlaneDistance;
182  QImage _imageArray[6];
183  void convertToCubemap();
184  void convertToEquirectangular();
185 };
186 
187 #endif // hifi_Snapshot_h