linkablemapobj.h
author insilmaril
Wed, 20 May 2009 15:40:14 +0000
changeset 772 e3f722759c7e
parent 757 c6908bc17d78
child 773 340bc29da9a0
permissions -rw-r--r--
Fixed segfault when closing a map
     1 #ifndef LINKABLEMAPOBJ_H
     2 #define LINKABLEMAPOBJ_H
     3 
     4 #include "animpoint.h"
     5 #include "noteobj.h"
     6 #include "headingobj.h"
     7 #include "flagrowobj.h"
     8 #include "treeitem.h"
     9 
    10 #define MAX_DEPTH 999
    11 
    12 class VymModel;
    13 
    14 
    15 
    16 /*! \brief This class adds links to MapObj 
    17 
    18 The links are connecting the branches (BranchObj) and images (FloatImageObj) in the map.
    19 */
    20 
    21 class LinkableMapObj:public QObject, public MapObj {
    22 	Q_OBJECT		// FIXME-3 really needed here?
    23 public:
    24 	/*! Orientation of an object depends on the position relative to the parent */
    25 	enum Orientation {
    26 		UndefinedOrientation, //!< Undefined
    27 		LeftOfCenter,			//!< Object is left of center
    28 		RightOfCenter			//!< Object is right of center
    29 	};
    30 
    31 	/*! Various drawing styles for links */
    32 	enum Style {
    33 		UndefinedStyle,	//!< Undefined
    34 		Line,			//!< Straight line
    35 		Parabel,		//!< Parabel
    36 		PolyLine,		//!< Polygon (thick line)
    37 		PolyParabel		//!< Thick parabel
    38 	};
    39 
    40 	/*! Vertical position of link in object */
    41 	enum Position {
    42 		Middle, //!< Link is drawn in the middle of object
    43 		Bottom  //!< Link is drawn at bottom of object
    44 	};
    45 
    46 	/*! Hint if link should use the default link color or the color of heading */
    47 	enum ColorHint {
    48 		DefaultColor,	//!< Link uses the default color
    49 		HeadingColor	//!< Link uses the color of heading
    50 	};
    51 
    52     LinkableMapObj ();
    53     LinkableMapObj (QGraphicsScene*);
    54     LinkableMapObj (LinkableMapObj*);
    55     ~LinkableMapObj ();
    56 	virtual void delLink();
    57     virtual void init ();
    58     virtual void copy (LinkableMapObj*);
    59 
    60 	virtual void setTreeItem(TreeItem *);
    61 	virtual TreeItem* getTreeItem() const;
    62 	virtual void setModel (VymModel *vm);
    63 	virtual VymModel* getModel ();
    64 
    65     void setChildObj (LinkableMapObj*);
    66     virtual void setParObj (LinkableMapObj*);
    67     virtual void setParObjTmp (LinkableMapObj*,QPointF,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 void setRelPos();				// set relPos to current parentPos
    73 	virtual void setRelPos(const QPointF&);	
    74 	virtual QPointF getRelPos();
    75 	virtual void setUseOrientation (const bool &);
    76 
    77 
    78 	virtual qreal getTopPad();
    79 	virtual qreal getLeftPad();
    80 	virtual qreal getRightPad();
    81 	Style getDefLinkStyle();
    82     void setLinkStyle(Style);            
    83 	Style getLinkStyle();
    84 	void setHideLinkUnselected(bool);
    85 	bool getHideLinkUnselected();
    86 	void setLinkPos (Position);
    87 	Position getLinkPos ();
    88 
    89 	virtual void setLinkColor();					// sets color according to colorhint, overloaded
    90 	virtual void setLinkColor(QColor);
    91 	QColor getLinkColor();
    92 	virtual void setVisibility (bool);
    93 	virtual void setOrientation();
    94     virtual void updateLink();				// update parPos and childPos
    95 											// depending on pos
    96 											// redraw link with given style
    97     LinkableMapObj* getChildObj();			// returns pointer to fromObj
    98     LinkableMapObj* getParObj();			// returns pointer to toObj
    99 	virtual void setDockPos()=0;				// sets childPos and parPos
   100     QPointF getChildPos();					// returns pos where children dock
   101     QPointF getParPos();						// returns pos where parents dock
   102     Orientation getOrientation();			// get orientation
   103 	virtual QPointF getRandPos();			// make randomised position
   104 
   105 	virtual void reposition();
   106 	virtual void requestReposition();		// do reposition after next user event
   107 	virtual void forceReposition();			// to force a reposition now (outside
   108 											// of mapeditor e.g. in noteeditor
   109 	virtual bool repositionRequested();
   110 
   111 	virtual void calcBBoxSizeWithChildren()=0;// calc size of  BBox including children recursivly
   112 
   113     virtual void select();
   114     virtual void unselect();
   115 
   116 protected:
   117 	void parabel(QPolygonF &,double,double,double,double);	// Create Parabel connecting two points
   118 	QString getLinkAttr();
   119 
   120     QPointF childPos;
   121     QPointF parPos;
   122 	bool link2ParPos;				// While moving around, sometimes link to parent
   123 
   124 	VymModel* model;												
   125     Orientation orientation;     
   126     qreal linkwidth;				// width of a link
   127 	QRectF bboxTotal;				// bounding box including children
   128 
   129     LinkableMapObj* childObj;
   130     LinkableMapObj* parObj;		// FIXME-2 really still needed? Better get from TreeItem
   131     LinkableMapObj* parObjTmpBuf;	// temporary buffer the original parent
   132     qreal bottomlineY;              // vertical offset of dockpos to pos
   133 
   134 	int thickness_start;			// for StylePoly*	
   135     Style style;					// Current style
   136 	Position linkpos;				// Link at bottom of object or middle of height
   137     QColor linkcolor;               // Link color
   138 	QPen pen;
   139     QGraphicsLineItem* l;           // line style
   140 	QGraphicsPolygonItem* p;		// poly styles
   141     int arcsegs;                    // arc: number of segments
   142     QList <QGraphicsLineItem*> segment; // a part of e.g. the parabel
   143 	QPolygonF pa0;					// For drawing of PolyParabel and PolyLine
   144 	QPolygonF pa1;					// For drawing of PolyParabel 
   145 	QPolygonF pa2;					// For drawing of PolyParabel	
   146     QGraphicsLineItem* bottomline;  // on bottom of BBox
   147 	bool repositionRequest;			// 
   148 
   149 	bool selected;					// Used for marking the selection
   150 	bool hideLinkUnselected;		// to hide links if unselected
   151 	qreal topPad, botPad,
   152 		leftPad, rightPad;          // padding within bbox
   153 
   154 	QPointF	 relPos;				// position relative to childPos of parent
   155 	//AnimPoint relPos;				// position relative to childPos of parent
   156 	bool useRelPos;
   157 	bool useOrientation;
   158 
   159 	TreeItem *treeItem;				// Crossrefence to treemodel
   160 };
   161 #endif