Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • tool
cameratool.h
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17
18#ifndef CAMERATOOL_H
19#define CAMERATOOL_H
20
21#include <QCursor>
22
23#include "basetool.h"
24#include "camerafieldoption.h"
25#include "preferencemanager.h"
26
27#include <QPen>
28
29enum class CameraMoveType {
30 PATH,
31 TOPLEFT,
32 TOPRIGHT,
33 BOTTOMLEFT,
34 BOTTOMRIGHT,
35 ROTATION,
36 CENTER,
37 NONE
38};
39
40class PointerEvent;
41class LayerCamera;
42class Camera;
43
44class CameraTool : public BaseTool
45{
46 Q_OBJECT
47
48public:
49 explicit CameraTool(QObject* object);
50 ~CameraTool() override;
51
52 enum ActionType {
53 RESET_PATH,
54 RESET_FIELD,
55 RESET_ROTATION,
56 RESET_TRANSLATION,
57 RESET_SCALING
58 };
59
60 QCursor cursor() override;
61 ToolType type() const override { return ToolType::CAMERA; }
62 bool isActive() const override { return true; }
63
64 void paint(QPainter& painter, const QRect&) override;
65
66 ToolProperties& toolProperties() override { return mSettings.toolProperties(); }
67 const CameraToolProperties& settings() const { return mSettings; }
68
69 void loadSettings() override;
70
71 void pointerPressEvent(PointerEvent* event) override;
72 void pointerReleaseEvent(PointerEvent* event) override;
73 void pointerMoveEvent(PointerEvent* event) override;
74
75 void setCameraPathEnabled(bool enabled);
76 void resetCameraPath();
77 void setPathDotColorType(DotColorType pathDotColor);
78 void resetTransform(CameraFieldOption option);
79
80 void transformView(LayerCamera* layerCamera, CameraMoveType mode, const QPointF& point, const QPointF& offset, qreal angle, int frameNumber) const;
81
82 void performAction(ActionType actionType);
83
84signals:
85 void pathColorChanged(DotColorType colorType);
86 void cameraPathEnabledChanged(bool enabled);
87
88private:
89
90 QPointF localRotationHandlePoint(const QPoint& origin, const QTransform& localT, const qreal objectScale, float worldScale) const;
91 QPointF worldRotationHandlePoint(const QPoint& origin, const QTransform& localT, const qreal objectScale, const QTransform& worldT, float worldScale) const;
92
93 void paintHandles(QPainter& painter, const QTransform& worldTransform, const QTransform& camTransform, const QRect& cameraRect, const QPointF translation, const qreal scale, const qreal rotation, bool hollowHandles) const;
94 void paintInterpolations(QPainter& painter, const QTransform& worldTransform, int currentFrame, const LayerCamera* cameraLayer, const Camera* keyframe, bool isPlaying) const;
95 void paintControlPoint(QPainter& painter, const QTransform& worldTransform, const LayerCamera* cameraLayer, const int frameIndex, const QPointF& pathPoint, bool hollowHandle) const;
96
97 void updateMoveMode(const QPointF& pos);
98 void transformCamera(const QPointF& pos, Qt::KeyboardModifiers keyMod);
99 void transformCameraPath(const QPointF& pos);
100 void updateSettings(const SETTING setting);
101 int constrainedRotation(const qreal rotatedAngle, const int rotationIncrement) const;
102
103 void updateProperties();
104 void updateUIAssists(const Layer* layer);
105
106 qreal getAngleBetween(const QPointF& pos1, const QPointF& pos2) const;
107
108 CameraMoveType getCameraMoveMode(const QPointF& point, qreal tolerance) const;
109 CameraMoveType getPathMoveMode(const LayerCamera* layerCamera, int frameNumber, const QPointF& point, qreal tolerance) const;
110
111 QPointF mTransformOffset;
112 CameraMoveType mCamMoveMode = CameraMoveType::NONE;
113 int mDragPathFrame = 1;
114 int mRotationIncrement = 0;
115
116 QRectF mCameraRect;
117 QPolygonF mCameraPolygon;
118 QPointF mRotationHandlePoint;
119
120 qreal mStartAngle = 0;
121 qreal mCurrentAngle = 0;
122
123 const int mDotWidth = 6;
124 const int mHandleWidth = 12;
125 const qreal mRotationHandleOffsetPercentage = 0.05;
126
127 QPen mHandlePen;
128 QColor mHandleColor;
129 QColor mHandleDisabledColor;
130 QColor mHandleTextColor;
131
132 CameraToolProperties mSettings;
133};
134
135#endif // CAMERATOOL_H
BaseTool
Definition: basetool.h:47
Camera
Definition: camera.h:25
CameraTool
Definition: cameratool.h:45
CameraTool::isActive
bool isActive() const override
Check if the tool is active.
Definition: cameratool.h:62
LayerCamera
Definition: layercamera.h:30
Layer
Definition: layer.h:33
PointerEvent
Definition: pointerevent.h:8
QColor
QCursor
QObject
QObject::Q_OBJECT
Q_OBJECTQ_OBJECT
QObject::event
virtual bool event(QEvent *e)
QPainter
QPen
QPoint
QPointF
QPolygonF
QRect
QRectF
Qt::KeyboardModifiers
typedef KeyboardModifiers
QTransform
CameraToolProperties
Definition: toolproperties.h:539
ToolProperties
Definition: toolproperties.h:204
Generated on Thu Jan 29 2026 05:10:58 for Pencil2D by doxygen 1.9.6 based on revision 2c971b937d0608b05aa496b0f7e9aebcddf8e7fc