1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2011 Jan Hambrecht <jaham@gmx.net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef KOCONNECTIONPOINT_H
22 #define KOCONNECTIONPOINT_H
23 
24 #include "flake_export.h"
25 #include <QPointF>
26 #include <QMap>
27 
28 /// Data of a single connection point
29 struct FLAKE_EXPORT KoConnectionPoint
30 {
31     /// Default connection point ids
32     enum PointId {
33         TopConnectionPoint = 0,         ///< default connection point on the middle of the top edge
34         RightConnectionPoint = 1,       ///< default connection point on the middle of the right edge
35         BottomConnectionPoint = 2,      ///< default connection point on the middle of the bottom edge
36         LeftConnectionPoint = 3,        ///< default connection point on the middle of the left edge
37         FirstCustomConnectionPoint = 4  ///< first custom connection point id
38     };
39 
40     /// Escape directions for connections connected to connection points
41     enum EscapeDirection {
42         AllDirections,        ///< connection can escape in all directions
43         HorizontalDirections, ///< connection can escape left and right
44         VerticalDirections,   ///< connection can escape top and down
45         LeftDirection,        ///< connection can escape left
46         RightDirection,       ///< connection can escape right
47         UpDirection,          ///< connection can escape up
48         DownDirection         ///< connection can escape down
49     };
50 
51     /// Alignments for connection points for shape resizing
52     enum Alignment {
53         AlignNone,         ///< align to nothing
54         AlignTopLeft,      ///< align to top and left edge
55         AlignTop,          ///< align to top edge, centered
56         AlignTopRight,     ///< align to top and right edge
57         AlignLeft,         ///< align to left edge, centered
58         AlignCenter,       ///< align to center
59         AlignRight,        ///< align to right edge, centered
60         AlignBottomLeft,   ///< align to bottom and left edge
61         AlignBottom,       ///< align to bottom edge, centered
62         AlignBottomRight   ///< align to bottom and right edge
63     };
64 
65     /// Default constructor
66     KoConnectionPoint();
67 
68     /// Creates connection point with specified position
69     KoConnectionPoint(const QPointF &position);
70 
71     /// Creates connection point with specified position and escape direction
72     KoConnectionPoint(const QPointF &position, EscapeDirection escapeDirection);
73 
74     /// Creates connection point with specified position, escape direction and alignment
75     KoConnectionPoint(const QPointF &position, EscapeDirection escapeDirection, Alignment alignment);
76 
77     /// Returns default connection point with specified id
78     static KoConnectionPoint defaultConnectionPoint(KoConnectionPoint::PointId connectionPointId);
79 
80     QPointF position; ///< the position of the connection point in shape coordinates
81     EscapeDirection escapeDirection; ///< the escape direction for connection attached to that connection point
82     Alignment alignment;      ///< specifies to which edge the connection point is aligned to
83 };
84 
85 /// Connection point container storing connection point data along their id
86 typedef QMap<int, KoConnectionPoint> KoConnectionPoints;
87 
88 #endif // KOCONNECTIONPOINT_H
89