summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Hartmann <Thomas.Hartmann@nokia.com>2011-05-10 15:09:26 +0200
committerThomas Hartmann <Thomas.Hartmann@nokia.com>2011-05-10 15:11:19 +0200
commitdf6f809927d4b4922de49c95d392821fe6c6b2e5 (patch)
tree6fe712c4298f7441634cd52f77368ca9e2dafcc4
parent4b19473a9bb88d925885155398844e7554a1a840 (diff)
downloadqt-creator-df6f809927d4b4922de49c95d392821fe6c6b2e5.tar.gz
QmlDesigner: allow aborting drag and drop with Escape
Also allows aborting the move tool. Reviewed-by: Marco Bubke Task-number: QTCREATORBUG-4322
-rw-r--r--src/plugins/qmldesigner/components/formeditor/abstractformeditortool.cpp1
-rw-r--r--src/plugins/qmldesigner/components/formeditor/dragtool.cpp36
-rw-r--r--src/plugins/qmldesigner/components/formeditor/dragtool.h2
-rw-r--r--src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp6
-rw-r--r--src/plugins/qmldesigner/components/formeditor/formeditorscene.h2
-rw-r--r--src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp5
-rw-r--r--src/plugins/qmldesigner/components/formeditor/formeditorwidget.h2
-rw-r--r--src/plugins/qmldesigner/components/formeditor/movetool.cpp5
8 files changed, 52 insertions, 7 deletions
diff --git a/src/plugins/qmldesigner/components/formeditor/abstractformeditortool.cpp b/src/plugins/qmldesigner/components/formeditor/abstractformeditortool.cpp
index a38c7286c9..a6cd449dba 100644
--- a/src/plugins/qmldesigner/components/formeditor/abstractformeditortool.cpp
+++ b/src/plugins/qmldesigner/components/formeditor/abstractformeditortool.cpp
@@ -169,7 +169,6 @@ FormEditorItem* AbstractFormEditorTool::topFormEditorItemWithRootItem(const QLis
void AbstractFormEditorTool::dropEvent(QGraphicsSceneDragDropEvent * /* event */)
{
- Q_ASSERT(false);
}
void AbstractFormEditorTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event)
diff --git a/src/plugins/qmldesigner/components/formeditor/dragtool.cpp b/src/plugins/qmldesigner/components/formeditor/dragtool.cpp
index 7af171c2af..f677311e31 100644
--- a/src/plugins/qmldesigner/components/formeditor/dragtool.cpp
+++ b/src/plugins/qmldesigner/components/formeditor/dragtool.cpp
@@ -34,6 +34,7 @@
#include "formeditorscene.h"
#include "formeditorview.h"
+#include "formeditorwidget.h"
#include "itemutilfunctions.h"
#include <customdraganddrop.h>
#include <metainfo.h>
@@ -62,7 +63,8 @@ DragTool::DragTool(FormEditorView *editorView)
m_moveManipulator(editorView->scene()->manipulatorLayerItem(), editorView),
m_selectionIndicator(editorView->scene()->manipulatorLayerItem()),
m_timerHandler(new Internal::TimerHandler(this)),
- m_blockMove(false)
+ m_blockMove(false),
+ m_Aborted(false)
{
// view()->setCursor(Qt::SizeAllCursor);
}
@@ -98,9 +100,13 @@ void DragTool::hoverMoveEvent(const QList<QGraphicsItem*> &,
}
-void DragTool::keyPressEvent(QKeyEvent *)
+void DragTool::keyPressEvent(QKeyEvent *event)
{
-
+ if (event->key() == Qt::Key_Escape) {
+ abort();
+ event->accept();
+ view()->changeToSelectionTool();
+ }
}
void DragTool::keyReleaseEvent(QKeyEvent *)
@@ -221,6 +227,23 @@ void DragTool::clearMoveDelay()
beginWithPoint(m_startPoint);
}
+void DragTool::abort()
+{
+ if (m_Aborted)
+ return;
+
+ m_Aborted = true;
+
+ if (m_dragNode.isValid())
+ m_dragNode.destroy();
+
+ QmlDesignerItemLibraryDragAndDrop::CustomDragAndDrop::hide();
+
+ if (m_rewriterTransaction.isValid())
+ m_rewriterTransaction.commit();
+
+}
+
void DragTool::dropEvent(QGraphicsSceneDragDropEvent * event)
{
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") ||
@@ -260,6 +283,8 @@ void DragTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event)
QList<Import> importToBeAddedList;
m_blockMove = false;
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo")) {
+ view()->widget()->setFocus();
+ m_Aborted = false;
Q_ASSERT(!event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo").isEmpty());
ItemLibraryEntry itemLibraryEntry = itemLibraryEntryFromData(event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo"));
if (!itemLibraryEntry.requiredImport().isEmpty()) {
@@ -309,6 +334,11 @@ void DragTool::dragMoveEvent(QGraphicsSceneDragDropEvent * event)
{
if (m_blockMove)
return;
+
+ if (m_Aborted) {
+ event->ignore();
+ return;
+ }
if (QmlDesignerItemLibraryDragAndDrop::CustomDragAndDrop::isAnimated())
return;
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") ||
diff --git a/src/plugins/qmldesigner/components/formeditor/dragtool.h b/src/plugins/qmldesigner/components/formeditor/dragtool.h
index 71b125203d..d397c73158 100644
--- a/src/plugins/qmldesigner/components/formeditor/dragtool.h
+++ b/src/plugins/qmldesigner/components/formeditor/dragtool.h
@@ -108,6 +108,7 @@ public:
void clearMoveDelay();
protected:
+ void abort();
private:
@@ -128,6 +129,7 @@ private:
QScopedPointer<Internal::TimerHandler> m_timerHandler;
bool m_blockMove;
QPointF m_startPoint;
+ bool m_Aborted;
};
diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp
index 7351674753..bb257b3278 100644
--- a/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp
+++ b/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp
@@ -231,7 +231,6 @@ FormEditorItem *FormEditorScene::addFormEditorItem(const QmlItemNode &qmlItemNod
return formEditorItem;
}
-
void FormEditorScene::dropEvent(QGraphicsSceneDragDropEvent * event)
{
currentTool()->dropEvent(event);
@@ -345,6 +344,11 @@ bool FormEditorScene::event(QEvent * event)
case QEvent::GraphicsSceneHoverLeave :
hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
return true;
+ case QEvent::ShortcutOverride :
+ if (static_cast<QKeyEvent*>(event)->key() == Qt::Key_Escape) {
+ currentTool()->keyPressEvent(static_cast<QKeyEvent*>(event));
+ return true;
+ }
default: return QGraphicsScene::event(event);
}
diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorscene.h b/src/plugins/qmldesigner/components/formeditor/formeditorscene.h
index ccbc358845..f0343dcde3 100644
--- a/src/plugins/qmldesigner/components/formeditor/formeditorscene.h
+++ b/src/plugins/qmldesigner/components/formeditor/formeditorscene.h
@@ -89,7 +89,6 @@ public:
void synchronizeState(const QmlItemNode &qmlItemNode);
FormEditorItem* calulateNewParent(FormEditorItem *widget);
- bool event(QEvent *event);
LayerItem* manipulatorLayerItem() const;
LayerItem* formLayerItem() const;
FormEditorView *editorView() const;
@@ -110,6 +109,7 @@ public slots:
bool showBoundingRects() const;
protected:
+ bool event(QEvent *event);
void dropEvent(QGraphicsSceneDragDropEvent * event);
void dragEnterEvent(QGraphicsSceneDragDropEvent * event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent * event);
diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp
index 8222525292..56e9060510 100644
--- a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp
+++ b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp
@@ -259,6 +259,11 @@ void FormEditorWidget::centerScene()
m_graphicsView->centerOn(rootItemRect().center());
}
+void FormEditorWidget::setFocus()
+{
+ m_graphicsView->setFocus(Qt::OtherFocusReason);
+}
+
ZoomAction *FormEditorWidget::zoomAction() const
{
return m_zoomAction.data();
diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.h b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.h
index 0fee0358a9..a9aaad2a29 100644
--- a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.h
+++ b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.h
@@ -82,6 +82,8 @@ public:
void resetView();
void centerScene();
+ void setFocus();
+
protected:
void wheelEvent(QWheelEvent *event);
diff --git a/src/plugins/qmldesigner/components/formeditor/movetool.cpp b/src/plugins/qmldesigner/components/formeditor/movetool.cpp
index 4e07e6b954..fbbd119eef 100644
--- a/src/plugins/qmldesigner/components/formeditor/movetool.cpp
+++ b/src/plugins/qmldesigner/components/formeditor/movetool.cpp
@@ -170,7 +170,10 @@ void MoveTool::keyPressEvent(QKeyEvent *event)
case Qt::Key_Down: m_moveManipulator.moveBy(0.0, moveStep); break;
}
-
+ if (event->key() == Qt::Key_Escape && !m_movingItems.isEmpty()) {
+ event->accept();
+ view()->changeToSelectionTool();
+ }
}
void MoveTool::keyReleaseEvent(QKeyEvent *keyEvent)