]> git.sven.stormbind.net Git - sven/vym.git/blob - mapeditor.h
ba6faa9a190640f077a33d265881cdbf0450ec18
[sven/vym.git] / mapeditor.h
1 #ifndef MAPEDITOR_H
2 #define MAPEDITOR_H
3
4 #include <QGraphicsView>
5 #include <QItemSelectionModel>
6 #include <QLineEdit>    
7 #include <QPropertyAnimation>   
8
9 #include "attribute.h"
10 #include "xlink.h"
11 #include "ornamentedobj.h"
12 #include "settings.h"
13 #include "vymmodel.h"
14
15
16 class XLinkItem;
17 class Winter;
18
19 /*! \brief Main widget in vym to display and edit a map */
20
21
22 class MapEditor : public QGraphicsView {    
23     Q_OBJECT
24
25 public:
26     enum EditorState {
27         Neutral,
28         EditingHeading,
29         EditingLink,
30         MovingObject,
31         MovingView,
32         PickingColor,
33         CopyingObject,
34         DrawingLink
35     };
36
37     MapEditor(VymModel *vm);
38     ~MapEditor();
39     VymModel* getModel();
40     QGraphicsScene * getScene();
41     MapEditor::EditorState getState();
42
43 // Animation of scrollbars
44 Q_PROPERTY(QPointF scrollBarPos READ getScrollBarPos WRITE setScrollBarPos)
45
46 protected:
47     QPointF scrollBarPos;
48     QPointF scrollBarPosTarget;
49     QPropertyAnimation scrollBarPosAnimation;
50     QTimer *panningTimer;
51     QPointF vPan;                       //! Direction of panning during moving of object
52     QPoint pointerPos;                  //! Pointer position in widget coordinates
53     Qt::KeyboardModifiers pointerMod;   //! modifiers of move event
54
55 private slots:
56     void panView();
57
58 public:
59     void scrollTo (const QModelIndex &index);
60     void setScrollBarPosTarget (QRectF rect);   //!  ensureVisible of rect
61     QPointF getScrollBarPosTarget ();
62     void setScrollBarPos (const QPointF &p);
63     QPointF getScrollBarPos();
64     void animateScrollBars();
65
66 // Animation of zoom
67 Q_PROPERTY(qreal zoomFactor READ getZoomFactor WRITE setZoomFactor)
68
69 protected:
70     qreal zoomFactor;
71     qreal zoomFactorTarget;
72     QPropertyAnimation zoomAnimation;
73
74 public:
75     void setZoomFactorTarget (const qreal &zf);
76     qreal getZoomFactorTarget();
77     void setZoomFactor (const qreal &zf);
78     qreal getZoomFactor();
79
80 // Animation of rotation
81 Q_PROPERTY(qreal angle READ getAngle WRITE setAngle)
82
83 protected:
84     qreal angle;
85     qreal angleTarget;
86     QPropertyAnimation rotationAnimation;
87
88 public:
89     void setAngleTarget (const qreal &a);
90     qreal getAngleTarget();
91     void setAngle (const qreal &a);
92     qreal getAngle();
93
94
95 // Animation of viewCenter    
96 Q_PROPERTY (QPointF viewCenter READ getViewCenter WRITE setViewCenter)
97
98 protected:
99     QPointF viewCenter;
100     QPointF viewCenterTarget;
101
102 public:
103     void setViewCenterTarget (
104         const QPointF &p, 
105         const qreal &zft, 
106         const qreal &at,
107         const int duration=2000,
108         const QEasingCurve &easingCurve=QEasingCurve::OutQuint);
109     void setViewCenterTarget ();    //! Convenience function, center on selected item
110     QPointF getViewCenterTarget();
111     void setViewCenter (const QPointF &p);
112     QPointF getViewCenter();
113     QPropertyAnimation viewCenterAnimation;
114
115     void updateMatrix();            //! Sets transformation matrix with current rotation and zoom values
116     void minimizeView();
117
118 // xmas egg
119 protected:
120     Winter *winter;
121
122 public:
123     void print();                   //!< Print the map
124     QRectF getTotalBBox();          //!< Bounding box of all items in map
125     QImage getImage (QPointF &offset);  //!< Get a pixmap of the map
126     void setAntiAlias (bool);       //!< Set or unset antialiasing
127     void setSmoothPixmap(bool);     //!< Set or unset smoothing of pixmaps
128 public slots:   
129     void autoLayout();              //!< Auto layout of map by using collision detection
130     void testFunction1();               //! just testing new stuff
131     void testFunction2();               //! just testing new stuff
132
133 public:
134     TreeItem *findMapItem (QPointF p,TreeItem *exclude);    //! find item in map at position p. Ignore item exclude 
135
136     AttributeTable* attributeTable();   // FIXME-3 Not used, testing only
137     void toggleWinter();
138
139     BranchItem* getBranchDirectAbove(BranchItem *bi);   //! get branch direct above bi (in TreeView) 
140     BranchItem* getBranchAbove(BranchItem *bi);         //! get branch above bi (in TreeView) 
141     BranchItem* getBranchDirectBelow(BranchItem *bi);   //! bet branch direct below bi (in TreeView)
142     BranchItem* getBranchBelow(BranchItem *bi);         //! bet branch below bi (in TreeView)
143     BranchItem* getLeftBranch(BranchItem *bi);          //! bet branch left of bi (in TreeView)
144     BranchItem* getRightBranch(BranchItem *bi);         //! bet branch right of bi (in TreeView)
145
146 public slots:
147     void cursorUp();
148     void cursorDown();
149     void cursorLeft();
150     void cursorRight();
151     void cursorFirst();
152     void cursorLast();
153     void editHeading();
154     void editHeadingFinished();
155 private:
156     QLineEdit *lineEdit;
157
158 protected:
159     virtual void contextMenuEvent ( QContextMenuEvent *e );
160     virtual void keyPressEvent(QKeyEvent*);
161     virtual void keyReleaseEvent(QKeyEvent*);
162     virtual void mousePressEvent(QMouseEvent*);
163     virtual void mouseMoveEvent(QMouseEvent*);
164     void moveObject ();
165     virtual void mouseReleaseEvent(QMouseEvent*);
166     virtual void mouseDoubleClickEvent(QMouseEvent*);
167     virtual void wheelEvent(QWheelEvent*);
168     virtual void focusOutEvent (QFocusEvent*);
169     virtual void resizeEvent( QResizeEvent * );
170
171     void dragEnterEvent (QDragEnterEvent *);
172     void dragMoveEvent (QDragMoveEvent *);
173     void dragLeaveEvent (QDragLeaveEvent *);
174     void dropEvent (QDropEvent *);
175
176
177 private:
178     QGraphicsScene *mapScene;
179     VymModel *model;            //!< Vym Map, includding several mapCenters
180
181     bool adjustCanvasRequested; // collect requests until end of user event
182     BranchObj *editingBO;       // entering Text into BO
183
184     QCursor HandOpenCursor;     // cursor while moving canvas view
185     QCursor PickColorCursor;    // cursor while picking color 
186     QCursor CopyCursor;         // cursor while picking color 
187     QCursor XLinkCursor;        // cursor while picking color 
188     EditorState state; 
189
190     void setState (EditorState);
191     bool objectMoved;           // true if object was not clicked, but moved with mouse
192
193     // Temporary used for linkx
194     Link* tmpLink;
195
196     MapObj* movingObj;              // moving a MapObj
197     QPointF movingObj_orgPos;       // org. pos of mouse before move
198     QPointF movingObj_orgRelPos;    // org. relative pos of mouse before move
199     QPointF movingObj_offset;       // offset of mousepointer to object
200     QPointF movingCont_start;       // inital pos of moving Content or
201     QPointF movingVec;              // how far has Content moved
202
203     QPointF contextMenuPos;         // position where context event was triggered
204
205     AttributeTable *attrTable;
206
207     bool printFrame;            // Print frame around map
208     bool printFooter;           // Print footer below map
209
210     QPoint exportOffset;        // set before export, used in save
211
212 //////////// Selection related
213 signals:
214     void selectionChanged(const QItemSelection &, const QItemSelection &);
215
216 private:    
217     QList <QGraphicsPathItem*> selPathList;
218     QColor selectionColor;
219
220 public slots:
221     void updateSelection(QItemSelection ,QItemSelection); // update selection
222     void updateData (const QModelIndex&); // update data
223 public:
224     void setSelectionColor (QColor c);
225     QColor getSelectionColor ();
226 };
227 #endif
228