linkablemapobj.h
author insilmaril
Tue, 08 Apr 2008 08:28:37 +0000
changeset 683 7df0b7986274
parent 616 16d63fc9ae42
child 721 12958f987bcf
permissions -rw-r--r--
1.11.7: Fixed hanging find function
     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 reposition();
   106 	virtual void requestReposition();		// do reposition after next user event
   107 	virtual void forceReposition();			// to force a reposition now (outside
   108 											// of mapeditor e.g. in noteeditor
   109 	virtual bool repositionRequested();
   110 
   111 	virtual void calcBBoxSizeWithChilds()=0;// calc size of  BBox including childs recursivly
   112 
   113     virtual void select();
   114     virtual void unselect();
   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 	QString objID;					// id set during load/save currently used for xLinks
   162 };
   163 #endif