]> git.sesse.net Git - kdenlive/blob - src/simplekeyframes/simplekeyframewidget.cpp
rotoscoping: allow to move keyframes
[kdenlive] / src / simplekeyframes / simplekeyframewidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2011 by Till Theato (root@ttill.de)                     *
3  *   This file is part of Kdenlive (www.kdenlive.org).                     *
4  *                                                                         *
5  *   Kdenlive is free software: you can redistribute it and/or modify      *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation, either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   Kdenlive is distributed in the hope that it will be useful,           *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with Kdenlive.  If not, see <http://www.gnu.org/licenses/>.     *
17  ***************************************************************************/
18
19 #include "simplekeyframes/simplekeyframewidget.h"
20 #include "simpletimelinewidget.h"
21 #include "timecodedisplay.h"
22
23 #include <QToolButton>
24 #include <QGridLayout>
25
26 #include <KIcon>
27 #include <KLocale>
28
29 SimpleKeyframeWidget::SimpleKeyframeWidget(Timecode t, int duration, QWidget *parent) :
30         QWidget(parent)
31 {
32     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
33
34     QGridLayout *l = new QGridLayout(this);
35
36     m_timeline = new SimpleTimelineWidget(this);
37     m_timeline->setDuration(duration);
38
39     m_buttonAddDelete = new QToolButton(this);
40     m_buttonAddDelete->setAutoRaise(true);
41     m_buttonAddDelete->setIcon(KIcon("document-new"));
42     m_buttonAddDelete->setToolTip(i18n("Add keyframe"));
43
44     m_buttonPrevious = new QToolButton(this);
45     m_buttonPrevious->setAutoRaise(true);
46     m_buttonPrevious->setIcon(KIcon("media-skip-backward"));
47     m_buttonPrevious->setToolTip(i18n("Go to previous keyframe"));
48
49     m_buttonNext = new QToolButton(this);
50     m_buttonNext->setAutoRaise(true);
51     m_buttonNext->setIcon(KIcon("media-skip-forward"));
52     m_buttonNext->setToolTip(i18n("Go to next keyframe"));
53
54     m_time = new TimecodeDisplay(t, this);
55     m_time->setRange(0, duration);
56
57     l->addWidget(m_timeline, 0, 0, 1, -1);
58     l->addWidget(m_buttonPrevious, 1, 0);
59     l->addWidget(m_buttonAddDelete, 1, 1);
60     l->addWidget(m_buttonNext, 1, 2);
61     l->addWidget(m_time, 1, 3, Qt::AlignRight);
62
63     connect(m_time, SIGNAL(editingFinished()), this, SLOT(slotSetPosition()));
64     connect(m_timeline, SIGNAL(positionChanged(int)), this, SLOT(slotSetPosition(int)));
65     connect(m_timeline, SIGNAL(keyframeAdded(int)), this, SIGNAL(keyframeAdded(int)));
66     connect(m_timeline, SIGNAL(keyframeRemoved(int)), this, SIGNAL(keyframeRemoved(int)));
67     connect(m_timeline, SIGNAL(keyframeMoved(int,int)), this, SIGNAL(keyframeMoved(int,int)));
68
69     connect(m_buttonAddDelete, SIGNAL(pressed()), m_timeline, SLOT(slotAddRemove()));
70     connect(m_buttonPrevious, SIGNAL(pressed()), m_timeline, SLOT(slotGoToPrev()));
71     connect(m_buttonNext, SIGNAL(pressed()), m_timeline, SLOT(slotGoToNext()));
72 }
73
74 SimpleKeyframeWidget::~SimpleKeyframeWidget()
75 {
76     delete m_timeline;
77     delete m_buttonAddDelete;
78     delete m_buttonPrevious;
79     delete m_buttonNext;
80     //delete m_buttonSync;
81     delete m_time;
82 }
83
84 void SimpleKeyframeWidget::slotSetPosition(int pos, bool update)
85 {
86     if (pos < 0) {
87         pos = m_time->getValue();
88         m_timeline->slotSetPosition(pos);
89     } else {
90         m_time->setValue(pos);
91         m_timeline->slotSetPosition(pos);
92     }
93
94     if (update)
95         emit positionChanged(pos);
96 }
97
98 int SimpleKeyframeWidget::getPosition()
99 {
100     return m_time->getValue();
101 }
102
103 void SimpleKeyframeWidget::setKeyframes(const QList< int >& keyframes)
104 {
105     m_timeline->setKeyframes(keyframes);
106 }
107
108 void SimpleKeyframeWidget::addKeyframe(int pos)
109 {
110     blockSignals(true);
111     m_timeline->slotAddKeyframe(pos);
112     blockSignals(false);
113 }
114
115
116 #include "simplekeyframewidget.moc"