timeremap.h 4.44 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/***************************************************************************
 *   Copyright (C) 2021 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

#ifndef TIMEREMAP_H
#define TIMEREMAP_H

#include "ui_timeremap_ui.h"

#include "definitions.h"
#include "timecode.h"
#include "timecodedisplay.h"

#include <QWidget>
30
#include <QTimer>
31

32
33
#include "mlt++/Mlt.h"

34
35
36
37
38
39
40
41
42
43
44
class ProjectClip;


/**
 * @class RemapView
 * @brief A widget to view remap keyframes.
 * @author Jean-Baptiste Mardelle
 */

class RemapView : public QWidget
{
45
46
    Q_OBJECT

47
48
public:
    explicit RemapView(QWidget *parent = nullptr);
49
50
51
    void setDuration(std::shared_ptr<ProjectClip> clip, int duration);
    void loadKeyframes(const QString &mapData);
    const QString getKeyframesData() const;
52
    QTimer timer;
53
54
55

protected:
    void paintEvent(QPaintEvent *event) override;
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    void mouseMoveEvent(QMouseEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;

public slots:
    void updateInPos(int pos);
    void updateOutPos(int pos);
    void slotSetPosition(int pos);
    void addKeyframe();
    void goNext();
    void goPrev();
    void updateBeforeSpeed(double speed);
    void updateAfterSpeed(double speed);
    void toggleMoveNext(bool moveNext);
70
    void reloadProducer();
71
72

private:
73
    enum MOVEMODE {NoMove, TopMove, BottomMove, CursorMove};
74
    int m_duration;
75
    int m_position;
76
77
78
    double m_scale;
    QColor m_colSelected;
    QColor m_colKeyframe;
79
    int m_zoomHeight;
80
81
82
    int m_lineHeight;
    double m_zoomFactor;
    double m_zoomStart;
83
    QMap<int, int>m_keyframes;
84
85
    QMap<int, int>m_keyframesOrigin;
    std::shared_ptr<ProjectClip> m_clip;
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
    /** @brief The zoom factor (start, end - between 0 and 1) */
    QPointF m_zoomHandle;
    QPointF m_lastZoomHandle;
    /** @brief Mouse is the zoom left handle */
    bool m_hoverZoomIn;
    /** @brief Mouse is the zoom right handle */
    bool m_hoverZoomOut;
    /** @brief Mouse is over the zoom bar */
    bool m_hoverZoom;
    std::pair<int, bool> m_hoverKeyframe;
    int m_bottomView;
    std::pair<int, int> m_currentKeyframe;
    std::pair<int,int> m_currentKeyframeOriginal;
    MOVEMODE m_moveKeyframeMode;
    double m_clickOffset;
    int m_clickPoint;
    bool m_moveNext;
    int m_clickEnd;
    int m_offset;
    QMap <int,int>m_selectedKeyframes;
    int getClosestKeyframe(int pos, bool bottomKeyframe = false) const;
    std::pair<double,double> getSpeed(std::pair<int,int>kf);

signals:
    void seekToPos(int);
    void selectedKf(std::pair<int,int>, std::pair<double,double>);
    /** When the cursor position changes inform parent if we are on a keyframe or not. */
    void atKeyframe(bool);
    void updateKeyframes();
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
};

 /**
 * @class TimeRemap
 * @brief A dialog for editing time remap effect.
 * @author Jean-Baptiste Mardelle
 */
class TimeRemap : public QWidget, public Ui::TimeRemap_UI
{
    Q_OBJECT

public:
    explicit TimeRemap(QWidget *parent = nullptr);
    ~TimeRemap() override;
    void setClip(std::shared_ptr<ProjectClip> clip, int in = -1, int out = -1);

131
132
133
private slots:
    void updateKeyframes();

134
private:
135
    std::shared_ptr<Mlt::Link> m_remapLink;
136
137
138
    TimecodeDisplay *m_in;
    TimecodeDisplay *m_out;
    RemapView *m_view;
139

140
141
142
};

#endif