QmlDesigner: Fix dragging effects, images, and fonts to 2D view

Fixes: QDS-14923
Change-Id: Icdd53a706ca3bb1bdbd09be22390db55a8e670cf
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2025-03-14 17:09:09 +02:00
parent 5dd4fcd1f4
commit 5731904f70
3 changed files with 22 additions and 16 deletions

View File

@@ -40,6 +40,23 @@ FormEditorScene* AbstractFormEditorTool::scene() const
return view()->scene();
}
bool AbstractFormEditorTool::hasDroppableAsset(const QMimeData *mimeData)
{
if (mimeData->hasFormat(Constants::MIME_TYPE_ASSETS)) {
const QStringList assetPaths
= QString::fromUtf8(mimeData->data(Constants::MIME_TYPE_ASSETS)).split(',');
for (const QString &assetPath : assetPaths) {
QString assetType = AssetsLibraryWidget::getAssetTypeAndData(assetPath).first;
if (assetType == Constants::MIME_TYPE_ASSET_IMAGE
|| assetType == Constants::MIME_TYPE_ASSET_FONT
|| assetType == Constants::MIME_TYPE_ASSET_EFFECT) {
return true;
}
}
}
return false;
}
void AbstractFormEditorTool::setItems(const QList<FormEditorItem*> &itemList)
{
m_itemList = itemList;
@@ -215,22 +232,8 @@ void AbstractFormEditorTool::dropEvent(const QList<QGraphicsItem*> &/*itemList*/
void AbstractFormEditorTool::dragEnterEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSceneDragDropEvent *event)
{
bool hasValidAssets = false;
if (event->mimeData()->hasFormat(Constants::MIME_TYPE_ASSETS)) {
const QStringList assetPaths = QString::fromUtf8(event->mimeData()
->data(Constants::MIME_TYPE_ASSETS)).split(',');
for (const QString &assetPath : assetPaths) {
QString assetType = AssetsLibraryWidget::getAssetTypeAndData(assetPath).first;
if (assetType == Constants::MIME_TYPE_ASSET_IMAGE
|| assetType == Constants::MIME_TYPE_ASSET_FONT
|| assetType == Constants::MIME_TYPE_ASSET_EFFECT) {
hasValidAssets = true;
break;
}
}
}
if (event->mimeData()->hasFormat(Constants::MIME_TYPE_ITEM_LIBRARY_INFO) || hasValidAssets) {
if (event->mimeData()->hasFormat(Constants::MIME_TYPE_ITEM_LIBRARY_INFO)
|| hasDroppableAsset(event->mimeData())) {
event->accept();
view()->changeToDragTool();
view()->currentTool()->dragEnterEvent(itemList, event);

View File

@@ -59,6 +59,7 @@ public:
void setItems(const QList<FormEditorItem*> &itemList);
QList<FormEditorItem*> items() const;
static bool hasDroppableAsset(const QMimeData *mimeData);
static QList<FormEditorItem*> toFormEditorItemList(const QList<QGraphicsItem*> &itemList);
static QGraphicsItem* topMovableGraphicsItem(const QList<QGraphicsItem*> &itemList);
static FormEditorItem* topMovableFormEditorItem(const QList<QGraphicsItem*> &itemList, bool selectOnlyContentItems);

View File

@@ -209,6 +209,8 @@ static ItemLibraryEntry itemLibraryEntryFromMimeData(const QMimeData *mimeData)
static bool canBeDropped(const QMimeData *mimeData, Model *model)
{
if (AbstractFormEditorTool::hasDroppableAsset(mimeData))
return true;
#ifdef QDS_USE_PROJECTSTORAGE
auto itemLibraryEntry = itemLibraryEntryFromMimeData(mimeData);
NodeMetaInfo metaInfo{itemLibraryEntry.typeId(), model->projectStorage()};