1 /* This file is part of the KDE project
2  * Copyright (C) 2007 Boudewijn Rempt <boud@kde.org>
3  * Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
4  * Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
5  * Copyright (C) 2009 Thomas Zander <zander@kde.org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef KO_CONNECTION_SHAPE_H
24 #define KO_CONNECTION_SHAPE_H
25 
26 #include "KoParameterShape.h"
27 
28 #include "kritaflake_export.h"
29 
30 #define KOCONNECTIONSHAPEID "KoConnectionShape"
31 
32 class KoConnectionShapePrivate;
33 
34 /// API docs go here
35 class KRITAFLAKE_EXPORT KoConnectionShape : public KoParameterShape
36 {
37 public:
38     enum Type {
39         Standard, ///< escapes connected shapes with straight lines, connects with perpendicular lines
40         Lines,    ///< escapes connected shapes with straight lines, connects with straight line
41         Straight, ///< one straight line between connected shapes
42         Curve     ///< a single curved line between connected shapes
43     };
44 
45     // IDs of the connecting handles
46     enum HandleId {
47         StartHandle,
48         EndHandle,
49         ControlHandle_1,
50         ControlHandle_2,
51         ControlHandle_3
52     };
53 
54     KoConnectionShape();
55     ~KoConnectionShape() override;
56 
57     KoShape* cloneShape() const override;
58 
59     // reimplemented
60     void saveOdf(KoShapeSavingContext &context) const override;
61 
62     // reimplemented
63     bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context) override;
64 
65     // reimplemented
66     QString pathShapeId() const override;
67 
68     /**
69      * Sets the first shape this connector is connected to
70      *
71      * Passing a null pointer as the first parameter will sever the connection.
72      *
73      * @param shape the shape to connect to or null to reset the connection
74      * @param connectionPointId the id of the connection point to connect to
75      * @return true if connection could be established, otherwise false
76      */
77     bool connectFirst(KoShape *shape, int connectionPointId);
78 
79     /**
80     * Sets the second shape the connector is connected to
81     *
82     * Passing a null pointer as the first parameter will sever the connection.
83     *
84     * @param shape the shape to connect to or null to reset the connection
85     * @param connectionPointId the id of the connection point to connect to
86     * @return true if connection could be established, otherwise false
87     */
88     bool connectSecond(KoShape *shape, int connectionPointId);
89 
90     /**
91      * Return the first shape this connection is attached to, or null if none.
92      */
93     KoShape *firstShape() const;
94 
95     /**
96      * Return the connection point id of the first shape we are connected to.
97      * In case we are not connected to a first shape the return value is undefined.
98      * @see firstShape(), KoShape::connectionPoints()
99      */
100     int firstConnectionId() const;
101 
102     /**
103      * Return the second shape this connection is attached to, or null if none.
104      */
105     KoShape *secondShape() const;
106 
107     /**
108      * Return the connection point id of the second shape we are connected to.
109      * In case we are not connected to a second shape the return value is undefined.
110      * @see firstShape(), KoShape::connectionPoints()
111      */
112     int secondConnectionId() const;
113 
114     /**
115      * Finishes the loading of a connection.
116      */
117     void finishLoadingConnection();
118 
119     /// Returns connection type
120     Type type() const;
121 
122     /// Sets the connection type
123     void setType(Type connectionType);
124 
125     /// Updates connections to shapes
126     void updateConnections();
127 
128 protected:
129     KoConnectionShape(const KoConnectionShape &rhs);
130 
131 
132     /// reimplemented
133     void moveHandleAction(int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers = Qt::NoModifier) override;
134 
135     /// reimplemented
136     void updatePath(const QSizeF &size) override;
137 
138     /// reimplemented
139     void shapeChanged(ChangeType type, KoShape *shape) override;
140 private:
141     QPointF escapeDirection(int handleId) const;
142 
143     /// Populate the path list by a normal way
144     void normalPath(const qreal MinimumEscapeLength);
145 
146 private:
147     class Private;
148     QSharedDataPointer<Private> d;
149 };
150 
151 #endif
152