~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to src/plugins/qmldesigner/components/formeditor/anchorindicator.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-11-15 12:25:23 UTC
  • mfrom: (1.1.28)
  • Revision ID: timo.jyrinki@canonical.com-20131115122523-i2kyamsu4gs2mu1m
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of Qt Creator.
 
7
**
 
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.
 
15
**
 
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.
 
23
**
 
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.
 
27
**
 
28
****************************************************************************/
 
29
 
 
30
#include "anchorindicator.h"
 
31
 
 
32
#include "qmlanchors.h"
 
33
#include "anchorindicatorgraphicsitem.h"
 
34
#include <QGraphicsScene>
 
35
#include <QGraphicsPathItem>
 
36
 
 
37
namespace QmlDesigner {
 
38
 
 
39
AnchorIndicator::AnchorIndicator(LayerItem *layerItem)
 
40
    : m_layerItem(layerItem)
 
41
{
 
42
}
 
43
 
 
44
AnchorIndicator::AnchorIndicator()
 
45
{
 
46
}
 
47
 
 
48
AnchorIndicator::~AnchorIndicator()
 
49
{
 
50
    clear();
 
51
}
 
52
 
 
53
void AnchorIndicator::show()
 
54
{
 
55
    if (m_indicatorTopShape)
 
56
        m_indicatorTopShape->show();
 
57
 
 
58
    if (m_indicatorBottomShape)
 
59
        m_indicatorBottomShape->show();
 
60
 
 
61
    if (m_indicatorLeftShape)
 
62
        m_indicatorLeftShape->show();
 
63
 
 
64
    if (m_indicatorRightShape)
 
65
        m_indicatorRightShape->show();
 
66
}
 
67
 
 
68
void AnchorIndicator::hide()
 
69
{
 
70
    if (m_indicatorTopShape)
 
71
        m_indicatorTopShape->hide();
 
72
 
 
73
    if (m_indicatorBottomShape)
 
74
        m_indicatorBottomShape->hide();
 
75
 
 
76
    if (m_indicatorLeftShape)
 
77
        m_indicatorLeftShape->hide();
 
78
 
 
79
    if (m_indicatorRightShape)
 
80
        m_indicatorRightShape->hide();
 
81
}
 
82
 
 
83
void AnchorIndicator::clear()
 
84
{
 
85
  delete m_indicatorTopShape;
 
86
  delete m_indicatorBottomShape;
 
87
  delete m_indicatorLeftShape;
 
88
  delete m_indicatorRightShape;
 
89
}
 
90
 
 
91
void AnchorIndicator::setItems(const QList<FormEditorItem *> &itemList)
 
92
{
 
93
    clear();
 
94
 
 
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();
 
100
 
 
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));
 
105
            }
 
106
 
 
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));
 
111
            }
 
112
 
 
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));
 
117
            }
 
118
 
 
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));
 
123
            }
 
124
        }
 
125
    }
 
126
}
 
127
 
 
128
void AnchorIndicator::updateItems(const QList<FormEditorItem *> &itemList)
 
129
{
 
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();
 
135
 
 
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));
 
141
                } else {
 
142
                    delete m_indicatorTopShape;
 
143
                }
 
144
 
 
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));
 
150
                } else {
 
151
                    delete m_indicatorBottomShape;
 
152
                }
 
153
 
 
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));
 
159
                } else {
 
160
                    delete m_indicatorLeftShape;
 
161
                }
 
162
 
 
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));
 
168
                } else {
 
169
                    delete m_indicatorRightShape;
 
170
                }
 
171
            }
 
172
 
 
173
            return;
 
174
        }
 
175
    }
 
176
}
 
177
 
 
178
} // namespace QmlDesigner