forked from qt-creator/qt-creator
More snapping with anchoring infrastructor
This commit is contained in:
@@ -393,12 +393,6 @@ void FormEditorView::setCursor(const QCursor &cursor)
|
|||||||
m_formEditorWidget->setCursor(cursor);
|
m_formEditorWidget->setCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FormEditorView::isSnapButtonChecked() const
|
|
||||||
{
|
|
||||||
return m_formEditorWidget->isSnapButtonChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void FormEditorView::nodeSlidedToIndex(const NodeListProperty &listProperty, int /*newIndex*/, int /*oldIndex*/)
|
void FormEditorView::nodeSlidedToIndex(const NodeListProperty &listProperty, int /*newIndex*/, int /*oldIndex*/)
|
||||||
{
|
{
|
||||||
QList<ModelNode> newOrderModelNodeList = listProperty.toModelNodeList();
|
QList<ModelNode> newOrderModelNodeList = listProperty.toModelNodeList();
|
||||||
|
|||||||
@@ -93,8 +93,6 @@ public:
|
|||||||
|
|
||||||
void setCursor(const QCursor &cursor);
|
void setCursor(const QCursor &cursor);
|
||||||
|
|
||||||
bool isSnapButtonChecked() const;
|
|
||||||
|
|
||||||
void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex);
|
void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex);
|
||||||
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
|
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
|
||||||
|
|
||||||
|
|||||||
@@ -233,6 +233,16 @@ QAction *FormEditorWidget::selectOnlyContentItemsAction() const
|
|||||||
return m_selectOnlyContentItemsAction.data();
|
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)
|
void FormEditorWidget::setZoomLevel(double zoomLevel)
|
||||||
{
|
{
|
||||||
m_graphicsView->resetTransform();
|
m_graphicsView->resetTransform();
|
||||||
@@ -255,11 +265,6 @@ ToolBox *FormEditorWidget::toolBox() const
|
|||||||
return m_toolBox.data();
|
return m_toolBox.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FormEditorWidget::isSnapButtonChecked() const
|
|
||||||
{
|
|
||||||
return m_snappingAction->isChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
double FormEditorWidget::spacing() const
|
double FormEditorWidget::spacing() const
|
||||||
{
|
{
|
||||||
return m_snappingSpacingAction->currentValue().toDouble();
|
return m_snappingSpacingAction->currentValue().toDouble();
|
||||||
|
|||||||
@@ -48,14 +48,14 @@ class FormEditorWidget : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
FormEditorWidget(FormEditorView *view);
|
FormEditorWidget(FormEditorView *view);
|
||||||
bool isSnapButtonChecked() const;
|
|
||||||
|
|
||||||
ZoomAction *zoomAction() const;
|
ZoomAction *zoomAction() const;
|
||||||
QAction *anchorToolAction() const;
|
QAction *anchorToolAction() const;
|
||||||
QAction *transformToolAction() const;
|
QAction *transformToolAction() const;
|
||||||
QAction *showBoundingRectAction() const;
|
QAction *showBoundingRectAction() const;
|
||||||
QAction *selectOnlyContentItemsAction() const;
|
QAction *selectOnlyContentItemsAction() const;
|
||||||
|
QAction *snappingAction() const;
|
||||||
|
QAction *snappingAndAnchoringAction() const;
|
||||||
|
|
||||||
void setScene(FormEditorScene *scene);
|
void setScene(FormEditorScene *scene);
|
||||||
ToolBox *toolBox() const;
|
ToolBox *toolBox() const;
|
||||||
|
|||||||
@@ -213,7 +213,13 @@ void MoveManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
|
|||||||
QPointF beginPointInContainerSpace(m_snapper.containerFormEditorItem()->mapFromScene(m_beginPoint));
|
QPointF beginPointInContainerSpace(m_snapper.containerFormEditorItem()->mapFromScene(m_beginPoint));
|
||||||
|
|
||||||
QPointF offsetVector(updatePointInContainerSpace - beginPointInContainerSpace);
|
QPointF offsetVector(updatePointInContainerSpace - beginPointInContainerSpace);
|
||||||
if (useSnapping == UseSnapping) {
|
|
||||||
|
if (useSnapping == UseSnappingAndAnchoring)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useSnapping == UseSnapping || useSnapping == UseSnappingAndAnchoring) {
|
||||||
offsetVector -= findSnappingOffset(tanslatedBoundingRects(m_beginItemRectHash.values(), offsetVector));
|
offsetVector -= findSnappingOffset(tanslatedBoundingRects(m_beginItemRectHash.values(), offsetVector));
|
||||||
generateSnappingLines(tanslatedBoundingRects(m_beginItemRectHash.values(), offsetVector));
|
generateSnappingLines(tanslatedBoundingRects(m_beginItemRectHash.values(), offsetVector));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class MoveManipulator
|
|||||||
public:
|
public:
|
||||||
enum Snapping {
|
enum Snapping {
|
||||||
UseSnapping,
|
UseSnapping,
|
||||||
|
UseSnappingAndAnchoring,
|
||||||
NoSnapping
|
NoSnapping
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include "formeditorscene.h"
|
#include "formeditorscene.h"
|
||||||
#include "formeditorview.h"
|
#include "formeditorview.h"
|
||||||
|
#include "formeditorwidget.h"
|
||||||
#include "modelutilities.h"
|
#include "modelutilities.h"
|
||||||
#include "itemutilfunctions.h"
|
#include "itemutilfunctions.h"
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QAction>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
@@ -96,9 +98,16 @@ void MoveTool::mouseMoveEvent(const QList<QGraphicsItem*> &itemList,
|
|||||||
m_moveManipulator.reparentTo(containerItem);
|
m_moveManipulator.reparentTo(containerItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool shouldSnapping = view()->widget()->snappingAction()->isChecked();
|
||||||
|
bool shouldSnappingAndAnchoring = view()->widget()->snappingAndAnchoringAction()->isChecked();
|
||||||
|
|
||||||
MoveManipulator::Snapping useSnapping = MoveManipulator::NoSnapping;
|
MoveManipulator::Snapping useSnapping = MoveManipulator::NoSnapping;
|
||||||
if (event->modifiers().testFlag(Qt::ControlModifier) != view()->isSnapButtonChecked())
|
if (event->modifiers().testFlag(Qt::ControlModifier) != (shouldSnapping || shouldSnappingAndAnchoring)) {
|
||||||
useSnapping = MoveManipulator::UseSnapping;
|
if (shouldSnappingAndAnchoring)
|
||||||
|
useSnapping = MoveManipulator::UseSnappingAndAnchoring;
|
||||||
|
else
|
||||||
|
useSnapping = MoveManipulator::UseSnapping;
|
||||||
|
}
|
||||||
|
|
||||||
m_moveManipulator.update(event->scenePos(), useSnapping);
|
m_moveManipulator.update(event->scenePos(), useSnapping);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
|
|||||||
|
|
||||||
deleteSnapLines();
|
deleteSnapLines();
|
||||||
|
|
||||||
|
bool snap = useSnapping == UseSnapping || useSnapping == UseSnappingAndAnchoring;
|
||||||
|
|
||||||
if (m_resizeController.isValid()) {
|
if (m_resizeController.isValid()) {
|
||||||
|
|
||||||
FormEditorItem *formEditorItem = m_resizeController.formEditorItem();
|
FormEditorItem *formEditorItem = m_resizeController.formEditorItem();
|
||||||
@@ -120,7 +122,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
|
|||||||
if (m_resizeHandle->isBottomRightHandle()) {
|
if (m_resizeHandle->isBottomRightHandle()) {
|
||||||
boundingRect.setBottomRight(updatePointInLocalSpace);
|
boundingRect.setBottomRight(updatePointInLocalSpace);
|
||||||
|
|
||||||
if (useSnapping == UseSnapping) {
|
if (snap) {
|
||||||
double rightOffset = m_snapper.snapRightOffset(boundingRect);
|
double rightOffset = m_snapper.snapRightOffset(boundingRect);
|
||||||
if (rightOffset < std::numeric_limits<double>::max())
|
if (rightOffset < std::numeric_limits<double>::max())
|
||||||
updatePointInLocalSpace.rx() -= rightOffset;
|
updatePointInLocalSpace.rx() -= rightOffset;
|
||||||
@@ -159,7 +161,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
|
|||||||
} else if (m_resizeHandle->isTopLeftHandle()) {
|
} else if (m_resizeHandle->isTopLeftHandle()) {
|
||||||
boundingRect.setTopLeft(updatePointInLocalSpace);
|
boundingRect.setTopLeft(updatePointInLocalSpace);
|
||||||
|
|
||||||
if (useSnapping == UseSnapping) {
|
if (snap) {
|
||||||
double leftOffset = m_snapper.snapLeftOffset(boundingRect);
|
double leftOffset = m_snapper.snapLeftOffset(boundingRect);
|
||||||
if (leftOffset < std::numeric_limits<double>::max())
|
if (leftOffset < std::numeric_limits<double>::max())
|
||||||
updatePointInLocalSpace.rx() -= leftOffset;
|
updatePointInLocalSpace.rx() -= leftOffset;
|
||||||
@@ -201,7 +203,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
|
|||||||
} else if (m_resizeHandle->isTopRightHandle()) {
|
} else if (m_resizeHandle->isTopRightHandle()) {
|
||||||
boundingRect.setTopRight(updatePointInLocalSpace);
|
boundingRect.setTopRight(updatePointInLocalSpace);
|
||||||
|
|
||||||
if (useSnapping == UseSnapping) {
|
if (snap) {
|
||||||
double rightOffset = m_snapper.snapRightOffset(boundingRect);
|
double rightOffset = m_snapper.snapRightOffset(boundingRect);
|
||||||
if (rightOffset < std::numeric_limits<double>::max())
|
if (rightOffset < std::numeric_limits<double>::max())
|
||||||
updatePointInLocalSpace.rx() -= rightOffset;
|
updatePointInLocalSpace.rx() -= rightOffset;
|
||||||
@@ -240,7 +242,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
|
|||||||
} else if (m_resizeHandle->isBottomLeftHandle()) {
|
} else if (m_resizeHandle->isBottomLeftHandle()) {
|
||||||
boundingRect.setBottomLeft(updatePointInLocalSpace);
|
boundingRect.setBottomLeft(updatePointInLocalSpace);
|
||||||
|
|
||||||
if (useSnapping == UseSnapping) {
|
if (snap) {
|
||||||
double leftOffset = m_snapper.snapLeftOffset(boundingRect);
|
double leftOffset = m_snapper.snapLeftOffset(boundingRect);
|
||||||
if (leftOffset < std::numeric_limits<double>::max())
|
if (leftOffset < std::numeric_limits<double>::max())
|
||||||
updatePointInLocalSpace.rx() -= leftOffset;
|
updatePointInLocalSpace.rx() -= leftOffset;
|
||||||
@@ -280,7 +282,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
|
|||||||
} else if (m_resizeHandle->isBottomHandle()) {
|
} else if (m_resizeHandle->isBottomHandle()) {
|
||||||
boundingRect.setBottom(updatePointInLocalSpace.y());
|
boundingRect.setBottom(updatePointInLocalSpace.y());
|
||||||
|
|
||||||
if (useSnapping == UseSnapping) {
|
if (snap) {
|
||||||
double bottomOffset = m_snapper.snapBottomOffset(boundingRect);
|
double bottomOffset = m_snapper.snapBottomOffset(boundingRect);
|
||||||
if (bottomOffset < std::numeric_limits<double>::max())
|
if (bottomOffset < std::numeric_limits<double>::max())
|
||||||
updatePointInLocalSpace.ry() -= bottomOffset;
|
updatePointInLocalSpace.ry() -= bottomOffset;
|
||||||
@@ -304,7 +306,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
|
|||||||
} else if (m_resizeHandle->isTopHandle()) {
|
} else if (m_resizeHandle->isTopHandle()) {
|
||||||
boundingRect.setTop(updatePointInLocalSpace.y());
|
boundingRect.setTop(updatePointInLocalSpace.y());
|
||||||
|
|
||||||
if (useSnapping == UseSnapping) {
|
if (snap) {
|
||||||
double topOffset = m_snapper.snapTopOffset(boundingRect);
|
double topOffset = m_snapper.snapTopOffset(boundingRect);
|
||||||
if (topOffset < std::numeric_limits<double>::max())
|
if (topOffset < std::numeric_limits<double>::max())
|
||||||
updatePointInLocalSpace.ry() -= topOffset;
|
updatePointInLocalSpace.ry() -= topOffset;
|
||||||
@@ -329,7 +331,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
|
|||||||
} else if (m_resizeHandle->isRightHandle()) {
|
} else if (m_resizeHandle->isRightHandle()) {
|
||||||
boundingRect.setRight(updatePointInLocalSpace.x());
|
boundingRect.setRight(updatePointInLocalSpace.x());
|
||||||
|
|
||||||
if (useSnapping == UseSnapping) {
|
if (snap) {
|
||||||
double rightOffset = m_snapper.snapRightOffset(boundingRect);
|
double rightOffset = m_snapper.snapRightOffset(boundingRect);
|
||||||
if (rightOffset < std::numeric_limits<double>::max())
|
if (rightOffset < std::numeric_limits<double>::max())
|
||||||
updatePointInLocalSpace.rx() -= rightOffset;
|
updatePointInLocalSpace.rx() -= rightOffset;
|
||||||
@@ -354,7 +356,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
|
|||||||
} else if (m_resizeHandle->isLeftHandle()) {
|
} else if (m_resizeHandle->isLeftHandle()) {
|
||||||
boundingRect.setLeft(updatePointInLocalSpace.x());
|
boundingRect.setLeft(updatePointInLocalSpace.x());
|
||||||
|
|
||||||
if (useSnapping == UseSnapping) {
|
if (snap) {
|
||||||
double leftOffset = m_snapper.snapLeftOffset(boundingRect);
|
double leftOffset = m_snapper.snapLeftOffset(boundingRect);
|
||||||
if (leftOffset < std::numeric_limits<double>::max())
|
if (leftOffset < std::numeric_limits<double>::max())
|
||||||
updatePointInLocalSpace.rx() -= leftOffset;
|
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_graphicsLineList = m_snapper.generateSnappingLines(boundingRect,
|
||||||
m_layerItem.data(),
|
m_layerItem.data(),
|
||||||
m_beginToSceneTransform);
|
m_beginToSceneTransform);
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class ResizeManipulator
|
|||||||
public:
|
public:
|
||||||
enum Snapping {
|
enum Snapping {
|
||||||
UseSnapping,
|
UseSnapping,
|
||||||
|
UseSnappingAndAnchoring,
|
||||||
NoSnapping
|
NoSnapping
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,11 +31,13 @@
|
|||||||
|
|
||||||
#include "formeditorscene.h"
|
#include "formeditorscene.h"
|
||||||
#include "formeditorview.h"
|
#include "formeditorview.h"
|
||||||
|
#include "formeditorwidget.h"
|
||||||
|
|
||||||
#include "resizehandleitem.h"
|
#include "resizehandleitem.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QAction>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
@@ -71,11 +73,16 @@ void ResizeTool::mousePressEvent(const QList<QGraphicsItem*> &itemList,
|
|||||||
void ResizeTool::mouseMoveEvent(const QList<QGraphicsItem*> &,
|
void ResizeTool::mouseMoveEvent(const QList<QGraphicsItem*> &,
|
||||||
QGraphicsSceneMouseEvent *event)
|
QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
bool shouldSnapping = view()->widget()->snappingAction()->isChecked();
|
||||||
|
bool shouldSnappingAndAnchoring = view()->widget()->snappingAndAnchoringAction()->isChecked();
|
||||||
|
|
||||||
ResizeManipulator::Snapping useSnapping = ResizeManipulator::NoSnapping;
|
ResizeManipulator::Snapping useSnapping = ResizeManipulator::NoSnapping;
|
||||||
if (event->modifiers().testFlag(Qt::ControlModifier) != view()->isSnapButtonChecked())
|
if (event->modifiers().testFlag(Qt::ControlModifier) != (shouldSnapping || shouldSnappingAndAnchoring)) {
|
||||||
useSnapping = ResizeManipulator::UseSnapping;
|
if (shouldSnappingAndAnchoring)
|
||||||
|
useSnapping = ResizeManipulator::UseSnappingAndAnchoring;
|
||||||
|
else
|
||||||
|
useSnapping = ResizeManipulator::UseSnapping;
|
||||||
|
}
|
||||||
|
|
||||||
m_resizeManipulator.update(event->scenePos(), useSnapping);
|
m_resizeManipulator.update(event->scenePos(), useSnapping);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user