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 scribusview.h - description
9 -------------------
10 begin : Fre Apr 6 21:47:55 CEST 2001
11 copyright : (C) 2001 by Franz Schmid
12 email : Franz.Schmid@altmuehlnet.de
13 ***************************************************************************/
14
15 /***************************************************************************
16 * *
17 * This program is free software; you can redistribute it and/or modify *
18 * it under the terms of the GNU General Public License as published by *
19 * the Free Software Foundation; either version 2 of the License, or *
20 * (at your option) any later version. *
21 * *
22 ***************************************************************************/
23
24 #ifndef SCRIBUSVIEW_H
25 #define SCRIBUSVIEW_H
26
27 #include <vector>
28 // include files for QT
29 #include <QDragLeaveEvent>
30 #include <QDragEnterEvent>
31 #include <QDragMoveEvent>
32 #include <QDropEvent>
33 #include <QElapsedTimer>
34 #include <QLabel>
35 #include <QLineEdit>
36 #include <QMap>
37 #include <QMouseEvent>
38 #include <QNativeGestureEvent>
39 #include <QPaintEvent>
40 #include <QPoint>
41 #include <QPushButton>
42 #include <QRect>
43 #include <QRectF>
44 #include <QSize>
45 #include <QStack>
46 #include <QTimer>
47 #include <QScrollArea>
48 #include <QScrollBar>
49 #include <QWheelEvent>
50
51 class QEvent;
52 class QMenu;
53 class QMimeData;
54
55 // application specific includes
56 #include "fpoint.h"
57 #include "observable.h"
58 #include "scribusapi.h"
59 #include "scribusdoc.h"
60 #include "selectionrubberband.h"
61 #include "ui/clockwidget.h"
62 #include "undotransaction.h"
63
64 class Canvas;
65 class CanvasMode;
66 class CanvasGesture;
67 class Hruler;
68 class Vruler;
69 class ScPage;
70 class RulerMover;
71 class PageItem;
72 class PageSelector;
73 class ScribusDoc;
74 class ScribusWin;
75 class ScribusMainWindow;
76 class ScrSpinBox;
77 class Selection;
78 class UndoManager;
79 class TransactionSettings;
80
81 /**
82 * This class provides an incomplete base for your application view.
83 */
84
85 class SCRIBUS_API ScribusView : public QScrollArea, public Observer<QRectF>
86 {
87 Q_OBJECT
88
89 public:
90 ScribusView(QWidget* win=0, ScribusMainWindow* mw=0, ScribusDoc* doc=0);
91 ~ScribusView();
92
93 friend class CanvasMode_CopyProperties;
94 friend class CanvasMode_Edit;
95 friend class CanvasMode_EditGradient;
96 friend class CanvasMode_EditMeshGradient;
97 friend class CanvasMode_EditMeshPatch;
98 friend class CanvasMode_EditTable;
99 friend class CanvasMode_EditWeldPoint;
100 friend class CanvasMode_EditPolygon;
101 friend class CanvasMode_EditArc;
102 friend class CanvasMode_EditSpiral;
103 friend class CanvasMode_FrameLinks;
104 friend class CanvasMode_ImageImport;
105 friend class CanvasMode_Magnifier;
106 friend class CanvasMode_NodeEdit;
107 friend class CanvasMode_Normal;
108 friend class CanvasMode_ObjImport;
109 friend class CanvasMode_Rotate;
110
111 struct ViewState
112 {
113 int currentPage { 0 };
114 int contentX { 0 };
115 int contentY { 0 };
116 double canvasScale { 1.0 };
117 FPoint minCanvasCoordinate;
118 FPoint maxCanvasCoordinate;
119 };
120
121 void requestMode(int appMode);
122 // void setCursorBasedOnAppMode(int appMode);
123 void startGesture(CanvasGesture*);
124 void stopGesture();
125
126 /** Vergroesserungseingabefeld */
127 RulerMover *rulerMover; //Widget between the two rulers for dragging the ruler origin
128 Hruler *horizRuler;
129 Vruler *vertRuler;
130 ClockWidget *clockLabel;
131 QPushButton *endEditButton;
132 /** Dokument zu dem die Seite gehoert */
133 ScribusDoc * const m_doc;
134 Canvas * const m_canvas;
135 CanvasMode* m_canvasMode; // might be a CanvasGesture FIXME make private
136 CanvasMode* canvasMode();
137 QMap<int, CanvasMode*> modeInstances;
138 ApplicationPrefs * const Prefs;
139 UndoManager * const undoManager;
140 ScribusMainWindow* m_ScMW;
141 double OldScale {0.0};
142 double dragX {0.0};
143 double dragY {0.0};
144 double dragW {0.0};
145 double dragH {0.0};
146 double oldW {-1.0};
147 int RotMode {0};
148 bool HaveSelRect {false};
149 bool DraggedGroup {false};
150 bool MidButt {false};
151 bool updateOn {true};
152 bool Magnify {false};
153 bool storedFramesShown;
154 bool storedShowControls;
155 int editStrokeGradient;
156 bool m_AnnotChanged;
157 bool m_EditModeWasOn;
158 bool m_ChangedState;
159 SelectionRubberBand *redrawMarker;
160 FPoint RCenter;
161 FPoint m_mousePointDoc;
162 void updatesOn(bool on);
163 //CB This MUST now be called AFTER a call to doc->addPage or doc->addMasterPage as it
164 //does NOT create a page anymore.
165 ScPage* addPage(int nr, bool mov = true);
166
167 void reformPages(bool moveObjects = true);
168 void reformPagesView();
169 void showMasterPage(int nr);
170 void hideMasterPage();
171 void showSymbolPage(const QString& symbolName);
172 void hideSymbolPage();
173 void showInlinePage(int id);
174 void hideInlinePage();
175
176 QImage PageToPixmap(int Nr, int maxGr, PageToPixmapFlags flags = Pixmap_DrawFrame | Pixmap_DrawBackground);
177 QImage MPageToPixmap(const QString& name, int maxGr, bool drawFrame = true);
178
179 /**
180 * Called when the ruler origin is dragged
181 * @param m mouse event
182 */
183 void setNewRulerOrigin(QMouseEvent *m);
184 void getDragRectScreen(double *x, double *y, double *w, double *h);
185 void getGroupRectScreen(double *x, double *y, double *w, double *h);
186 bool PointOnLine(QPoint Start, QPoint Ende, QRect MArea);
187 void TransformPoly(int mode, int rot = 1, double scaling = 1.0);
188 bool slotSetCurs(int x, int y);
189 // \brief return a resize cursor if the mouse is on a handle.
190 Qt::CursorShape getResizeCursor(PageItem *currItem, QRect mpo, Qt::CursorShape cursorShape = Qt::ArrowCursor);
191 void deselectItems(bool prop = true);
192 void selectItemByNumber(int nr, bool draw = true, bool single = false);
193 void selectItem(PageItem *pi, bool draw = true, bool single = false);
194 void rememberOldZoomLocation(int mx=0, int my=0);
groupTransactionStarted()195 bool groupTransactionStarted() { return m_groupTransactions > 0; }
196 void startGroupTransaction(const QString &actionName = "",
197 const QString &description = "",
198 QPixmap *actionPixmap = 0,
199 Selection* customSelection = 0);
200 void endGroupTransaction();
201 void cancelGroupTransaction();
202 void setScale(const double newScale);
203 double scale() const;
204
205 void changed(QRectF re, bool) override;
206
207 void updateCanvas(QRectF box = QRectF());
updateCanvas(double x,double y,double width,double height)208 void updateCanvas(double x, double y, double width, double height) { updateCanvas(QRectF(x, y, width, height)); }
209 void setCanvasOrigin(double x, double y);
210 void setCanvasCenter(double x, double y);
211 FPoint canvasOrigin() const;
212 QRectF visibleCanvasRect() const;
213 void setRedrawMarkerShown(bool shown);
214
215 private:
216 // legacy:
217 void updateContents(QRect box = QRect());
218 void updateContents(int x, int y, int w, int h);
219 void repaintContents(QRect box);
220 void resizeContents(int w, int h);
221 QPoint contentsToViewport(QPoint p);
222 QPoint viewportToContents(QPoint p);
223
224 public: // for now
225 int contentsX();
226 int contentsY();
227 int contentsWidth();
228 int contentsHeight();
visibleWidth()229 int visibleWidth() { return viewport()->size().width(); };
visibleHeight()230 int visibleHeight() { return viewport()->size().height(); };
231
232 void setCanvasPos(double x, double y);
233 void setCanvasCenterPos(double x, double y);
234 void setContentsPos(int x, int y);
235
236 void scrollBy(int x, int y);
237 void scrollCanvasBy(double deltaX, double deltaY);
238 void scrollContentsBy(int dx, int dy) override;
239
240 void zoom(double scale = 0.0);
241 void zoom(int canvasX, int canvasY, double scale, bool preservePoint);
242
243 void saveViewState();
244 void restoreViewState();
topViewState()245 const ViewState& topViewState() const { return m_viewStates.top(); }
246
247 public slots: // Public slots
248 void iconSetChange();
249 void languageChange();
250 void toggleCMS(bool cmsOn);
251 void switchPreviewVisual(int vis);
252 void togglePreviewEdit(bool edit);
253 void togglePreview(bool inPreview);
254 void unitChange();
255 void setRulersShown(bool isShown);
256 /** Zooms in or out */
257 void slotZoom100();
258 /** Zooms in */
259 void slotZoomIn(int mx = 0, int my = 0, bool preservePoint = false);
260 void slotZoomOut(int mx = 0, int my = 0, bool preservePoint = false);
261 /** Redraws everything */
262 void DrawNew();
263 void GotoPa(int pageNumber);
264 void GotoLayer(int l);
265 void GotoPage(int pageIndex);
266 void ChgUnit(int art);
267
268 void editExtendedImageProperties();
269 void RefreshGradient(PageItem *currItem, double dx = 8, double dy = 8);
270 void ToPicFrame();
271 void ToPolyFrame();
272 void ToTextFrame();
273 void ToBezierFrame();
274 void ToPathText();
275 void FromPathText();
276 void Bezier2Poly();
277 void PasteToPage();
278 void TextToPath();
279
280 //for linking frame after draw new frame
281 private:
282 PageItem * firstFrame;
283
284 private: // Private attributes
285 int m_previousMode;
286 QMenu *pmen3;
287 QMenu *pmenResolution;
288 QPoint m_pressLocation;
289 QElapsedTimer m_moveTimer;
290 QTimer *m_dragTimer;
291 bool m_dragTimerFired;
292 bool m_ready {false};
293 int m_oldZoomX {0};
294 int m_oldZoomY {0};
295 QSize m_oldCanvasSize;
296 int m_groupTransactions {0};
297 UndoTransaction m_groupTransaction;
298 bool _isGlobalMode {true};
299 bool linkAfterDraw {false};
300 bool ImageAfterDraw {false};
301 QStack<ViewState> m_viewStates;
302
303 private slots:
304 void setZoom();
305 /**
306 * Called to update the GUI when the canvas(view) scrollbars are moved
307 * @param x
308 * @param y
309 */
310 void setRulerPos(int x, int y);
311 void setObjectUndoMode();
312 void setGlobalUndoMode();
313 void dragTimerTimeOut();
314
315 public:
316 void wheelEvent(QWheelEvent *ev) override;
317 void changeEvent(QEvent *e) override;
318 void nativeGestureEvent(QNativeGestureEvent *e);
319 void keyPressEvent(QKeyEvent *k) override;
320 void keyReleaseEvent(QKeyEvent *k) override;
321 void inputMethodEvent(QInputMethodEvent * event) override;
322 QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
323
324 inline void registerMousePress(QPoint p);
325 bool mousePressed();
326 void resetMousePressed();
327 inline QPoint mousePressLocation();
328 inline bool moveTimerElapsed();
329 inline void resetMoveTimer();
330
331 inline void startDragTimer();
332 inline void stopDragTimer();
333 inline void resetDragTimer();
334 inline bool dragTimerElapsed();
335 void stopAllDrags();
336
337 bool handleObjectImport(QMimeData* mimeData, TransactionSettings* trSettings = nullptr);
338
339 protected: // Protected methods
340 void enterEvent(QEvent *) override;
341 void leaveEvent(QEvent *) override;
342 void resizeEvent(QResizeEvent *event) override;
343 bool eventFilter(QObject *obj, QEvent *event) override;
344
345 // those appear to be gone from QScrollArea:
346 virtual void contentsDragEnterEvent(QDragEnterEvent *e);
347 virtual void contentsDragMoveEvent(QDragMoveEvent *e);
348 virtual void contentsDragLeaveEvent(QDragLeaveEvent *e);
349 virtual void contentsDropEvent(QDropEvent *e);
350 virtual void setHBarGeometry(QScrollBar &bar, int x, int y, int w, int h);
351 virtual void setVBarGeometry(QScrollBar &bar, int x, int y, int w, int h);
352
353 //The width of vertical ruler/height of horizontal ruler, set to 17 in scribusview.cpp
354 int m_vhRulerHW;
355
356 signals:
357 void unitChanged(int);
358 void layerChanged(int);
359 void HaveSel();
360 void DocChanged();
361 void ItemGeom();
362 void PolyOpen();
363 void ItemCharStyle(const CharStyle&);
364 void ItemTextAlign(int);
365 void ItemTextEffects(int);
366 void AddBM(PageItem *);
367 void DelBM(PageItem *);
368 void ChBMText(PageItem *);
369 void LoadElem(QString, double, double, bool, bool, ScribusDoc *, ScribusView *);
370 void HavePoint(bool, bool);
371 void ClipPo(double, double);
372 void PolyStatus(int, uint);
373 void MousePos(double, double);
374 };
375
376
377
378
registerMousePress(QPoint p)379 inline void ScribusView::registerMousePress(QPoint p)
380 {
381 m_pressLocation = p;
382 m_moveTimer.start();
383 m_dragTimerFired = false;
384 }
385
386
mousePressLocation()387 inline QPoint ScribusView::mousePressLocation()
388 {
389 return m_pressLocation;
390 }
391
392
moveTimerElapsed()393 inline bool ScribusView::moveTimerElapsed()
394 {
395 return (m_moveTimer.elapsed() > Prefs->uiPrefs.mouseMoveTimeout);
396 }
397
398
resetMoveTimer()399 inline void ScribusView::resetMoveTimer()
400 {
401 m_moveTimer.start();
402 }
403
404
startDragTimer()405 inline void ScribusView::startDragTimer()
406 {
407 m_dragTimerFired = false;
408 m_dragTimer->setSingleShot(true);
409 m_dragTimer->start(1000); // set Timeout for starting a Drag operation to 1 sec.
410 }
411
stopDragTimer()412 inline void ScribusView::stopDragTimer()
413 {
414 m_dragTimer->stop();
415 }
416
417
resetDragTimer()418 inline void ScribusView::resetDragTimer()
419 {
420 m_dragTimerFired = false;
421 }
422
423
dragTimerElapsed()424 inline bool ScribusView::dragTimerElapsed()
425 {
426 return m_dragTimerFired;
427 }
428
canvasMode()429 inline CanvasMode* ScribusView::canvasMode()
430 {
431 return m_canvasMode;
432 }
433
434 #endif
435