2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
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"
|
|
|
|
|
#include <customdraganddrop.h>
|
|
|
|
|
#include <metainfo.h>
|
2010-09-24 13:45:42 +02:00
|
|
|
#include <rewritingexception.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2013-04-25 11:50:38 +02:00
|
|
|
#include <QMimeData>
|
2010-09-24 13:45:42 +02:00
|
|
|
#include <QMessageBox>
|
2010-12-06 17:44:25 +01:00
|
|
|
#include <QTimer>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
2010-12-06 17:44:25 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
void TimerHandler::clearMoveDelay()
|
|
|
|
|
{
|
|
|
|
|
m_dragTool->clearMoveDelay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
DragTool::DragTool(FormEditorView *editorView)
|
|
|
|
|
: AbstractFormEditorTool(editorView),
|
|
|
|
|
m_moveManipulator(editorView->scene()->manipulatorLayerItem(), editorView),
|
2010-12-06 17:44:25 +01:00
|
|
|
m_selectionIndicator(editorView->scene()->manipulatorLayerItem()),
|
|
|
|
|
m_timerHandler(new Internal::TimerHandler(this)),
|
2011-05-10 15:09:26 +02:00
|
|
|
m_blockMove(false),
|
|
|
|
|
m_Aborted(false)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DragTool::~DragTool()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::clear()
|
|
|
|
|
{
|
|
|
|
|
m_moveManipulator.clear();
|
|
|
|
|
m_selectionIndicator.clear();
|
|
|
|
|
m_movingItem.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::mousePressEvent(const QList<QGraphicsItem*> &,
|
|
|
|
|
QGraphicsSceneMouseEvent *)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::mouseMoveEvent(const QList<QGraphicsItem*> &,
|
|
|
|
|
QGraphicsSceneMouseEvent *)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::hoverMoveEvent(const QList<QGraphicsItem*> &,
|
|
|
|
|
QGraphicsSceneMouseEvent * /*event*/)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
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-01-02 15:21:09 +01:00
|
|
|
commitTransaction();
|
2011-05-10 15:09:26 +02:00
|
|
|
view()->changeToSelectionTool();
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::keyReleaseEvent(QKeyEvent *)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DragTool::mouseReleaseEvent(const QList<QGraphicsItem*> &/*itemList*/,
|
|
|
|
|
QGraphicsSceneMouseEvent *)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::mouseDoubleClickEvent(const QList<QGraphicsItem*> & /*itemList*/,
|
|
|
|
|
QGraphicsSceneMouseEvent * /*event*/)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::itemsAboutToRemoved(const QList<FormEditorItem*> & /* removedItemList */)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::selectedItemsChanged(const QList<FormEditorItem*> &)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DragTool::updateMoveManipulator()
|
|
|
|
|
{
|
|
|
|
|
if (m_moveManipulator.isActive())
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::beginWithPoint(const QPointF &beginPoint)
|
|
|
|
|
{
|
|
|
|
|
m_movingItem = scene()->itemForQmlItemNode(m_dragNode);
|
|
|
|
|
|
|
|
|
|
m_moveManipulator.setItem(m_movingItem.data());
|
|
|
|
|
m_moveManipulator.begin(beginPoint);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 12:49:13 +02:00
|
|
|
void DragTool::createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, QmlItemNode parentNode, QPointF scenePos)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
MetaInfo metaInfo = MetaInfo::global();
|
|
|
|
|
|
|
|
|
|
FormEditorItem *parentItem = scene()->itemForQmlItemNode(parentNode);
|
|
|
|
|
QPointF pos = parentItem->mapFromScene(scenePos);
|
|
|
|
|
|
2013-07-29 16:23:00 +02:00
|
|
|
m_dragNode = QmlItemNode::createQmlItemNode(view(), itemLibraryEntry, pos, parentNode);
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
Q_ASSERT(m_dragNode.modelNode().isValid());
|
|
|
|
|
|
|
|
|
|
QList<QmlItemNode> nodeList;
|
2012-11-28 20:28:42 +02:00
|
|
|
nodeList.append(m_dragNode);
|
2010-01-07 12:14:35 +01:00
|
|
|
m_selectionIndicator.setItems(scene()->itemsForQmlItemNodes(nodeList));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::createQmlItemNodeFromImage(const QString &imageName, QmlItemNode parentNode, QPointF scenePos)
|
|
|
|
|
{
|
2010-04-06 15:08:46 +02:00
|
|
|
if (!parentNode.isValid())
|
|
|
|
|
return;
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
MetaInfo metaInfo = MetaInfo::global();
|
|
|
|
|
|
|
|
|
|
FormEditorItem *parentItem = scene()->itemForQmlItemNode(parentNode);
|
|
|
|
|
QPointF pos = parentItem->mapFromScene(scenePos);
|
|
|
|
|
|
2013-07-29 16:23:00 +02:00
|
|
|
m_dragNode = QmlItemNode::createQmlItemNodeFromImage(view(), imageName, pos, parentNode);
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
QList<QmlItemNode> nodeList;
|
|
|
|
|
nodeList.append(m_dragNode);
|
|
|
|
|
m_selectionIndicator.setItems(scene()->itemsForQmlItemNodes(nodeList));
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-15 18:21:05 +02:00
|
|
|
static inline bool isAncestorOf(FormEditorItem *formEditorItem, FormEditorItem *newParentItem)
|
|
|
|
|
{
|
|
|
|
|
if (formEditorItem && newParentItem)
|
|
|
|
|
return formEditorItem->isAncestorOf(newParentItem);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
FormEditorItem* DragTool::calculateContainer(const QPointF &point, FormEditorItem * currentItem)
|
|
|
|
|
{
|
|
|
|
|
QList<QGraphicsItem *> list = scene()->items(point);
|
|
|
|
|
foreach (QGraphicsItem *item, list) {
|
|
|
|
|
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
|
2011-07-15 18:21:05 +02:00
|
|
|
if (formEditorItem && formEditorItem != currentItem && formEditorItem->isContainer()
|
|
|
|
|
&& !isAncestorOf(currentItem, formEditorItem))
|
2010-01-07 12:14:35 +01:00
|
|
|
return formEditorItem;
|
|
|
|
|
}
|
2010-03-15 17:39:37 +01:00
|
|
|
|
2011-03-08 16:58:35 +01:00
|
|
|
if (scene()->rootFormEditorItem())
|
2010-03-15 17:39:37 +01:00
|
|
|
return scene()->rootFormEditorItem();
|
2010-01-07 12:14:35 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-20 17:02:11 +01:00
|
|
|
QList<Import> DragTool::missingImportList(const ItemLibraryEntry &itemLibraryEntry)
|
|
|
|
|
{
|
|
|
|
|
QList<Import> importToBeAddedList;
|
|
|
|
|
|
|
|
|
|
if (!itemLibraryEntry.requiredImport().isEmpty()) {
|
|
|
|
|
const QString newImportUrl = itemLibraryEntry.requiredImport();
|
|
|
|
|
const QString newImportVersion = QString("%1.%2").arg(QString::number(itemLibraryEntry.majorVersion()), QString::number(itemLibraryEntry.minorVersion()));
|
|
|
|
|
Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
|
|
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (itemLibraryEntry.majorVersion() == -1 && itemLibraryEntry.minorVersion() == -1)
|
2012-12-20 17:02:11 +01:00
|
|
|
newImport = Import::createFileImport(newImportUrl, QString());
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2012-12-20 17:02:11 +01:00
|
|
|
newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
|
|
|
|
|
}
|
|
|
|
|
return importToBeAddedList;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
void DragTool::formEditorItemsChanged(const QList<FormEditorItem*> & itemList)
|
|
|
|
|
{
|
|
|
|
|
if (m_movingItem && itemList.contains(m_movingItem.data())) {
|
|
|
|
|
QList<FormEditorItem*> updateItemList;
|
|
|
|
|
updateItemList.append(m_movingItem.data());
|
|
|
|
|
m_selectionIndicator.updateItems(updateItemList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-10 22:46:18 +01:00
|
|
|
void DragTool::instancesCompleted(const QList<FormEditorItem*> &itemList)
|
|
|
|
|
{
|
2010-12-10 23:04:02 +01:00
|
|
|
foreach (FormEditorItem* item, itemList)
|
|
|
|
|
if (item->qmlItemNode() == m_dragNode)
|
|
|
|
|
clearMoveDelay();
|
2011-03-08 16:58:35 +01:00
|
|
|
QmlDesignerItemLibraryDragAndDrop::CustomDragAndDrop::hide();
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-18 14:24:14 +01:00
|
|
|
void DragTool::instancePropertyChange(const QList<QPair<ModelNode, PropertyName> > & /*propertyList*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
2011-06-30 17:30:17 +02:00
|
|
|
|
2010-12-06 17:44:25 +01:00
|
|
|
void DragTool::clearMoveDelay()
|
|
|
|
|
{
|
2010-12-10 23:04:02 +01:00
|
|
|
if (!m_blockMove)
|
|
|
|
|
return;
|
2010-12-06 17:44:25 +01:00
|
|
|
m_blockMove = false;
|
|
|
|
|
if (m_dragNode.isValid())
|
2010-12-08 16:10:32 +01:00
|
|
|
beginWithPoint(m_startPoint);
|
2010-12-06 17:44:25 +01:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2011-05-10 15:09:26 +02:00
|
|
|
void DragTool::abort()
|
|
|
|
|
{
|
|
|
|
|
if (m_Aborted)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_Aborted = true;
|
|
|
|
|
|
|
|
|
|
if (m_dragNode.isValid())
|
|
|
|
|
m_dragNode.destroy();
|
|
|
|
|
|
|
|
|
|
QmlDesignerItemLibraryDragAndDrop::CustomDragAndDrop::hide();
|
2014-01-02 15:21:09 +01:00
|
|
|
}
|
2011-05-10 15:09:26 +02:00
|
|
|
|
2014-01-02 15:21:09 +01:00
|
|
|
void DragTool::commitTransaction()
|
|
|
|
|
{
|
|
|
|
|
try {
|
2011-05-10 15:09:26 +02:00
|
|
|
m_rewriterTransaction.commit();
|
2014-01-02 15:21:09 +01:00
|
|
|
} catch (RewritingException &e) {
|
|
|
|
|
QMessageBox::warning(0, "Error", e.description());
|
|
|
|
|
}
|
2011-05-10 15:09:26 +02:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void DragTool::dropEvent(QGraphicsSceneDragDropEvent * event)
|
|
|
|
|
{
|
|
|
|
|
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") ||
|
|
|
|
|
event->mimeData()->hasFormat("application/vnd.bauhaus.libraryresource")) {
|
|
|
|
|
event->accept();
|
2013-05-14 16:21:29 +02:00
|
|
|
end(generateUseSnapping(event->modifiers()));
|
|
|
|
|
|
2014-01-02 15:21:09 +01:00
|
|
|
commitTransaction();
|
|
|
|
|
|
2010-12-09 16:38:28 +01:00
|
|
|
if (m_dragNode.isValid()) {
|
|
|
|
|
QList<QmlItemNode> nodeList;
|
|
|
|
|
nodeList.append(m_dragNode);
|
2013-07-24 15:09:57 +02:00
|
|
|
view()->setSelectedModelNodes(toModelNodeList(nodeList));
|
2010-12-09 16:38:28 +01:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
m_dragNode = ModelNode();
|
|
|
|
|
view()->changeToSelectionTool();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-09 16:39:15 +01:00
|
|
|
static ItemLibraryEntry itemLibraryEntryFromData(const QByteArray &data)
|
|
|
|
|
{
|
|
|
|
|
QDataStream stream(data);
|
|
|
|
|
|
|
|
|
|
ItemLibraryEntry itemLibraryEntry;
|
|
|
|
|
stream >> itemLibraryEntry;
|
|
|
|
|
|
|
|
|
|
return itemLibraryEntry;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void DragTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event)
|
|
|
|
|
{
|
|
|
|
|
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") ||
|
|
|
|
|
event->mimeData()->hasFormat("application/vnd.bauhaus.libraryresource")) {
|
2011-02-10 15:44:40 +01:00
|
|
|
QList<Import> importToBeAddedList;
|
2010-12-10 23:04:02 +01:00
|
|
|
m_blockMove = false;
|
2010-12-09 16:39:15 +01:00
|
|
|
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo")) {
|
2013-03-14 16:41:35 +01:00
|
|
|
view()->widgetInfo().widget->setFocus();
|
2011-05-10 15:09:26 +02:00
|
|
|
m_Aborted = false;
|
2010-12-09 16:39:15 +01:00
|
|
|
Q_ASSERT(!event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo").isEmpty());
|
|
|
|
|
|
2012-12-20 17:02:11 +01:00
|
|
|
importToBeAddedList = missingImportList(
|
|
|
|
|
itemLibraryEntryFromData(event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo")));
|
2010-12-09 16:39:15 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-10 15:44:40 +01:00
|
|
|
view()->model()->changeImports(importToBeAddedList, QList<Import>());
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
if (!m_rewriterTransaction.isValid()) {
|
2010-03-31 12:59:16 +02:00
|
|
|
view()->clearSelectedModelNodes();
|
2014-01-06 12:51:56 +01:00
|
|
|
m_rewriterTransaction = view()->beginRewriterTransaction(QByteArrayLiteral("DragTool::dragEnterEvent"));
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::dragLeaveEvent(QGraphicsSceneDragDropEvent * event)
|
|
|
|
|
{
|
|
|
|
|
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") ||
|
|
|
|
|
event->mimeData()->hasFormat("application/vnd.bauhaus.libraryresource")) {
|
|
|
|
|
event->accept();
|
|
|
|
|
if (m_dragNode.isValid())
|
|
|
|
|
m_dragNode.destroy();
|
2013-05-14 16:21:29 +02:00
|
|
|
|
|
|
|
|
m_moveManipulator.end();
|
|
|
|
|
clear();
|
2010-09-24 13:45:42 +02:00
|
|
|
|
2014-01-02 15:21:09 +01:00
|
|
|
commitTransaction();
|
2010-09-24 13:45:42 +02:00
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
QmlDesignerItemLibraryDragAndDrop::CustomDragAndDrop::show();
|
|
|
|
|
QList<QmlItemNode> nodeList;
|
2013-07-24 15:09:57 +02:00
|
|
|
view()->setSelectedModelNodes(toModelNodeList(nodeList));
|
2010-01-07 12:14:35 +01:00
|
|
|
view()->changeToSelectionTool();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::dragMoveEvent(QGraphicsSceneDragDropEvent * event)
|
|
|
|
|
{
|
2010-12-06 17:44:25 +01:00
|
|
|
if (m_blockMove)
|
|
|
|
|
return;
|
2011-05-10 15:09:26 +02:00
|
|
|
|
|
|
|
|
if (m_Aborted) {
|
|
|
|
|
event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-03-08 16:58:35 +01:00
|
|
|
if (QmlDesignerItemLibraryDragAndDrop::CustomDragAndDrop::isAnimated())
|
|
|
|
|
return;
|
2010-01-07 12:14:35 +01:00
|
|
|
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") ||
|
|
|
|
|
event->mimeData()->hasFormat("application/vnd.bauhaus.libraryresource")) {
|
|
|
|
|
event->accept();
|
|
|
|
|
QPointF scenePos = event->scenePos();
|
|
|
|
|
if (m_dragNode.isValid()) {
|
|
|
|
|
|
2010-05-18 16:48:57 +02:00
|
|
|
FormEditorItem *parentItem = calculateContainer(event->scenePos() + QPoint(2, 2));
|
2010-01-07 12:14:35 +01:00
|
|
|
if (!parentItem) { //if there is no parent any more - the use left the scene
|
2013-05-14 16:21:29 +02:00
|
|
|
end();
|
2010-01-07 12:14:35 +01:00
|
|
|
QmlDesignerItemLibraryDragAndDrop::CustomDragAndDrop::show();
|
2010-05-18 16:48:57 +02:00
|
|
|
m_dragNode.destroy(); //delete the node then
|
2010-01-07 12:14:35 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//move
|
|
|
|
|
move(event->scenePos());
|
|
|
|
|
} else {
|
|
|
|
|
//create new node if container
|
2010-09-24 13:45:42 +02:00
|
|
|
if (m_dragNode.modelNode().isValid())
|
|
|
|
|
return;
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2011-03-08 16:58:35 +01:00
|
|
|
FormEditorItem *parentItem = calculateContainer(scenePos);
|
2010-01-07 12:14:35 +01:00
|
|
|
if (!parentItem)
|
|
|
|
|
return;
|
2010-12-06 17:44:25 +01:00
|
|
|
QmlItemNode parentNode;
|
2010-01-07 12:14:35 +01:00
|
|
|
if (parentItem)
|
|
|
|
|
parentNode = parentItem->qmlItemNode();
|
|
|
|
|
|
|
|
|
|
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo")) {
|
|
|
|
|
Q_ASSERT(!event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo").isEmpty());
|
2010-05-07 12:49:13 +02:00
|
|
|
ItemLibraryEntry itemLibraryEntry = itemLibraryEntryFromData(event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo"));
|
|
|
|
|
createQmlItemNode(itemLibraryEntry, parentNode, event->scenePos());
|
2010-01-07 12:14:35 +01:00
|
|
|
} else if (event->mimeData()->hasFormat("application/vnd.bauhaus.libraryresource")) {
|
|
|
|
|
Q_ASSERT(!event->mimeData()->data("application/vnd.bauhaus.libraryresource").isEmpty());
|
2011-07-12 12:06:59 +02:00
|
|
|
QString imageName = QString::fromUtf8((event->mimeData()->data("application/vnd.bauhaus.libraryresource")));
|
2010-01-07 12:14:35 +01:00
|
|
|
createQmlItemNodeFromImage(imageName, parentNode, event->scenePos());
|
|
|
|
|
} else Q_ASSERT(false);
|
2010-12-06 17:44:25 +01:00
|
|
|
m_blockMove = true;
|
2010-12-08 16:10:32 +01:00
|
|
|
m_startPoint = event->scenePos();
|
2013-06-06 13:10:36 +02:00
|
|
|
QTimer::singleShot(10000, m_timerHandler.data(), SLOT(clearMoveDelay()));
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
2011-06-30 17:30:17 +02:00
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
if (event->mimeData()->hasFormat("application/vnd.bauhaus.libraryresource")) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DragTool::move(QPointF scenePos)
|
|
|
|
|
{
|
|
|
|
|
if (!m_movingItem)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
FormEditorItem *containerItem = calculateContainer(scenePos - QPoint(2, 2), m_movingItem.data());
|
2011-07-11 12:19:54 +02:00
|
|
|
if (containerItem && m_movingItem->parentItem() &&
|
2010-04-23 11:14:30 +02:00
|
|
|
containerItem != m_movingItem->parentItem()) {
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
m_moveManipulator.reparentTo(containerItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//MoveManipulator::Snapping useSnapping = MoveManipulator::NoSnapping;
|
2013-05-14 16:21:29 +02:00
|
|
|
Snapper::Snapping useSnapping = Snapper::UseSnapping;
|
2010-01-07 12:14:35 +01:00
|
|
|
/* if (event->modifiers().testFlag(Qt::ControlModifier) != view()->isSnapButtonChecked())
|
|
|
|
|
useSnapping = MoveManipulator::UseSnapping;*/
|
|
|
|
|
|
2010-05-26 16:03:38 +02:00
|
|
|
m_moveManipulator.update(scenePos, useSnapping, MoveManipulator::UseBaseState);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|