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