2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2015-09-18 11:34:48 +02:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
2016-01-15 14:57:40 +01:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
#include "dragtool.h"
|
|
|
|
|
|
|
|
|
|
#include "formeditorscene.h"
|
|
|
|
|
#include "formeditorview.h"
|
2022-02-03 19:49:27 +02:00
|
|
|
#include "assetslibrarywidget.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
#include <metainfo.h>
|
2017-01-24 15:30:08 +01:00
|
|
|
#include <nodehints.h>
|
2010-09-24 13:45:42 +02:00
|
|
|
#include <rewritingexception.h>
|
2022-05-10 20:31:05 +03:00
|
|
|
#include "qmldesignerconstants.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2022-06-07 13:39:25 +03:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2017-02-09 12:18:25 +01:00
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
|
#include <QLoggingCategory>
|
2013-04-25 11:50:38 +02:00
|
|
|
#include <QMimeData>
|
2010-12-06 17:44:25 +01:00
|
|
|
#include <QTimer>
|
2014-05-13 14:35:39 +02:00
|
|
|
#include <QWidget>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2018-10-12 09:33:30 +03:00
|
|
|
static Q_LOGGING_CATEGORY(dragToolInfo, "qtc.qmldesigner.formeditor", QtWarningMsg);
|
2017-02-09 12:18:25 +01:00
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
|
|
DragTool::DragTool(FormEditorView *editorView)
|
|
|
|
|
: AbstractFormEditorTool(editorView),
|
|
|
|
|
m_moveManipulator(editorView->scene()->manipulatorLayerItem(), editorView),
|
2021-06-15 17:24:24 +03:00
|
|
|
m_selectionIndicator(editorView->scene()->manipulatorLayerItem())
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-24 23:56:45 +02:00
|
|
|
DragTool::~DragTool() = default;
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
void DragTool::clear()
|
|
|
|
|
{
|
|
|
|
|
m_moveManipulator.clear();
|
|
|
|
|
m_selectionIndicator.clear();
|
2021-06-15 17:24:24 +03:00
|
|
|
m_movingItems.clear();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-27 15:57:15 +02:00
|
|
|
void DragTool::mousePressEvent(const QList<QGraphicsItem *> &, QGraphicsSceneMouseEvent *) {}
|
|
|
|
|
void DragTool::mouseMoveEvent(const QList<QGraphicsItem *> &, QGraphicsSceneMouseEvent *) {}
|
|
|
|
|
void DragTool::hoverMoveEvent(const QList<QGraphicsItem *> &, QGraphicsSceneMouseEvent *) {}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2011-05-10 15:09:26 +02:00
|
|
|
void DragTool::keyPressEvent(QKeyEvent *event)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2011-05-10 15:09:26 +02:00
|
|
|
if (event->key() == Qt::Key_Escape) {
|
|
|
|
|
abort();
|
|
|
|
|
event->accept();
|
2014-08-05 17:39:05 +02:00
|
|
|
commitTransaction();
|
2011-05-10 15:09:26 +02:00
|
|
|
view()->changeToSelectionTool();
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-27 15:57:15 +02:00
|
|
|
void DragTool::keyReleaseEvent(QKeyEvent *) {}
|
|
|
|
|
void DragTool::mouseReleaseEvent(const QList<QGraphicsItem *> &, QGraphicsSceneMouseEvent *) {}
|
|
|
|
|
void DragTool::mouseDoubleClickEvent(const QList<QGraphicsItem *> &, QGraphicsSceneMouseEvent *) {}
|
|
|
|
|
void DragTool::itemsAboutToRemoved(const QList<FormEditorItem *> &) {}
|
|
|
|
|
void DragTool::selectedItemsChanged(const QList<FormEditorItem *> &) {}
|
|
|
|
|
void DragTool::updateMoveManipulator() {}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
void DragTool::beginWithPoint(const QPointF &beginPoint)
|
|
|
|
|
{
|
2021-06-15 17:24:24 +03:00
|
|
|
m_movingItems = scene()->itemsForQmlItemNodes(m_dragNodes);
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
m_moveManipulator.setItems(m_movingItems);
|
2010-01-07 12:14:35 +01:00
|
|
|
m_moveManipulator.begin(beginPoint);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 20:21:14 +03:00
|
|
|
void DragTool::createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry,
|
|
|
|
|
const QmlItemNode &parentNode,
|
2014-07-21 18:06:07 +02:00
|
|
|
const QPointF &scenePosition)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
MetaInfo metaInfo = MetaInfo::global();
|
|
|
|
|
|
|
|
|
|
FormEditorItem *parentItem = scene()->itemForQmlItemNode(parentNode);
|
2020-01-29 15:12:55 +01:00
|
|
|
const QPointF positonInItemSpace = parentItem->qmlItemNode().instanceSceneContentItemTransform().inverted().map(scenePosition);
|
|
|
|
|
QPointF itemPos = positonInItemSpace;
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2020-01-29 15:12:55 +01:00
|
|
|
const bool rootIsFlow = QmlItemNode(view()->rootModelNode()).isFlowView();
|
|
|
|
|
|
2020-04-07 18:31:59 +02:00
|
|
|
QmlItemNode adjustedParentNode = parentNode;
|
|
|
|
|
|
|
|
|
|
if (rootIsFlow) {
|
2020-01-29 15:12:55 +01:00
|
|
|
itemPos = QPointF();
|
2020-04-07 18:31:59 +02:00
|
|
|
adjustedParentNode = view()->rootModelNode();
|
|
|
|
|
}
|
2020-01-29 15:12:55 +01:00
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
m_dragNodes.append(QmlItemNode::createQmlItemNode(view(), itemLibraryEntry, itemPos, adjustedParentNode));
|
2020-01-29 15:12:55 +01:00
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
if (rootIsFlow) {
|
|
|
|
|
for (QmlItemNode &dragNode : m_dragNodes)
|
|
|
|
|
dragNode.setFlowItemPosition(positonInItemSpace);
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
m_selectionIndicator.setItems(scene()->itemsForQmlItemNodes(m_dragNodes));
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
void DragTool::createQmlItemNodeFromImage(const QString &imagePath,
|
2014-05-21 20:21:14 +03:00
|
|
|
const QmlItemNode &parentNode,
|
2014-07-21 18:06:07 +02:00
|
|
|
const QPointF &scenePosition)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2014-07-17 15:27:59 +02:00
|
|
|
if (parentNode.isValid()) {
|
|
|
|
|
MetaInfo metaInfo = MetaInfo::global();
|
2010-04-06 15:08:46 +02:00
|
|
|
|
2014-07-17 15:27:59 +02:00
|
|
|
FormEditorItem *parentItem = scene()->itemForQmlItemNode(parentNode);
|
2014-07-21 18:34:26 +02:00
|
|
|
QPointF positonInItemSpace = parentItem->qmlItemNode().instanceSceneContentItemTransform().inverted().map(scenePosition);
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
m_dragNodes.append(QmlItemNode::createQmlItemNodeFromImage(view(), imagePath, positonInItemSpace, parentNode));
|
2014-07-17 15:27:59 +02:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
void DragTool::createQmlItemNodeFromFont(const QString &fontPath,
|
2020-12-23 14:58:58 +02:00
|
|
|
const QmlItemNode &parentNode,
|
|
|
|
|
const QPointF &scenePos)
|
|
|
|
|
{
|
|
|
|
|
if (parentNode.isValid()) {
|
|
|
|
|
MetaInfo metaInfo = MetaInfo::global();
|
|
|
|
|
|
|
|
|
|
FormEditorItem *parentItem = scene()->itemForQmlItemNode(parentNode);
|
|
|
|
|
QPointF positonInItemSpace = parentItem->qmlItemNode().instanceSceneContentItemTransform()
|
|
|
|
|
.inverted().map(scenePos);
|
|
|
|
|
|
2022-02-03 19:49:27 +02:00
|
|
|
const auto typeAndData = AssetsLibraryWidget::getAssetTypeAndData(fontPath);
|
2021-06-15 17:24:24 +03:00
|
|
|
QString fontFamily = QString::fromUtf8(typeAndData.second);
|
2020-12-23 14:58:58 +02:00
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
m_dragNodes.append(QmlItemNode::createQmlItemNodeFromFont(view(), fontFamily,
|
|
|
|
|
positonInItemSpace, parentNode));
|
2020-12-23 14:58:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
FormEditorItem *DragTool::targetContainerOrRootItem(const QList<QGraphicsItem *> &itemList,
|
|
|
|
|
const QList<FormEditorItem *> ¤tItems)
|
2014-07-21 13:05:35 +02:00
|
|
|
{
|
2021-06-15 17:24:24 +03:00
|
|
|
FormEditorItem *formEditorItem = containerFormEditorItem(itemList, currentItems);
|
2010-03-15 17:39:37 +01:00
|
|
|
|
2014-07-21 13:05:35 +02:00
|
|
|
if (!formEditorItem)
|
|
|
|
|
formEditorItem = scene()->rootFormEditorItem();
|
2014-07-17 15:27:59 +02:00
|
|
|
|
2014-07-21 13:05:35 +02:00
|
|
|
return formEditorItem;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-27 15:57:15 +02:00
|
|
|
void DragTool::formEditorItemsChanged(const QList<FormEditorItem *> &itemList)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2021-06-15 17:24:24 +03:00
|
|
|
if (!m_movingItems.isEmpty()) {
|
|
|
|
|
for (auto item : std::as_const(m_movingItems)) {
|
|
|
|
|
if (itemList.contains(item)) {
|
|
|
|
|
m_selectionIndicator.updateItems(m_movingItems);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 15:57:15 +02:00
|
|
|
void DragTool::instancesCompleted(const QList<FormEditorItem *> &itemList)
|
2010-12-10 22:46:18 +01:00
|
|
|
{
|
2014-05-13 15:03:20 +02:00
|
|
|
m_moveManipulator.synchronizeInstanceParent(itemList);
|
2021-06-15 17:24:24 +03:00
|
|
|
for (FormEditorItem *item : itemList) {
|
|
|
|
|
for (const QmlItemNode &dragNode : std::as_const(m_dragNodes)) {
|
|
|
|
|
if (item->qmlItemNode() == dragNode) {
|
|
|
|
|
clearMoveDelay();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-10 22:46:18 +01:00
|
|
|
}
|
|
|
|
|
|
2011-06-30 17:30:17 +02:00
|
|
|
void DragTool::instancesParentChanged(const QList<FormEditorItem *> &itemList)
|
|
|
|
|
{
|
|
|
|
|
m_moveManipulator.synchronizeInstanceParent(itemList);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 15:57:15 +02:00
|
|
|
void DragTool::instancePropertyChange(const QList<QPair<ModelNode, PropertyName> > &) {}
|
2011-06-30 17:30:17 +02:00
|
|
|
|
2010-12-06 17:44:25 +01:00
|
|
|
void DragTool::clearMoveDelay()
|
|
|
|
|
{
|
2014-07-17 15:27:59 +02:00
|
|
|
if (m_blockMove) {
|
|
|
|
|
m_blockMove = false;
|
2021-06-15 17:24:24 +03:00
|
|
|
if (!m_dragNodes.isEmpty())
|
2014-07-17 15:27:59 +02:00
|
|
|
beginWithPoint(m_startPoint);
|
|
|
|
|
}
|
2010-12-06 17:44:25 +01:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2020-01-27 15:57:15 +02:00
|
|
|
void DragTool::focusLost() {}
|
2016-10-11 13:04:07 +02:00
|
|
|
|
2011-05-10 15:09:26 +02:00
|
|
|
void DragTool::abort()
|
|
|
|
|
{
|
2014-07-17 15:27:59 +02:00
|
|
|
if (!m_isAborted) {
|
|
|
|
|
m_isAborted = true;
|
|
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
for (auto &node : m_dragNodes) {
|
|
|
|
|
if (node.isValid())
|
|
|
|
|
node.destroy();
|
|
|
|
|
}
|
|
|
|
|
m_dragNodes.clear();
|
2014-07-17 15:27:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
2011-05-10 15:09:26 +02:00
|
|
|
|
2017-01-24 15:30:08 +01:00
|
|
|
static ItemLibraryEntry itemLibraryEntryFromMimeData(const QMimeData *mimeData)
|
|
|
|
|
{
|
2022-05-10 20:31:05 +03:00
|
|
|
QDataStream stream(mimeData->data(Constants::MIME_TYPE_ITEM_LIBRARY_INFO));
|
2017-01-24 15:30:08 +01:00
|
|
|
|
|
|
|
|
ItemLibraryEntry itemLibraryEntry;
|
|
|
|
|
stream >> itemLibraryEntry;
|
|
|
|
|
|
|
|
|
|
return itemLibraryEntry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool canBeDropped(const QMimeData *mimeData)
|
|
|
|
|
{
|
|
|
|
|
return NodeHints::fromItemLibraryEntry(itemLibraryEntryFromMimeData(mimeData)).canBeDroppedInFormEditor();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 14:58:58 +02:00
|
|
|
static bool hasItemLibraryInfo(const QMimeData *mimeData)
|
2014-07-17 15:27:59 +02:00
|
|
|
{
|
2022-05-10 20:31:05 +03:00
|
|
|
return mimeData->hasFormat(Constants::MIME_TYPE_ITEM_LIBRARY_INFO);
|
2014-07-17 15:27:59 +02:00
|
|
|
}
|
2011-05-10 15:09:26 +02:00
|
|
|
|
2020-01-27 15:57:15 +02:00
|
|
|
void DragTool::dropEvent(const QList<QGraphicsItem *> &/*itemList*/, QGraphicsSceneDragDropEvent *event)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2021-06-15 17:24:24 +03:00
|
|
|
if (canBeDropped(event->mimeData())) {
|
2010-01-07 12:14:35 +01:00
|
|
|
event->accept();
|
2013-05-14 16:21:29 +02:00
|
|
|
end(generateUseSnapping(event->modifiers()));
|
|
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
bool resetPuppet = false;
|
|
|
|
|
for (auto &node : m_dragNodes) {
|
|
|
|
|
if (node.isValid()) {
|
|
|
|
|
if ((node.instanceParentItem().isValid()
|
|
|
|
|
&& node.instanceParent().modelNode().metaInfo().isLayoutable())
|
|
|
|
|
|| node.isFlowItem()) {
|
|
|
|
|
node.removeProperty("x");
|
|
|
|
|
node.removeProperty("y");
|
|
|
|
|
resetPuppet = true;
|
|
|
|
|
}
|
2017-03-06 11:19:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-15 17:24:24 +03:00
|
|
|
if (resetPuppet)
|
|
|
|
|
view()->resetPuppet(); // Otherwise the layout might not reposition the items
|
2017-03-06 11:19:33 +01:00
|
|
|
|
2014-08-05 17:39:05 +02:00
|
|
|
commitTransaction();
|
2014-01-02 15:21:09 +01:00
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
if (!m_dragNodes.isEmpty()) {
|
|
|
|
|
QList<ModelNode> nodeList;
|
|
|
|
|
for (auto &node : std::as_const(m_dragNodes)) {
|
|
|
|
|
if (node.isValid())
|
|
|
|
|
nodeList.append(node);
|
|
|
|
|
}
|
|
|
|
|
view()->setSelectedModelNodes(nodeList);
|
|
|
|
|
}
|
|
|
|
|
m_dragNodes.clear();
|
2014-07-17 15:27:59 +02:00
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
view()->changeToSelectionTool();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 15:57:15 +02:00
|
|
|
void DragTool::dragEnterEvent(const QList<QGraphicsItem *> &/*itemList*/, QGraphicsSceneDragDropEvent *event)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2021-06-15 17:24:24 +03:00
|
|
|
if (canBeDropped(event->mimeData())) {
|
2010-12-10 23:04:02 +01:00
|
|
|
m_blockMove = false;
|
2017-01-24 15:30:08 +01:00
|
|
|
|
2014-07-17 15:27:59 +02:00
|
|
|
if (hasItemLibraryInfo(event->mimeData())) {
|
2013-03-14 16:41:35 +01:00
|
|
|
view()->widgetInfo().widget->setFocus();
|
2014-07-17 15:27:59 +02:00
|
|
|
m_isAborted = false;
|
2010-12-09 16:39:15 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
if (!m_rewriterTransaction.isValid()) {
|
2014-01-06 12:51:56 +01:00
|
|
|
m_rewriterTransaction = view()->beginRewriterTransaction(QByteArrayLiteral("DragTool::dragEnterEvent"));
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 15:57:15 +02:00
|
|
|
void DragTool::dragLeaveEvent(const QList<QGraphicsItem *> &/*itemList*/, QGraphicsSceneDragDropEvent *event)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2021-06-15 17:24:24 +03:00
|
|
|
if (canBeDropped(event->mimeData())) {
|
2010-01-07 12:14:35 +01:00
|
|
|
event->accept();
|
2013-05-14 16:21:29 +02:00
|
|
|
|
|
|
|
|
m_moveManipulator.end();
|
|
|
|
|
clear();
|
2021-06-15 17:24:24 +03:00
|
|
|
|
|
|
|
|
for (auto &node : m_dragNodes) {
|
|
|
|
|
if (node.isValid())
|
|
|
|
|
node.destroy();
|
|
|
|
|
}
|
|
|
|
|
m_dragNodes.clear();
|
2010-09-24 13:45:42 +02:00
|
|
|
|
2014-08-05 17:39:05 +02:00
|
|
|
commitTransaction();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
2020-01-27 15:57:15 +02:00
|
|
|
|
|
|
|
|
view()->changeToSelectionTool();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
void DragTool::createDragNodes(const QMimeData *mimeData, const QPointF &scenePosition,
|
|
|
|
|
const QList<QGraphicsItem *> &itemList)
|
2020-12-23 14:58:58 +02:00
|
|
|
{
|
2021-06-15 17:24:24 +03:00
|
|
|
if (m_dragNodes.isEmpty()) {
|
2014-07-21 13:05:35 +02:00
|
|
|
FormEditorItem *targetContainerFormEditorItem = targetContainerOrRootItem(itemList);
|
2014-07-17 15:27:59 +02:00
|
|
|
if (targetContainerFormEditorItem) {
|
2021-06-15 17:24:24 +03:00
|
|
|
QmlItemNode targetContainerQmlItemNode = targetContainerFormEditorItem->qmlItemNode();
|
2014-07-17 15:27:59 +02:00
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
if (hasItemLibraryInfo(mimeData)) {
|
|
|
|
|
createQmlItemNode(itemLibraryEntryFromMimeData(mimeData), targetContainerQmlItemNode,
|
|
|
|
|
scenePosition);
|
|
|
|
|
} else {
|
|
|
|
|
const QStringList assetPaths = QString::fromUtf8(mimeData
|
2022-05-10 20:31:05 +03:00
|
|
|
->data(Constants::MIME_TYPE_ASSETS)).split(',');
|
2021-06-15 17:24:24 +03:00
|
|
|
for (const QString &assetPath : assetPaths) {
|
2022-02-03 19:49:27 +02:00
|
|
|
QString assetType = AssetsLibraryWidget::getAssetTypeAndData(assetPath).first;
|
2022-05-10 20:31:05 +03:00
|
|
|
if (assetType == Constants::MIME_TYPE_ASSET_IMAGE)
|
2021-06-15 17:24:24 +03:00
|
|
|
createQmlItemNodeFromImage(assetPath, targetContainerQmlItemNode, scenePosition);
|
2022-05-10 20:31:05 +03:00
|
|
|
else if (assetType == Constants::MIME_TYPE_ASSET_FONT)
|
2021-06-15 17:24:24 +03:00
|
|
|
createQmlItemNodeFromFont(assetPath, targetContainerQmlItemNode, scenePosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_dragNodes.isEmpty())
|
|
|
|
|
m_selectionIndicator.setItems(scene()->itemsForQmlItemNodes(m_dragNodes));
|
|
|
|
|
}
|
2014-05-13 14:35:39 +02:00
|
|
|
|
2010-12-06 17:44:25 +01:00
|
|
|
m_blockMove = true;
|
2014-07-17 15:27:59 +02:00
|
|
|
m_startPoint = scenePosition;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
2014-07-17 15:27:59 +02:00
|
|
|
}
|
2011-06-30 17:30:17 +02:00
|
|
|
|
2020-01-27 15:57:15 +02:00
|
|
|
void DragTool::dragMoveEvent(const QList<QGraphicsItem *> &itemList, QGraphicsSceneDragDropEvent *event)
|
2014-07-17 15:27:59 +02:00
|
|
|
{
|
2021-06-15 17:24:24 +03:00
|
|
|
if (!m_blockMove && !m_isAborted && canBeDropped(event->mimeData())) {
|
2014-07-21 14:11:59 +02:00
|
|
|
event->accept();
|
2021-06-15 17:24:24 +03:00
|
|
|
if (!m_dragNodes.isEmpty()) {
|
2014-07-21 14:11:59 +02:00
|
|
|
FormEditorItem *targetContainerItem = targetContainerOrRootItem(itemList);
|
|
|
|
|
if (targetContainerItem) {
|
|
|
|
|
move(event->scenePos(), itemList);
|
|
|
|
|
} else {
|
|
|
|
|
end();
|
2021-06-15 17:24:24 +03:00
|
|
|
for (auto &node : m_dragNodes) {
|
|
|
|
|
if (node.isValid())
|
|
|
|
|
node.destroy();
|
|
|
|
|
}
|
|
|
|
|
m_dragNodes.clear();
|
2014-07-17 15:27:59 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2021-06-15 17:24:24 +03:00
|
|
|
createDragNodes(event->mimeData(), event->scenePos(), itemList);
|
2014-07-17 15:27:59 +02:00
|
|
|
}
|
2020-01-27 15:57:15 +02:00
|
|
|
} else {
|
2014-07-21 14:11:59 +02:00
|
|
|
event->ignore();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-14 16:21:29 +02:00
|
|
|
void DragTool::end()
|
|
|
|
|
{
|
|
|
|
|
m_moveManipulator.end();
|
|
|
|
|
clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::end(Snapper::Snapping useSnapping)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2013-05-14 16:21:29 +02:00
|
|
|
m_moveManipulator.end(useSnapping);
|
2010-01-07 12:14:35 +01:00
|
|
|
clear();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
void DragTool::move(const QPointF &scenePosition, const QList<QGraphicsItem *> &itemList)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2021-06-15 17:24:24 +03:00
|
|
|
if (!m_movingItems.isEmpty()) {
|
|
|
|
|
FormEditorItem *containerItem = targetContainerOrRootItem(itemList, m_movingItems);
|
|
|
|
|
for (auto &movingItem : std::as_const(m_movingItems)) {
|
|
|
|
|
if (containerItem && movingItem->parentItem() &&
|
|
|
|
|
containerItem != movingItem->parentItem()) {
|
|
|
|
|
const QmlItemNode movingNode = movingItem->qmlItemNode();
|
|
|
|
|
const QmlItemNode containerNode = containerItem->qmlItemNode();
|
|
|
|
|
|
|
|
|
|
qCInfo(dragToolInfo()) << Q_FUNC_INFO << movingNode << containerNode << movingNode.canBereparentedTo(containerNode);
|
|
|
|
|
|
|
|
|
|
if (movingNode.canBereparentedTo(containerNode))
|
|
|
|
|
m_moveManipulator.reparentTo(containerItem);
|
|
|
|
|
}
|
2014-07-17 15:27:59 +02:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2014-07-17 15:27:59 +02:00
|
|
|
Snapper::Snapping useSnapping = Snapper::UseSnapping;
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2014-07-21 18:06:07 +02:00
|
|
|
m_moveManipulator.update(scenePosition, useSnapping, MoveManipulator::UseBaseState);
|
2014-07-17 15:27:59 +02:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-05 17:39:05 +02:00
|
|
|
void DragTool::commitTransaction()
|
|
|
|
|
{
|
|
|
|
|
try {
|
2022-06-07 13:39:25 +03:00
|
|
|
handleView3dDrop();
|
2014-08-05 17:39:05 +02:00
|
|
|
m_rewriterTransaction.commit();
|
2014-11-28 11:15:37 +01:00
|
|
|
} catch (const RewritingException &e) {
|
2014-08-05 17:39:05 +02:00
|
|
|
e.showException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-07 13:39:25 +03:00
|
|
|
void DragTool::handleView3dDrop()
|
|
|
|
|
{
|
|
|
|
|
// If a View3D is dropped, we need to assign material to the included model
|
|
|
|
|
for (const QmlItemNode &dragNode : qAsConst(m_dragNodes)) {
|
|
|
|
|
if (dragNode.modelNode().isSubclassOf("QtQuick3D.View3D")) {
|
|
|
|
|
const QList<ModelNode> models = dragNode.modelNode().subModelNodesOfType("QtQuick3D.Model");
|
|
|
|
|
QTC_ASSERT(models.size() == 1, return);
|
|
|
|
|
view()->assignMaterialTo3dModel(models.at(0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-15 17:24:24 +03:00
|
|
|
} // namespace QmlDesigner
|