linkablemapobj.h
author insilmaril
Mon, 04 Aug 2008 10:43:06 +0000
changeset 723 11f9124c1cca
parent 721 12958f987bcf
child 726 7f43b93242aa
permissions -rw-r--r--
Adding/moving MCO works 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 
     9 #define MAX_DEPTH 999
    10 
    11 class MapEditor;
    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
    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 setModel (VymModel *vm);
    61 	virtual VymModel* getModel ();
    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 setID (const QString &s);
    88 	virtual QString getID ();
    89 
    90 	virtual void setLinkColor();					// sets color according to colorhint, overloaded
    91 	virtual void setLinkColor(QColor);
    92 	QColor getLinkColor();
    93 	virtual void setVisibility (bool);
    94 	virtual void setOrientation();
    95     virtual void updateLink();				// update parPos and childPos
    96 											// depending on pos
    97 											// redraw link with given style
    98     LinkableMapObj* getChildObj();			// returns pointer to fromObj
    99     LinkableMapObj* getParObj();			// returns pointer to toObj
   100     virtual LinkableMapObj* findObjBySelect(QString s);	// find obj by selectstring
   101 	virtual void setDockPos()=0;				// sets childPos and parPos
   102     QPointF getChildPos();					// returns pos where children dock
   103     QPointF getParPos();						// returns pos where parents dock
   104     Orientation getOrientation();			// get orientation
   105     virtual int getDepth();					// return depth
   106 	virtual void setMapEditor(MapEditor*);	// set MapEditor (needed in LMO::updateNoteFlag) FIXME not needed
   107 	virtual MapEditor* getMapEditor();		// get MapEditor (usually from parent);          FIXME not needed
   108 	virtual QPointF getRandPos();			// make randomised position
   109 
   110 	virtual void reposition();
   111 	virtual void requestReposition();		// do reposition after next user event
   112 	virtual void forceReposition();			// to force a reposition now (outside
   113 											// of mapeditor e.g. in noteeditor
   114 	virtual bool repositionRequested();
   115 
   116 	virtual void calcBBoxSizeWithChildren()=0;// calc size of  BBox including children recursivly
   117 
   118     virtual void select();
   119     virtual void unselect();
   120 
   121 protected:
   122 	void parabel(QPolygonF &,double,double,double,double);	// Create Parabel connecting two points
   123 	QString getLinkAttr();
   124 
   125     QPointF childPos;
   126     QPointF parPos;
   127 	bool link2ParPos;				// While moving around, sometimes link to parent
   128 	MapEditor* mapEditor;			// for and toggleScroll(), get default styles	FIXME should not be needed with model available
   129 									// and mapEditor->updateActions()
   130 									// and mapEditor->updateSelection()
   131 
   132 	VymModel* model;												
   133     Orientation orientation;     
   134     qreal linkwidth;				// width of a link
   135     int depth;						// depth: undef=-1 mapCenter=0 branch=1..n
   136 	QRectF bboxTotal;				// bounding box including children
   137 
   138     LinkableMapObj* childObj;
   139     LinkableMapObj* parObj;
   140     LinkableMapObj* parObjTmpBuf;	// temporary buffer the original parent
   141     qreal bottomlineY;              // vertical offset of dockpos to pos
   142 
   143 	int thickness_start;			// for StylePoly*	
   144     Style style;					// Current style
   145 	Position linkpos;				// Link at bottom of object or middle of height
   146     QColor linkcolor;               // Link color
   147 	QPen pen;
   148     QGraphicsLineItem* l;           // line style
   149 	QGraphicsPolygonItem* p;		// poly styles
   150     int arcsegs;                    // arc: number of segments
   151     QList <QGraphicsLineItem*> segment; // a part of e.g. the parabel
   152 	QPolygonF pa0;					// For drawing of PolyParabel and PolyLine
   153 	QPolygonF pa1;					// For drawing of PolyParabel 
   154 	QPolygonF pa2;					// For drawing of PolyParabel	
   155     QGraphicsLineItem* bottomline;  // on bottom of BBox
   156 	bool repositionRequest;			// 
   157 
   158 	bool selected;					// Used for marking the selection
   159 	bool hideLinkUnselected;		// to hide links if unselected
   160 	qreal topPad, botPad,
   161 		leftPad, rightPad;          // padding within bbox
   162 
   163 	QPointF	 relPos;				// position relative to childPos of parent
   164 	//AnimPoint relPos;				// position relative to childPos of parent
   165 	bool useRelPos;
   166 	bool useOrientation;
   167 
   168 	QString objID;					// id set during load/save currently used for xLinks
   169 };
   170 #endif