forked from qt-creator/qt-creator
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:
@@ -40,6 +40,23 @@ FormEditorScene* AbstractFormEditorTool::scene() const
|
|||||||
return view()->scene();
|
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)
|
void AbstractFormEditorTool::setItems(const QList<FormEditorItem*> &itemList)
|
||||||
{
|
{
|
||||||
m_itemList = itemList;
|
m_itemList = itemList;
|
||||||
@@ -215,22 +232,8 @@ void AbstractFormEditorTool::dropEvent(const QList<QGraphicsItem*> &/*itemList*/
|
|||||||
|
|
||||||
void AbstractFormEditorTool::dragEnterEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSceneDragDropEvent *event)
|
void AbstractFormEditorTool::dragEnterEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSceneDragDropEvent *event)
|
||||||
{
|
{
|
||||||
bool hasValidAssets = false;
|
if (event->mimeData()->hasFormat(Constants::MIME_TYPE_ITEM_LIBRARY_INFO)
|
||||||
if (event->mimeData()->hasFormat(Constants::MIME_TYPE_ASSETS)) {
|
|| hasDroppableAsset(event->mimeData())) {
|
||||||
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) {
|
|
||||||
event->accept();
|
event->accept();
|
||||||
view()->changeToDragTool();
|
view()->changeToDragTool();
|
||||||
view()->currentTool()->dragEnterEvent(itemList, event);
|
view()->currentTool()->dragEnterEvent(itemList, event);
|
||||||
|
@@ -59,6 +59,7 @@ public:
|
|||||||
void setItems(const QList<FormEditorItem*> &itemList);
|
void setItems(const QList<FormEditorItem*> &itemList);
|
||||||
QList<FormEditorItem*> items() const;
|
QList<FormEditorItem*> items() const;
|
||||||
|
|
||||||
|
static bool hasDroppableAsset(const QMimeData *mimeData);
|
||||||
static QList<FormEditorItem*> toFormEditorItemList(const QList<QGraphicsItem*> &itemList);
|
static QList<FormEditorItem*> toFormEditorItemList(const QList<QGraphicsItem*> &itemList);
|
||||||
static QGraphicsItem* topMovableGraphicsItem(const QList<QGraphicsItem*> &itemList);
|
static QGraphicsItem* topMovableGraphicsItem(const QList<QGraphicsItem*> &itemList);
|
||||||
static FormEditorItem* topMovableFormEditorItem(const QList<QGraphicsItem*> &itemList, bool selectOnlyContentItems);
|
static FormEditorItem* topMovableFormEditorItem(const QList<QGraphicsItem*> &itemList, bool selectOnlyContentItems);
|
||||||
|
@@ -209,6 +209,8 @@ static ItemLibraryEntry itemLibraryEntryFromMimeData(const QMimeData *mimeData)
|
|||||||
|
|
||||||
static bool canBeDropped(const QMimeData *mimeData, Model *model)
|
static bool canBeDropped(const QMimeData *mimeData, Model *model)
|
||||||
{
|
{
|
||||||
|
if (AbstractFormEditorTool::hasDroppableAsset(mimeData))
|
||||||
|
return true;
|
||||||
#ifdef QDS_USE_PROJECTSTORAGE
|
#ifdef QDS_USE_PROJECTSTORAGE
|
||||||
auto itemLibraryEntry = itemLibraryEntryFromMimeData(mimeData);
|
auto itemLibraryEntry = itemLibraryEntryFromMimeData(mimeData);
|
||||||
NodeMetaInfo metaInfo{itemLibraryEntry.typeId(), model->projectStorage()};
|
NodeMetaInfo metaInfo{itemLibraryEntry.typeId(), model->projectStorage()};
|
||||||
|
Reference in New Issue
Block a user