forked from qt-creator/qt-creator
QmlDesigner: Add support any pickable node with 3d view context menu
Previously only 3D models could be picked for context menu target. Now any node that can be resolved from a point at 3D edit view can be picked. Fixes: QDS-7518 Change-Id: Id4a30d96744c42907d45688493776bdff35b934e Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -40,7 +40,7 @@ public:
|
||||
ActiveSceneChanged,
|
||||
RenderModelNodePreviewImage,
|
||||
Import3DSupport,
|
||||
ModelAtPos,
|
||||
NodeAtPos,
|
||||
None };
|
||||
|
||||
PuppetToCreatorCommand(Type type, const QVariant &data);
|
||||
|
@@ -60,7 +60,7 @@ public:
|
||||
SelectGridColor,
|
||||
ResetBackgroundColor,
|
||||
SyncBackgroundColor,
|
||||
GetModelAtPos
|
||||
GetNodeAtPos
|
||||
};
|
||||
|
||||
View3DActionCommand(Type type, const QVariant &value);
|
||||
|
@@ -547,6 +547,19 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
function gizmoAt(x, y)
|
||||
{
|
||||
for (var i = 0; i < lightIconGizmos.length; ++i) {
|
||||
if (lightIconGizmos[i].visible && lightIconGizmos[i].hasPoint(x, y))
|
||||
return lightIconGizmos[i].targetNode;
|
||||
}
|
||||
for (var i = 0; i < cameraGizmos.length; ++i) {
|
||||
if (cameraGizmos[i].visible && cameraGizmos[i].hasPoint(x, y))
|
||||
return cameraGizmos[i].targetNode;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
createEditView();
|
||||
selectObjects([]);
|
||||
|
@@ -52,6 +52,17 @@ Item {
|
||||
|
||||
signal clicked(Node node, bool multi)
|
||||
|
||||
function hasPoint(x, y)
|
||||
{
|
||||
if (!view3D || !targetNode)
|
||||
return false;
|
||||
|
||||
var point = view3D.mapToItem(iconMouseArea, x, y);
|
||||
|
||||
return point.x >= iconMouseArea.x && (point.x <= iconMouseArea.x + iconMouseArea.width)
|
||||
&& point.y >= iconMouseArea.y && (point.y <= iconMouseArea.y + iconMouseArea.height);
|
||||
}
|
||||
|
||||
onSelectedChanged: {
|
||||
if (selected)
|
||||
hasMouse = false;
|
||||
|
@@ -670,6 +670,23 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
function gizmoAt(x, y)
|
||||
{
|
||||
for (var i = 0; i < lightIconGizmos.length; ++i) {
|
||||
if (lightIconGizmos[i].visible && lightIconGizmos[i].hasPoint(x, y))
|
||||
return lightIconGizmos[i].targetNode;
|
||||
}
|
||||
for (var i = 0; i < cameraGizmos.length; ++i) {
|
||||
if (cameraGizmos[i].visible && cameraGizmos[i].hasPoint(x, y))
|
||||
return cameraGizmos[i].targetNode;
|
||||
}
|
||||
for (var i = 0; i < particleSystemIconGizmos.length; ++i) {
|
||||
if (particleSystemIconGizmos[i].visible && particleSystemIconGizmos[i].hasPoint(x, y))
|
||||
return particleSystemIconGizmos[i].targetNode;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
createEditView();
|
||||
selectObjects([]);
|
||||
|
@@ -53,6 +53,17 @@ Item {
|
||||
|
||||
signal clicked(Node node, bool multi)
|
||||
|
||||
function hasPoint(x, y)
|
||||
{
|
||||
if (!view3D || !targetNode)
|
||||
return false;
|
||||
|
||||
var point = view3D.mapToItem(iconMouseArea, x, y);
|
||||
|
||||
return point.x >= iconMouseArea.x && (point.x <= iconMouseArea.x + iconMouseArea.width)
|
||||
&& point.y >= iconMouseArea.y && (point.y <= iconMouseArea.y + iconMouseArea.height);
|
||||
}
|
||||
|
||||
onSelectedChanged: {
|
||||
if (selected)
|
||||
hasMouse = false;
|
||||
|
@@ -294,7 +294,7 @@ void Qt5InformationNodeInstanceServer::handleInputEvents()
|
||||
|
||||
// Context menu requested
|
||||
if (command.button() == Qt::RightButton && command.modifiers() == Qt::NoModifier)
|
||||
getModelAtPos(command.pos());
|
||||
getNodeAtPos(command.pos());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,7 +409,7 @@ void Qt5InformationNodeInstanceServer::removeRotationBlocks(const QVector<qint32
|
||||
#endif
|
||||
}
|
||||
|
||||
void Qt5InformationNodeInstanceServer::getModelAtPos(const QPointF &pos)
|
||||
void Qt5InformationNodeInstanceServer::getNodeAtPos(const QPointF &pos)
|
||||
{
|
||||
#ifdef QUICK3D_MODULE
|
||||
// pick a Quick3DModel at view position
|
||||
@@ -421,13 +421,25 @@ void Qt5InformationNodeInstanceServer::getModelAtPos(const QPointF &pos)
|
||||
QObject *obj = qvariant_cast<QObject *>(editViewProp.read());
|
||||
QQuick3DViewport *editView = qobject_cast<QQuick3DViewport *>(obj);
|
||||
|
||||
QQuick3DModel *hitModel = helper->pickViewAt(editView, pos.x(), pos.y()).objectHit();
|
||||
// Non-model nodes with icon gizmos are also valid results
|
||||
QVariant gizmoVar;
|
||||
QMetaObject::invokeMethod(m_editView3DData.rootItem, "gizmoAt", Qt::DirectConnection,
|
||||
Q_RETURN_ARG(QVariant, gizmoVar),
|
||||
Q_ARG(QVariant, pos.x()),
|
||||
Q_ARG(QVariant, pos.y()));
|
||||
QObject *gizmoObj = qvariant_cast<QObject *>(gizmoVar);
|
||||
QVariant instance = -1;
|
||||
|
||||
// filter out picks of models created dynamically or inside components
|
||||
QQuick3DModel *resolvedPick = qobject_cast<QQuick3DModel *>(helper->resolvePick(hitModel));
|
||||
if (gizmoObj && hasInstanceForObject(gizmoObj)) {
|
||||
instance = instanceForObject(gizmoObj).instanceId();
|
||||
} else {
|
||||
QQuick3DModel *hitModel = helper->pickViewAt(editView, pos.x(), pos.y()).objectHit();
|
||||
QObject *resolvedPick = helper->resolvePick(hitModel);
|
||||
if (hasInstanceForObject(resolvedPick))
|
||||
instance = instanceForObject(resolvedPick).instanceId();
|
||||
}
|
||||
|
||||
QVariant instance = resolvedPick ? instanceForObject(resolvedPick).instanceId() : -1;
|
||||
nodeInstanceClient()->handlePuppetToCreatorCommand({PuppetToCreatorCommand::ModelAtPos, instance});
|
||||
nodeInstanceClient()->handlePuppetToCreatorCommand({PuppetToCreatorCommand::NodeAtPos, instance});
|
||||
#else
|
||||
Q_UNUSED(pos)
|
||||
#endif
|
||||
@@ -2426,8 +2438,8 @@ void Qt5InformationNodeInstanceServer::view3DAction(const View3DActionCommand &c
|
||||
break;
|
||||
#endif
|
||||
#ifdef QUICK3D_MODULE
|
||||
case View3DActionCommand::GetModelAtPos: {
|
||||
getModelAtPos(command.value().toPointF());
|
||||
case View3DActionCommand::GetNodeAtPos: {
|
||||
getNodeAtPos(command.value().toPointF());
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
@@ -148,7 +148,7 @@ private:
|
||||
void updateMaterialPreviewData(const QVector<PropertyValueContainer> &valueChanges);
|
||||
void updateRotationBlocks(const QVector<PropertyValueContainer> &valueChanges);
|
||||
void removeRotationBlocks(const QVector<qint32> &instanceIds);
|
||||
void getModelAtPos(const QPointF &pos);
|
||||
void getNodeAtPos(const QPointF &pos);
|
||||
|
||||
void createAuxiliaryQuickView(const QUrl &url, RenderViewData &viewData);
|
||||
#ifdef QUICK3D_PARTICLES_MODULE
|
||||
|
@@ -290,28 +290,29 @@ void Edit3DView::customNotification(const AbstractView *view, const QString &ide
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get model at position from puppet process
|
||||
* @brief Get node at position from puppet process
|
||||
*
|
||||
* Response from puppet process for the model at requested position
|
||||
*
|
||||
* @param modelNode 3D model picked at the requested position, invalid node if no model exists
|
||||
* @param modelNode Node picked at the requested position or invalid node if nothing could be picked
|
||||
*/
|
||||
void Edit3DView::modelAtPosReady(const ModelNode &modelNode)
|
||||
void Edit3DView::nodeAtPosReady(const ModelNode &modelNode)
|
||||
{
|
||||
if (m_modelAtPosReqType == ModelAtPosReqType::ContextMenu) {
|
||||
if (m_nodeAtPosReqType == NodeAtPosReqType::ContextMenu) {
|
||||
// Make sure right-clicked item is selected. Due to a bug in puppet side right-clicking an item
|
||||
// while the context-menu is shown doesn't select the item.
|
||||
if (modelNode.isValid() && !modelNode.isSelected())
|
||||
setSelectedModelNode(modelNode);
|
||||
m_edit3DWidget->showContextMenu(m_contextMenuPos, modelNode);
|
||||
} else if (m_modelAtPosReqType == ModelAtPosReqType::MaterialDrop) {
|
||||
if (m_droppedMaterial.isValid() && modelNode.isValid()) {
|
||||
} else if (m_nodeAtPosReqType == NodeAtPosReqType::MaterialDrop) {
|
||||
if (m_droppedMaterial.isValid() && modelNode.isValid()
|
||||
&& modelNode.isSubclassOf("QtQuick3D.Model")) {
|
||||
executeInTransaction(__FUNCTION__, [&] {
|
||||
assignMaterialTo3dModel(modelNode, m_droppedMaterial);
|
||||
});
|
||||
}
|
||||
}
|
||||
m_modelAtPosReqType = ModelAtPosReqType::None;
|
||||
m_nodeAtPosReqType = NodeAtPosReqType::None;
|
||||
}
|
||||
|
||||
void Edit3DView::sendInputEvent(QInputEvent *e) const
|
||||
@@ -697,18 +698,18 @@ void Edit3DView::addQuick3DImport()
|
||||
}
|
||||
|
||||
// This method is called upon right-clicking the view to prepare for context-menu creation. The actual
|
||||
// context menu is created when modelAtPosReady() is received from puppet
|
||||
// context menu is created when nodeAtPosReady() is received from puppet
|
||||
void Edit3DView::startContextMenu(const QPoint &pos)
|
||||
{
|
||||
m_contextMenuPos = pos;
|
||||
m_modelAtPosReqType = ModelAtPosReqType::ContextMenu;
|
||||
m_nodeAtPosReqType = NodeAtPosReqType::ContextMenu;
|
||||
}
|
||||
|
||||
void Edit3DView::dropMaterial(const ModelNode &matNode, const QPointF &pos)
|
||||
{
|
||||
m_modelAtPosReqType = ModelAtPosReqType::MaterialDrop;
|
||||
m_nodeAtPosReqType = NodeAtPosReqType::MaterialDrop;
|
||||
m_droppedMaterial = matNode;
|
||||
QmlDesignerPlugin::instance()->viewManager().nodeInstanceView()->view3DAction({View3DActionCommand::GetModelAtPos, pos});
|
||||
QmlDesignerPlugin::instance()->viewManager().nodeInstanceView()->view3DAction({View3DActionCommand::GetNodeAtPos, pos});
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
@@ -63,7 +63,7 @@ public:
|
||||
void modelAboutToBeDetached(Model *model) override;
|
||||
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports) override;
|
||||
void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data) override;
|
||||
void modelAtPosReady(const ModelNode &modelNode) override;
|
||||
void nodeAtPosReady(const ModelNode &modelNode) override;
|
||||
|
||||
void sendInputEvent(QInputEvent *e) const;
|
||||
void edit3DViewResized(const QSize &size) const;
|
||||
@@ -85,7 +85,7 @@ private slots:
|
||||
void onEntriesChanged();
|
||||
|
||||
private:
|
||||
enum class ModelAtPosReqType {
|
||||
enum class NodeAtPosReqType {
|
||||
MaterialDrop,
|
||||
ContextMenu,
|
||||
None
|
||||
@@ -130,7 +130,7 @@ private:
|
||||
int particlemode;
|
||||
ModelCache<QImage> m_canvasCache;
|
||||
ModelNode m_droppedMaterial;
|
||||
ModelAtPosReqType m_modelAtPosReqType;
|
||||
NodeAtPosReqType m_nodeAtPosReqType;
|
||||
QPoint m_contextMenuPos;
|
||||
QTimer m_compressionTimer;
|
||||
};
|
||||
|
@@ -300,8 +300,10 @@ void Edit3DWidget::showContextMenu(const QPoint &pos, const ModelNode &modelNode
|
||||
{
|
||||
m_contextMenuTarget = modelNode;
|
||||
|
||||
m_editMaterialAction->setEnabled(modelNode.isValid());
|
||||
m_deleteAction->setEnabled(modelNode.isValid());
|
||||
const bool isValid = modelNode.isValid();
|
||||
const bool isModel = isValid && modelNode.isSubclassOf("QtQuick3D.Model");
|
||||
m_editMaterialAction->setEnabled(isModel);
|
||||
m_deleteAction->setEnabled(isValid && !modelNode.isRootNode());
|
||||
|
||||
m_contextMenu->popup(mapToGlobal(pos));
|
||||
}
|
||||
|
@@ -166,7 +166,7 @@ public:
|
||||
void emitUpdateActiveScene3D(const QVariantMap &sceneState);
|
||||
void emitModelNodelPreviewPixmapChanged(const ModelNode &node, const QPixmap &pixmap);
|
||||
void emitImport3DSupportChanged(const QVariantMap &supportMap);
|
||||
void emitModelAtPosResult(const ModelNode &modelNode);
|
||||
void emitNodeAtPosResult(const ModelNode &modelNode);
|
||||
|
||||
void sendTokenToInstances(const QString &token, int number, const QVector<ModelNode> &nodeVector);
|
||||
|
||||
@@ -232,7 +232,7 @@ public:
|
||||
virtual void renderImage3DChanged(const QImage &image);
|
||||
virtual void updateActiveScene3D(const QVariantMap &sceneState);
|
||||
virtual void updateImport3DSupport(const QVariantMap &supportMap);
|
||||
virtual void modelAtPosReady(const ModelNode &modelNode);
|
||||
virtual void nodeAtPosReady(const ModelNode &modelNode);
|
||||
virtual void modelNodePreviewPixmapChanged(const ModelNode &node, const QPixmap &pixmap);
|
||||
|
||||
virtual void dragStarted(QMimeData *mimeData);
|
||||
|
@@ -1705,9 +1705,9 @@ void NodeInstanceView::handlePuppetToCreatorCommand(const PuppetToCreatorCommand
|
||||
} else if (command.type() == PuppetToCreatorCommand::Import3DSupport) {
|
||||
const QVariantMap supportMap = qvariant_cast<QVariantMap>(command.data());
|
||||
emitImport3DSupportChanged(supportMap);
|
||||
} else if (command.type() == PuppetToCreatorCommand::ModelAtPos) {
|
||||
} else if (command.type() == PuppetToCreatorCommand::NodeAtPos) {
|
||||
ModelNode modelNode = modelNodeForInternalId(command.data().toUInt());
|
||||
emitModelAtPosResult(modelNode);
|
||||
emitNodeAtPosResult(modelNode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -409,7 +409,7 @@ void AbstractView::updateImport3DSupport(const QVariantMap & /*supportMap*/)
|
||||
}
|
||||
|
||||
// a Quick3DModel that is picked at the requested position in the 3D Editor
|
||||
void AbstractView::modelAtPosReady(const ModelNode & /*modelNode*/) {}
|
||||
void AbstractView::nodeAtPosReady(const ModelNode & /*modelNode*/) {}
|
||||
|
||||
void AbstractView::modelNodePreviewPixmapChanged(const ModelNode & /*node*/, const QPixmap & /*pixmap*/)
|
||||
{
|
||||
@@ -802,10 +802,10 @@ void AbstractView::emitImport3DSupportChanged(const QVariantMap &supportMap)
|
||||
model()->d->notifyImport3DSupportChanged(supportMap);
|
||||
}
|
||||
|
||||
void AbstractView::emitModelAtPosResult(const ModelNode &modelNode)
|
||||
void AbstractView::emitNodeAtPosResult(const ModelNode &modelNode)
|
||||
{
|
||||
if (model())
|
||||
model()->d->notifyModelAtPosResult(modelNode);
|
||||
model()->d->notifyNodeAtPosResult(modelNode);
|
||||
}
|
||||
|
||||
void AbstractView::emitRewriterEndTransaction()
|
||||
|
@@ -598,9 +598,9 @@ void ModelPrivate::notifyImport3DSupportChanged(const QVariantMap &supportMap)
|
||||
notifyInstanceChanges([&](AbstractView *view) { view->updateImport3DSupport(supportMap); });
|
||||
}
|
||||
|
||||
void ModelPrivate::notifyModelAtPosResult(const ModelNode &modelNode)
|
||||
void ModelPrivate::notifyNodeAtPosResult(const ModelNode &modelNode)
|
||||
{
|
||||
notifyInstanceChanges([&](AbstractView *view) { view->modelAtPosReady(modelNode); });
|
||||
notifyInstanceChanges([&](AbstractView *view) { view->nodeAtPosReady(modelNode); });
|
||||
}
|
||||
|
||||
void ModelPrivate::notifyDragStarted(QMimeData *mimeData)
|
||||
|
@@ -186,7 +186,7 @@ public:
|
||||
void notifyUpdateActiveScene3D(const QVariantMap &sceneState);
|
||||
void notifyModelNodePreviewPixmapChanged(const ModelNode &node, const QPixmap &pixmap);
|
||||
void notifyImport3DSupportChanged(const QVariantMap &supportMap);
|
||||
void notifyModelAtPosResult(const ModelNode &modelNode);
|
||||
void notifyNodeAtPosResult(const ModelNode &modelNode);
|
||||
|
||||
void notifyDragStarted(QMimeData *mimeData);
|
||||
void notifyDragEnded();
|
||||
|
Reference in New Issue
Block a user