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