All Classes Namespaces Functions Variables Enumerations Properties Pages
timelinecells.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 TIMELINECELLS_H
19 #define TIMELINECELLS_H
20 
21 #include <QString>
22 #include <QWidget>
23 #include "layercamera.h"
24 
25 class Layer;
26 enum class LayerVisibility;
27 class TimeLine;
28 class QPaintEvent;
29 class QMouseEvent;
30 class QResizeEvent;
31 class Editor;
32 class PreferenceManager;
33 class QMenu;
34 class QAction;
35 enum class SETTING;
36 
37 enum class TIMELINE_CELL_TYPE
38 {
39  Layers,
40  Tracks
41 };
42 
43 class TimeLineCells : public QWidget
44 {
45  Q_OBJECT
46 
47 public:
48  TimeLineCells( TimeLine* parent, Editor* editor, TIMELINE_CELL_TYPE );
49  ~TimeLineCells() override;
50 
51  static int getOffsetX() { return mOffsetX; }
52  static int getOffsetY() { return mOffsetY; }
53  int getLayerHeight() const { return mLayerHeight; }
54 
55  int getFrameLength() const { return mFrameLength; }
56  int getFrameSize() const { return mFrameSize; }
57 
58  void setFrameLength(int n) { mFrameLength = n; }
59  void setFrameSize(int size);
60  void clearCache() { delete mCache; mCache = new QPixmap( size() ); }
61 
62  bool didDetachLayer() const;
63 
64  void showCameraMenu(QPoint pos);
65 
66 signals:
67  void mouseMovedY(int);
68  void lengthChanged(int);
69  void offsetChanged(int);
70  void selectionChanged();
71  void insertNewKeyFrame();
72 
73 public slots:
74  void updateContent();
75  void updateFrame(int frameNumber);
76  void hScrollChange(int);
77  void vScrollChange(int);
78  void setMouseMoveY(int x);
79 
80 protected:
81  bool event(QEvent *event) override;
82  void paintEvent(QPaintEvent* event) override;
83  void resizeEvent(QResizeEvent* event) override;
84  void mousePressEvent(QMouseEvent* event) override;
85  void mouseMoveEvent(QMouseEvent* event) override;
86  void mouseReleaseEvent(QMouseEvent* event) override;
87  void mouseDoubleClickEvent(QMouseEvent* event) override;
88 
89 private slots:
90  void loadSetting(SETTING setting);
91 
92  void setHold(int frame);
93  void setCameraEasing(CameraEasingType type, int frame);
94 
95 private:
96  int getLayerNumber(int y) const;
97  int getInbetweenLayerNumber(int y) const;
98  int getLayerY(int layerNumber) const;
99  int getFrameX(int frameNumber) const;
100  int getFrameNumber(int x) const;
101 
102  void onDidLeaveWidget();
103 
104  void trackScrubber();
105  void drawContent();
106  void paintTicks(QPainter& painter, const QPalette& palette) const;
107  void paintOnionSkin(QPainter& painter) const;
108  void paintLayerGutter(QPainter& painter) const;
109  void paintTrack(QPainter& painter, const Layer* layer, int x, int y, int width, int height, bool selected, int frameSize) const;
110  void paintFrames(QPainter& painter, QColor trackCol, const Layer* layer, int y, int height, bool selected, int frameSize) const;
111  void paintFrameCursorOnCurrentLayer(QPainter& painter, int recTop, int recWidth, int recHeight) const;
112  void paintSelectedFrames(QPainter& painter, const Layer* layer, const int layerIndex) const;
113  void paintLabel(QPainter& painter, const Layer* layer, int x, int y, int height, int width, bool selected, LayerVisibility layerVisibility) const;
114  void paintSelection(QPainter& painter, int x, int y, int width, int height) const;
115 
116  void editLayerProperties(Layer* layer) const;
117  void editLayerProperties(LayerCamera *layer) const;
118  void editLayerName(Layer* layer) const;
119 
120  TimeLine* mTimeLine;
121  Editor* mEditor; // the editor for which this timeLine operates
122  PreferenceManager* mPrefs;
123 
124  TIMELINE_CELL_TYPE mType;
125 
126  QPixmap* mCache = nullptr;
127  bool mDrawFrameNumber = true;
128  bool mbShortScrub = false;
129  int mFrameLength = 1;
130  int mFrameSize = 0;
131  int mFontSize = 10;
132  bool mScrubbing = false;
133  int mLayerHeight = 20;
134  int mStartY = 0;
135  int mEndY = 0;
136 
137  int mCurrentLayerNumber = 0;
138  int mLastScrubFrame = 0;
139 
140  int mFromLayer = 0;
141  int mToLayer = 1;
142  int mStartLayerNumber = -1;
143  int mStartFrameNumber = 0;
144  int mLastFrameNumber = -1;
145 
146  // is used to move layers, don't use this to get mousePos;
147  int mMouseMoveY = 0;
148  int mPrevFrame = 0;
149  int mFrameOffset = 0;
150  int mLayerOffset = 0;
151  Qt::MouseButton primaryButton = Qt::NoButton;
152 
153  bool mCanMoveFrame = false;
154  bool mMovingFrames = false;
155 
156  bool mCanBoxSelect = false;
157  bool mBoxSelecting = false;
158 
159  bool mClickSelecting = false;
160 
161  int mFramePosMoveX = 0;
162  int mLayerPosMoveY = 0;
163 
164  int mMouseMoveX = 0;
165  int mMousePressX = 0;
166 
167  const static int mOffsetX = 0;
168  const static int mOffsetY = 20;
169  const static int mLayerDetachThreshold = 5;
170 
171  QMenu* mEasingMenu = nullptr;
172  QMenu* mInterpolationMenu = nullptr;
173  QAction* mHoldAction = nullptr;
174 };
175 
176 #endif // TIMELINECELLS_H
const QPalette & palette() const const
int y() const const
MouseButton
QSize frameSize() const const
int width() const const
QSize size() const const
int x() const const
Q_OBJECTQ_OBJECT
Definition: layer.h:38
QPoint pos() const const
Definition: editor.h:55
QObject * parent() const const
int height() const const