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