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