diff options
author | Marco Bubke <marco.bubke@digia.com> | 2013-08-29 14:45:20 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@digia.com> | 2013-09-03 11:47:05 +0200 |
commit | 480d014b44e60d071ce3573ac2e418c158187c4d (patch) | |
tree | 0d3b9e73c60793579269bb6d86f10f31b9b1fabc /src/plugins/qmldesigner | |
parent | 036ab272b84accd3adeccbd380d4690c1f17202b (diff) | |
download | qt-creator-480d014b44e60d071ce3573ac2e418c158187c4d.tar.gz |
QmlDesigner: Add AnchorIndicator
Change-Id: I0cd4b3c9dc0178936ffd96d8acb443ce1a228d1f
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
Diffstat (limited to 'src/plugins/qmldesigner')
11 files changed, 609 insertions, 3 deletions
diff --git a/src/plugins/qmldesigner/components/formeditor/anchorindicator.cpp b/src/plugins/qmldesigner/components/formeditor/anchorindicator.cpp new file mode 100644 index 0000000000..e11f117eaa --- /dev/null +++ b/src/plugins/qmldesigner/components/formeditor/anchorindicator.cpp @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "anchorindicator.h" + +#include "qmlanchors.h" +#include "anchorindicatorgraphicsitem.h" +#include <QGraphicsScene> +#include <QGraphicsPathItem> + +namespace QmlDesigner { + +AnchorIndicator::AnchorIndicator(LayerItem *layerItem) + : m_layerItem(layerItem) +{ +} + +AnchorIndicator::AnchorIndicator() +{ +} + +AnchorIndicator::~AnchorIndicator() +{ + clear(); +} + +void AnchorIndicator::show() +{ + if (m_indicatorTopShape) + m_indicatorTopShape->show(); + + if (m_indicatorBottomShape) + m_indicatorBottomShape->show(); + + if (m_indicatorLeftShape) + m_indicatorLeftShape->show(); + + if (m_indicatorRightShape) + m_indicatorRightShape->show(); +} + +void AnchorIndicator::hide() +{ + if (m_indicatorTopShape) + m_indicatorTopShape->hide(); + + if (m_indicatorBottomShape) + m_indicatorBottomShape->hide(); + + if (m_indicatorLeftShape) + m_indicatorLeftShape->hide(); + + if (m_indicatorRightShape) + m_indicatorRightShape->hide(); +} + +void AnchorIndicator::clear() +{ + delete m_indicatorTopShape; + delete m_indicatorBottomShape; + delete m_indicatorLeftShape; + delete m_indicatorRightShape; +} + +void AnchorIndicator::setItems(const QList<FormEditorItem *> &itemList) +{ + clear(); + + if (itemList.count() == 1) { + m_formEditorItem = itemList.first(); + QmlItemNode sourceQmlItemNode = m_formEditorItem->qmlItemNode(); + QmlAnchors qmlAnchors = sourceQmlItemNode.anchors(); + + if (qmlAnchors.modelHasAnchor(AnchorLine::Top)) { + m_indicatorTopShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); + m_indicatorTopShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Top), + qmlAnchors.modelAnchor(AnchorLine::Top)); + } + + if (qmlAnchors.modelHasAnchor(AnchorLine::Bottom)) { + m_indicatorBottomShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); + m_indicatorBottomShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Bottom), + qmlAnchors.modelAnchor(AnchorLine::Bottom)); + } + + if (qmlAnchors.modelHasAnchor(AnchorLine::Left)) { + m_indicatorLeftShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); + m_indicatorLeftShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Left), + qmlAnchors.modelAnchor(AnchorLine::Left)); + } + + if (qmlAnchors.modelHasAnchor(AnchorLine::Right)) { + m_indicatorRightShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); + m_indicatorRightShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Right), + qmlAnchors.modelAnchor(AnchorLine::Right)); + } + } +} + +void AnchorIndicator::updateItems(const QList<FormEditorItem *> &itemList) +{ + foreach (FormEditorItem *formEditorItem, itemList) { + if (formEditorItem == m_formEditorItem) { + QmlItemNode sourceQmlItemNode = m_formEditorItem->qmlItemNode(); + QmlAnchors qmlAnchors = formEditorItem->qmlItemNode().anchors(); + + if (qmlAnchors.modelHasAnchor(AnchorLine::Top)) { + if (m_indicatorTopShape.isNull()) + m_indicatorTopShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); + m_indicatorTopShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Top), + qmlAnchors.modelAnchor(AnchorLine::Top)); + } else { + delete m_indicatorTopShape; + } + + if (qmlAnchors.modelHasAnchor(AnchorLine::Bottom)) { + if (m_indicatorBottomShape.isNull()) + m_indicatorBottomShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); + m_indicatorBottomShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Bottom), + qmlAnchors.modelAnchor(AnchorLine::Bottom)); + } else { + delete m_indicatorBottomShape; + } + + if (qmlAnchors.modelHasAnchor(AnchorLine::Left)) { + if (m_indicatorLeftShape.isNull()) + m_indicatorLeftShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); + m_indicatorLeftShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Left), + qmlAnchors.modelAnchor(AnchorLine::Left)); + } else { + delete m_indicatorLeftShape; + } + + if (qmlAnchors.modelHasAnchor(AnchorLine::Right)) { + if (m_indicatorRightShape.isNull()) + m_indicatorRightShape = new AnchorIndicatorGraphicsItem(m_layerItem.data()); + m_indicatorRightShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Right), + qmlAnchors.modelAnchor(AnchorLine::Right)); + } else { + delete m_indicatorRightShape; + } + + return; + } + } +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/formeditor/anchorindicator.h b/src/plugins/qmldesigner/components/formeditor/anchorindicator.h new file mode 100644 index 0000000000..307fcc3e14 --- /dev/null +++ b/src/plugins/qmldesigner/components/formeditor/anchorindicator.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QMLDESIGNER_ANCHORINDICATOR_H +#define QMLDESIGNER_ANCHORINDICATOR_H + +#include <QPointer> +#include "layeritem.h" +#include "formeditoritem.h" + + +namespace QmlDesigner { + +class FormEditorItem; +class AnchorIndicatorGraphicsItem; + +class AnchorIndicator +{ +public: + AnchorIndicator(LayerItem *layerItem); + AnchorIndicator(); + ~AnchorIndicator(); + + void show(); + void hide(); + + void clear(); + + void setItems(const QList<FormEditorItem*> &itemList); + void updateItems(const QList<FormEditorItem*> &itemList); + + +private: + QPointer<LayerItem> m_layerItem; + QPointer<FormEditorItem> m_formEditorItem; + QPointer<AnchorIndicatorGraphicsItem> m_indicatorTopShape; + QPointer<AnchorIndicatorGraphicsItem> m_indicatorBottomShape; + QPointer<AnchorIndicatorGraphicsItem> m_indicatorLeftShape; + QPointer<AnchorIndicatorGraphicsItem> m_indicatorRightShape; +}; + +} // namespace QmlDesigner + +#endif // QMLDESIGNER_ANCHORINDICATOR_H diff --git a/src/plugins/qmldesigner/components/formeditor/anchorindicatorgraphicsitem.cpp b/src/plugins/qmldesigner/components/formeditor/anchorindicatorgraphicsitem.cpp new file mode 100644 index 0000000000..aefaeb66f5 --- /dev/null +++ b/src/plugins/qmldesigner/components/formeditor/anchorindicatorgraphicsitem.cpp @@ -0,0 +1,261 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "anchorindicatorgraphicsitem.h" + +#include <QPainter> +#include <QPainterPath> + +namespace QmlDesigner { + +AnchorIndicatorGraphicsItem::AnchorIndicatorGraphicsItem(QGraphicsItem *parent) : + QGraphicsObject(parent) +{ + setZValue(-3); +} + +int startAngleForAnchorLine(const AnchorLine::Type &anchorLineType) +{ + switch (anchorLineType) { + case AnchorLine::Top: + return 0; + case AnchorLine::Bottom: + return 180 * 16; + case AnchorLine::Left: + return 90 * 16; + case AnchorLine::Right: + return 270 * 16; + default: + return 0; + } +} + +void AnchorIndicatorGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) +{ + painter->save(); + + QPen linePen(QColor(0, 0, 0, 150)); + linePen.setDashPattern(QVector<double>() << 3. << 2.); + + painter->setPen(linePen); + + painter->drawLine(m_startPoint, m_firstControlPoint); + painter->drawLine(m_firstControlPoint, m_secondControlPoint); + painter->drawLine(m_secondControlPoint, m_endPoint); + + linePen.setColor(QColor(255, 255, 255, 150)); + linePen.setDashPattern(QVector<double>() << 2. << 3.); + linePen.setDashOffset(2.); + + painter->setPen(linePen); + + painter->drawLine(m_startPoint, m_firstControlPoint); + painter->drawLine(m_firstControlPoint, m_secondControlPoint); + painter->drawLine(m_secondControlPoint, m_endPoint); + + static QRectF bumpRectangle(0., 0., 8., 8.); + + painter->setPen(QPen(QColor(0, 255 , 0), 2)); + painter->drawLine(m_sourceAnchorLineFirstPoint, m_sourceAnchorLineSecondPoint); + + bumpRectangle.moveTo(m_startPoint.x() - 4., m_startPoint.y() - 4.); + painter->setBrush(painter->pen().color()); + painter->setRenderHint(QPainter::Antialiasing, true); + painter->drawChord(bumpRectangle, startAngleForAnchorLine(m_sourceAnchorLineType), 180 * 16); + painter->setRenderHint(QPainter::Antialiasing, false); + + painter->setPen(QPen(QColor(0, 0 , 255), 2)); + painter->drawLine(m_targetAnchorLineFirstPoint, m_targetAnchorLineSecondPoint); + + bumpRectangle.moveTo(m_endPoint.x() - 4., m_endPoint.y() - 4.); + painter->setBrush(painter->pen().color()); + painter->setRenderHint(QPainter::Antialiasing, true); + painter->drawChord(bumpRectangle, startAngleForAnchorLine(m_targetAnchorLineType), 180 * 16); + painter->setRenderHint(QPainter::Antialiasing, false); + + painter->restore(); +} + +QRectF AnchorIndicatorGraphicsItem::boundingRect() const +{ + return m_boundingRect; +} + +static QPointF createParentAnchorPoint(const QmlItemNode &parentQmlItemNode, AnchorLine::Type anchorLineType, const QmlItemNode &childQmlItemNode) +{ + QRectF parentBoundingRect = parentQmlItemNode.instanceSceneTransform().mapRect(parentQmlItemNode.instanceBoundingRect().adjusted(0., 0., 1., 1.)); + QRectF childBoundingRect = childQmlItemNode.instanceSceneTransform().mapRect(childQmlItemNode.instanceBoundingRect().adjusted(0., 0., 1., 1.)); + + QPointF anchorPoint; + + switch (anchorLineType) { + case AnchorLine::Top: + anchorPoint = QPointF(childBoundingRect.center().x(), parentBoundingRect.top()); + break; + case AnchorLine::Bottom: + anchorPoint = QPointF(childBoundingRect.center().x(), parentBoundingRect.bottom()); + break; + case AnchorLine::Left: + anchorPoint = QPointF(parentBoundingRect.left(), childBoundingRect.center().y()); + break; + case AnchorLine::Right: + anchorPoint = QPointF(parentBoundingRect.right(), childBoundingRect.center().y()); + break; + default: + break; + } + + return anchorPoint; +} + +static QPointF createAnchorPoint(const QmlItemNode &qmlItemNode, AnchorLine::Type anchorLineType) +{ + QRectF boundingRect = qmlItemNode.instanceBoundingRect().adjusted(0., 0., 1., 1.); + + QPointF anchorPoint; + + switch (anchorLineType) { + case AnchorLine::Top: + anchorPoint = QPointF(boundingRect.center().x(), boundingRect.top()); + break; + case AnchorLine::Bottom: + anchorPoint = QPointF(boundingRect.center().x(), boundingRect.bottom()); + break; + case AnchorLine::Left: + anchorPoint = QPointF(boundingRect.left(), boundingRect.center().y()); + break; + case AnchorLine::Right: + anchorPoint = QPointF(boundingRect.right(), boundingRect.center().y()); + break; + default: + break; + } + + return qmlItemNode.instanceSceneTransform().map(anchorPoint); +} + +static QPointF createControlPoint(const QPointF &firstEditPoint, AnchorLine::Type anchorLineType, const QPointF &secondEditPoint) +{ + QPointF controlPoint = firstEditPoint; + + switch (anchorLineType) { + case AnchorLine::Top: + case AnchorLine::Bottom: + controlPoint.ry() += (secondEditPoint.y() - firstEditPoint.y()) / 2.0; + break; + case AnchorLine::Left: + case AnchorLine::Right: + controlPoint.rx() += (secondEditPoint.x() - firstEditPoint.x()) / 2.0; + break; + default: + break; + } + + return controlPoint; +} + +static void updateAnchorLinePoints(QPointF *firstPoint, QPointF *secondPoint, const AnchorLine &anchorLine) +{ + QRectF boundingRectangle = anchorLine.qmlItemNode().instanceBoundingRect().adjusted(0., 0., 1., 1.); + + switch (anchorLine.type()) { + case AnchorLine::Top: + *firstPoint = boundingRectangle.topLeft(); + *secondPoint = boundingRectangle.topRight(); + break; + case AnchorLine::Bottom: + *firstPoint = boundingRectangle.bottomLeft(); + *secondPoint = boundingRectangle.bottomRight(); + break; + case AnchorLine::Left: + *firstPoint = boundingRectangle.topLeft(); + *secondPoint = boundingRectangle.bottomLeft(); + break; + case AnchorLine::Right: + *firstPoint = boundingRectangle.topRight(); + *secondPoint = boundingRectangle.bottomRight(); + break; + default: + break; + } + + *firstPoint = anchorLine.qmlItemNode().instanceSceneTransform().map(*firstPoint); + *secondPoint = anchorLine.qmlItemNode().instanceSceneTransform().map(*secondPoint); +} + +void AnchorIndicatorGraphicsItem::updateAnchorIndicator(const AnchorLine &sourceAnchorLine, const AnchorLine targetAnchorLine) +{ + m_sourceAnchorLineType = sourceAnchorLine.type(); + m_targetAnchorLineType = targetAnchorLine.type(); + + m_startPoint = createAnchorPoint(sourceAnchorLine.qmlItemNode(), sourceAnchorLine.type()); + + if (targetAnchorLine.qmlItemNode() == sourceAnchorLine.qmlItemNode().instanceParentItem()) + m_endPoint = createParentAnchorPoint(targetAnchorLine.qmlItemNode(), targetAnchorLine.type(), sourceAnchorLine.qmlItemNode()); + else + m_endPoint = createAnchorPoint(targetAnchorLine.qmlItemNode(), targetAnchorLine.type()); + + m_firstControlPoint = createControlPoint(m_startPoint, sourceAnchorLine.type(), m_endPoint); + m_secondControlPoint = createControlPoint(m_endPoint, targetAnchorLine.type(), m_startPoint); + + updateAnchorLinePoints(&m_sourceAnchorLineFirstPoint, &m_sourceAnchorLineSecondPoint, sourceAnchorLine); + updateAnchorLinePoints(&m_targetAnchorLineFirstPoint, &m_targetAnchorLineSecondPoint, targetAnchorLine); + + updateBoundingRect(); +} + +void AnchorIndicatorGraphicsItem::updateBoundingRect() +{ + QPolygonF controlPolygon(QVector<QPointF>() + << m_startPoint + << m_firstControlPoint + << m_secondControlPoint + << m_endPoint + << m_sourceAnchorLineFirstPoint + << m_sourceAnchorLineSecondPoint + << m_targetAnchorLineFirstPoint + << m_targetAnchorLineSecondPoint + ); + + m_boundingRect = controlPolygon.boundingRect().adjusted(-10., -10., 10., 10.); +} +AnchorLine::Type AnchorIndicatorGraphicsItem::sourceAnchorLineType() const +{ + return m_sourceAnchorLineType; +} + +void AnchorIndicatorGraphicsItem::setSourceAnchorLineType(const AnchorLine::Type &sourceAnchorLineType) +{ + m_sourceAnchorLineType = sourceAnchorLineType; +} + + + + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/formeditor/anchorindicatorgraphicsitem.h b/src/plugins/qmldesigner/components/formeditor/anchorindicatorgraphicsitem.h new file mode 100644 index 0000000000..75b859a950 --- /dev/null +++ b/src/plugins/qmldesigner/components/formeditor/anchorindicatorgraphicsitem.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QMLDESIGNER_ANCHORINDICATORGRAPHICSITEM_H +#define QMLDESIGNER_ANCHORINDICATORGRAPHICSITEM_H + +#include <QGraphicsObject> + +#include <qmlanchors.h> + +namespace QmlDesigner { + +class AnchorIndicatorGraphicsItem : public QGraphicsObject +{ + Q_OBJECT +public: + explicit AnchorIndicatorGraphicsItem(QGraphicsItem *parent = 0); + + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + QRectF boundingRect() const; + + void updateAnchorIndicator(const AnchorLine &sourceAnchorLine, const AnchorLine targetAnchorLine); + + AnchorLine::Type sourceAnchorLineType() const; + void setSourceAnchorLineType(const AnchorLine::Type &sourceAnchorLineType); + +protected: + void updateBoundingRect(); + +private: + QPointF m_startPoint; + QPointF m_firstControlPoint; + QPointF m_secondControlPoint; + QPointF m_endPoint; + QPointF m_sourceAnchorLineFirstPoint; + QPointF m_sourceAnchorLineSecondPoint; + QPointF m_targetAnchorLineFirstPoint; + QPointF m_targetAnchorLineSecondPoint; + AnchorLine::Type m_sourceAnchorLineType; + AnchorLine::Type m_targetAnchorLineType; + QRectF m_boundingRect; +}; + +} // namespace QmlDesigner + +#endif // QMLDESIGNER_ANCHORINDICATORGRAPHICSITEM_H diff --git a/src/plugins/qmldesigner/components/formeditor/formeditor.pri b/src/plugins/qmldesigner/components/formeditor/formeditor.pri index 76f18b6a9c..0db9cbe809 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditor.pri +++ b/src/plugins/qmldesigner/components/formeditor/formeditor.pri @@ -30,7 +30,9 @@ SOURCES += formeditoritem.cpp \ formeditorgraphicsview.cpp \ numberseriesaction.cpp \ lineeditaction.cpp \ - abstractcustomtool.cpp + abstractcustomtool.cpp \ + anchorindicator.cpp \ + components/formeditor/anchorindicatorgraphicsitem.cpp HEADERS += formeditorscene.h \ formeditorwidget.h \ formeditoritem.h \ @@ -62,5 +64,7 @@ HEADERS += formeditorscene.h \ formeditorgraphicsview.h \ numberseriesaction.h \ lineeditaction.h \ - abstractcustomtool.h + abstractcustomtool.h \ + anchorindicator.h \ + components/formeditor/anchorindicatorgraphicsitem.h RESOURCES += formeditor.qrc diff --git a/src/plugins/qmldesigner/components/formeditor/movetool.cpp b/src/plugins/qmldesigner/components/formeditor/movetool.cpp index eda48d1216..0b75c262cd 100644 --- a/src/plugins/qmldesigner/components/formeditor/movetool.cpp +++ b/src/plugins/qmldesigner/components/formeditor/movetool.cpp @@ -46,7 +46,8 @@ MoveTool::MoveTool(FormEditorView *editorView) : AbstractFormEditorTool(editorView), m_moveManipulator(editorView->scene()->manipulatorLayerItem(), editorView), m_selectionIndicator(editorView->scene()->manipulatorLayerItem()), - m_resizeIndicator(editorView->scene()->manipulatorLayerItem()) + m_resizeIndicator(editorView->scene()->manipulatorLayerItem()), + m_anchorIndicator(editorView->scene()->manipulatorLayerItem()) { m_selectionIndicator.setCursor(Qt::SizeAllCursor); } @@ -63,6 +64,7 @@ void MoveTool::clear() m_movingItems.clear(); m_selectionIndicator.clear(); m_resizeIndicator.clear(); + m_anchorIndicator.clear(); AbstractFormEditorTool::clear(); } @@ -93,6 +95,7 @@ void MoveTool::mouseMoveEvent(const QList<QGraphicsItem*> &itemList, // m_selectionIndicator.hide(); m_resizeIndicator.hide(); + m_anchorIndicator.hide(); FormEditorItem *containerItem = containerFormEditorItem(itemList, m_movingItems); if (containerItem && view()->currentState().isBaseState()) { @@ -150,6 +153,7 @@ void MoveTool::keyPressEvent(QKeyEvent *event) m_moveManipulator.setItems(movableItems); // m_selectionIndicator.hide(); m_resizeIndicator.hide(); + m_anchorIndicator.hide(); m_moveManipulator.beginRewriterTransaction(); } @@ -182,6 +186,7 @@ void MoveTool::keyReleaseEvent(QKeyEvent *keyEvent) m_moveManipulator.clear(); // m_selectionIndicator.show(); m_resizeIndicator.show(); + m_anchorIndicator.show(); } } @@ -206,6 +211,7 @@ void MoveTool::mouseReleaseEvent(const QList<QGraphicsItem*> &itemList, m_selectionIndicator.show(); m_resizeIndicator.show(); + m_anchorIndicator.show(); m_movingItems.clear(); } @@ -227,6 +233,7 @@ void MoveTool::selectedItemsChanged(const QList<FormEditorItem*> &itemList) { m_selectionIndicator.setItems(movingItems(itemList)); m_resizeIndicator.setItems(itemList); + m_anchorIndicator.setItems(itemList); updateMoveManipulator(); } @@ -375,6 +382,7 @@ void MoveTool::formEditorItemsChanged(const QList<FormEditorItem*> &itemList) { m_selectionIndicator.updateItems(itemList); m_resizeIndicator.updateItems(itemList); + m_anchorIndicator.updateItems(itemList); } } diff --git a/src/plugins/qmldesigner/components/formeditor/movetool.h b/src/plugins/qmldesigner/components/formeditor/movetool.h index 2611219b60..e767cfa51b 100644 --- a/src/plugins/qmldesigner/components/formeditor/movetool.h +++ b/src/plugins/qmldesigner/components/formeditor/movetool.h @@ -34,6 +34,7 @@ #include "movemanipulator.h" #include "selectionindicator.h" #include "resizeindicator.h" +#include "anchorindicator.h" namespace QmlDesigner { @@ -93,6 +94,7 @@ private: MoveManipulator m_moveManipulator; SelectionIndicator m_selectionIndicator; ResizeIndicator m_resizeIndicator; + AnchorIndicator m_anchorIndicator; QList<FormEditorItem*> m_movingItems; }; diff --git a/src/plugins/qmldesigner/components/formeditor/resizetool.cpp b/src/plugins/qmldesigner/components/formeditor/resizetool.cpp index 78d8f094cd..48f36d6fbd 100644 --- a/src/plugins/qmldesigner/components/formeditor/resizetool.cpp +++ b/src/plugins/qmldesigner/components/formeditor/resizetool.cpp @@ -45,6 +45,7 @@ ResizeTool::ResizeTool(FormEditorView *editorView) : AbstractFormEditorTool(editorView), m_selectionIndicator(editorView->scene()->manipulatorLayerItem()), m_resizeIndicator(editorView->scene()->manipulatorLayerItem()), + m_anchorIndicator(editorView->scene()->manipulatorLayerItem()), m_resizeManipulator(editorView->scene()->manipulatorLayerItem(), editorView) { } @@ -66,6 +67,7 @@ void ResizeTool::mousePressEvent(const QList<QGraphicsItem*> &itemList, m_resizeManipulator.setHandle(resizeHandle); m_resizeManipulator.begin(event->scenePos()); m_resizeIndicator.hide(); + m_anchorIndicator.hide(); } } @@ -116,6 +118,7 @@ void ResizeTool::mouseReleaseEvent(const QList<QGraphicsItem*> &itemList, m_selectionIndicator.show(); m_resizeIndicator.show(); + m_anchorIndicator.show(); m_resizeManipulator.end(generateUseSnapping(event->modifiers())); } @@ -176,12 +179,14 @@ void ResizeTool::selectedItemsChanged(const QList<FormEditorItem*> & /*itemList* { m_selectionIndicator.setItems(items()); m_resizeIndicator.setItems(items()); + m_anchorIndicator.setItems(items()); } void ResizeTool::clear() { m_selectionIndicator.clear(); m_resizeIndicator.clear(); + m_anchorIndicator.clear(); m_resizeManipulator.clear(); } @@ -189,6 +194,7 @@ void ResizeTool::formEditorItemsChanged(const QList<FormEditorItem*> &itemList) { m_selectionIndicator.updateItems(itemList); m_resizeIndicator.updateItems(itemList); + m_anchorIndicator.updateItems(itemList); } void ResizeTool::instancesCompleted(const QList<FormEditorItem*> &/*itemList*/) diff --git a/src/plugins/qmldesigner/components/formeditor/resizetool.h b/src/plugins/qmldesigner/components/formeditor/resizetool.h index a8d3f9a645..81954b5e67 100644 --- a/src/plugins/qmldesigner/components/formeditor/resizetool.h +++ b/src/plugins/qmldesigner/components/formeditor/resizetool.h @@ -33,6 +33,7 @@ #include "abstractformeditortool.h" #include "selectionindicator.h" #include "resizeindicator.h" +#include "anchorindicator.h" #include "resizemanipulator.h" @@ -77,6 +78,7 @@ public: private: SelectionIndicator m_selectionIndicator; ResizeIndicator m_resizeIndicator; + AnchorIndicator m_anchorIndicator; ResizeManipulator m_resizeManipulator; }; diff --git a/src/plugins/qmldesigner/components/formeditor/selectiontool.cpp b/src/plugins/qmldesigner/components/formeditor/selectiontool.cpp index c79db97195..6f49f11803 100644 --- a/src/plugins/qmldesigner/components/formeditor/selectiontool.cpp +++ b/src/plugins/qmldesigner/components/formeditor/selectiontool.cpp @@ -48,6 +48,7 @@ SelectionTool::SelectionTool(FormEditorView *editorView) m_singleSelectionManipulator(editorView), m_selectionIndicator(editorView->scene()->manipulatorLayerItem()), m_resizeIndicator(editorView->scene()->manipulatorLayerItem()), + m_anchorIndicator(editorView->scene()->manipulatorLayerItem()), m_selectOnlyContentItems(false) { m_selectionIndicator.setCursor(Qt::ArrowCursor); @@ -258,6 +259,7 @@ void SelectionTool::clear() m_singleSelectionManipulator.clear(); m_selectionIndicator.clear(); m_resizeIndicator.clear(); + m_anchorIndicator.clear(); AbstractFormEditorTool::clear(); } @@ -266,12 +268,14 @@ void SelectionTool::selectedItemsChanged(const QList<FormEditorItem*> &itemList) { m_selectionIndicator.setItems(itemList); m_resizeIndicator.setItems(itemList); + m_anchorIndicator.setItems(itemList); } void SelectionTool::formEditorItemsChanged(const QList<FormEditorItem*> &itemList) { m_selectionIndicator.updateItems(itemList); m_resizeIndicator.updateItems(itemList); + m_anchorIndicator.updateItems(itemList); } void SelectionTool::instancesCompleted(const QList<FormEditorItem*> &/*itemList*/) diff --git a/src/plugins/qmldesigner/components/formeditor/selectiontool.h b/src/plugins/qmldesigner/components/formeditor/selectiontool.h index 464630f59e..80c1dabe69 100644 --- a/src/plugins/qmldesigner/components/formeditor/selectiontool.h +++ b/src/plugins/qmldesigner/components/formeditor/selectiontool.h @@ -36,6 +36,7 @@ #include "singleselectionmanipulator.h" #include "selectionindicator.h" #include "resizeindicator.h" +#include "anchorindicator.h" #include <QTime> @@ -92,6 +93,7 @@ private: SingleSelectionManipulator m_singleSelectionManipulator; SelectionIndicator m_selectionIndicator; ResizeIndicator m_resizeIndicator; + AnchorIndicator m_anchorIndicator; QTime m_mousePressTimer; bool m_selectOnlyContentItems; QCursor m_cursor; |