summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@nokia.com>2010-01-20 15:51:58 +0100
committerMarco Bubke <marco.bubke@nokia.com>2010-01-21 20:02:22 +0100
commit4e17c0e831abb7357654bd3ca4e91ef15105dfb4 (patch)
treef360c4e2a6edc3d7796b0ab8f217ec978a7f5542
parent58571da7a42952ac41be9f843cd53378d4b9f2c5 (diff)
downloadqt-creator-4e17c0e831abb7357654bd3ca4e91ef15105dfb4.tar.gz
More snapping with anchoring infrastructor
-rw-r--r--src/plugins/qmldesigner/components/formeditor/formeditorview.cpp6
-rw-r--r--src/plugins/qmldesigner/components/formeditor/formeditorview.h2
-rw-r--r--src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp15
-rw-r--r--src/plugins/qmldesigner/components/formeditor/formeditorwidget.h4
-rw-r--r--src/plugins/qmldesigner/components/formeditor/movemanipulator.cpp8
-rw-r--r--src/plugins/qmldesigner/components/formeditor/movemanipulator.h1
-rw-r--r--src/plugins/qmldesigner/components/formeditor/movetool.cpp13
-rw-r--r--src/plugins/qmldesigner/components/formeditor/resizemanipulator.cpp20
-rw-r--r--src/plugins/qmldesigner/components/formeditor/resizemanipulator.h1
-rw-r--r--src/plugins/qmldesigner/components/formeditor/resizetool.cpp13
10 files changed, 53 insertions, 30 deletions
diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp
index 3f533bf789..02ae0dc29c 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 6f8f7d4317..6230ca36f4 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 8178c29544..0101260832 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 3246fbbffc..647566e134 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 01fa6c804e..4ce6ae605c 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 3501625b4d..7c6445bc43 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 09f5ec73c1..6126c77ae3 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 24e9ef43bd..ac1cc0e6a0 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 913966537f..4988e53fb9 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 bd7d5157e1..3f4e118e20 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);
}