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