]> git.sesse.net Git - kdenlive/blob - src/simplekeyframes/simplekeyframewidget.cpp
rotoscoping:
[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 in, int out, 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->setRange(in ,out);
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(in, out);
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
68     connect(m_buttonAddDelete, SIGNAL(pressed()), m_timeline, SLOT(slotAddRemove()));
69     connect(m_buttonPrevious, SIGNAL(pressed()), m_timeline, SLOT(slotGoToPrev()));
70     connect(m_buttonNext, SIGNAL(pressed()), m_timeline, SLOT(slotGoToNext()));
71 }
72
73 SimpleKeyframeWidget::~SimpleKeyframeWidget()
74 {
75     delete m_timeline;
76     delete m_buttonAddDelete;
77     delete m_buttonPrevious;
78     delete m_buttonNext;
79     //delete m_buttonSync;
80     delete m_time;
81 }
82
83 void SimpleKeyframeWidget::slotSetPosition(int pos, bool update)
84 {
85     if (pos < 0) {
86         pos = m_time->getValue();
87         m_timeline->slotSetPosition(pos);
88     } else {
89         m_time->setValue(pos);
90         m_timeline->slotSetPosition(pos);
91     }
92
93     if (update)
94         emit positionChanged(pos);
95 }
96
97 int SimpleKeyframeWidget::getPosition()
98 {
99     return m_time->getValue();
100 }
101
102 void SimpleKeyframeWidget::setKeyframes(const QList< int >& keyframes)
103 {
104     m_timeline->setKeyframes(keyframes);
105 }
106
107 void SimpleKeyframeWidget::addKeyframe(int pos)
108 {
109     blockSignals(true);
110     m_timeline->slotAddKeyframe(pos);
111     blockSignals(false);
112 }
113
114
115 #include "simplekeyframewidget.moc"