1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
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 The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #pragma once
27 
28 #include <QList>
29 #include <QPair>
30 #include <QPoint>
31 
32 #include "controlpoint.h"
33 
34 namespace QmlDesigner {
35 
36 class PathItem;
37 
38 struct SelectionPoint
39 {
40     SelectionPoint();
41     SelectionPoint(const ControlPoint &controlPoint);
42     ControlPoint controlPoint;
43     QPointF startPosition;
44 };
45 
46 class PathSelectionManipulator
47 {
48 public:
49     PathSelectionManipulator(PathItem *pathItem);
50 
51     void clear();
52     void clearSingleSelection();
53     void clearMultiSelection();
54 
55     void addMultiSelectionControlPoint(const ControlPoint &controlPoint);
56     void addSingleControlPoint(const ControlPoint &controlPoint);
57     void addSingleControlPointSmartly(const ControlPoint &editPoint);
58 
59     QList<SelectionPoint> singleSelectedPoints();
60     QList<SelectionPoint> automaticallyAddedSinglePoints();
61     QList<SelectionPoint> allSelectionSinglePoints();
62     QList<SelectionPoint> multiSelectedPoints();
63     QList<SelectionPoint> allSelectionPoints();
64 
65     QList<ControlPoint> allControlPoints();
66 
67     bool hasSingleSelection() const;
68     bool hasMultiSelection() const;
69 
70     void startMultiSelection(const QPointF &startPoint);
71     void updateMultiSelection(const QPointF &updatePoint);
72     void endMultiSelection();
73     QPointF multiSelectionStartPoint() const;
74     bool isMultiSelecting() const;
75 
76     QRectF multiSelectionRectangle() const;
77 
78     void setStartPoint(const QPointF &startPoint);
79     QPointF startPoint() const;
80     void startMoving(const QPointF &startPoint);
81     void updateMoving(const QPointF &updatePoint, Qt::KeyboardModifiers keyboardModifier);
82     void endMoving();
83     bool isMoving() const;
84 
85     void updateMultiSelectedStartPoint();
86 
87 private:
88     QList<SelectionPoint> m_singleSelectedPoints;
89     QList<SelectionPoint> m_automaticallyAddedSinglePoints;
90     QList<SelectionPoint> m_multiSelectedPoints;
91     QPointF m_startPoint;
92     QPointF m_updatePoint;
93     PathItem *m_pathItem;
94     bool m_isMultiSelecting;
95     bool m_isMoving;
96 };
97 
98 bool operator ==(const SelectionPoint& firstSelectionPoint, const SelectionPoint& secondSelectionPoint);
99 
100 } // namespace QmlDesigner
101