blob: 56878dc97ef303086d3f749d1cca2ed30058b248 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "singleselectionmanipulator.h"
#include "formeditorscene.h"
#include "formeditorview.h"
#include <QDebug>
namespace QmlDesigner {
SingleSelectionManipulator::SingleSelectionManipulator(FormEditorView *editorView)
: m_editorView(editorView),
m_isActive(false)
{
}
void SingleSelectionManipulator::begin(const QPointF &beginPoint)
{
m_beginPoint = beginPoint;
m_isActive = true;
m_oldSelectionList = toQmlItemNodeList(m_editorView->selectedModelNodes());
}
void SingleSelectionManipulator::update(const QPointF &/*updatePoint*/)
{
m_oldSelectionList.clear();
}
void SingleSelectionManipulator::clear()
{
m_beginPoint = QPointF();
m_oldSelectionList.clear();
}
void SingleSelectionManipulator::end(const QPointF &/*updatePoint*/)
{
m_oldSelectionList.clear();
m_isActive = false;
}
void SingleSelectionManipulator::select(SelectionType selectionType)
{
QList<QGraphicsItem*> itemList = m_editorView->scene()->items(m_beginPoint);
QmlItemNode selectedNode;
FormEditorItem *formEditorItem = m_editorView->currentTool()->nearestFormEditorItem(m_beginPoint, itemList);
if (formEditorItem && formEditorItem->qmlItemNode().isValid())
selectedNode = formEditorItem->qmlItemNode();
if (formEditorItem && formEditorItem->qmlItemNode().isFlowTransition())
selectedNode = formEditorItem->qmlItemNode();
QList<QmlItemNode> nodeList;
switch (selectionType) {
case AddToSelection: {
nodeList.append(m_oldSelectionList);
nodeList.append(selectedNode);
}
break;
case ReplaceSelection: {
nodeList.append(selectedNode);
}
break;
case RemoveFromSelection: {
nodeList.append(m_oldSelectionList);
nodeList.removeAll(selectedNode);
}
break;
case InvertSelection: {
nodeList.append(m_oldSelectionList);
if (!m_oldSelectionList.contains(selectedNode))
nodeList.append(selectedNode);
else
nodeList.removeAll(selectedNode);
}
}
m_editorView->setSelectedModelNodes(toModelNodeList(nodeList));
}
bool SingleSelectionManipulator::isActive() const
{
return m_isActive;
}
QPointF SingleSelectionManipulator::beginPoint() const
{
return m_beginPoint;
}
}
|