summaryrefslogtreecommitdiffstats
path: root/tests/manual/rendercapture-cpp/mycapture.h
blob: 8df852214d6501325ac72e07311753c14511e9c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef MYCAPTURE_H
#define MYCAPTURE_H

#include <QLabel>
#include <Qt3DRender/QRenderCapture>

class MyCapture : public QObject
{
    Q_OBJECT
public:
    MyCapture(Qt3DRender::QRenderCapture* capture, QLabel *imageLabel)
        : m_capture(capture)
        , m_reply(nullptr)
        , m_imageLabel(imageLabel)
        , m_continuous(false)
    {
    }

public slots:
    void onCompleted()
    {
        QObject::disconnect(connection);

        m_imageLabel->setPixmap(QPixmap::fromImage(m_reply->image()));

        m_reply->saveImage("capture.bmp");

        m_reply->deleteLater();
        m_reply = nullptr;

        if (m_continuous)
            capture();
    }

    void setContinuous(bool continuos)
    {
        m_continuous = continuos;
    }

    void capture()
    {
        if (!m_reply) {
            m_reply = m_capture->requestCapture();
            connection = QObject::connect(m_reply, &Qt3DRender::QRenderCaptureReply::completed,
                                          this, &MyCapture::onCompleted);
        }
    }

private:
    Qt3DRender::QRenderCapture* m_capture;
    Qt3DRender::QRenderCaptureReply *m_reply;
    QMetaObject::Connection connection;
    QLabel *m_imageLabel;
    bool m_continuous;
};

#endif