1/****************************************************************************
2**
3** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef SCENE3DITEM_H
41#define SCENE3DITEM_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtCore/qpointer.h>
55#include <QtQuick/QQuickItem>
56
57QT_BEGIN_NAMESPACE
58
59class QOffscreenSurface;
60
61namespace Qt3DCore {
62class QAspectEngine;
63class QEntity;
64}
65
66namespace Qt3DRender {
67
68class QCamera;
69class QRenderAspect;
70class Scene3DRenderer;
71class Scene3DCleaner;
72
73class Scene3DItem : public QQuickItem
74{
75 Q_OBJECT
76 Q_PROPERTY(Qt3DCore::QEntity* entity READ entity WRITE setEntity NOTIFY entityChanged)
77 Q_PROPERTY(QStringList aspects READ aspects WRITE setAspects NOTIFY aspectsChanged)
78 Q_PROPERTY(bool multisample READ multisample WRITE setMultisample NOTIFY multisampleChanged)
79 Q_PROPERTY(CameraAspectRatioMode cameraAspectRatioMode READ cameraAspectRatioMode WRITE setCameraAspectRatioMode NOTIFY cameraAspectRatioModeChanged)
80 Q_PROPERTY(bool hoverEnabled READ isHoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
81 Q_CLASSINFO("DefaultProperty", "entity")
82public:
83 explicit Scene3DItem(QQuickItem *parent = 0);
84 ~Scene3DItem();
85
86 QStringList aspects() const;
87 Qt3DCore::QEntity *entity() const;
88
89 bool multisample() const;
90 void setMultisample(bool enable);
91 Q_INVOKABLE void setItemAreaAndDevicePixelRatio(QSize area, qreal devicePixelRatio);
92 bool isHoverEnabled() const;
93
94 enum CameraAspectRatioMode {
95 AutomaticAspectRatio,
96 UserAspectRatio
97 };
98 Q_ENUM(CameraAspectRatioMode); // LCOV_EXCL_LINE
99 CameraAspectRatioMode cameraAspectRatioMode() const;
100
101public Q_SLOTS:
102 void setAspects(const QStringList &aspects);
103 void setEntity(Qt3DCore::QEntity *entity);
104 void setCameraAspectRatioMode(CameraAspectRatioMode mode);
105 void setHoverEnabled(bool enabled);
106
107Q_SIGNALS:
108 void aspectsChanged();
109 void entityChanged();
110 void multisampleChanged();
111 void cameraAspectRatioModeChanged(CameraAspectRatioMode mode);
112 void hoverEnabledChanged();
113
114private Q_SLOTS:
115 void applyRootEntityChange();
116
117private:
118 QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *nodeData) override;
119 void setWindowSurface(QObject *rootObject);
120 void setCameraAspectModeHelper();
121 void updateCameraAspectRatio();
122 void mousePressEvent(QMouseEvent *event) override;
123
124 QStringList m_aspects;
125 Qt3DCore::QEntity *m_entity;
126
127 Qt3DCore::QAspectEngine *m_aspectEngine;
128 QRenderAspect *m_renderAspect;
129 Scene3DRenderer *m_renderer;
130 Scene3DCleaner *m_rendererCleaner;
131
132 bool m_multisample;
133
134 QPointer<Qt3DRender::QCamera> m_camera;
135 CameraAspectRatioMode m_cameraAspectRatioMode;
136 QOffscreenSurface *m_dummySurface;
137};
138
139} // Qt3DRender
140
141QT_END_NAMESPACE
142
143#endif
144