linkablemapobj.h
author insilmaril
Tue, 07 Jul 2009 11:21:27 +0000
changeset 780 fe839bdfd10c
parent 779 1fb50e79661c
child 786 6269016c9905
permissions -rw-r--r--
vymLinks working again
     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 
    63     void setChildObj (LinkableMapObj*);
    64     virtual void setParObj (LinkableMapObj*);
    65     virtual void setParObjTmp (LinkableMapObj*,QPointF,int);	// Only for moving Obj around
    66 	virtual void unsetParObjTmp();						// reuse original ParObj
    67 	virtual bool hasParObjTmp();
    68 
    69 	virtual void setUseRelPos (const bool&);
    70 	virtual void setRelPos();				// set relPos to current parentPos
    71 	virtual void setRelPos(const QPointF&);	
    72 	virtual QPointF getRelPos();
    73 
    74 	virtual qreal getTopPad();
    75 	virtual qreal getLeftPad();
    76 	virtual qreal getRightPad();
    77 	Style getDefLinkStyle();
    78     void setLinkStyle(Style);            
    79 	Style getLinkStyle();
    80 
    81 	void setHideLinkUnselected();
    82 	void setLinkPos (Position);
    83 	Position getLinkPos ();
    84 
    85 	virtual void setLinkColor();			// sets color according to colorhint, overloaded
    86 	virtual void setLinkColor(QColor);
    87 	QColor getLinkColor();
    88 	virtual void setVisibility (bool);
    89 	virtual void setOrientation();
    90     virtual void updateVisibility();		//! hides/unhides link depending on selection
    91 
    92     /*! update parPos, childPos 
    93 		depending on pos
    94 		redraw link with given style */
    95     virtual void updateLinkGeometry();		
    96 
    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 protected:
   114 	void parabel(QPolygonF &,double,double,double,double);	// Create Parabel connecting two points
   115 
   116     QPointF childPos;
   117     QPointF parPos;
   118 	bool link2ParPos;				// While moving around, sometimes link to parent
   119 
   120     Orientation orientation;     
   121     qreal linkwidth;				// width of a link
   122 	QRectF bboxTotal;				// bounding box including children
   123 
   124     LinkableMapObj* parObj;		
   125     LinkableMapObj* parObjTmpBuf;	// temporary buffer the original parent
   126     qreal bottomlineY;              // vertical offset of dockpos to pos
   127 
   128 	int thickness_start;			// for StylePoly*	
   129     Style style;					// Current style
   130 	Position linkpos;				// Link at bottom of object or middle of height
   131     QColor linkcolor;               // Link color
   132 	QPen pen;
   133     QGraphicsLineItem* l;           // line style
   134 	QGraphicsPolygonItem* p;		// poly styles
   135     int arcsegs;                    // arc: number of segments
   136     QList <QGraphicsLineItem*> segment; // a part of e.g. the parabel
   137 	QPolygonF pa0;					// For drawing of PolyParabel and PolyLine
   138 	QPolygonF pa1;					// For drawing of PolyParabel 
   139 	QPolygonF pa2;					// For drawing of PolyParabel	
   140     QGraphicsLineItem* bottomline;  // on bottom of BBox
   141 	bool repositionRequest;			// 
   142 
   143 	qreal topPad, botPad,
   144 		leftPad, rightPad;          // padding within bbox
   145 
   146 	QPointF	 relPos;				// position relative to childPos of parent
   147 	bool useRelPos;
   148 
   149 	TreeItem *treeItem;				// Crossrefence to treemodel
   150 };
   151 #endif