mapeditor.h
author insilmaril
Fri, 11 Sep 2009 12:56:15 +0000
changeset 794 d922fb6ea482
parent 790 133e2ed6b9c5
child 798 d251c7b2de54
permissions -rw-r--r--
more fixes for collisions
     1 #ifndef MAPEDITOR_H
     2 #define MAPEDITOR_H
     3 
     4 #include <QGraphicsView>
     5 #include <QItemSelectionModel>
     6 
     7 #include <QtPropertyAnimation>	//! Not yet officially in Qt!
     8 
     9 #include "attribute.h"
    10 #include "ornamentedobj.h"
    11 #include "settings.h"
    12 #include "vymmodel.h"
    13 
    14 
    15 class XLinkItem;
    16 
    17 /*! \brief Main widget in vym to display and edit a map */
    18 
    19 
    20 class MapEditor : public QGraphicsView {	
    21     Q_OBJECT
    22 	Q_PROPERTY(qreal zoomFactor READ getZoomFactor WRITE setZoomFactor)
    23 	Q_PROPERTY(QPointF scrollBarPos READ getScrollBarPos WRITE setScrollBarPos)
    24 
    25 public:
    26     MapEditor(VymModel *vm);
    27 	~MapEditor();
    28 	VymModel* getModel();
    29 	QGraphicsScene * getScene();
    30 
    31 protected:
    32 	QPointF scrollBarPos;
    33 	QPointF scrollBarPosTarget;
    34 	QtPropertyAnimation scrollBarPosAnimation;
    35 public:
    36 	void scrollTo (const QModelIndex &index);
    37 	void setScrollBarPosTarget (const QRectF &rect);	//!  ensureVisible of rect
    38 	QPointF getScrollBarPosTarget ();
    39 	void setScrollBarPos (const QPointF &p);
    40 	QPointF getScrollBarPos();
    41 
    42 protected:
    43 	qreal zoomFactor;
    44 	qreal zoomFactorTarget;
    45 	QtPropertyAnimation zoomAnimation;
    46 public:
    47 	void setZoomFactorTarget (const qreal &zf);
    48 	qreal getZoomFactorTarget();
    49 	void setZoomFactor (const qreal &zf);
    50 	qreal getZoomFactor();
    51 
    52 public:
    53     void print();				//!< Print the map
    54 	QRectF getTotalBBox();		//!< Bounding box of all items in map
    55 	QPixmap getPixmap();		//!< Get a pixmap of the map
    56 	void setAntiAlias (bool);	//!< Set or unset antialiasing
    57 	void setSmoothPixmap(bool); //!< Set or unset smoothing of pixmaps
    58 public:
    59 	TreeItem *findMapItem (QPointF p,TreeItem *exclude);	//! find item in map at position p. Ignore item exclude 
    60 
    61 	AttributeTable* attributeTable();	// FIXME-3
    62     void testFunction1();				// just testing new stuff
    63     void testFunction2();				// just testing new stuff
    64 
    65 protected:	
    66 	BranchItem* getBranchDirectAbove(BranchItem *bi);	//!  get branch direct above bi (in TreeView) 
    67 	BranchItem* getBranchAbove(BranchItem *bi);			//! get branch above bi (in TreeView) 
    68 	BranchItem* getBranchDirectBelow(BranchItem *bi);	//!  bet branch direct below bi (in TreeView)
    69 	BranchItem* getBranchBelow(BranchItem *bi);			//! bet branch below bi (in TreeView)
    70 	BranchItem* getLeftBranch(BranchItem *bi);			//! bet branch left of bi (in TreeView)
    71 	BranchItem* getRightBranch(BranchItem *bi);			//! bet branch right of bi (in TreeView)
    72 
    73 public slots:
    74 	void cursorUp();
    75 	void cursorDown();
    76 	void cursorLeft();
    77 	void cursorRight();
    78 	void cursorFirst();
    79 	void cursorLast();
    80 	void editHeading();
    81 	void editHeadingFinished();
    82 private:
    83 	bool editingHeading;
    84 	QLineEdit *lineEdit;
    85 
    86 protected:
    87 	virtual void contextMenuEvent ( QContextMenuEvent *e );
    88     virtual void keyPressEvent(QKeyEvent*);
    89     virtual void keyReleaseEvent(QKeyEvent*);
    90     virtual void mousePressEvent(QMouseEvent*);
    91     virtual void mouseMoveEvent(QMouseEvent*);
    92     virtual void mouseReleaseEvent(QMouseEvent*);
    93     virtual void mouseDoubleClickEvent(QMouseEvent*);
    94     virtual void resizeEvent( QResizeEvent * );
    95 
    96 	void dragEnterEvent (QDragEnterEvent *);
    97 	void dragMoveEvent (QDragMoveEvent *);
    98 	void dragLeaveEvent (QDragLeaveEvent *);
    99 	void dropEvent (QDropEvent *);
   100 
   101 
   102 private:
   103 	QGraphicsScene *mapScene;
   104 	VymModel *model;			//!< Vym Map, includding several mapCenters
   105 
   106 	bool adjustCanvasRequested;	// collect requests until end of user event
   107 	BranchObj *editingBO;		// entering Text into BO
   108 
   109     QCursor HandOpenCursor;		// cursor while moving canvas view
   110 	QCursor PickColorCursor;	// cursor while picking color 
   111 	QCursor CopyCursor;			// cursor while picking color 
   112 	QCursor XLinkCursor;		// cursor while picking color 
   113 	bool pickingColor;
   114 	bool drawingLink;			// true while creating a link
   115 	bool copyingObj;			// true while creating a link
   116 	XLinkItem* tmpXLink;
   117 
   118 	MapObj* movingObj;				// moving a MapObj
   119     QPointF movingObj_orgPos;		// org. pos of mouse before move
   120     QPointF movingObj_orgRelPos;	// org. relative pos of mouse before move
   121     QPointF movingObj_start;		// rel. pos of mouse to absPos 
   122     QPointF movingCont_start;		// inital pos of moving Content or
   123     QPointF movingVec;				// how far has Content moved
   124 
   125 	QPointF contextMenuPos;			// position where context event was triggered
   126 
   127     QPrinter* printer;				// Printing
   128 
   129 	AttributeTable *attrTable;
   130 
   131 	bool printFrame;			// Print frame around map
   132 	bool printFooter;			// Print footer below map
   133 
   134 	QPoint exportOffset;		// set before export, used in save
   135 
   136 //////////// Selection related
   137 signals:
   138 	void selectionChanged(const QItemSelection &, const QItemSelection &);
   139 
   140 private:	
   141 	QList <QGraphicsRectItem*> selboxList;
   142 	QColor selectionColor;
   143 
   144 public slots:
   145 	void updateSelection(QItemSelection ,QItemSelection); // update selection
   146 	void updateData (const QModelIndex&); // update data
   147 public:
   148 	void setSelectionColor (QColor c);
   149 	QColor getSelectionColor ();
   150 };
   151 #endif
   152