diff options
author | Mahmoud Badri <mahmoud.badri@qt.io> | 2019-11-01 10:51:09 +0200 |
---|---|---|
committer | Mahmoud Badri <mahmoud.badri@qt.io> | 2019-11-12 10:00:34 +0000 |
commit | 5df7ad94ecd44681b38e78641471754d0ab90eda (patch) | |
tree | e59318f760eb4fdbe212dd71a2a680ad3a5f2933 /share | |
parent | 1d357f6b33a7a062e6272c0afea8dfa0bcde78ec (diff) | |
download | qt-creator-5df7ad94ecd44681b38e78641471754d0ab90eda.tar.gz |
Implement DnD 3D objects from the item library to the EditView3D
Proof of concept drag and drop implementation. Basic functionality
working but needs polish.
Task-number: QDS-1132
Change-Id: Ie3b9e80de9a414c4955d6e38daf338045bc1e614
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'share')
12 files changed, 170 insertions, 0 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/commands/commands.pri b/share/qtcreator/qml/qmlpuppet/commands/commands.pri index 78dfcd8eb1..8bca5ce88a 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/commands.pri +++ b/share/qtcreator/qml/qmlpuppet/commands/commands.pri @@ -27,6 +27,7 @@ HEADERS += $$PWD/changeauxiliarycommand.h HEADERS += $$PWD/removesharedmemorycommand.h HEADERS += $$PWD/puppetalivecommand.h HEADERS += $$PWD/changeselectioncommand.h +HEADERS += $$PWD/drop3dlibraryitemcommand.h SOURCES += $$PWD/synchronizecommand.cpp SOURCES += $$PWD/debugoutputcommand.cpp @@ -55,3 +56,4 @@ SOURCES += $$PWD/changeauxiliarycommand.cpp SOURCES += $$PWD/removesharedmemorycommand.cpp SOURCES += $$PWD/puppetalivecommand.cpp SOURCES += $$PWD/changeselectioncommand.cpp +SOURCES += $$PWD/drop3dlibraryitemcommand.cpp diff --git a/share/qtcreator/qml/qmlpuppet/commands/drop3dlibraryitemcommand.cpp b/share/qtcreator/qml/qmlpuppet/commands/drop3dlibraryitemcommand.cpp new file mode 100644 index 0000000000..aa7c826065 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/commands/drop3dlibraryitemcommand.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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 +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** 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. +** +****************************************************************************/ + +#include "drop3dlibraryitemcommand.h" + +#include <QDataStream> + +namespace QmlDesigner { + +Drop3DLibraryItemCommand::Drop3DLibraryItemCommand(const QByteArray &itemData) + : m_itemData(itemData) +{ +} + +QDataStream &operator<<(QDataStream &out, const Drop3DLibraryItemCommand &command) +{ + out << command.itemData(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, Drop3DLibraryItemCommand &command) +{ + in >> command.m_itemData; + + return in; +} + +bool operator==(const Drop3DLibraryItemCommand &first, const Drop3DLibraryItemCommand &second) +{ + return first.m_itemData == second.m_itemData; +} + +} // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/commands/drop3dlibraryitemcommand.h b/share/qtcreator/qml/qmlpuppet/commands/drop3dlibraryitemcommand.h new file mode 100644 index 0000000000..1aa11a85f9 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/commands/drop3dlibraryitemcommand.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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 +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** 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. +** +****************************************************************************/ + +#pragma once + +#include <QVector> +#include <QDataStream> +#include <QMimeData> + +#include "instancecontainer.h" + +namespace QmlDesigner { + +class Drop3DLibraryItemCommand +{ + friend QDataStream &operator>>(QDataStream &in, Drop3DLibraryItemCommand &command); + friend QDebug operator<<(QDebug debug, const Drop3DLibraryItemCommand &command); + friend bool operator==(const Drop3DLibraryItemCommand &first, + const Drop3DLibraryItemCommand &second); + +public: + explicit Drop3DLibraryItemCommand(const QByteArray &itemData); + Drop3DLibraryItemCommand() = default; + + QByteArray itemData() const { return m_itemData; } + +private: + QByteArray m_itemData; +}; + +QDataStream &operator<<(QDataStream &out, const Drop3DLibraryItemCommand &command); +QDataStream &operator>>(QDataStream &in, Drop3DLibraryItemCommand &command); +bool operator==(const Drop3DLibraryItemCommand &first, const Drop3DLibraryItemCommand &second); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::Drop3DLibraryItemCommand) diff --git a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp index 3e57baffd0..7d46fcbfc1 100644 --- a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp +++ b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.cpp @@ -68,6 +68,7 @@ #include "debugoutputcommand.h" #include "puppetalivecommand.h" #include "changeselectioncommand.h" +#include "drop3dlibraryitemcommand.h" namespace QmlDesigner { @@ -139,6 +140,7 @@ bool compareCommands(const QVariant &command, const QVariant &controlCommand) static const int tokenCommandType = QMetaType::type("TokenCommand"); static const int debugOutputCommandType = QMetaType::type("DebugOutputCommand"); static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand"); + static const int drop3DLibraryItemCommandType = QMetaType::type("Drop3DLibraryItemCommand"); if (command.userType() == controlCommand.userType()) { if (command.userType() == informationChangedCommandType) @@ -163,6 +165,8 @@ bool compareCommands(const QVariant &command, const QVariant &controlCommand) return command.value<DebugOutputCommand>() == controlCommand.value<DebugOutputCommand>(); else if (command.userType() == changeSelectionCommandType) return command.value<ChangeSelectionCommand>() == controlCommand.value<ChangeSelectionCommand>(); + else if (command.userType() == drop3DLibraryItemCommandType) + return command.value<Drop3DLibraryItemCommand>() == controlCommand.value<Drop3DLibraryItemCommand>(); } return false; @@ -250,6 +254,11 @@ void NodeInstanceClientProxy::selectionChanged(const ChangeSelectionCommand &com writeCommand(QVariant::fromValue(command)); } +void NodeInstanceClientProxy::library3DItemDropped(const Drop3DLibraryItemCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + void NodeInstanceClientProxy::flush() { } diff --git a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h index edf290f38a..2b41bf83cb 100644 --- a/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h +++ b/share/qtcreator/qml/qmlpuppet/instances/nodeinstanceclientproxy.h @@ -57,6 +57,7 @@ class ChangeStateCommand; class ChangeNodeSourceCommand; class EndPuppetCommand; class ChangeSelectionCommand; +class Drop3DLibraryItemCommand; class NodeInstanceClientProxy : public QObject, public NodeInstanceClientInterface { @@ -76,6 +77,7 @@ public: void debugOutput(const DebugOutputCommand &command) override; void puppetAlive(const PuppetAliveCommand &command); void selectionChanged(const ChangeSelectionCommand &command) override; + void library3DItemDropped(const Drop3DLibraryItemCommand &command) override; void flush() override; void synchronizeWithClientProcess() override; diff --git a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceclientinterface.h b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceclientinterface.h index 0b5a5ca334..10688cdd89 100644 --- a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceclientinterface.h +++ b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceclientinterface.h @@ -41,6 +41,7 @@ class RemoveSharedMemoryCommand; class DebugOutputCommand; class PuppetAliveCommand; class ChangeSelectionCommand; +class Drop3DLibraryItemCommand; class NodeInstanceClientInterface { @@ -55,6 +56,7 @@ public: virtual void token(const TokenCommand &command) = 0; virtual void debugOutput(const DebugOutputCommand &command) = 0; virtual void selectionChanged(const ChangeSelectionCommand &command) = 0; + virtual void library3DItemDropped(const Drop3DLibraryItemCommand &command) = 0; virtual void flush() {} virtual void synchronizeWithClientProcess() {} diff --git a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp index d2b7cb2620..e58ef1011e 100644 --- a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp +++ b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.cpp @@ -46,6 +46,7 @@ #include "addimportcontainer.h" #include "changenodesourcecommand.h" #include "changeselectioncommand.h" +#include "drop3dlibraryitemcommand.h" #include "informationchangedcommand.h" #include "pixmapchangedcommand.h" @@ -107,6 +108,9 @@ void NodeInstanceServerInterface::registerCommands() qRegisterMetaType<ChangeSelectionCommand>("ChangeSelectionCommand"); qRegisterMetaTypeStreamOperators<ChangeSelectionCommand>("ChangeSelectionCommand"); + qRegisterMetaType<Drop3DLibraryItemCommand>("Drop3DLibraryItemCommand"); + qRegisterMetaTypeStreamOperators<Drop3DLibraryItemCommand>("Drop3DLibraryItemCommand"); + qRegisterMetaType<RemovePropertiesCommand>("RemovePropertiesCommand"); qRegisterMetaTypeStreamOperators<RemovePropertiesCommand>("RemovePropertiesCommand"); diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml index e82391f8bc..024c8c5d1b 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml @@ -161,6 +161,10 @@ Window { } } + DropArea { + anchors.fill: parent + } + View3D { id: editView anchors.fill: parent diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp index 9103ef5de0..e2e6564c89 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp @@ -67,6 +67,7 @@ #include <tokencommand.h> #include <removesharedmemorycommand.h> #include <changeselectioncommand.h> +#include <drop3dlibraryitemcommand.h> #include <QDebug> #include <QQmlEngine> @@ -1171,6 +1172,11 @@ ChangeSelectionCommand NodeInstanceServer::createChangeSelectionCommand(const QL return ChangeSelectionCommand(idVector); } +Drop3DLibraryItemCommand NodeInstanceServer::createDrop3DLibraryItemCommand(const QByteArray &itemData) +{ + return Drop3DLibraryItemCommand(itemData); +} + ValuesChangedCommand NodeInstanceServer::createValuesChangedCommand(const QVector<InstancePropertyPair> &propertyList) const { QVector<PropertyValueContainer> valueVector; diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h index 7af63c0b5b..9eab649af7 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.h @@ -70,6 +70,7 @@ class AddImportContainer; class MockupTypeContainer; class IdContainer; class ChangeSelectionCommand; +class Drop3DLibraryItemCommand; namespace Internal { class ChildrenChangeEventFilter; @@ -180,6 +181,7 @@ protected: ChildrenChangedCommand createChildrenChangedCommand(const ServerNodeInstance &parentInstance, const QList<ServerNodeInstance> &instanceList) const; ComponentCompletedCommand createComponentCompletedCommand(const QList<ServerNodeInstance> &instanceList); ChangeSelectionCommand createChangeSelectionCommand(const QList<ServerNodeInstance> &instanceList); + Drop3DLibraryItemCommand createDrop3DLibraryItemCommand(const QByteArray &itemData); void addChangedProperty(const InstancePropertyPair &property); diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index a0783eff57..546593ca82 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -27,6 +27,8 @@ #include <QQuickItem> #include <QQuickView> +#include <QDropEvent> +#include <QMimeData> #include "servernodeinstance.h" #include "childrenchangeeventfilter.h" @@ -57,6 +59,7 @@ #include "removesharedmemorycommand.h" #include "changeselectioncommand.h" #include "objectnodeinstance.h" +#include <drop3dlibraryitemcommand.h> #include "dummycontextobject.h" #include "../editor3d/cameracontrolhelper.h" @@ -79,6 +82,25 @@ static QVariant objectToVariant(QObject *object) return QVariant::fromValue(object); } +bool Qt5InformationNodeInstanceServer::eventFilter(QObject *, QEvent *event) +{ + switch (event->type()) { + case QEvent::Drop: { + QDropEvent *dropEvent = static_cast<QDropEvent *>(event); + QByteArray data = dropEvent->mimeData()->data( + QStringLiteral("application/vnd.bauhaus.itemlibraryinfo")); + if (!data.isEmpty()) + nodeInstanceClient()->library3DItemDropped(createDrop3DLibraryItemCommand(data)); + + } break; + + default: + break; + } + + return false; +} + QObject *Qt5InformationNodeInstanceServer::createEditView3D(QQmlEngine *engine) { auto helper = new QmlDesigner::Internal::CameraControlHelper(); @@ -98,6 +120,7 @@ QObject *Qt5InformationNodeInstanceServer::createEditView3D(QQmlEngine *engine) return nullptr; } + window->installEventFilter(this); QObject::connect(window, SIGNAL(objectClicked(QVariant)), this, SLOT(objectClicked(QVariant))); QObject::connect(window, SIGNAL(commitObjectProperty(QVariant, QVariant)), this, SLOT(handleObjectPropertyCommit(QVariant, QVariant))); diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h index dc1e342fbd..0597947024 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h @@ -57,6 +57,7 @@ private slots: protected: void collectItemChangesAndSendChangeCommands() override; + bool eventFilter(QObject *obj, QEvent *event) override; void sendChildrenChangedCommand(const QList<ServerNodeInstance> &childList); void sendTokenBack(); bool isDirtyRecursiveForNonInstanceItems(QQuickItem *item) const; |