forked from qt-creator/qt-creator
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:
@@ -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)
|
||||||
|
@@ -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") ||
|
||||||
|
@@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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);
|
||||||
|
@@ -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();
|
||||||
|
@@ -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);
|
||||||
|
@@ -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)
|
||||||
|
Reference in New Issue
Block a user