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  void resetView();
45 
46  QPointF mapCanvasToScreen(QPointF p) const;
47  QPointF mapScreenToCanvas(QPointF p) const;
48 
49  QRectF mapCanvasToScreen(const QRectF& rect) const;
50  QRectF mapScreenToCanvas(const QRectF& rect) const;
51 
52  QPolygonF mapPolygonToScreen(const QPolygonF& polygon) const;
53  QPolygonF mapPolygonToCanvas(const QPolygonF& polygon) const;
54 
55  QPainterPath mapCanvasToScreen(const QPainterPath& path) const;
56  QPainterPath mapScreenToCanvas(const QPainterPath& path) const;
57 
58  QPointF translation() const;
59  void translate(float dx, float dy);
60  void translate(QPointF offset);
61  void centerView();
62 
63  float rotation();
64  void rotate(float degree);
65  void resetRotation();
66 
67  qreal scaling();
68  void scale(qreal scaleValue);
69  void scaleWithOffset(qreal scaleValue, QPointF offset);
70  void scaleUp();
71  void scaleDown();
72  void scale400();
73  void scale300();
74  void scale200();
75  void scale100();
76  void scale50();
77  void scale33();
78  void scale25();
79 
80  void flipHorizontal(bool b);
81  void flipVertical(bool b);
82  void setOverlayCenter(bool b);
83  void setOverlayThirds(bool b);
84  void setOverlayGoldenRatio(bool b);
85  void setOverlaySafeAreas(bool b);
86 
87  bool isFlipHorizontal() const { return mIsFlipHorizontal; }
88  bool isFlipVertical() const { return mIsFlipVertical; }
89  bool getOverlayCenter() const { return mOverlayCenter; }
90  bool getOverlayThirds() const { return mOverlayThirds; }
91  bool getOverlayGoldenRatio() const { return mOverlayGoldenRatio; }
92  bool getOverlaySafeAreas() const { return mOverlaySafeAreas; }
93 
94 
95  void setCanvasSize(QSize size);
96  void setCameraLayer(Layer* layer);
97 
98  QTransform getImportView() { return mImportView; }
99  void setImportView(const QTransform& newView) { mImportView = newView; }
100 
101  void setImportFollowsCamera(bool b) { mImportFollowsCamera = b; }
102  bool getImportFollowsCamera() { return mImportFollowsCamera; }
103 
104  void updateViewTransforms();
105 
106 signals:
107  void viewChanged();
108  void viewFlipped();
109 
110 private:
111 
112  void onCurrentFrameChanged();
113 
114  QTransform mView;
115  QTransform mViewInverse;
116  QTransform mViewCanvas;
117  QTransform mViewCanvasInverse;
118  QTransform mCentre;
119  QTransform mImportView;
120 
121  Camera* mDefaultEditorCamera = nullptr;
122  Camera* mCurrentCamera = nullptr;
123 
124  QSize mCanvasSize = { 1, 1 };
125 
126  bool mIsFlipHorizontal = false;
127  bool mIsFlipVertical = false;
128  bool mOverlayCenter = false;
129  bool mOverlayThirds = false;
130  bool mOverlayGoldenRatio = false;
131  bool mOverlaySafeAreas = false;
132 
133  bool mImportFollowsCamera = false;
134 
135  LayerCamera* mCameraLayer = nullptr;
136 };
137 
138 #endif // VIEWMANAGER_H
Definition: camera.h:24
Q_OBJECTQ_OBJECT
Definition: layer.h:39
Definition: object.h:54
Definition: editor.h:51