Commit 4e17c0e8 authored by Marco Bubke's avatar Marco Bubke
Browse files

More snapping with anchoring infrastructor

parent 58571da7
......@@ -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();
......
......@@ -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);
......
......@@ -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();
......
......@@ -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;
......
......@@ -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));
}
......
......@@ -53,6 +53,7 @@ class MoveManipulator
public:
enum Snapping {
UseSnapping,
UseSnappingAndAnchoring,
NoSnapping
};
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -46,6 +46,7 @@ class ResizeManipulator
public:
enum Snapping {
UseSnapping,
UseSnappingAndAnchoring,
NoSnapping
};
......
......@@ -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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment