diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp index 3f533bf789b61c9e17c02db3bc670d87383bdea7..02ae0dc29c76f3cee0e97b5e74d3a18096cf0d0a 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp @@ -393,12 +393,6 @@ void FormEditorView::setCursor(const QCursor &cursor) m_formEditorWidget->setCursor(cursor); } -bool FormEditorView::isSnapButtonChecked() const -{ - return m_formEditorWidget->isSnapButtonChecked(); -} - - void FormEditorView::nodeSlidedToIndex(const NodeListProperty &listProperty, int /*newIndex*/, int /*oldIndex*/) { QList<ModelNode> newOrderModelNodeList = listProperty.toModelNodeList(); diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorview.h b/src/plugins/qmldesigner/components/formeditor/formeditorview.h index 6f8f7d43172b3899380bc3c7177d3e45ced4f531..6230ca36f40d4ad091f69e5165c08466c3bc76ec 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorview.h +++ b/src/plugins/qmldesigner/components/formeditor/formeditorview.h @@ -93,8 +93,6 @@ public: void setCursor(const QCursor &cursor); - bool isSnapButtonChecked() const; - void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex); void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data); diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp index 8178c29544f0aacbe2cf6c00bfb06e1f6e823423..0101260832897e2f8165fc12160e35701fe0f595 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp @@ -233,6 +233,16 @@ QAction *FormEditorWidget::selectOnlyContentItemsAction() const return m_selectOnlyContentItemsAction.data(); } +QAction *FormEditorWidget::snappingAction() const +{ + return m_snappingAction.data(); +} + +QAction *FormEditorWidget::snappingAndAnchoringAction() const +{ + return m_snappingAndAnchoringAction.data(); +} + void FormEditorWidget::setZoomLevel(double zoomLevel) { m_graphicsView->resetTransform(); @@ -255,11 +265,6 @@ ToolBox *FormEditorWidget::toolBox() const return m_toolBox.data(); } -bool FormEditorWidget::isSnapButtonChecked() const -{ - return m_snappingAction->isChecked(); -} - double FormEditorWidget::spacing() const { return m_snappingSpacingAction->currentValue().toDouble(); diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.h b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.h index 3246fbbffcd5962cffe55e8b4189b8e7848ba1ea..647566e134b012ba375a4ceac9bc79b72c811b01 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.h +++ b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.h @@ -48,14 +48,14 @@ class FormEditorWidget : public QWidget Q_OBJECT public: FormEditorWidget(FormEditorView *view); - bool isSnapButtonChecked() const; ZoomAction *zoomAction() const; QAction *anchorToolAction() const; QAction *transformToolAction() const; QAction *showBoundingRectAction() const; QAction *selectOnlyContentItemsAction() const; - + QAction *snappingAction() const; + QAction *snappingAndAnchoringAction() const; void setScene(FormEditorScene *scene); ToolBox *toolBox() const; diff --git a/src/plugins/qmldesigner/components/formeditor/movemanipulator.cpp b/src/plugins/qmldesigner/components/formeditor/movemanipulator.cpp index 01fa6c804e6cfd4646df2fa89286490031d3e21c..4ce6ae605c65c73e13b4eeb5c582ea4e00624c49 100644 --- a/src/plugins/qmldesigner/components/formeditor/movemanipulator.cpp +++ b/src/plugins/qmldesigner/components/formeditor/movemanipulator.cpp @@ -213,7 +213,13 @@ void MoveManipulator::update(const QPointF& updatePoint, Snapping useSnapping) QPointF beginPointInContainerSpace(m_snapper.containerFormEditorItem()->mapFromScene(m_beginPoint)); QPointF offsetVector(updatePointInContainerSpace - beginPointInContainerSpace); - if (useSnapping == UseSnapping) { + + if (useSnapping == UseSnappingAndAnchoring) + { + + } + + if (useSnapping == UseSnapping || useSnapping == UseSnappingAndAnchoring) { offsetVector -= findSnappingOffset(tanslatedBoundingRects(m_beginItemRectHash.values(), offsetVector)); generateSnappingLines(tanslatedBoundingRects(m_beginItemRectHash.values(), offsetVector)); } diff --git a/src/plugins/qmldesigner/components/formeditor/movemanipulator.h b/src/plugins/qmldesigner/components/formeditor/movemanipulator.h index 3501625b4d9b17f0ee3c3e28ba67b3ff86a3c909..7c6445bc43b361a43911d525323bc95d21a93fac 100644 --- a/src/plugins/qmldesigner/components/formeditor/movemanipulator.h +++ b/src/plugins/qmldesigner/components/formeditor/movemanipulator.h @@ -53,6 +53,7 @@ class MoveManipulator public: enum Snapping { UseSnapping, + UseSnappingAndAnchoring, NoSnapping }; diff --git a/src/plugins/qmldesigner/components/formeditor/movetool.cpp b/src/plugins/qmldesigner/components/formeditor/movetool.cpp index 09f5ec73c161d95e97626a4b1ec883af48e703b0..6126c77ae3af743afb12819609eb585d460fb7a3 100644 --- a/src/plugins/qmldesigner/components/formeditor/movetool.cpp +++ b/src/plugins/qmldesigner/components/formeditor/movetool.cpp @@ -31,6 +31,7 @@ #include "formeditorscene.h" #include "formeditorview.h" +#include "formeditorwidget.h" #include "modelutilities.h" #include "itemutilfunctions.h" @@ -38,6 +39,7 @@ #include <QApplication> #include <QGraphicsSceneMouseEvent> +#include <QAction> #include <QtDebug> namespace QmlDesigner { @@ -96,9 +98,16 @@ void MoveTool::mouseMoveEvent(const QList<QGraphicsItem*> &itemList, m_moveManipulator.reparentTo(containerItem); } + bool shouldSnapping = view()->widget()->snappingAction()->isChecked(); + bool shouldSnappingAndAnchoring = view()->widget()->snappingAndAnchoringAction()->isChecked(); + MoveManipulator::Snapping useSnapping = MoveManipulator::NoSnapping; - if (event->modifiers().testFlag(Qt::ControlModifier) != view()->isSnapButtonChecked()) - useSnapping = MoveManipulator::UseSnapping; + if (event->modifiers().testFlag(Qt::ControlModifier) != (shouldSnapping || shouldSnappingAndAnchoring)) { + if (shouldSnappingAndAnchoring) + useSnapping = MoveManipulator::UseSnappingAndAnchoring; + else + useSnapping = MoveManipulator::UseSnapping; + } m_moveManipulator.update(event->scenePos(), useSnapping); } diff --git a/src/plugins/qmldesigner/components/formeditor/resizemanipulator.cpp b/src/plugins/qmldesigner/components/formeditor/resizemanipulator.cpp index 24e9ef43bd185b113e9083b896de06fc33caf83e..ac1cc0e6a0de125fbe30751bd7edec36b9451b5b 100644 --- a/src/plugins/qmldesigner/components/formeditor/resizemanipulator.cpp +++ b/src/plugins/qmldesigner/components/formeditor/resizemanipulator.cpp @@ -105,6 +105,8 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping) deleteSnapLines(); + bool snap = useSnapping == UseSnapping || useSnapping == UseSnappingAndAnchoring; + if (m_resizeController.isValid()) { FormEditorItem *formEditorItem = m_resizeController.formEditorItem(); @@ -120,7 +122,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping) if (m_resizeHandle->isBottomRightHandle()) { boundingRect.setBottomRight(updatePointInLocalSpace); - if (useSnapping == UseSnapping) { + if (snap) { double rightOffset = m_snapper.snapRightOffset(boundingRect); if (rightOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.rx() -= rightOffset; @@ -159,7 +161,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping) } else if (m_resizeHandle->isTopLeftHandle()) { boundingRect.setTopLeft(updatePointInLocalSpace); - if (useSnapping == UseSnapping) { + if (snap) { double leftOffset = m_snapper.snapLeftOffset(boundingRect); if (leftOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.rx() -= leftOffset; @@ -201,7 +203,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping) } else if (m_resizeHandle->isTopRightHandle()) { boundingRect.setTopRight(updatePointInLocalSpace); - if (useSnapping == UseSnapping) { + if (snap) { double rightOffset = m_snapper.snapRightOffset(boundingRect); if (rightOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.rx() -= rightOffset; @@ -240,7 +242,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping) } else if (m_resizeHandle->isBottomLeftHandle()) { boundingRect.setBottomLeft(updatePointInLocalSpace); - if (useSnapping == UseSnapping) { + if (snap) { double leftOffset = m_snapper.snapLeftOffset(boundingRect); if (leftOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.rx() -= leftOffset; @@ -280,7 +282,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping) } else if (m_resizeHandle->isBottomHandle()) { boundingRect.setBottom(updatePointInLocalSpace.y()); - if (useSnapping == UseSnapping) { + if (snap) { double bottomOffset = m_snapper.snapBottomOffset(boundingRect); if (bottomOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.ry() -= bottomOffset; @@ -304,7 +306,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping) } else if (m_resizeHandle->isTopHandle()) { boundingRect.setTop(updatePointInLocalSpace.y()); - if (useSnapping == UseSnapping) { + if (snap) { double topOffset = m_snapper.snapTopOffset(boundingRect); if (topOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.ry() -= topOffset; @@ -329,7 +331,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping) } else if (m_resizeHandle->isRightHandle()) { boundingRect.setRight(updatePointInLocalSpace.x()); - if (useSnapping == UseSnapping) { + if (snap) { double rightOffset = m_snapper.snapRightOffset(boundingRect); if (rightOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.rx() -= rightOffset; @@ -354,7 +356,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping) } else if (m_resizeHandle->isLeftHandle()) { boundingRect.setLeft(updatePointInLocalSpace.x()); - if (useSnapping == UseSnapping) { + if (snap) { double leftOffset = m_snapper.snapLeftOffset(boundingRect); if (leftOffset < std::numeric_limits<double>::max()) updatePointInLocalSpace.rx() -= leftOffset; @@ -378,7 +380,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping) } } - if (useSnapping == UseSnapping) + if (snap) m_graphicsLineList = m_snapper.generateSnappingLines(boundingRect, m_layerItem.data(), m_beginToSceneTransform); diff --git a/src/plugins/qmldesigner/components/formeditor/resizemanipulator.h b/src/plugins/qmldesigner/components/formeditor/resizemanipulator.h index 913966537f1a478aee84a62d23f1980eef02d5f6..4988e53fb932d902322cfb02200c408bd5ea3552 100644 --- a/src/plugins/qmldesigner/components/formeditor/resizemanipulator.h +++ b/src/plugins/qmldesigner/components/formeditor/resizemanipulator.h @@ -46,6 +46,7 @@ class ResizeManipulator public: enum Snapping { UseSnapping, + UseSnappingAndAnchoring, NoSnapping }; diff --git a/src/plugins/qmldesigner/components/formeditor/resizetool.cpp b/src/plugins/qmldesigner/components/formeditor/resizetool.cpp index bd7d5157e1fe9cd3840b2a5b97ebcb55864e0321..3f4e118e20b366beba2311f773617333ec2df019 100644 --- a/src/plugins/qmldesigner/components/formeditor/resizetool.cpp +++ b/src/plugins/qmldesigner/components/formeditor/resizetool.cpp @@ -31,11 +31,13 @@ #include "formeditorscene.h" #include "formeditorview.h" +#include "formeditorwidget.h" #include "resizehandleitem.h" #include <QApplication> #include <QGraphicsSceneMouseEvent> +#include <QAction> #include <QtDebug> namespace QmlDesigner { @@ -71,11 +73,16 @@ void ResizeTool::mousePressEvent(const QList<QGraphicsItem*> &itemList, void ResizeTool::mouseMoveEvent(const QList<QGraphicsItem*> &, QGraphicsSceneMouseEvent *event) { - + bool shouldSnapping = view()->widget()->snappingAction()->isChecked(); + bool shouldSnappingAndAnchoring = view()->widget()->snappingAndAnchoringAction()->isChecked(); ResizeManipulator::Snapping useSnapping = ResizeManipulator::NoSnapping; - if (event->modifiers().testFlag(Qt::ControlModifier) != view()->isSnapButtonChecked()) - useSnapping = ResizeManipulator::UseSnapping; + if (event->modifiers().testFlag(Qt::ControlModifier) != (shouldSnapping || shouldSnappingAndAnchoring)) { + if (shouldSnappingAndAnchoring) + useSnapping = ResizeManipulator::UseSnappingAndAnchoring; + else + useSnapping = ResizeManipulator::UseSnapping; + } m_resizeManipulator.update(event->scenePos(), useSnapping); }