summaryrefslogtreecommitdiffstats
path: root/src/quick3d/quick3dscene2d
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-05-20 14:57:26 +0100
committerSean Harmer <sean.harmer@kdab.com>2017-05-20 14:57:53 +0100
commitcd9059a22604307f483764db134d51b15c540758 (patch)
tree9ceea8edf2b41e55f17a49552d9cf37fcdedc9b2 /src/quick3d/quick3dscene2d
parent1d024678ba16dd979a8c7023b35cdc76db357d37 (diff)
parent9bf4daddeb62ec6a40e2d90587a7327acbb3780f (diff)
Merge branch '5.9.0' into 5.9
Diffstat (limited to 'src/quick3d/quick3dscene2d')
-rw-r--r--src/quick3d/quick3dscene2d/items/qscene2d.cpp203
-rw-r--r--src/quick3d/quick3dscene2d/items/qscene2d.h22
-rw-r--r--src/quick3d/quick3dscene2d/items/qscene2d_p.h7
-rw-r--r--src/quick3d/quick3dscene2d/items/scene2d.cpp108
-rw-r--r--src/quick3d/quick3dscene2d/items/scene2d_p.h2
-rw-r--r--src/quick3d/quick3dscene2d/items/scene2dmanager.cpp141
-rw-r--r--src/quick3d/quick3dscene2d/items/scene2dmanager_p.h15
7 files changed, 192 insertions, 306 deletions
diff --git a/src/quick3d/quick3dscene2d/items/qscene2d.cpp b/src/quick3d/quick3dscene2d/items/qscene2d.cpp
index 3470ac9d8..52e2be094 100644
--- a/src/quick3d/quick3dscene2d/items/qscene2d.cpp
+++ b/src/quick3d/quick3dscene2d/items/qscene2d.cpp
@@ -59,21 +59,75 @@ namespace Quick {
\brief This class enables rendering qml into a texture, which then can be
used as a part of 3D scene.
- The component uses QQuickRenderControl to render the given QML source into an
+ This class uses QQuickRenderControl to render the given QQuickItem into an
offscreen surface, which is attached to a texture provided by the user. This allows the
component to directly render into the texture without intermediate copy and the user to
freely specify how the texture is used in the 3D scene.
+ The entities using the QScene2D can be associated with the class to enable interaction
+ with the item; if an entity has a QObjectPicker component, the pick events from that picker
+ are sent to the QScene2D and converted to mouse events and finally sent to the item.
+
\since 5.9
*/
/*!
\qmltype Scene2D
\inqmlmodule Qt3D.Scene2D
- \since
- \ingroup
+ \since 5.9
\instantiates Qt3DRender::Quick::QScene2D
- \brief Scene2D
+
+ \brief This type enables rendering qml into a texture, which then can be
+ used as a part of 3D scene.
+
+ This object uses RenderControl to render the given Item into an
+ offscreen surface, which is attached to a texture provided by the user. This allows the
+ component to directly render into the texture without intermediate copy and the user to
+ freely specify how the texture is used in the 3D scene.
+
+ The entities using the Scene2D can be associated with the type to enable interaction
+ with the item; if an entity has an ObjectPicker component, the pick events from that picker
+ are sent to the Scene2D and converted to mouse events and finally sent to the item.
+
+ Usage:
+ \qml
+ Entity {
+ id: sceneRoot
+
+ // specify Scene2D inside the entity hierarchy
+ Scene2D {
+ // specify output
+ output: RenderTargetOutput {
+ attachmentPoint: RenderTargetOutput.Color0
+ texture: Texture2D {
+ id: textureId
+ width: 1024
+ height: 1024
+ format: Texture.RGBA8_UNorm
+ }
+ }
+ // specify entities
+ entities: [entityId]
+
+ // specify rendered content
+ Rectangle {
+ color: "red"
+ }
+ }
+
+ Entity {
+ id: entityId
+
+ property Material material: TextureMaterial {
+ texture: textureId
+ }
+ property ObjectPicker picker: ObjectPicker {
+ hoverEnabled: true
+ dragEnabled: true
+ }
+ ...
+
+ \endqml
*/
/*!
@@ -91,18 +145,34 @@ namespace Quick {
*/
/*!
- \qmlproperty QUrl Qt3D.Render::Scene2D::source
- Holds the qml source url.
- */
-
-/*!
\qmlproperty enumeration Qt3D.Render::Scene2D::renderPolicy
Holds the render policy of this Scene2D.
+
+ \list
+ \li Continuous The Scene2D is rendering continuously. This is the default render policy.
+ \li SingleShot The Scene2D renders to the texture only once after which the resources
+ allocated for rendering are released.
+ \endlist
+ */
+/*!
+ \qmlproperty Item Qt3D.Render::Scene2D::item
+ Holds the Item, which is rendered by Scene2D to the texture.
*/
/*!
- \qmlproperty bool Qt3D.Render::Scene2D::loaded
- Holds whether the source has been loaded.
+ \qmlproperty bool Qt3D.Render::Scene2D::mouseEnabled
+ Holds whether mouse events are enabled for the rendered item. The mouse events are
+ generated from object picking events of the entities added to the Scene2D.
+ Mouse is enabled by default.
+
+ \note Events sent to items are delayed by one frame due to object picking
+ happening in the backend.
+ */
+/*!
+ \qmlproperty list<Entity> Qt3D.Render::Scene2D::entities
+ Holds the list of entities which are associated with the Scene2D object. If the
+ entities have ObjectPicker, the pick events from that entity are sent to Scene2D
+ and converted to mouse events.
*/
QScene2DPrivate::QScene2DPrivate()
@@ -118,6 +188,15 @@ QScene2DPrivate::~QScene2DPrivate()
delete m_renderManager;
}
+void QScene2DPrivate::setScene(Qt3DCore::QScene *scene)
+{
+ Q_Q(QScene2D);
+ QNodePrivate::setScene(scene);
+ const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(q->id());
+ change->setPropertyName("sceneInitialized");
+ notifyObservers(change);
+}
+
/*!
The constructor creates a new QScene2D instance with the specified \a parent.
@@ -125,58 +204,12 @@ QScene2DPrivate::~QScene2DPrivate()
QScene2D::QScene2D(Qt3DCore::QNode *parent)
: Qt3DCore::QNode(*new QScene2DPrivate, parent)
{
- Q_D(QScene2D);
- connect(d->m_renderManager, &Scene2DManager::onLoadedChanged,
- this, &QScene2D::sourceLoaded);
-}
-
-QScene2D::QScene2D(QQmlEngine *engine, Qt3DCore::QNode *parent)
- : Qt3DCore::QNode(*new QScene2DPrivate, parent)
-{
- Q_D(QScene2D);
- connect(d->m_renderManager, &Scene2DManager::onLoadedChanged,
- this, &QScene2D::sourceLoaded);
- d->m_renderManager->setEngine(engine);
-}
-
-QScene2D::~QScene2D()
-{
-}
-
-bool QScene2D::loaded() const
-{
- Q_D(const QScene2D);
- return d->m_renderManager->m_initialized;
}
/*!
- \property QScene2D::source
- \brief Specifies the url for the qml.
-
- This property specifies the url to the qml being rendered to the texture.
- The source must specify QQuickItem as a root. The item must specify width
- and height. The rendered qml is scaled to the texture size.
- The property can not be changed after the rendering has been initialized.
+ \property QScene2D::item
+ Holds the QQuickItem, which is rendered by QScene2D to the texture.
*/
-QUrl QScene2D::source() const
-{
- Q_D(const QScene2D);
- return d->m_renderManager->m_source;
-}
-
-void QScene2D::setSource(const QUrl &url)
-{
- Q_D(QScene2D);
- if (d->m_renderManager->m_initialized) {
- qWarning() << "Unable to set source after initialization.";
- return;
- }
- if (d->m_renderManager->m_source != url) {
- d->m_renderManager->setSource(url);
- emit sourceChanged(url);
- }
-}
-
QQuickItem* QScene2D::item() const
{
Q_D(const QScene2D);
@@ -250,46 +283,29 @@ Qt3DCore::QNodeCreatedChangeBasePtr QScene2D::createNodeCreationChange() const
data.output = d->m_output ? d->m_output->id() : Qt3DCore::QNodeId();
for (Qt3DCore::QEntity *e : d->m_entities)
data.entityIds.append(e->id());
+ data.mouseEnabled = d->m_renderManager->m_mouseEnabled;
return creationChange;
}
-bool QScene2D::event(QEvent *event)
-{
- Q_D(QScene2D);
- d->m_renderManager->forwardEvent(event);
- return true;
-}
-
-/*!
- Returns the qml engine used by the QScene2D.
- */
-QQmlEngine *QScene2D::engine() const
+bool QScene2D::isMouseEnabled() const
{
Q_D(const QScene2D);
- return d->m_renderManager->m_qmlEngine;
-}
-
-bool QScene2D::isGrabMouseEnabled() const
-{
- Q_D(const QScene2D);
- return d->m_renderManager->m_grabMouse;
+ return d->m_renderManager->m_mouseEnabled;
}
/*!
- \internal
+ Retrieve entities associated with the QScene2D.
*/
-void QScene2D::sourceLoaded()
-{
- emit loadedChanged(true);
-}
-
-
QVector<Qt3DCore::QEntity*> QScene2D::entities()
{
Q_D(const QScene2D);
return d->m_entities;
}
+/*!
+ Adds an \a entity to the the QScene2D object. If the entities have QObjectPicker,
+ the pick events from that entity are sent to QScene2D and converted to mouse events.
+*/
void QScene2D::addEntity(Qt3DCore::QEntity *entity)
{
Q_D(QScene2D);
@@ -306,6 +322,9 @@ void QScene2D::addEntity(Qt3DCore::QEntity *entity)
}
}
+/*!
+ Removes an \a entity from the the QScene2D object.
+*/
void QScene2D::removeEntity(Qt3DCore::QEntity *entity)
{
Q_D(QScene2D);
@@ -322,12 +341,20 @@ void QScene2D::removeEntity(Qt3DCore::QEntity *entity)
}
}
-void QScene2D::setGrabMouseEnabled(bool grab)
+/*!
+ \property QScene2D::mouseEnabled
+ Holds whether mouse events are enabled for the rendered item. The mouse events are
+ generated from object picking events of the entities added to the QScene2D.
+ Mouse is enabled by default.
+
+ \note Events are delayed by one frame due to object picking happening in the backend.
+ */
+void QScene2D::setMouseEnabled(bool enabled)
{
Q_D(QScene2D);
- if (d->m_renderManager->m_grabMouse != grab) {
- d->m_renderManager->m_grabMouse = grab;
- emit grabMouseChanged(grab);
+ if (d->m_renderManager->m_mouseEnabled != enabled) {
+ d->m_renderManager->m_mouseEnabled = enabled;
+ emit mouseEnabledChanged(enabled);
}
}
diff --git a/src/quick3d/quick3dscene2d/items/qscene2d.h b/src/quick3d/quick3dscene2d/items/qscene2d.h
index 2c982668a..73322a9e9 100644
--- a/src/quick3d/quick3dscene2d/items/qscene2d.h
+++ b/src/quick3d/quick3dscene2d/items/qscene2d.h
@@ -60,11 +60,9 @@ class QT3DQUICKSCENE2DSHARED_EXPORT QScene2D : public Qt3DCore::QNode
Q_OBJECT
Q_PROPERTY(Qt3DRender::QRenderTargetOutput *output READ output WRITE setOutput NOTIFY outputChanged)
- Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(QScene2D::RenderPolicy renderPolicy READ renderPolicy WRITE setRenderPolicy NOTIFY renderPolicyChanged)
- Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
Q_PROPERTY(QQuickItem *item READ item WRITE setItem NOTIFY itemChanged)
- Q_PROPERTY(bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled NOTIFY grabMouseChanged)
+ Q_PROPERTY(bool mouseEnabled READ isMouseEnabled WRITE setMouseEnabled NOTIFY mouseEnabledChanged)
Q_CLASSINFO("DefaultProperty", "item")
@@ -77,18 +75,11 @@ public:
Q_ENUM(RenderPolicy)
explicit QScene2D(Qt3DCore::QNode *parent = nullptr);
- QScene2D(QQmlEngine *engine, Qt3DCore::QNode *parent = nullptr);
- ~QScene2D();
Qt3DRender::QRenderTargetOutput *output() const;
- QUrl source() const;
- bool loaded() const;
QScene2D::RenderPolicy renderPolicy() const;
QQuickItem *item() const;
- QQmlEngine *engine() const;
- bool isGrabMouseEnabled() const;
-
- bool event(QEvent *event) Q_DECL_OVERRIDE;
+ bool isMouseEnabled() const;
QVector<Qt3DCore::QEntity *> entities();
void addEntity(Qt3DCore::QEntity *entity);
@@ -96,26 +87,21 @@ public:
public Q_SLOTS:
void setOutput(Qt3DRender::QRenderTargetOutput *output);
- void setSource(const QUrl &url);
void setRenderPolicy(QScene2D::RenderPolicy policy);
void setItem(QQuickItem *item);
- void setGrabMouseEnabled(bool grab);
+ void setMouseEnabled(bool enabled);
Q_SIGNALS:
void outputChanged(Qt3DRender::QRenderTargetOutput *output);
- void sourceChanged(const QUrl &url);
- void loadedChanged(bool loaded);
void renderPolicyChanged(QScene2D::RenderPolicy policy);
void itemChanged(QQuickItem *item);
- void grabMouseChanged(bool grab);
+ void mouseEnabledChanged(bool enabled);
protected:
Q_DECLARE_PRIVATE(QScene2D)
private:
Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE;
-
- void sourceLoaded();
};
} // namespace Quick
diff --git a/src/quick3d/quick3dscene2d/items/qscene2d_p.h b/src/quick3d/quick3dscene2d/items/qscene2d_p.h
index e40d3d6a9..217058f5c 100644
--- a/src/quick3d/quick3dscene2d/items/qscene2d_p.h
+++ b/src/quick3d/quick3dscene2d/items/qscene2d_p.h
@@ -55,6 +55,10 @@
QT_BEGIN_NAMESPACE
+namespace Qt3DCore {
+class QScene;
+}
+
namespace Qt3DRender {
namespace Quick {
@@ -70,6 +74,8 @@ public:
QScene2DPrivate();
~QScene2DPrivate();
+ void setScene(Qt3DCore::QScene *scene) Q_DECL_OVERRIDE;
+
Scene2DManager *m_renderManager;
QMetaObject::Connection m_textureDestroyedConnection;
Qt3DRender::QRenderTargetOutput *m_output;
@@ -82,6 +88,7 @@ struct QScene2DData
Scene2DSharedObjectPtr sharedObject;
Qt3DCore::QNodeId output;
QVector<Qt3DCore::QNodeId> entityIds;
+ bool mouseEnabled;
};
} // namespace Quick
diff --git a/src/quick3d/quick3dscene2d/items/scene2d.cpp b/src/quick3d/quick3dscene2d/items/scene2d.cpp
index ded595b36..b0c58c6c5 100644
--- a/src/quick3d/quick3dscene2d/items/scene2d.cpp
+++ b/src/quick3d/quick3dscene2d/items/scene2d.cpp
@@ -118,6 +118,7 @@ Scene2D::Scene2D()
, m_rbo(0)
, m_initialized(false)
, m_renderInitialized(false)
+ , m_mouseEnabled(true)
, m_renderPolicy(Qt3DRender::Quick::QScene2D::Continuous)
{
renderThreadClientCount->fetchAndAddAcquire(1);
@@ -125,12 +126,7 @@ Scene2D::Scene2D()
Scene2D::~Scene2D()
{
- // this gets called from aspect thread. Wait for the render thread then delete it.
- // TODO: render thread deletion
-// if (m_renderThread) {
-// m_renderThread->wait(1000);
-// delete m_renderThread;
-// }
+ stopGrabbing();
}
void Scene2D::setOutput(Qt3DCore::QNodeId outputId)
@@ -177,6 +173,7 @@ void Scene2D::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &chan
setSharedObject(data.sharedObject);
setOutput(data.output);
m_entities = data.entityIds;
+ m_mouseEnabled = data.mouseEnabled;
}
void Scene2D::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
@@ -192,49 +189,42 @@ void Scene2D::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
} else if (propertyChange->propertyName() == QByteArrayLiteral("output")) {
Qt3DCore::QNodeId outputId = propertyChange->value().value<Qt3DCore::QNodeId>();
setOutput(outputId);
- } else if (propertyChange->propertyName() == QByteArrayLiteral("sharedObject")) {
- const Scene2DSharedObjectPtr sharedObject
- = propertyChange->value().value<Scene2DSharedObjectPtr>();
- setSharedObject(sharedObject);
} else if (propertyChange->propertyName() == QByteArrayLiteral("pressed")) {
QPickEventPtr ev = propertyChange->value().value<QPickEventPtr>();
handlePickEvent(QEvent::MouseButtonPress, ev);
} else if (propertyChange->propertyName() == QByteArrayLiteral("released")) {
QPickEventPtr ev = propertyChange->value().value<QPickEventPtr>();
handlePickEvent(QEvent::MouseButtonRelease, ev);
- } else if (propertyChange->propertyName() == QByteArrayLiteral("clicked")) {
- QPickEventPtr ev = propertyChange->value().value<QPickEventPtr>();
- handlePickEvent(QEvent::MouseButtonDblClick, ev);
} else if (propertyChange->propertyName() == QByteArrayLiteral("moved")) {
QPickEventPtr ev = propertyChange->value().value<QPickEventPtr>();
handlePickEvent(QEvent::MouseMove, ev);
- } else if (propertyChange->propertyName() == QByteArrayLiteral("grabMouse")) {
- if (propertyChange->value().toBool()) {
- startGrabbing();
- } else {
- stopGrabbing();
+ } else if (propertyChange->propertyName() == QByteArrayLiteral("mouseEnabled")) {
+ m_mouseEnabled = propertyChange->value().toBool();
+ if (m_mouseEnabled && !m_cachedPickEvent.isNull()) {
+ handlePickEvent(QEvent::MouseButtonPress, m_cachedPickEvent);
+ m_cachedPickEvent.clear();
}
+ } else if (propertyChange->propertyName() == QByteArrayLiteral("sceneInitialized")) {
+ startGrabbing();
}
- /* TODO: handle these?
- else if (propertyChange->propertyName() == QByteArrayLiteral("entered")) {
-
- } else if (propertyChange->propertyName() == QByteArrayLiteral("exited")) {
-
- }*/
break;
}
case Qt3DCore::PropertyValueAdded: {
const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeAddedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("entities"))
+ if (change->propertyName() == QByteArrayLiteral("entities")) {
m_entities.push_back(change->addedNodeId());
+ registerObjectPickerEvents(change->addedNodeId());
+ }
break;
}
case Qt3DCore::PropertyValueRemoved: {
const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeRemovedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("entities"))
+ if (change->propertyName() == QByteArrayLiteral("entities")) {
m_entities.removeOne(change->removedNodeId());
+ unregisterObjectPickerEvents(change->removedNodeId());
+ }
break;
}
@@ -468,46 +458,54 @@ void Scene2D::unregisterObjectPickerEvents(Qt3DCore::QNodeId entityId)
void Scene2D::handlePickEvent(int type, const Qt3DRender::QPickEventPtr &ev)
{
- QPickTriangleEvent *pickTriangle = static_cast<QPickTriangleEvent *>(ev.data());
- Entity *entity = nullptr;
- if (!resourceAccessor()->accessResource(RenderBackendResourceAccessor::EntityHandle,
- QPickEventPrivate::get(pickTriangle)->m_entity,
- (void**)&entity, nullptr)) {
+ if (!isEnabled())
return;
- }
- CoordinateReader reader(renderer()->nodeManagers());
- if (reader.setGeometry(entity->renderComponent<GeometryRenderer>(),
- QAttribute::defaultTextureCoordinateAttributeName())) {
- QVector4D c0 = reader.getCoordinate(pickTriangle->vertex1Index());
- QVector4D c1 = reader.getCoordinate(pickTriangle->vertex2Index());
- QVector4D c2 = reader.getCoordinate(pickTriangle->vertex3Index());
- QVector4D ci = c0 * pickTriangle->uvw().x()
- + c1 * pickTriangle->uvw().y() + c2 * pickTriangle->uvw().z();
- ci.setW(1.0f);
-
- const QSize size = m_sharedObject->m_quickWindow->size();
- QPointF pos = QPointF(ci.x() * size.width(), ci.y() * size.height());
- QMouseEvent *mouseEvent
- = new QMouseEvent(static_cast<QEvent::Type>(type),
- pos, pos, pos,
- static_cast<Qt::MouseButton>(pickTriangle->button()),
- static_cast<Qt::MouseButtons>(pickTriangle->buttons()),
- static_cast<Qt::KeyboardModifiers>(pickTriangle->modifiers()),
- Qt::MouseEventSynthesizedByApplication);
-
- QCoreApplication::postEvent(m_sharedObject->m_quickWindow, mouseEvent);
+ if (m_mouseEnabled) {
+ QPickTriangleEvent *pickTriangle = static_cast<QPickTriangleEvent *>(ev.data());
+ Entity *entity = nullptr;
+ if (!resourceAccessor()->accessResource(RenderBackendResourceAccessor::EntityHandle,
+ QPickEventPrivate::get(pickTriangle)->m_entity,
+ (void**)&entity, nullptr)) {
+ return;
+ }
+ CoordinateReader reader(renderer()->nodeManagers());
+ if (reader.setGeometry(entity->renderComponent<GeometryRenderer>(),
+ QAttribute::defaultTextureCoordinateAttributeName())) {
+ QVector4D c0 = reader.getCoordinate(pickTriangle->vertex1Index());
+ QVector4D c1 = reader.getCoordinate(pickTriangle->vertex2Index());
+ QVector4D c2 = reader.getCoordinate(pickTriangle->vertex3Index());
+ QVector4D ci = c0 * pickTriangle->uvw().x()
+ + c1 * pickTriangle->uvw().y() + c2 * pickTriangle->uvw().z();
+ ci.setW(1.0f);
+
+ const QSize size = m_sharedObject->m_quickWindow->size();
+ QPointF pos = QPointF(ci.x() * size.width(), (1.0f - ci.y()) * size.height());
+ QMouseEvent *mouseEvent
+ = new QMouseEvent(static_cast<QEvent::Type>(type),
+ pos, pos, pos,
+ static_cast<Qt::MouseButton>(pickTriangle->button()),
+ static_cast<Qt::MouseButtons>(pickTriangle->buttons()),
+ static_cast<Qt::KeyboardModifiers>(pickTriangle->modifiers()),
+ Qt::MouseEventSynthesizedByApplication);
+
+ QCoreApplication::postEvent(m_sharedObject->m_quickWindow, mouseEvent);
+ }
+ } else if (type == QEvent::MouseButtonPress) {
+ m_cachedPickEvent = ev;
+ } else {
+ m_cachedPickEvent.clear();
}
}
void Scene2D::startGrabbing()
{
- for (Qt3DCore::QNodeId e : m_entities)
+ for (Qt3DCore::QNodeId e : qAsConst(m_entities))
registerObjectPickerEvents(e);
}
void Scene2D::stopGrabbing()
{
- for (Qt3DCore::QNodeId e : m_entities)
+ for (Qt3DCore::QNodeId e : qAsConst(m_entities))
unregisterObjectPickerEvents(e);
}
diff --git a/src/quick3d/quick3dscene2d/items/scene2d_p.h b/src/quick3d/quick3dscene2d/items/scene2d_p.h
index d2845d847..b42089306 100644
--- a/src/quick3d/quick3dscene2d/items/scene2d_p.h
+++ b/src/quick3d/quick3dscene2d/items/scene2d_p.h
@@ -119,8 +119,10 @@ public:
bool m_initialized;
bool m_renderInitialized;
+ bool m_mouseEnabled;
Qt3DRender::Quick::QScene2D::RenderPolicy m_renderPolicy;
QVector<Qt3DCore::QNodeId> m_entities;
+ Qt3DRender::QPickEventPtr m_cachedPickEvent;
};
} // Quick
diff --git a/src/quick3d/quick3dscene2d/items/scene2dmanager.cpp b/src/quick3d/quick3dscene2d/items/scene2dmanager.cpp
index f0d6a6e34..20c080dec 100644
--- a/src/quick3d/quick3dscene2d/items/scene2dmanager.cpp
+++ b/src/quick3d/quick3dscene2d/items/scene2dmanager.cpp
@@ -72,9 +72,7 @@ QWindow *RenderControl::renderWindow(QPoint *offset)
Constructs qml render manager.
*/
Scene2DManager::Scene2DManager(QScene2DPrivate *priv)
- : m_qmlEngine(nullptr)
- , m_qmlComponent(nullptr)
- , m_rootItem(nullptr)
+ : m_rootItem(nullptr)
, m_item(nullptr)
, m_priv(priv)
, m_sharedObject(new Scene2DSharedObject(this))
@@ -83,9 +81,7 @@ Scene2DManager::Scene2DManager(QScene2DPrivate *priv)
, m_initialized(false)
, m_renderSyncRequested(false)
, m_backendInitialized(false)
- , m_noSourceMode(false)
- , m_ownEngine(false)
- , m_grabMouse(false)
+ , m_mouseEnabled(true)
{
m_sharedObject->m_surface = new QOffscreenSurface;
m_sharedObject->m_surface->setFormat(QSurfaceFormat::defaultFormat());
@@ -135,38 +131,17 @@ void Scene2DManager::requestRenderSync()
void Scene2DManager::startIfInitialized()
{
- if (!m_initialized && m_backendInitialized) {
- if (m_source.isValid() && !m_noSourceMode) {
- // Create a QML engine.
- if (!m_qmlEngine) {
- m_qmlEngine = new QQmlEngine;
- if (!m_qmlEngine->incubationController()) {
- m_qmlEngine->setIncubationController(m_sharedObject->m_quickWindow
- ->incubationController());
- }
- }
-
- // create component
- m_ownEngine = true;
- m_qmlComponent = new QQmlComponent(m_qmlEngine, m_source);
- if (m_qmlComponent->isLoading()) {
- connect(m_qmlComponent, &QQmlComponent::statusChanged,
- this, &Scene2DManager::run);
- } else {
- run();
- }
- } else if (m_item != nullptr) {
- m_rootItem = m_item;
+ if (!m_initialized && m_backendInitialized && m_item != nullptr) {
+ m_rootItem = m_item;
- // Associate root item with the window.
- m_rootItem->setParentItem(m_sharedObject->m_quickWindow->contentItem());
+ // Associate root item with the window.
+ m_rootItem->setParentItem(m_sharedObject->m_quickWindow->contentItem());
- // Update window size.
- updateSizes();
+ // Update window size.
+ updateSizes();
- m_initialized = true;
- m_sharedObject->setInitialized();
- }
+ m_initialized = true;
+ m_sharedObject->setInitialized();
}
}
@@ -177,54 +152,9 @@ void Scene2DManager::stopAndClean()
m_sharedObject->requestQuit();
m_sharedObject->wait();
m_sharedObject->cleanup();
- if (m_ownEngine) {
- QObject::disconnect(m_connection);
- delete m_qmlEngine;
- }
- delete m_qmlComponent;
- m_qmlEngine = nullptr;
- m_qmlComponent = nullptr;
}
}
-void Scene2DManager::run()
-{
- disconnect(m_qmlComponent, &QQmlComponent::statusChanged, this, &Scene2DManager::run);
-
- if (m_qmlComponent->isError()) {
- QList<QQmlError> errorList = m_qmlComponent->errors();
- for (const QQmlError &error: errorList)
- qWarning() << error.url() << error.line() << error;
- return;
- }
-
- QObject *rootObject = m_qmlComponent->create();
- if (m_qmlComponent->isError()) {
- QList<QQmlError> errorList = m_qmlComponent->errors();
- for (const QQmlError &error: errorList)
- qWarning() << error.url() << error.line() << error;
- return;
- }
-
- m_rootItem = qobject_cast<QQuickItem *>(rootObject);
- if (!m_rootItem) {
- qWarning("QScene2D: Root item is not a QQuickItem.");
- delete rootObject;
- return;
- }
-
- // The root item is ready. Associate it with the window.
- m_rootItem->setParentItem(m_sharedObject->m_quickWindow->contentItem());
-
- // Update window size.
- updateSizes();
-
- m_initialized = true;
- m_sharedObject->setInitialized();
-
- emit onLoadedChanged();
-}
-
void Scene2DManager::updateSizes()
{
const int width = m_rootItem->width();
@@ -236,15 +166,8 @@ void Scene2DManager::updateSizes()
m_sharedObject->m_quickWindow->setGeometry(0, 0, width, height);
}
-void Scene2DManager::setSource(const QUrl &url)
-{
- m_source = url;
- startIfInitialized();
-}
-
void Scene2DManager::setItem(QQuickItem *item)
{
- m_noSourceMode = true;
m_item = item;
startIfInitialized();
}
@@ -302,33 +225,6 @@ bool Scene2DManager::event(QEvent *e)
return QObject::event(e);
}
-bool Scene2DManager::forwardEvent(QEvent *event)
-{
- switch (event->type()) {
-
- case QEvent::MouseMove:
- case QEvent::MouseButtonDblClick:
- case QEvent::MouseButtonPress:
- case QEvent::MouseButtonRelease: {
- QMouseEvent* me = static_cast<QMouseEvent *>(event);
- QPointF pos = me->localPos();
- pos = QPointF(pos.x() * m_rootItem->width(), pos.y() * m_rootItem->height());
- QMouseEvent nme = QMouseEvent(me->type(), pos, pos, pos, me->button(), me->buttons(),
- me->modifiers(), Qt::MouseEventSynthesizedByApplication);
- QCoreApplication::sendEvent(m_sharedObject->m_quickWindow, &nme);
- } break;
-
- case QEvent::KeyPress:
- case QEvent::KeyRelease: {
- QCoreApplication::sendEvent(m_sharedObject->m_quickWindow, event);
- } break;
-
- default:
- break;
- }
- return false;
-}
-
void Scene2DManager::doRenderSync()
{
QMutexLocker lock(&m_sharedObject->m_mutex);
@@ -346,23 +242,6 @@ void Scene2DManager::cleanup()
stopAndClean();
}
-void Scene2DManager::setEngine(QQmlEngine *engine)
-{
- m_qmlEngine = engine;
- m_ownEngine = false;
- if (engine) {
- m_connection = QObject::connect(engine, &QObject::destroyed,
- this, &Scene2DManager::engineDestroyed);
- }
-}
-
-void Scene2DManager::engineDestroyed()
-{
- QObject::disconnect(m_connection);
- m_qmlEngine = nullptr;
- m_ownEngine = false;
-}
-
} // namespace Quick
} // namespace Qt3DRender
diff --git a/src/quick3d/quick3dscene2d/items/scene2dmanager_p.h b/src/quick3d/quick3dscene2d/items/scene2dmanager_p.h
index d3c3a60a2..821616f47 100644
--- a/src/quick3d/quick3dscene2d/items/scene2dmanager_p.h
+++ b/src/quick3d/quick3dscene2d/items/scene2dmanager_p.h
@@ -75,46 +75,33 @@ public:
Scene2DManager(QScene2DPrivate *priv);
~Scene2DManager();
- QQmlEngine *m_qmlEngine;
- QQmlComponent *m_qmlComponent;
QQuickItem *m_rootItem;
QQuickItem *m_item;
QScene2DPrivate *m_priv;
QSharedPointer<Scene2DSharedObject> m_sharedObject;
- QUrl m_source;
Qt3DCore::QNodeId m_id;
- QMetaObject::Connection m_connection;
QScene2D::RenderPolicy m_renderPolicy;
bool m_requested;
bool m_initialized;
bool m_renderSyncRequested;
bool m_backendInitialized;
- bool m_noSourceMode;
- bool m_ownEngine;
- bool m_grabMouse;
+ bool m_mouseEnabled;
void requestRender();
void requestRenderSync();
void doRenderSync();
void startIfInitialized();
void stopAndClean();
- void run();
void updateSizes();
- void setSource(const QUrl &url);
void setItem(QQuickItem *item);
bool event(QEvent *e) Q_DECL_OVERRIDE;
- bool forwardEvent(QEvent *event);
-
- Q_SIGNAL void onLoadedChanged();
void cleanup();
- void setEngine(QQmlEngine *engine);
- void engineDestroyed();
};
} // namespace Quick