1 | // Copyright (C) 2023 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QWINDOWCAPTURE_H |
5 | #define QWINDOWCAPTURE_H |
6 | |
7 | #include <QtMultimedia/qtmultimediaexports.h> |
8 | #include <QtMultimedia/qcapturablewindow.h> |
9 | #include <QtCore/qobject.h> |
10 | #include <QtCore/qlist.h> |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | class QPlatformSurfaceCapture; |
15 | |
16 | class Q_MULTIMEDIA_EXPORT QWindowCapture : public QObject |
17 | { |
18 | Q_OBJECT |
19 | Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) |
20 | Q_PROPERTY(QCapturableWindow window READ window WRITE setWindow NOTIFY windowChanged) |
21 | Q_PROPERTY(Error error READ error NOTIFY errorChanged) |
22 | Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) |
23 | public: |
24 | enum Error { |
25 | NoError = 0, |
26 | InternalError = 1, |
27 | CapturingNotSupported = 2, |
28 | CaptureFailed = 4, |
29 | NotFound = 5, |
30 | }; |
31 | Q_ENUM(Error) |
32 | |
33 | explicit QWindowCapture(QObject *parent = nullptr); |
34 | ~QWindowCapture() override; |
35 | |
36 | Q_INVOKABLE static QList<QCapturableWindow> capturableWindows(); |
37 | |
38 | QMediaCaptureSession *captureSession() const; |
39 | |
40 | void setWindow(QCapturableWindow window); |
41 | |
42 | QCapturableWindow window() const; |
43 | |
44 | bool isActive() const; |
45 | |
46 | Error error() const; |
47 | QString errorString() const; |
48 | |
49 | public Q_SLOTS: |
50 | void setActive(bool active); |
51 | void start() { setActive(true); } |
52 | void stop() { setActive(false); } |
53 | |
54 | Q_SIGNALS: |
55 | void activeChanged(bool); |
56 | void windowChanged(QCapturableWindow window); |
57 | void errorChanged(); |
58 | void errorOccurred(QWindowCapture::Error error, const QString &errorString); |
59 | |
60 | private: |
61 | void setCaptureSession(QMediaCaptureSession *captureSession); |
62 | QPlatformSurfaceCapture *platformWindowCapture() const; |
63 | |
64 | friend class QMediaCaptureSession; |
65 | Q_DISABLE_COPY(QWindowCapture) |
66 | Q_DECLARE_PRIVATE(QWindowCapture) |
67 | }; |
68 | |
69 | QT_END_NAMESPACE |
70 | |
71 | #endif // QWINDOWCAPTURE_H |
72 |