1 /***************************************************************************
2 * Copyright (C) 2011 by Till Theato (root@ttill.de) *
3 * This file is part of Kdenlive (www.kdenlive.org). *
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. *
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. *
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 ***************************************************************************/
19 #include "simplekeyframewidget.h"
20 #include "simpletimelinewidget.h"
21 #include "timecodedisplay.h"
23 #include <QToolButton>
24 #include <QGridLayout>
29 SimpleKeyframeWidget::SimpleKeyframeWidget(const Timecode &t, int duration, QWidget *parent) :
32 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
34 QGridLayout *l = new QGridLayout(this);
36 m_timeline = new SimpleTimelineWidget(this);
37 m_timeline->setDuration(duration);
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"));
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"));
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"));
54 m_time = new TimecodeDisplay(t, this);
55 m_time->setRange(0, duration);
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);
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)));
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()));
78 SimpleKeyframeWidget::~SimpleKeyframeWidget()
81 delete m_buttonAddDelete;
82 delete m_buttonPrevious;
87 void SimpleKeyframeWidget::slotSetPosition(int pos, bool update)
90 pos = m_time->getValue();
91 m_timeline->slotSetPosition(pos);
93 m_time->setValue(pos);
94 m_timeline->slotSetPosition(pos);
98 emit positionChanged(pos);
101 int SimpleKeyframeWidget::getPosition() const
103 return m_time->getValue();
106 void SimpleKeyframeWidget::setKeyframes(const QList< int >& keyframes)
108 m_timeline->setKeyframes(keyframes);
112 void SimpleKeyframeWidget::addKeyframe(int pos)
115 m_timeline->slotAddKeyframe(pos);
120 void SimpleKeyframeWidget::updateTimecodeFormat()
122 m_time->slotUpdateTimeCodeFormat();
125 void SimpleKeyframeWidget::slotAtKeyframe(bool atKeyframe)
128 m_buttonAddDelete->setIcon(KIcon("edit-delete"));
129 m_buttonAddDelete->setToolTip(i18n("Delete keyframe"));
131 m_buttonAddDelete->setIcon(KIcon("document-new"));
132 m_buttonAddDelete->setToolTip(i18n("Add keyframe"));
136 #include "simplekeyframewidget.moc"