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