All Classes Namespaces Functions Variables Enumerations Properties Pages
viewmanager.h
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #ifndef VIEWMANAGER_H
19 #define VIEWMANAGER_H
20 
21 #include <QTransform>
22 #include "basemanager.h"
23 
24 class Layer;
25 class LayerCamera;
26 class Camera;
27 
28 
29 class ViewManager : public BaseManager
30 {
31  Q_OBJECT
32 
33 public:
34  explicit ViewManager(Editor* editor);
35  ~ViewManager() override;
36 
37  bool init() override;
38  Status load(Object*) override;
39  Status save(Object*) override;
40  void workingLayerChanged(Layer* layer) override;
41 
42  QTransform getView() const;
43  QTransform getViewInverse() const;
44  qreal getViewScaleInverse() const;
45  void resetView();
46 
47  QPointF mapCanvasToScreen(QPointF p) const;
48  QPointF mapScreenToCanvas(QPointF p) const;
49 
50  QRectF mapCanvasToScreen(const QRectF& rect) const;
51  QRectF mapScreenToCanvas(const QRectF& rect) const;
52 
53  QPolygonF mapPolygonToScreen(const QPolygonF& polygon) const;
54  QPolygonF mapPolygonToCanvas(const QPolygonF& polygon) const;
55 
56  QPainterPath mapCanvasToScreen(const QPainterPath& path) const;
57  QPainterPath mapScreenToCanvas(const QPainterPath& path) const;
58 
59  QPointF translation() const;
60  void translate(float dx, float dy);
61  void translate(QPointF offset);
62  void centerView();
63 
64  float rotation();
65  void rotate(float degree);
66  void resetRotation();
67 
68  qreal scaling();
69  void scale(qreal scaleValue);
70  void scaleWithOffset(qreal scaleValue, QPointF offset);
71  void scaleUp();
72  void scaleDown();
73  void scale400();
74  void scale300();
75  void scale200();
76  void scale100();
77  void scale50();
78  void scale33();
79  void scale25();
80 
81  void flipHorizontal(bool b);
82  void flipVertical(bool b);
83 
84  void setOverlayCenter(bool b);
85  void setOverlayThirds(bool b);
86  void setOverlayGoldenRatio(bool b);
87  void setOverlaySafeAreas(bool b);
88 
89  bool isFlipHorizontal() const { return mIsFlipHorizontal; }
90  bool isFlipVertical() const { return mIsFlipVertical; }
91  bool getOverlayCenter() const { return mOverlayCenter; }
92  bool getOverlayThirds() const { return mOverlayThirds; }
93  bool getOverlayGoldenRatio() const { return mOverlayGoldenRatio; }
94  bool getOverlaySafeAreas() const { return mOverlaySafeAreas; }
95 
96  void setCanvasSize(QSize size);
97  void setCameraLayer(Layer* layer);
98 
99  QTransform getImportView() { return mImportView; }
100  void setImportView(const QTransform& newView) { mImportView = newView; }
101 
102  void setImportFollowsCamera(bool b) { mImportFollowsCamera = b; }
103  bool getImportFollowsCamera() { return mImportFollowsCamera; }
104 
105  void forceUpdateViewTransform();
106 
107 signals:
108  void viewChanged();
109  void viewFlipped();
110 
111 private:
112  void updateViewTransforms();
113  void onCurrentFrameChanged();
114 
115  QTransform mView;
116  QTransform mViewInverse;
117  QTransform mViewCanvas;
118  QTransform mViewCanvasInverse;
119  QTransform mCentre;
120  QTransform mImportView;
121 
122  Camera* mDefaultEditorCamera = nullptr;
123  Camera* mCurrentCamera = nullptr;
124 
125  QSize mCanvasSize = { 1, 1 };
126 
127  bool mIsFlipHorizontal = false;
128  bool mIsFlipVertical = false;
129 
130  bool mImportFollowsCamera = false;
131 
132  bool mOverlayCenter = false;
133  bool mOverlayThirds = false;
134  bool mOverlayGoldenRatio = false;
135  bool mOverlaySafeAreas = false;
136 
137  LayerCamera* mCameraLayer = nullptr;
138 };
139 
140 #endif // VIEWMANAGER_H
Definition: camera.h:24
Q_OBJECTQ_OBJECT
Definition: layer.h:38
Definition: object.h:41
Definition: editor.h:55