QmlDesigner: Allow drag effects to only QtQuickItem elements

- While drag an effect from asset library,
it only applies to elements that are type of QtQuickItem and has layer.effect property.
- Highlight those elements when start dragging an effect,
so user know correct elements to drag to.

Task-number: QDS-8579
Change-Id: Iedeed0e5ac65ce8b635f5cca6311b05c85197695
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Amr Essam
2023-01-04 11:39:54 +02:00
committed by Amr Elsayed
parent c81f5ba7d1
commit 1482bc0ae1
5 changed files with 32 additions and 1 deletions

View File

@@ -39,6 +39,8 @@ ChooseFromPropertyListFilter::ChooseFromPropertyListFilter(const NodeMetaInfo &i
// -> Model // -> Model
// BundleMaterial // BundleMaterial
// -> Model // -> Model
// Effect
// -> Item
if (insertInfo.isQtQuick3DTexture()) { if (insertInfo.isQtQuick3DTexture()) {
if (parentInfo.isQtQuick3DDefaultMaterial() || parentInfo.isQtQuick3DPrincipledMaterial() if (parentInfo.isQtQuick3DDefaultMaterial() || parentInfo.isQtQuick3DPrincipledMaterial()
@@ -93,6 +95,9 @@ ChooseFromPropertyListFilter::ChooseFromPropertyListFilter(const NodeMetaInfo &i
// TODO merge conflict between Change-Id: If3c58f82797beabe76baf99ea2dddc59032729df and Change-Id: Iff2dea66e253b412105427134bd49cb16ed76193 // TODO merge conflict between Change-Id: If3c58f82797beabe76baf99ea2dddc59032729df and Change-Id: Iff2dea66e253b412105427134bd49cb16ed76193
// } else if (insertInfo.typeName().startsWith("ComponentBundles.MaterialBundle")) { // } else if (insertInfo.typeName().startsWith("ComponentBundles.MaterialBundle")) {
// if (parentInfo.isSubclassOf("QtQuick3D.Model")) // if (parentInfo.isSubclassOf("QtQuick3D.Model"))
} else if (insertInfo.isEffectMaker()) {
if (parentInfo.isQtQuickItem())
propertyList.append("effect");
} }
} }

View File

@@ -1019,7 +1019,8 @@ ModelNode NavigatorTreeModel::handleItemLibraryEffectDrop(const QString &effectP
ModelNode targetNode(modelNodeForIndex(rowModelIndex)); ModelNode targetNode(modelNodeForIndex(rowModelIndex));
ModelNode newModelNode; ModelNode newModelNode;
if (targetNode.hasParentProperty() && targetNode.parentProperty().name() == "layer.effect") if ((targetNode.hasParentProperty() && targetNode.parentProperty().name() == "layer.effect")
|| !targetNode.metaInfo().isQtQuickItem())
return newModelNode; return newModelNode;
if (ModelNodeOperations::validateEffect(effectPath)) { if (ModelNodeOperations::validateEffect(effectPath)) {

View File

@@ -7,6 +7,7 @@
#include "qmldesignerconstants.h" #include "qmldesignerconstants.h"
#include "qmldesignericons.h" #include "qmldesignericons.h"
#include "qmldesignerplugin.h" #include "qmldesignerplugin.h"
#include "assetslibrarywidget.h"
#include "nameitemdelegate.h" #include "nameitemdelegate.h"
#include "iconcheckboxitemdelegate.h" #include "iconcheckboxitemdelegate.h"
@@ -266,6 +267,19 @@ void NavigatorView::dragStarted(QMimeData *mimeData)
m_widget->setDragType(bundleMatType); m_widget->setDragType(bundleMatType);
m_widget->update(); m_widget->update();
} else if (mimeData->hasFormat(Constants::MIME_TYPE_ASSETS)) {
const QStringList assetsPaths = QString::fromUtf8(mimeData->data(Constants::MIME_TYPE_ASSETS)).split(',');
if (assetsPaths.count() > 0) {
auto assetTypeAndData = AssetsLibraryWidget::getAssetTypeAndData(assetsPaths[0]);
QString assetType = assetTypeAndData.first;
if (assetType == Constants::MIME_TYPE_ASSET_EFFECT) {
qint32 internalId = mimeData->data(Constants::MIME_TYPE_ASSET_EFFECT).toInt();
ModelNode effectNode = modelNodeForInternalId(internalId);
m_widget->setDragType(effectNode.metaInfo().typeName());
m_widget->update();
}
}
} }
} }

View File

@@ -100,6 +100,7 @@ public:
bool isAlias() const; bool isAlias() const;
bool isBool() const; bool isBool() const;
bool isColor() const; bool isColor() const;
bool isEffectMaker() const;
bool isFloat() const; bool isFloat() const;
bool isFlowViewFlowActionArea() const; bool isFlowViewFlowActionArea() const;
bool isFlowViewFlowDecision() const; bool isFlowViewFlowDecision() const;

View File

@@ -2535,6 +2535,16 @@ bool NodeMetaInfo::isColor() const
} }
} }
bool NodeMetaInfo::isEffectMaker() const
{
if constexpr (useProjectStorage()) {
using namespace Storage::Info;
return isBasedOnCommonType<Effect, Item>(m_projectStorage, m_typeId);
} else {
return isValid() && m_privateData->properties().contains("layer.effect");
}
}
bool NodeMetaInfo::isBool() const bool NodeMetaInfo::isBool() const
{ {
if constexpr (useProjectStorage()) { if constexpr (useProjectStorage()) {