QmlDesigner: allow aborting drag and drop with Escape

Also allows aborting the move tool.

Reviewed-by: Marco Bubke
Task-number: QTCREATORBUG-4322
This commit is contained in:
Thomas Hartmann
2011-05-10 15:09:26 +02:00
parent 4b19473a9b
commit df6f809927
8 changed files with 52 additions and 7 deletions

View File

@@ -169,7 +169,6 @@ FormEditorItem* AbstractFormEditorTool::topFormEditorItemWithRootItem(const QLis
void AbstractFormEditorTool::dropEvent(QGraphicsSceneDragDropEvent * /* event */) void AbstractFormEditorTool::dropEvent(QGraphicsSceneDragDropEvent * /* event */)
{ {
Q_ASSERT(false);
} }
void AbstractFormEditorTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event) void AbstractFormEditorTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event)

View File

@@ -34,6 +34,7 @@
#include "formeditorscene.h" #include "formeditorscene.h"
#include "formeditorview.h" #include "formeditorview.h"
#include "formeditorwidget.h"
#include "itemutilfunctions.h" #include "itemutilfunctions.h"
#include <customdraganddrop.h> #include <customdraganddrop.h>
#include <metainfo.h> #include <metainfo.h>
@@ -62,7 +63,8 @@ DragTool::DragTool(FormEditorView *editorView)
m_moveManipulator(editorView->scene()->manipulatorLayerItem(), editorView), m_moveManipulator(editorView->scene()->manipulatorLayerItem(), editorView),
m_selectionIndicator(editorView->scene()->manipulatorLayerItem()), m_selectionIndicator(editorView->scene()->manipulatorLayerItem()),
m_timerHandler(new Internal::TimerHandler(this)), m_timerHandler(new Internal::TimerHandler(this)),
m_blockMove(false) m_blockMove(false),
m_Aborted(false)
{ {
// view()->setCursor(Qt::SizeAllCursor); // 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 *) void DragTool::keyReleaseEvent(QKeyEvent *)
@@ -221,6 +227,23 @@ void DragTool::clearMoveDelay()
beginWithPoint(m_startPoint); 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) void DragTool::dropEvent(QGraphicsSceneDragDropEvent * event)
{ {
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") || if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") ||
@@ -260,6 +283,8 @@ void DragTool::dragEnterEvent(QGraphicsSceneDragDropEvent * event)
QList<Import> importToBeAddedList; QList<Import> importToBeAddedList;
m_blockMove = false; m_blockMove = false;
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo")) { if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo")) {
view()->widget()->setFocus();
m_Aborted = false;
Q_ASSERT(!event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo").isEmpty()); Q_ASSERT(!event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo").isEmpty());
ItemLibraryEntry itemLibraryEntry = itemLibraryEntryFromData(event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo")); ItemLibraryEntry itemLibraryEntry = itemLibraryEntryFromData(event->mimeData()->data("application/vnd.bauhaus.itemlibraryinfo"));
if (!itemLibraryEntry.requiredImport().isEmpty()) { if (!itemLibraryEntry.requiredImport().isEmpty()) {
@@ -309,6 +334,11 @@ void DragTool::dragMoveEvent(QGraphicsSceneDragDropEvent * event)
{ {
if (m_blockMove) if (m_blockMove)
return; return;
if (m_Aborted) {
event->ignore();
return;
}
if (QmlDesignerItemLibraryDragAndDrop::CustomDragAndDrop::isAnimated()) if (QmlDesignerItemLibraryDragAndDrop::CustomDragAndDrop::isAnimated())
return; return;
if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") || if (event->mimeData()->hasFormat("application/vnd.bauhaus.itemlibraryinfo") ||

View File

@@ -108,6 +108,7 @@ public:
void clearMoveDelay(); void clearMoveDelay();
protected: protected:
void abort();
private: private:
@@ -128,6 +129,7 @@ private:
QScopedPointer<Internal::TimerHandler> m_timerHandler; QScopedPointer<Internal::TimerHandler> m_timerHandler;
bool m_blockMove; bool m_blockMove;
QPointF m_startPoint; QPointF m_startPoint;
bool m_Aborted;
}; };

View File

@@ -231,7 +231,6 @@ FormEditorItem *FormEditorScene::addFormEditorItem(const QmlItemNode &qmlItemNod
return formEditorItem; return formEditorItem;
} }
void FormEditorScene::dropEvent(QGraphicsSceneDragDropEvent * event) void FormEditorScene::dropEvent(QGraphicsSceneDragDropEvent * event)
{ {
currentTool()->dropEvent(event); currentTool()->dropEvent(event);
@@ -345,6 +344,11 @@ bool FormEditorScene::event(QEvent * event)
case QEvent::GraphicsSceneHoverLeave : case QEvent::GraphicsSceneHoverLeave :
hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent *>(event)); hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
return true; 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); default: return QGraphicsScene::event(event);
} }

View File

@@ -89,7 +89,6 @@ public:
void synchronizeState(const QmlItemNode &qmlItemNode); void synchronizeState(const QmlItemNode &qmlItemNode);
FormEditorItem* calulateNewParent(FormEditorItem *widget); FormEditorItem* calulateNewParent(FormEditorItem *widget);
bool event(QEvent *event);
LayerItem* manipulatorLayerItem() const; LayerItem* manipulatorLayerItem() const;
LayerItem* formLayerItem() const; LayerItem* formLayerItem() const;
FormEditorView *editorView() const; FormEditorView *editorView() const;
@@ -110,6 +109,7 @@ public slots:
bool showBoundingRects() const; bool showBoundingRects() const;
protected: protected:
bool event(QEvent *event);
void dropEvent(QGraphicsSceneDragDropEvent * event); void dropEvent(QGraphicsSceneDragDropEvent * event);
void dragEnterEvent(QGraphicsSceneDragDropEvent * event); void dragEnterEvent(QGraphicsSceneDragDropEvent * event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent * event); void dragLeaveEvent(QGraphicsSceneDragDropEvent * event);

View File

@@ -259,6 +259,11 @@ void FormEditorWidget::centerScene()
m_graphicsView->centerOn(rootItemRect().center()); m_graphicsView->centerOn(rootItemRect().center());
} }
void FormEditorWidget::setFocus()
{
m_graphicsView->setFocus(Qt::OtherFocusReason);
}
ZoomAction *FormEditorWidget::zoomAction() const ZoomAction *FormEditorWidget::zoomAction() const
{ {
return m_zoomAction.data(); return m_zoomAction.data();

View File

@@ -82,6 +82,8 @@ public:
void resetView(); void resetView();
void centerScene(); void centerScene();
void setFocus();
protected: protected:
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);

View File

@@ -170,7 +170,10 @@ void MoveTool::keyPressEvent(QKeyEvent *event)
case Qt::Key_Down: m_moveManipulator.moveBy(0.0, moveStep); break; 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) void MoveTool::keyReleaseEvent(QKeyEvent *keyEvent)