linkablemapobj.h
author insilmaril
Mon, 18 Jun 2007 15:10:18 +0000
changeset 506 fcd1836b68e6
parent 486 9c86935835a4
child 531 be24af55da40
permissions -rw-r--r--
1.8.73 - beta testing
     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 setLinkColor();					// sets color according to colorhint, overloaded
    81 	virtual void setLinkColor(QColor);
    82 	QColor getLinkColor();
    83 	virtual void setVisibility (bool);
    84 	virtual void setOrientation();
    85     virtual void updateLink();				// update parPos and childPos
    86 											// depending on pos
    87 											// redraw link with given style
    88     LinkableMapObj* getChildObj();			// returns pointer to fromObj
    89     LinkableMapObj* getParObj();			// returns pointer to toObj
    90     virtual LinkableMapObj* findObjBySelect(QString s);	// find obj by selectstring
    91 	virtual void setDockPos()=0;				// sets childPos and parPos
    92     QPointF getChildPos();					// returns pos where childs dock
    93     QPointF getParPos();						// returns pos where parents dock
    94     Orientation getOrientation();			// get orientation
    95     virtual int getDepth();					// return depth
    96 	virtual void setMapEditor(MapEditor*);	// set MapEditor (needed in LMO::updateNoteFlag)
    97 	virtual MapEditor* getMapEditor();		// get MapEditor (usually from parent);
    98 	virtual QPointF getRandPos();			// make randomised position
    99 
   100     //virtual void alignRelativeTo(const QPointF );
   101 	virtual void reposition();
   102 	virtual void requestReposition();		// do reposition after next user event
   103 	virtual void forceReposition();			// to force a reposition now (outside
   104 											// of mapeditor e.g. in noteeditor
   105 	virtual bool repositionRequested();
   106 
   107 	//virtual QRectF getTotalBBox();			// return BBox including childs			
   108 	//virtual QRectF getBBoxSizeWithChilds();// return size of BBox including childs  
   109 	virtual void calcBBoxSizeWithChilds()=0;// calc size of  BBox including childs recursivly
   110 
   111     virtual void select();
   112     virtual void unselect();
   113 	virtual	QString getSelectString()=0;
   114 	//virtual QString saveToDir (const QString&,const QString&, const QPointF&);// Save data to XML
   115 
   116 protected:
   117 	void parabel(QPolygonF &,double,double,double,double);	// Create Parabel connecting two points
   118 	QString getLinkAttr();
   119 
   120     QPointF childPos;
   121     QPointF parPos;
   122 	bool link2ParPos;				// While moving around, sometimes link to parent
   123 	MapEditor* mapEditor;			// for and toggleScroll(), get default styles
   124 									// and mapEditor->updateActions()
   125 									// and mapEditor->updateSelection()
   126     Orientation orientation;     
   127     qreal linkwidth;				// width of a link
   128     int depth;						// depth: undef=-1 mapCenter=0 branch=1..n
   129 	QRectF bboxTotal;				// bounding box including childs
   130 
   131     LinkableMapObj* childObj;
   132     LinkableMapObj* parObj;
   133     LinkableMapObj* parObjTmpBuf;	// temporary buffer the original parent
   134     qreal bottomlineY;              // vertical offset of dockpos to pos
   135 
   136 	int thickness_start;			// for StylePoly*	
   137     Style style;					// Current style
   138 	Position linkpos;				// Link at bottom of object or middle of height
   139     QColor linkcolor;               // Link color
   140 	QPen pen;
   141     QGraphicsLineItem* l;           // line style
   142 	QGraphicsPolygonItem* p;		// poly styles
   143     int arcsegs;                    // arc: number of segments
   144     QList <QGraphicsLineItem*> segment; // a part of e.g. the parabel
   145 	QPolygonF pa0;					// For drawing of PolyParabel and PolyLine
   146 	QPolygonF pa1;					// For drawing of PolyParabel 
   147 	QPolygonF pa2;					// For drawing of PolyParabel	
   148     QGraphicsLineItem* bottomline;  // on bottom of BBox
   149 	bool repositionRequest;			// 
   150 
   151 	bool selected;					// Used for marking the selection
   152 	bool hideLinkUnselected;		// to hide links if unselected
   153 	qreal topPad, botPad,
   154 		leftPad, rightPad;          // padding within bbox
   155 
   156 	QPointF	 relPos;				// position relative to childPos of parent
   157 	//AnimPoint relPos;				// position relative to childPos of parent
   158 	bool useRelPos;
   159 	bool useOrientation;
   160 };
   161 #endif