1
/****************************************************************************
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of Qt Creator.
8
** Commercial License Usage
9
** Licensees holding valid commercial Qt licenses may use this file in
10
** accordance with the commercial license agreement provided with the
11
** Software or, alternatively, in accordance with the terms contained in
12
** a written agreement between you and Digia. For licensing terms and
13
** conditions see http://qt.digia.com/licensing. For further information
14
** use the contact form at http://qt.digia.com/contact-us.
16
** GNU Lesser General Public License Usage
17
** Alternatively, this file may be used under the terms of the GNU Lesser
18
** General Public License version 2.1 as published by the Free Software
19
** Foundation and appearing in the file LICENSE.LGPL included in the
20
** packaging of this file. Please review the following information to
21
** ensure the GNU Lesser General Public License version 2.1 requirements
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
** In addition, as a special exception, Digia gives you certain additional
25
** rights. These rights are described in the Digia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
****************************************************************************/
30
#include "anchorindicator.h"
32
#include "qmlanchors.h"
33
#include "anchorindicatorgraphicsitem.h"
34
#include <QGraphicsScene>
35
#include <QGraphicsPathItem>
37
namespace QmlDesigner {
39
AnchorIndicator::AnchorIndicator(LayerItem *layerItem)
40
: m_layerItem(layerItem)
44
AnchorIndicator::AnchorIndicator()
48
AnchorIndicator::~AnchorIndicator()
53
void AnchorIndicator::show()
55
if (m_indicatorTopShape)
56
m_indicatorTopShape->show();
58
if (m_indicatorBottomShape)
59
m_indicatorBottomShape->show();
61
if (m_indicatorLeftShape)
62
m_indicatorLeftShape->show();
64
if (m_indicatorRightShape)
65
m_indicatorRightShape->show();
68
void AnchorIndicator::hide()
70
if (m_indicatorTopShape)
71
m_indicatorTopShape->hide();
73
if (m_indicatorBottomShape)
74
m_indicatorBottomShape->hide();
76
if (m_indicatorLeftShape)
77
m_indicatorLeftShape->hide();
79
if (m_indicatorRightShape)
80
m_indicatorRightShape->hide();
83
void AnchorIndicator::clear()
85
delete m_indicatorTopShape;
86
delete m_indicatorBottomShape;
87
delete m_indicatorLeftShape;
88
delete m_indicatorRightShape;
91
void AnchorIndicator::setItems(const QList<FormEditorItem *> &itemList)
95
if (itemList.count() == 1) {
96
m_formEditorItem = itemList.first();
97
QmlItemNode sourceQmlItemNode = m_formEditorItem->qmlItemNode();
98
if (!sourceQmlItemNode.modelNode().isRootNode()) {
99
QmlAnchors qmlAnchors = sourceQmlItemNode.anchors();
101
if (qmlAnchors.modelHasAnchor(AnchorLine::Top)) {
102
m_indicatorTopShape = new AnchorIndicatorGraphicsItem(m_layerItem.data());
103
m_indicatorTopShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Top),
104
qmlAnchors.modelAnchor(AnchorLine::Top));
107
if (qmlAnchors.modelHasAnchor(AnchorLine::Bottom)) {
108
m_indicatorBottomShape = new AnchorIndicatorGraphicsItem(m_layerItem.data());
109
m_indicatorBottomShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Bottom),
110
qmlAnchors.modelAnchor(AnchorLine::Bottom));
113
if (qmlAnchors.modelHasAnchor(AnchorLine::Left)) {
114
m_indicatorLeftShape = new AnchorIndicatorGraphicsItem(m_layerItem.data());
115
m_indicatorLeftShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Left),
116
qmlAnchors.modelAnchor(AnchorLine::Left));
119
if (qmlAnchors.modelHasAnchor(AnchorLine::Right)) {
120
m_indicatorRightShape = new AnchorIndicatorGraphicsItem(m_layerItem.data());
121
m_indicatorRightShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Right),
122
qmlAnchors.modelAnchor(AnchorLine::Right));
128
void AnchorIndicator::updateItems(const QList<FormEditorItem *> &itemList)
130
foreach (FormEditorItem *formEditorItem, itemList) {
131
if (formEditorItem == m_formEditorItem) {
132
QmlItemNode sourceQmlItemNode = m_formEditorItem->qmlItemNode();
133
if (!sourceQmlItemNode.modelNode().isRootNode()) {
134
QmlAnchors qmlAnchors = formEditorItem->qmlItemNode().anchors();
136
if (qmlAnchors.modelHasAnchor(AnchorLine::Top)) {
137
if (m_indicatorTopShape.isNull())
138
m_indicatorTopShape = new AnchorIndicatorGraphicsItem(m_layerItem.data());
139
m_indicatorTopShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Top),
140
qmlAnchors.modelAnchor(AnchorLine::Top));
142
delete m_indicatorTopShape;
145
if (qmlAnchors.modelHasAnchor(AnchorLine::Bottom)) {
146
if (m_indicatorBottomShape.isNull())
147
m_indicatorBottomShape = new AnchorIndicatorGraphicsItem(m_layerItem.data());
148
m_indicatorBottomShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Bottom),
149
qmlAnchors.modelAnchor(AnchorLine::Bottom));
151
delete m_indicatorBottomShape;
154
if (qmlAnchors.modelHasAnchor(AnchorLine::Left)) {
155
if (m_indicatorLeftShape.isNull())
156
m_indicatorLeftShape = new AnchorIndicatorGraphicsItem(m_layerItem.data());
157
m_indicatorLeftShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Left),
158
qmlAnchors.modelAnchor(AnchorLine::Left));
160
delete m_indicatorLeftShape;
163
if (qmlAnchors.modelHasAnchor(AnchorLine::Right)) {
164
if (m_indicatorRightShape.isNull())
165
m_indicatorRightShape = new AnchorIndicatorGraphicsItem(m_layerItem.data());
166
m_indicatorRightShape->updateAnchorIndicator(AnchorLine(sourceQmlItemNode, AnchorLine::Right),
167
qmlAnchors.modelAnchor(AnchorLine::Right));
169
delete m_indicatorRightShape;
178
} // namespace QmlDesigner