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 "flake_export.h" 29 30 #define KOCONNECTIONSHAPEID "KoConnectionShape" 31 32 class KoConnectionShapePrivate; 33 34 /// API docs go here 35 class FLAKE_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 // reimplemented 58 void saveOdf(KoShapeSavingContext &context) const override; 59 60 // reimplemented 61 bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context) override; 62 63 // reimplemented 64 QString pathShapeId() const override; 65 66 /** 67 * Sets the first shape this connector is connected to 68 * 69 * Passing a null pointer as the first parameter will sever the connection. 70 * 71 * @param shape the shape to connect to or null to reset the connection 72 * @param connectionPointId the id of the connection point to connect to 73 * @return true if connection could be established, otherwise false 74 */ 75 bool connectFirst(KoShape *shape, int connectionPointId); 76 77 /** 78 * Sets the second shape the connector is connected to 79 * 80 * Passing a null pointer as the first parameter will sever the connection. 81 * 82 * @param shape the shape to connect to or null to reset the connection 83 * @param connectionPointId the id of the connection point to connect to 84 * @return true if connection could be established, otherwise false 85 */ 86 bool connectSecond(KoShape *shape, int connectionPointId); 87 88 /** 89 * Return the first shape this connection is attached to, or null if none. 90 */ 91 KoShape *firstShape() const; 92 93 /** 94 * Return the connection point id of the first shape we are connected to. 95 * In case we are not connected to a first shape the return value is undefined. 96 * @see firstShape(), KoShape::connectionPoints() 97 */ 98 int firstConnectionId() const; 99 100 /** 101 * Return the second shape this connection is attached to, or null if none. 102 */ 103 KoShape *secondShape() const; 104 105 /** 106 * Return the connection point id of the second shape we are connected to. 107 * In case we are not connected to a second shape the return value is undefined. 108 * @see firstShape(), KoShape::connectionPoints() 109 */ 110 int secondConnectionId() const; 111 112 /** 113 * Finishes the loading of a connection. 114 */ 115 void finishLoadingConnection(); 116 117 /// Returns connection type 118 Type type() const; 119 120 /// Sets the connection type 121 void setType(Type connectionType); 122 123 /// Updates connections to shapes 124 void updateConnections(); 125 126 protected: 127 /// reimplemented 128 void moveHandleAction(int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers = Qt::NoModifier) override; 129 130 /// reimplemented 131 void updatePath(const QSizeF &size) override; 132 133 /// reimplemented 134 void shapeChanged(ChangeType type, KoShape *shape) override; 135 136 private: 137 Q_DECLARE_PRIVATE(KoConnectionShape) 138 }; 139 140 #endif 141