1// Copyright (C) 2022 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 QSCREENCAPTURE_H
5#define QSCREENCAPTURE_H
6
7#include <QtCore/qobject.h>
8#include <QtCore/qnamespace.h>
9#include <QtGui/qscreen.h>
10#include <QtGui/qwindow.h>
11#include <QtGui/qwindowdefs.h>
12#include <QtMultimedia/qtmultimediaglobal.h>
13
14QT_BEGIN_NAMESPACE
15
16class QMediaCaptureSession;
17class QPlatformSurfaceCapture;
18class QScreenCapturePrivate;
19
20class Q_MULTIMEDIA_EXPORT QScreenCapture : public QObject
21{
22 Q_OBJECT
23 Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
24 Q_PROPERTY(QScreen *screen READ screen WRITE setScreen NOTIFY screenChanged)
25 Q_PROPERTY(Error error READ error NOTIFY errorChanged)
26 Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
27
28public:
29 enum Error {
30 NoError = 0,
31 InternalError = 1,
32 CapturingNotSupported = 2,
33 CaptureFailed = 4,
34 NotFound = 5,
35 };
36 Q_ENUM(Error)
37
38 explicit QScreenCapture(QObject *parent = nullptr);
39 ~QScreenCapture() override;
40
41 QMediaCaptureSession *captureSession() const;
42
43 void setScreen(QScreen *screen);
44 QScreen *screen() const;
45
46 bool isActive() const;
47
48 Error error() const;
49 QString errorString() const;
50
51public Q_SLOTS:
52 void setActive(bool active);
53 void start() { setActive(true); }
54 void stop() { setActive(false); }
55
56Q_SIGNALS:
57 void activeChanged(bool);
58 void errorChanged();
59 void screenChanged(QScreen *);
60 void errorOccurred(QScreenCapture::Error error, const QString &errorString);
61
62private:
63 void setCaptureSession(QMediaCaptureSession *captureSession);
64 QPlatformSurfaceCapture *platformScreenCapture() const;
65 friend class QMediaCaptureSession;
66 Q_DISABLE_COPY(QScreenCapture)
67 Q_DECLARE_PRIVATE(QScreenCapture)
68};
69
70QT_END_NAMESPACE
71
72#endif // QSCREENCAPTURE_H
73

source code of qtmultimedia/src/multimedia/recording/qscreencapture.h