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 enum class SETTING;
34 
35 enum class TIMELINE_CELL_TYPE
36 {
37  Layers,
38  Tracks
39 };
40 
41 class TimeLineCells : public QWidget
42 {
43  Q_OBJECT
44 
45 public:
46  TimeLineCells( TimeLine* parent, Editor* editor, TIMELINE_CELL_TYPE );
47  ~TimeLineCells() override;
48 
49  int getLayerNumber(int y);
50  int getInbetweenLayerNumber(int y);
51  int getLayerY(int layerNumber);
52  int getFrameNumber(int x) const;
53  int getFrameX(int frameNumber) const;
54  int getMouseMoveY() const { return mMouseMoveY; }
55  static int getOffsetX() { return mOffsetX; }
56  static int getOffsetY() { return mOffsetY; }
57  int getLayerHeight() const { return mLayerHeight; }
58 
59  int getFrameLength() const { return mFrameLength; }
60  void setFrameLength(int n) { mFrameLength = n; }
61  void setFrameSize(int size);
62 
63  int getFrameSize() const { return mFrameSize; }
64  void clearCache() { delete mCache; mCache = new QPixmap( size() ); }
65  void paintLayerGutter(QPainter& painter);
66  bool didDetachLayer() const;
67  int getCurrentFrame() const { return mCurrentFrame; }
68 
69 signals:
70  void mouseMovedY(int);
71  void lengthChanged(int);
72  void offsetChanged(int);
73 
74 public slots:
75  void updateContent();
76  void updateFrame(int frameNumber);
77  void hScrollChange(int);
78  void vScrollChange(int);
79  void setMouseMoveY(int x);
80 
81 protected:
82  void trackScrubber();
83  void drawContent();
84  void paintOnionSkin(QPainter& painter);
85  void paintEvent(QPaintEvent* event) override;
86  void resizeEvent(QResizeEvent* event) override;
87  void mousePressEvent(QMouseEvent* event) override;
88  void mouseMoveEvent(QMouseEvent* event) override;
89  void mouseReleaseEvent(QMouseEvent* event) override;
90  void mouseDoubleClickEvent(QMouseEvent* event) override;
91 
92 private slots:
93  void loadSetting(SETTING setting);
94 
95 private:
96  void paintTrack(QPainter& painter, const Layer* layer, int x, int y, int width, int height, bool selected, int frameSize) const;
97  void paintFrames(QPainter& painter, const Layer* layer, QColor trackCol, int y, int height, bool selected, int frameSize) const;
98  void paintLabel(QPainter& painter, const Layer* layer, int x, int y, int height, int width, bool selected, LayerVisibility layerVisibility) const;
99  void paintSelection(QPainter& painter, int x, int y, int width, int height) const;
100 
101  void editLayerProperties(Layer* layer) const;
102  void editLayerProperties(LayerCamera *layer) const;
103  void editLayerName(Layer* layer) const;
104 
105  TimeLine* mTimeLine;
106  Editor* mEditor; // the editor for which this timeLine operates
107  PreferenceManager* mPrefs;
108 
109  TIMELINE_CELL_TYPE mType;
110 
111  QPixmap* mCache = nullptr;
112  bool mDrawFrameNumber = true;
113  bool mbShortScrub = false;
114  int mFrameLength = 1;
115  int mFrameSize = 0;
116  int mFontSize = 10;
117  bool mScrubbing = false;
118  int mLayerHeight = 20;
119  int mStartY = 0;
120  int mEndY = 0;
121 
122  int mCurrentFrame = 0;
123  int mLastScrubFrame = 0;
124 
125  int mFromLayer = 0;
126  int mToLayer = 1;
127  int mStartLayerNumber = -1;
128  int mStartFrameNumber = 0;
129  int mLastFrameNumber = -1;
130  int mMouseMoveY = 0;
131  int mPrevFrame = 0;
132  int mFrameOffset = 0;
133  int mLayerOffset = 0;
134  Qt::MouseButton primaryButton = Qt::NoButton;
135 
136  bool mCanMoveFrame = false;
137  bool mMovingFrames = false;
138 
139  bool mCanBoxSelect = false;
140  bool mBoxSelecting = false;
141 
142  bool mClickSelecting = false;
143 
144  const static int mOffsetX = 0;
145  const static int mOffsetY = 20;
146  const static int mLayerDetachThreshold = 5;
147 };
148 
149 #endif // TIMELINECELLS_H
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:39
Definition: editor.h:51
QObject * parent() const const
virtual bool event(QEvent *event) override
int height() const const