linkablemapobj.h
author insilmaril
Tue, 26 May 2009 11:23:44 +0000
changeset 773 340bc29da9a0
parent 757 c6908bc17d78
child 779 1fb50e79661c
permissions -rw-r--r--
Various fixes and simplifications
     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 	virtual void setUseOrientation (const bool &);
    74 
    75 
    76 	virtual qreal getTopPad();
    77 	virtual qreal getLeftPad();
    78 	virtual qreal getRightPad();
    79 	Style getDefLinkStyle();
    80     void setLinkStyle(Style);            
    81 	Style getLinkStyle();
    82 	void setHideLinkUnselected(bool);
    83 	bool getHideLinkUnselected();
    84 	void setLinkPos (Position);
    85 	Position getLinkPos ();
    86 
    87 	virtual void setLinkColor();					// sets color according to colorhint, overloaded
    88 	virtual void setLinkColor(QColor);
    89 	QColor getLinkColor();
    90 	virtual void setVisibility (bool);
    91 	virtual void setOrientation();
    92     virtual void updateLink();				// update parPos and childPos
    93 											// depending on pos
    94 											// redraw link with given style
    95     LinkableMapObj* getChildObj();			// returns pointer to fromObj
    96     LinkableMapObj* getParObj();			// returns pointer to toObj
    97 	virtual void setDockPos()=0;				// sets childPos and parPos
    98     QPointF getChildPos();					// returns pos where children dock
    99     QPointF getParPos();						// returns pos where parents dock
   100     Orientation getOrientation();			// get orientation
   101 	virtual QPointF getRandPos();			// make randomised position
   102 
   103 	virtual void reposition();
   104 	virtual void requestReposition();		// do reposition after next user event
   105 	virtual void forceReposition();			// to force a reposition now (outside
   106 											// of mapeditor e.g. in noteeditor
   107 	virtual bool repositionRequested();
   108 
   109 	virtual void calcBBoxSizeWithChildren()=0;// calc size of  BBox including children recursivly
   110 
   111     virtual void select();					// FIXME-3  show/hide links...
   112     virtual void unselect();
   113 
   114 protected:
   115 	void parabel(QPolygonF &,double,double,double,double);	// Create Parabel connecting two points
   116 	QString getLinkAttr();
   117 
   118     QPointF childPos;
   119     QPointF parPos;
   120 	bool link2ParPos;				// While moving around, sometimes link to parent
   121 
   122     Orientation orientation;     
   123     qreal linkwidth;				// width of a link
   124 	QRectF bboxTotal;				// bounding box including children
   125 
   126     LinkableMapObj* parObj;		
   127     LinkableMapObj* parObjTmpBuf;	// temporary buffer the original parent
   128     qreal bottomlineY;              // vertical offset of dockpos to pos
   129 
   130 	int thickness_start;			// for StylePoly*	
   131     Style style;					// Current style
   132 	Position linkpos;				// Link at bottom of object or middle of height
   133     QColor linkcolor;               // Link color
   134 	QPen pen;
   135     QGraphicsLineItem* l;           // line style
   136 	QGraphicsPolygonItem* p;		// poly styles
   137     int arcsegs;                    // arc: number of segments
   138     QList <QGraphicsLineItem*> segment; // a part of e.g. the parabel
   139 	QPolygonF pa0;					// For drawing of PolyParabel and PolyLine
   140 	QPolygonF pa1;					// For drawing of PolyParabel 
   141 	QPolygonF pa2;					// For drawing of PolyParabel	
   142     QGraphicsLineItem* bottomline;  // on bottom of BBox
   143 	bool repositionRequest;			// 
   144 
   145 	bool selected;					// Used for marking the selection
   146 	bool hideLinkUnselected;		// to hide links if unselected
   147 	qreal topPad, botPad,
   148 		leftPad, rightPad;          // padding within bbox
   149 
   150 	QPointF	 relPos;				// position relative to childPos of parent
   151 	bool useRelPos;
   152 	bool useOrientation;
   153 
   154 	TreeItem *treeItem;				// Crossrefence to treemodel
   155 };
   156 #endif