blob: d19c4ec308337b9fcef3565ce0faa0f020aebd99 (
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QApplication>
#include <QtQml/QQmlContext>
#include <QtQuick/QQuickView>
#include <Qt3DRender/QAbstractTexture>
#include <QWindow>
#include <QTimer>
#include <QQuickView>
#include "videoplayer.h"
template<typename Obj>
QHash<int, QString> enumToNameMap(const char *enumName)
{
const QMetaObject metaObj = Obj::staticMetaObject;
const int indexOfEnum = metaObj.indexOfEnumerator(enumName);
const QMetaEnum metaEnum = metaObj.enumerator(indexOfEnum);
const int keysCount = metaEnum.keyCount();
QHash<int, QString> v;
v.reserve(keysCount);
for (int i = 0; i < keysCount; ++i)
v[metaEnum.value(i)] = metaEnum.key(i);
return v;
}
class EnumNameMapper : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE QString statusName(int v) const { return m_statusMap.value(v); }
Q_INVOKABLE QString formatName(int v) const { return m_formatMap.value(v); }
Q_INVOKABLE QString targetName(int v) const { return m_targetMap.value(v); }
private:
const QHash<int, QString> m_statusMap = enumToNameMap<Qt3DRender::QAbstractTexture>("Status");
const QHash<int, QString> m_formatMap = enumToNameMap<Qt3DRender::QAbstractTexture>("TextureFormat");
const QHash<int, QString> m_targetMap = enumToNameMap<Qt3DRender::QAbstractTexture>("Target");
};
int main(int argc, char* argv[])
{
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
format.setMajorVersion(4);
format.setMinorVersion(5);
format.setDepthBufferSize(16);
format.setStencilBufferSize(8);
format.setProfile(QSurfaceFormat::CoreProfile);
format.setRenderableType(QSurfaceFormat::OpenGL);
QSurfaceFormat::setDefaultFormat(format);
// Make the OpenGLWidget's shared context be qt_gl_global_share_context
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QApplication app(argc, argv);
// Multimedia player
TextureWidget textureWidget;
VideoPlayer *videoPlayer = new VideoPlayer(&textureWidget);
textureWidget.resize(800, 600);
textureWidget.show();
// Qt3D QtQuick Scene (uses qt_global_share_context by default)
QQuickView view;
QQmlContext *ctx = view.rootContext();
EnumNameMapper mapper;
ctx->setContextProperty(QStringLiteral("_nameMapper"), &mapper);
ctx->setContextProperty(QStringLiteral("_textureWidget"), &textureWidget);
view.resize(800, 600);
view.setSource(QUrl("qrc:/main.qml"));
view.show();
return app.exec();
}
#include "main.moc"
|