]> git.sesse.net Git - kdenlive/blob - src/simplekeyframes/simplekeyframewidget.cpp
af8e477e6cd3a33509090a7d6d7553eb04792bc0
[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 "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(const 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(timeCodeEditingFinished()), this, SLOT(slotSetPosition()));
64     connect(m_timeline, SIGNAL(positionChanged(int)), this, SLOT(slotSetPosition(int)));
65     connect(m_timeline, SIGNAL(atKeyframe(bool)), this, SLOT(slotAtKeyframe(bool)));
66     connect(m_timeline, SIGNAL(keyframeAdded(int)), this, SIGNAL(keyframeAdded(int)));
67     connect(m_timeline, SIGNAL(keyframeRemoved(int)), this, SIGNAL(keyframeRemoved(int)));
68     connect(m_timeline, SIGNAL(keyframeMoved(int,int)), this, SIGNAL(keyframeMoved(int,int)));
69
70     connect(m_buttonAddDelete, SIGNAL(pressed()), m_timeline, SLOT(slotAddRemove()));
71     connect(m_buttonPrevious, SIGNAL(pressed()), m_timeline, SLOT(slotGoToPrev()));
72     connect(m_buttonNext, SIGNAL(pressed()), m_timeline, SLOT(slotGoToNext()));
73
74     // no keyframes yet
75     setEnabled(false);
76 }
77
78 SimpleKeyframeWidget::~SimpleKeyframeWidget()
79 {
80     delete m_timeline;
81     delete m_buttonAddDelete;
82     delete m_buttonPrevious;
83     delete m_buttonNext;
84     delete m_time;
85 }
86
87 void SimpleKeyframeWidget::slotSetPosition(int pos, bool update)
88 {
89     if (pos < 0) {
90         pos = m_time->getValue();
91         m_timeline->slotSetPosition(pos);
92     } else {
93         m_time->setValue(pos);
94         m_timeline->slotSetPosition(pos);
95     }
96
97     if (update)
98         emit positionChanged(pos);
99 }
100
101 int SimpleKeyframeWidget::getPosition() const
102 {
103     return m_time->getValue();
104 }
105
106 void SimpleKeyframeWidget::setKeyframes(const QList< int >& keyframes)
107 {
108     m_timeline->setKeyframes(keyframes);
109     setEnabled(true);
110 }
111
112 void SimpleKeyframeWidget::addKeyframe(int pos)
113 {
114     blockSignals(true);
115     m_timeline->slotAddKeyframe(pos);
116     blockSignals(false);
117     setEnabled(true);
118 }
119
120 void SimpleKeyframeWidget::updateTimecodeFormat()
121 {
122     m_time->slotUpdateTimeCodeFormat();
123 }
124
125 void SimpleKeyframeWidget::slotAtKeyframe(bool atKeyframe)
126 {
127     if (atKeyframe) {
128         m_buttonAddDelete->setIcon(KIcon("edit-delete"));
129         m_buttonAddDelete->setToolTip(i18n("Delete keyframe"));
130     } else {
131         m_buttonAddDelete->setIcon(KIcon("document-new"));
132         m_buttonAddDelete->setToolTip(i18n("Add keyframe"));
133     }
134 }
135
136 #include "simplekeyframewidget.moc"