mapeditor.h
author insilmaril
Mon, 15 Mar 2010 11:49:42 +0000
changeset 835 31841b366d5e
parent 834 0fad394bc330
child 837 5ecd0462f76b
permissions -rw-r--r--
Fixes for autoLayout (later)
     1 #ifndef MAPEDITOR_H
     2 #define MAPEDITOR_H
     3 
     4 #include <QGraphicsView>
     5 #include <QItemSelectionModel>
     6 
     7 #include <QtPropertyAnimation>	
     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 	QImage getImage ();			//!< 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 	void setHideTmp (bool);		//!< Hide parts temporary
    59 	void autoLayout();			//!< Auto layout of map by using collision detection
    60 public:
    61 	TreeItem *findMapItem (QPointF p,TreeItem *exclude);	//! find item in map at position p. Ignore item exclude 
    62 
    63 	AttributeTable* attributeTable();	// FIXME-3
    64     void testFunction1();				// just testing new stuff
    65     void testFunction2();				// just testing new stuff
    66 
    67 protected:	
    68 	BranchItem* getBranchDirectAbove(BranchItem *bi);	//!  get branch direct above bi (in TreeView) 
    69 	BranchItem* getBranchAbove(BranchItem *bi);			//! get branch above bi (in TreeView) 
    70 	BranchItem* getBranchDirectBelow(BranchItem *bi);	//!  bet branch direct below bi (in TreeView)
    71 	BranchItem* getBranchBelow(BranchItem *bi);			//! bet branch below bi (in TreeView)
    72 	BranchItem* getLeftBranch(BranchItem *bi);			//! bet branch left of bi (in TreeView)
    73 	BranchItem* getRightBranch(BranchItem *bi);			//! bet branch right of bi (in TreeView)
    74 
    75 public slots:
    76 	void cursorUp();
    77 	void cursorDown();
    78 	void cursorLeft();
    79 	void cursorRight();
    80 	void cursorFirst();
    81 	void cursorLast();
    82 	void editHeading();
    83 	void editHeadingFinished();
    84 private:
    85 	bool editingHeading;
    86 	QLineEdit *lineEdit;
    87 
    88 protected:
    89 	virtual void contextMenuEvent ( QContextMenuEvent *e );
    90     virtual void keyPressEvent(QKeyEvent*);
    91     virtual void keyReleaseEvent(QKeyEvent*);
    92     virtual void mousePressEvent(QMouseEvent*);
    93     virtual void mouseMoveEvent(QMouseEvent*);
    94     virtual void mouseReleaseEvent(QMouseEvent*);
    95     virtual void mouseDoubleClickEvent(QMouseEvent*);
    96     virtual void resizeEvent( QResizeEvent * );
    97 
    98 	void dragEnterEvent (QDragEnterEvent *);
    99 	void dragMoveEvent (QDragMoveEvent *);
   100 	void dragLeaveEvent (QDragLeaveEvent *);
   101 	void dropEvent (QDropEvent *);
   102 
   103 
   104 private:
   105 	QGraphicsScene *mapScene;
   106 	VymModel *model;			//!< Vym Map, includding several mapCenters
   107 
   108 	bool adjustCanvasRequested;	// collect requests until end of user event
   109 	BranchObj *editingBO;		// entering Text into BO
   110 
   111     QCursor HandOpenCursor;		// cursor while moving canvas view
   112 	QCursor PickColorCursor;	// cursor while picking color 
   113 	QCursor CopyCursor;			// cursor while picking color 
   114 	QCursor XLinkCursor;		// cursor while picking color 
   115 	bool pickingColor;
   116 	bool drawingLink;			// true while creating a link
   117 	bool copyingObj;			// true while modModeCopy
   118 	bool objectMoved;			// true if object was not clicked, but moved with mouse
   119 	XLinkItem* tmpXLink;
   120 
   121 	MapObj* movingObj;				// moving a MapObj
   122     QPointF movingObj_orgPos;		// org. pos of mouse before move
   123     QPointF movingObj_orgRelPos;	// org. relative pos of mouse before move
   124     QPointF movingObj_start;		// rel. pos of mouse to absPos 
   125     QPointF movingCont_start;		// inital pos of moving Content or
   126     QPointF movingVec;				// how far has Content moved
   127 
   128 	QPointF contextMenuPos;			// position where context event was triggered
   129 
   130     QPrinter* printer;				// Printing
   131 
   132 	AttributeTable *attrTable;
   133 
   134 	bool printFrame;			// Print frame around map
   135 	bool printFooter;			// Print footer below map
   136 
   137 	QPoint exportOffset;		// set before export, used in save
   138 
   139 //////////// Selection related
   140 signals:
   141 	void selectionChanged(const QItemSelection &, const QItemSelection &);
   142 
   143 private:	
   144 	QList <QGraphicsRectItem*> selboxList;
   145 	QColor selectionColor;
   146 
   147 public slots:
   148 	void updateSelection(QItemSelection ,QItemSelection); // update selection
   149 	void updateData (const QModelIndex&); // update data
   150 public:
   151 	void setSelectionColor (QColor c);
   152 	QColor getSelectionColor ();
   153 };
   154 #endif
   155