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