linkablemapobj.h
author insilmaril
Tue, 31 Mar 2009 15:36:10 +0000
changeset 748 edb78a44240b
parent 726 7f43b93242aa
child 753 25a77484ec72
permissions -rw-r--r--
Removing branches and mapcenters works
     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 MapEditor;
    13 class VymModel;
    14 
    15 
    16 
    17 /*! \brief This class adds links to MapObj 
    18 
    19 The links are connecting the branches (BranchObj) and images (FloatImageObj) in the map.
    20 */
    21 
    22 class LinkableMapObj:public QObject, public MapObj {
    23 	Q_OBJECT
    24 public:
    25 	/*! Orientation of an object depends on the position relative to the parent */
    26 	enum Orientation {
    27 		UndefinedOrientation, //!< Undefined
    28 		LeftOfCenter,			//!< Object is left of center
    29 		RightOfCenter			//!< Object is right of center
    30 	};
    31 
    32 	/*! Various drawing styles for links */
    33 	enum Style {
    34 		UndefinedStyle,	//!< Undefined
    35 		Line,			//!< Straight line
    36 		Parabel,		//!< Parabel
    37 		PolyLine,		//!< Polygon (thick line)
    38 		PolyParabel		//!< Thick parabel
    39 	};
    40 
    41 	/*! Vertical position of link in object */
    42 	enum Position {
    43 		Middle, //!< Link is drawn in the middle of object
    44 		Bottom  //!< Link is drawn at bottom of object
    45 	};
    46 
    47 	/*! Hint if link should use the default link color or the color of heading */
    48 	enum ColorHint {
    49 		DefaultColor,	//!< Link uses the default color
    50 		HeadingColor	//!< Link uses the color of heading
    51 	};
    52 
    53     LinkableMapObj ();
    54     LinkableMapObj (QGraphicsScene*);
    55     LinkableMapObj (LinkableMapObj*);
    56     ~LinkableMapObj ();
    57 	virtual void delLink();
    58     virtual void init ();
    59     virtual void copy (LinkableMapObj*);
    60 
    61 	virtual void setTreeItem(TreeItem *);
    62 	virtual TreeItem* getTreeItem();
    63 	virtual void setModel (VymModel *vm);
    64 	virtual VymModel* getModel ();
    65 
    66     void setChildObj (LinkableMapObj*);
    67     virtual void setParObj (LinkableMapObj*);
    68     virtual void setParObjTmp (LinkableMapObj*,QPointF,int);	// Only for moving Obj around
    69 	virtual void unsetParObjTmp();						// reuse original ParObj
    70 	virtual bool hasParObjTmp();
    71 
    72 	virtual void setUseRelPos (const bool&);
    73 	virtual void setRelPos();				// set relPos to current parentPos
    74 	virtual void setRelPos(const QPointF&);	
    75 	virtual QPointF getRelPos();
    76 	virtual void setUseOrientation (const bool &);
    77 
    78 
    79 	virtual qreal getTopPad();
    80 	virtual qreal getLeftPad();
    81 	virtual qreal getRightPad();
    82 	Style getDefLinkStyle();
    83     void setLinkStyle(Style);            
    84 	Style getLinkStyle();
    85 	void setHideLinkUnselected(bool);
    86 	bool getHideLinkUnselected();
    87 	void setLinkPos (Position);
    88 	Position getLinkPos ();
    89 
    90 	virtual void setID (const QString &s);
    91 	virtual QString getID ();
    92 
    93 	virtual void setLinkColor();					// sets color according to colorhint, overloaded
    94 	virtual void setLinkColor(QColor);
    95 	QColor getLinkColor();
    96 	virtual void setVisibility (bool);
    97 	virtual void setOrientation();
    98     virtual void updateLink();				// update parPos and childPos
    99 											// depending on pos
   100 											// redraw link with given style
   101     LinkableMapObj* getChildObj();			// returns pointer to fromObj
   102     LinkableMapObj* getParObj();			// returns pointer to toObj
   103     virtual LinkableMapObj* findObjBySelect(QString s);	// find obj by selectstring
   104 	virtual void setDockPos()=0;				// sets childPos and parPos
   105     QPointF getChildPos();					// returns pos where children dock
   106     QPointF getParPos();						// returns pos where parents dock
   107     Orientation getOrientation();			// get orientation
   108     virtual int getDepth();					// return depth
   109 	virtual void setMapEditor(MapEditor*);	// set MapEditor (needed in LMO::updateNoteFlag) FIXME not needed
   110 	virtual MapEditor* getMapEditor();		// get MapEditor (usually from parent);          FIXME not needed
   111 	virtual QPointF getRandPos();			// make randomised position
   112 
   113 	virtual void reposition();
   114 	virtual void requestReposition();		// do reposition after next user event
   115 	virtual void forceReposition();			// to force a reposition now (outside
   116 											// of mapeditor e.g. in noteeditor
   117 	virtual bool repositionRequested();
   118 
   119 	virtual void calcBBoxSizeWithChildren()=0;// calc size of  BBox including children recursivly
   120 
   121     virtual void select();
   122     virtual void unselect();
   123 
   124 protected:
   125 	void parabel(QPolygonF &,double,double,double,double);	// Create Parabel connecting two points
   126 	QString getLinkAttr();
   127 
   128     QPointF childPos;
   129     QPointF parPos;
   130 	bool link2ParPos;				// While moving around, sometimes link to parent
   131 	MapEditor* mapEditor;			// for and toggleScroll(), get default styles	FIXME should not be needed with model available
   132 									// and mapEditor->updateActions()
   133 									// and mapEditor->updateSelection()
   134 
   135 	VymModel* model;												
   136     Orientation orientation;     
   137     qreal linkwidth;				// width of a link
   138     int depth;						// depth: undef=-1 mapCenter=0 branch=1..n
   139 	QRectF bboxTotal;				// bounding box including children
   140 
   141     LinkableMapObj* childObj;
   142     LinkableMapObj* parObj;
   143     LinkableMapObj* parObjTmpBuf;	// temporary buffer the original parent
   144     qreal bottomlineY;              // vertical offset of dockpos to pos
   145 
   146 	int thickness_start;			// for StylePoly*	
   147     Style style;					// Current style
   148 	Position linkpos;				// Link at bottom of object or middle of height
   149     QColor linkcolor;               // Link color
   150 	QPen pen;
   151     QGraphicsLineItem* l;           // line style
   152 	QGraphicsPolygonItem* p;		// poly styles
   153     int arcsegs;                    // arc: number of segments
   154     QList <QGraphicsLineItem*> segment; // a part of e.g. the parabel
   155 	QPolygonF pa0;					// For drawing of PolyParabel and PolyLine
   156 	QPolygonF pa1;					// For drawing of PolyParabel 
   157 	QPolygonF pa2;					// For drawing of PolyParabel	
   158     QGraphicsLineItem* bottomline;  // on bottom of BBox
   159 	bool repositionRequest;			// 
   160 
   161 	bool selected;					// Used for marking the selection
   162 	bool hideLinkUnselected;		// to hide links if unselected
   163 	qreal topPad, botPad,
   164 		leftPad, rightPad;          // padding within bbox
   165 
   166 	QPointF	 relPos;				// position relative to childPos of parent
   167 	//AnimPoint relPos;				// position relative to childPos of parent
   168 	bool useRelPos;
   169 	bool useOrientation;
   170 
   171 	QString objID;					// id set during load/save currently used for xLinks
   172 
   173 	TreeItem *treeItem;				// Crossrefence to treemodel
   174 };
   175 #endif