Scribus
Open source desktop publishing at your fingertips
canvasmode.h
1 /*
2  For general Scribus (>=1.3.2) copyright and licensing information please refer
3  to the COPYING file provided with the program. Following this notice may exist
4  a copyright and/or license notice that predates the release of Scribus 1.3.2
5  for which a new license (GPL+exception) is in place.
6  */
7 /***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15 
16 
17 
18 #ifndef CANVAS_MODE_H
19 #define CANVAS_MODE_H
20 
21 #include "scribusapi.h"
22 
23 #include <QBrush>
24 #include <QCursor>
25 #include <QMap>
26 #include <QPen>
27 #include <QPointF>
28 
29 class QDragEnterEvent;
30 class QDragMoveEvent;
31 class QDragLeaveEvent;
32 class QDropEvent;
33 class QEvent;
34 class QInputMethodEvent;
35 class QImage;
36 class QMouseEvent;
37 class QKeyEvent;
38 class QPainter;
39 
40 class UndoManager;
41 class Canvas;
42 struct CanvasViewMode;
43 class PanGesture;
44 class ScribusDoc;
45 class ScribusView;
46 class ScribusMainWindow;
47 class PageItem;
48 class PageItemPreview;
49 class PageItem_TextFrame;
50 
51 #include "fpoint.h"
52 
54 enum SubMode
55 {
56  submodeFirstSubmode = 1000,
57  submodePaintingDone, // return to normal mode
58  submodeEndNodeEdit, // return from node/shape editing
59  submodeLoadPic, // open GetImage dialog
60  submodeStatusPic, // open ManageImages dialog
61  submodeEditExternal, // open external image editor
62  submodeAnnotProps, // open properties dialog
63  submodeEditSymbol, // open Symbol editor
64  submodeLastSubmode
65 };
66 
67 
72 class SCRIBUS_API CanvasMode : public QObject
73 {
74  Q_OBJECT
75 protected:
76  explicit CanvasMode (ScribusView* view);
77 
78 public:
79  static CanvasMode* createForAppMode(ScribusView* view, int appMode);
80 
86  virtual void activate(bool fromGesture) {}
91  virtual void deactivate(bool forGesture) {}
92 
93  virtual void enterEvent(QEvent *) {}
94  virtual void leaveEvent(QEvent *) {}
95 
96  virtual void dragEnterEvent(QDragEnterEvent *e) {}
97  virtual void dragMoveEvent(QDragMoveEvent *e) {}
98  virtual void dragLeaveEvent(QDragLeaveEvent *e) {}
99  virtual void dropEvent(QDropEvent *e) {}
100 
101  virtual void mouseDoubleClickEvent(QMouseEvent *m) {}
102  virtual void mouseReleaseEvent(QMouseEvent *m) {}
103  virtual void mouseMoveEvent(QMouseEvent *m) {}
104  virtual void mousePressEvent(QMouseEvent *m) {}
105 
106  virtual void keyPressEvent(QKeyEvent *e) {}
107  virtual void keyReleaseEvent(QKeyEvent *e) {}
108  virtual void inputMethodEvent(QInputMethodEvent *e) {}
109 
110  virtual bool handleKeyEvents() { return false; }
111 
115  virtual void updateViewMode(CanvasViewMode* viewmode);
116 
121  virtual void drawControls(QPainter* p) { }
122 
123 
125  void drawSelectionHandles(QPainter *psx, QRectF selectionRect, bool background, bool insideGroup = false, double sx = 1.0, double sy = 1.0);
127  void drawSelection(QPainter* psx, bool drawHandles);
129  void drawSnapLine(QPainter* psx);
131  void drawOutline(QPainter* p, double scalex=1.0, double scaley=1.0, double deltax=0.0, double deltay=0.0);
132 #ifdef GESTURE_FRAME_PREVIEW
133  // I don’t know why the methods above have been implemented here and left non-virtual.
134  // I need to setup some companion members - pm
135  private:
136  QMap<PageItem*, PageItemPreview*> m_pixmapCache;
137  public:
138  void clearPixmapCache();
139 #endif // GESTURE_FRAME_PREVIEW
140 
141  QCursor modeCursor();
142  void setModeCursor();
143 
145  virtual CanvasMode* delegate() { return 0; }
146  ScribusView* view() const { return m_view; }
147  virtual ~CanvasMode();
148 
149 
150 protected:
151  ScribusView * const m_view;
152  Canvas * const m_canvas;
153  ScribusDoc * const m_doc;
154  PanGesture * m_panGesture;
155  UndoManager* undoManager;
156  double xSnap,ySnap;
157 
158  void setResizeCursor(int how, double rot = 0.0);
159  bool commonMouseMove(QMouseEvent *m);
160  void commonDrawControls(QPainter* p, bool drawHandles);
162  void commonDrawTextCursor(QPainter* p, PageItem_TextFrame* textframe, const QPointF& offset);
163  void commonkeyPressEvent_NormalNodeEdit(QKeyEvent *e);
164  void commonkeyReleaseEvent(QKeyEvent *e);
165 
166 private:
167  QMap<QString,QPen> m_pen;
168  QMap<QString,QBrush> m_brush;
169 
170  bool m_keyRepeat;
171  bool m_arrowKeyDown;
172  //FPoint m_mousePointDoc;
173 };
174 
175 
176 #endif
virtual CanvasMode * delegate()
Definition: canvasmode.h:145
Definition: canvas.h:80
Definition: pageitem_textframe.h:45
virtual void deactivate(bool forGesture)
Definition: canvasmode.h:91
Definition: canvas.h:49
This Class is the base class for your application. It sets up the main window and providing a menubar...
Definition: scribus.h:123
virtual void drawControls(QPainter *p)
Definition: canvasmode.h:121
Definition: canvasgesture_pan.h:26
the Document Class
Definition: scribusdoc.h:90
Definition: canvasmode.h:72
Definition: pageitem.h:92
UndoManager handles the undo stack.
Definition: undomanager.h:81
Definition: scribusview.h:87
virtual void activate(bool fromGesture)
Definition: canvasmode.h:86
Definition: pageitempreview.h:21