]> git.sven.stormbind.net Git - sven/vym.git/blob - src/linkablemapobj.h
Replace Pierre as the maintainer
[sven/vym.git] / src / linkablemapobj.h
1 #ifndef LINKABLEMAPOBJ_H
2 #define LINKABLEMAPOBJ_H
3
4 #include "animpoint.h"
5 #include "flagrowobj.h"
6 #include "headingobj.h"
7 #include "vymnote.h"
8
9 #define MAX_DEPTH 999
10
11 class VymModel;
12 class TreeItem;
13
14 /*! \brief This class adds links to MapObj
15
16 The links are connecting the branches (BranchObj) and images (FloatImageObj) in
17 the map.
18 */
19
20 class LinkableMapObj : public MapObj {
21   public:
22     /*! Orientation of an object depends on the position relative to the parent
23      */
24     enum Orientation {
25         UndefinedOrientation, //!< Undefined
26         LeftOfCenter,         //!< Object is left of center
27         RightOfCenter         //!< Object is right of center
28     };
29
30     /*! Various drawing styles for links */
31     enum Style {
32         UndefinedStyle, //!< Undefined
33         Line,           //!< Straight line
34         Parabel,        //!< Parabel
35         PolyLine,       //!< Polygon (thick line)
36         PolyParabel     //!< Thick parabel
37     };
38
39     /*! Vertical position of link in object */
40     enum Position {
41         Middle, //!< Link is drawn in the middle of object
42         Bottom  //!< Link is drawn at bottom of object
43     };
44
45     /*! Hint if link should use the default link color or the color of heading
46      */
47     enum ColorHint {
48         DefaultColor, //!< Link uses the default color
49         HeadingColor  //!< Link uses the color of heading
50     };
51
52     LinkableMapObj();
53     LinkableMapObj(QGraphicsItem *, TreeItem *ti = NULL);
54     virtual ~LinkableMapObj();
55
56   protected:
57     virtual void init();
58     virtual void createBottomLine();
59
60   public:
61     virtual void delLink();
62     virtual void copy(LinkableMapObj *);
63
64     void setChildObj(LinkableMapObj *);
65     virtual void setParObj(LinkableMapObj *);
66     virtual void setParObjTmp(LinkableMapObj *, QPointF,
67                               int); // Only for moving Obj around
68     virtual void unsetParObjTmp();  // reuse original ParObj
69     virtual bool hasParObjTmp();
70
71     virtual void setUseRelPos(const bool &);
72     virtual bool getUseRelPos();
73     virtual void setRelPos(); // set relPos to current parentPos
74     virtual void setRelPos(const QPointF &);
75     virtual QPointF getRelPos();
76
77     virtual qreal getTopPad();
78     virtual qreal getLeftPad();
79     virtual qreal getRightPad();
80     Style getDefLinkStyle(TreeItem *parent);
81     void setLinkStyle(Style);
82     Style getLinkStyle();
83
84     void setLinkPos(Position);
85     Position getLinkPos();
86
87     virtual void
88     setLinkColor(); // sets color according to colorhint, overloaded
89     virtual void setLinkColor(QColor);
90     QColor getLinkColor();
91     virtual void setVisibility(bool);
92     virtual void setOrientation();
93     virtual void
94     updateVisibility(); //! hides/unhides link depending on selection
95
96     /*! update parPos, childRefPos
97     depending on pos
98     redraw link with given style */
99     virtual void updateLinkGeometry();
100
101     virtual void setDockPos() = 0; // sets childRefPos and parPos
102     QPointF getChildRefPos();      // returns pos where children dock
103     QPointF getFloatRefPos();      // returns pos where floats dock
104     QPointF getParPos();           // returns pos where parents dock
105     Orientation getOrientation();  // get orientation
106
107     virtual void reposition();
108     virtual void requestReposition(); // do reposition after next user event
109     virtual void forceReposition();   // to force a reposition now (outside
110     // of mapeditor e.g. in noteeditor
111     virtual bool repositionRequested();
112
113     virtual void calcBBoxSizeWithChildren() = 0; // calc size of  BBox including
114                                                  // children recursivly
115
116   protected:
117     void parabel(QPolygonF &, qreal, qreal, qreal,
118                  qreal); // Create Parabel connecting two points
119
120     QPointF childRefPos;
121     QPointF floatRefPos;
122     QPointF parPos;
123     bool link2ParPos; // While moving around, sometimes link to parent
124
125     Orientation orientation;
126     qreal linkwidth;  // width of a link
127     QRectF bboxTotal; // bounding box including children
128
129     LinkableMapObj *parObj;
130     LinkableMapObj *parObjTmpBuf; // temporary buffer the original parent
131     bool tmpParent;
132
133     int thickness_start; // for StylePoly*
134     Style style;         // Current style
135     Position linkpos;    // Link at bottom of object or middle of height
136     QColor linkcolor;    // Link color
137     QPen pen;
138     QGraphicsLineItem *l;               // line style
139     QGraphicsPolygonItem *p;            // poly styles
140     int arcsegs;                        // arc: number of segments
141     QList<QGraphicsLineItem *> segment; // a part of e.g. the parabel
142     QPolygonF pa0; // For drawing of PolyParabel and PolyLine
143     QPolygonF pa1; // For drawing of PolyParabel
144     QPolygonF pa2; // For drawing of PolyParabel
145
146     QGraphicsLineItem *bottomline; // on bottom of BBox
147     bool useBottomline;            //! Hint if bottomline should be used
148     qreal bottomlineY;             // vertical offset of dockpos to pos
149
150     bool repositionRequest; //
151
152     qreal topPad, botPad, leftPad, rightPad; // padding within bbox
153
154     QPointF relPos; // position relative to childRefPos of parent
155     bool useRelPos;
156 };
157 #endif