linkablemapobj.h
author insilmaril
Thu, 23 Apr 2009 12:15:31 +0000
changeset 755 ed5b407975b3
parent 754 db0ec4bcf416
child 757 c6908bc17d78
permissions -rw-r--r--
more data in Tree, less in 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 LinkableMapObj* findObjBySelect(QString s);	// find obj by selectstring
   100 	virtual void setDockPos()=0;				// sets childPos and parPos
   101     QPointF getChildPos();					// returns pos where children dock
   102     QPointF getParPos();						// returns pos where parents dock
   103     Orientation getOrientation();			// get orientation
   104 	virtual QPointF getRandPos();			// make randomised position
   105 
   106 	virtual void reposition();
   107 	virtual void requestReposition();		// do reposition after next user event
   108 	virtual void forceReposition();			// to force a reposition now (outside
   109 											// of mapeditor e.g. in noteeditor
   110 	virtual bool repositionRequested();
   111 
   112 	virtual void calcBBoxSizeWithChildren()=0;// calc size of  BBox including children recursivly
   113 
   114     virtual void select();
   115     virtual void unselect();
   116 
   117 protected:
   118 	void parabel(QPolygonF &,double,double,double,double);	// Create Parabel connecting two points
   119 	QString getLinkAttr();
   120 
   121     QPointF childPos;
   122     QPointF parPos;
   123 	bool link2ParPos;				// While moving around, sometimes link to parent
   124 
   125 	VymModel* model;												
   126     Orientation orientation;     
   127     qreal linkwidth;				// width of a link
   128 	QRectF bboxTotal;				// bounding box including children
   129 
   130     LinkableMapObj* childObj;
   131     LinkableMapObj* parObj;		// FIXME-2 really still needed? Better get from TreeItem
   132     LinkableMapObj* parObjTmpBuf;	// temporary buffer the original parent
   133     qreal bottomlineY;              // vertical offset of dockpos to pos
   134 
   135 	int thickness_start;			// for StylePoly*	
   136     Style style;					// Current style
   137 	Position linkpos;				// Link at bottom of object or middle of height
   138     QColor linkcolor;               // Link color
   139 	QPen pen;
   140     QGraphicsLineItem* l;           // line style
   141 	QGraphicsPolygonItem* p;		// poly styles
   142     int arcsegs;                    // arc: number of segments
   143     QList <QGraphicsLineItem*> segment; // a part of e.g. the parabel
   144 	QPolygonF pa0;					// For drawing of PolyParabel and PolyLine
   145 	QPolygonF pa1;					// For drawing of PolyParabel 
   146 	QPolygonF pa2;					// For drawing of PolyParabel	
   147     QGraphicsLineItem* bottomline;  // on bottom of BBox
   148 	bool repositionRequest;			// 
   149 
   150 	bool selected;					// Used for marking the selection
   151 	bool hideLinkUnselected;		// to hide links if unselected
   152 	qreal topPad, botPad,
   153 		leftPad, rightPad;          // padding within bbox
   154 
   155 	QPointF	 relPos;				// position relative to childPos of parent
   156 	//AnimPoint relPos;				// position relative to childPos of parent
   157 	bool useRelPos;
   158 	bool useOrientation;
   159 
   160 	TreeItem *treeItem;				// Crossrefence to treemodel
   161 };
   162 #endif