1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include "clipdurationdialog.h"
23 #include "kdenlivesettings.h"
26 #include <KMessageBox>
28 #include <QWheelEvent>
30 ClipDurationDialog::ClipDurationDialog(AbstractClipItem *clip, Timecode tc, QWidget * parent):
35 setFont(KGlobalSettings::toolBarFont());
39 bool allowCrop = true;
40 if (clip->type() == AVWIDGET) {
41 ClipItem *item = static_cast <ClipItem *>(clip);
42 int t = item->clipType();
43 if (t == COLOR || t == IMAGE || t == TEXT) allowCrop = false;
46 if (!allowCrop || clip->type() == TRANSITIONWIDGET) {
47 m_view.crop_up->hide();
48 m_view.crop_down->hide();
49 m_view.crop_position->hide();
50 m_view.crop_label->hide();
53 m_view.clip_position->setText(tc.getTimecode(m_clip->startPos()));
54 m_view.crop_position->setText(tc.getTimecode(m_clip->cropStart()));
55 m_view.clip_duration->setText(tc.getTimecode(m_clip->cropDuration()));
56 connect(m_view.position_up, SIGNAL(clicked()), this, SLOT(slotPosUp()));
57 connect(m_view.position_down, SIGNAL(clicked()), this, SLOT(slotPosDown()));
58 connect(m_view.crop_up, SIGNAL(clicked()), this, SLOT(slotCropUp()));
59 connect(m_view.crop_down, SIGNAL(clicked()), this, SLOT(slotCropDown()));
60 connect(m_view.duration_up, SIGNAL(clicked()), this, SLOT(slotDurUp()));
61 connect(m_view.duration_down, SIGNAL(clicked()), this, SLOT(slotDurDown()));
62 connect(m_view.crop_position, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckCrop()));
66 ClipDurationDialog::~ClipDurationDialog()
70 void ClipDurationDialog::setMargins(GenTime min, GenTime max)
74 connect(m_view.clip_position, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckStart()));
75 connect(m_view.clip_duration, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckDuration()));
78 void ClipDurationDialog::slotCheckStart()
80 int pos = m_tc.getFrameCount(m_view.clip_position->text());
81 int dur = m_tc.getFrameCount(m_view.clip_duration->text());
82 GenTime start(pos, m_fps);
83 GenTime duration(dur, m_fps);
84 if (m_min != GenTime() && start < m_min) {
85 m_view.clip_position->setText(m_tc.getTimecode(m_min));
86 } else if (m_max != GenTime() && start + duration > m_max) {
87 m_view.clip_position->setText(m_tc.getTimecode(m_max - duration));
91 void ClipDurationDialog::slotCheckDuration()
93 int pos = m_tc.getFrameCount(m_view.clip_position->text());
94 int dur = m_tc.getFrameCount(m_view.clip_duration->text());
95 GenTime start(pos, m_fps);
96 GenTime duration(dur, m_fps);
98 if (m_clip->maxDuration() == GenTime()) maxDuration = m_max;
99 else maxDuration = m_max == GenTime() ? start + m_clip->maxDuration() : qMin(m_max, start + m_clip->maxDuration());
100 if (maxDuration != GenTime() && start + duration > maxDuration) {
101 m_view.clip_duration->setText(m_tc.getTimecode(maxDuration - start));
105 void ClipDurationDialog::slotCheckCrop()
107 int dur = m_tc.getFrameCount(m_view.clip_duration->text());
108 int crop = m_tc.getFrameCount(m_view.crop_position->text());
109 GenTime duration(dur, m_fps);
110 GenTime cropStart(crop, m_fps);
111 GenTime maxDuration = m_clip->maxDuration();
112 if (maxDuration != GenTime() && cropStart + duration > maxDuration) {
113 m_view.crop_position->setText(m_tc.getTimecode(maxDuration - duration));
117 void ClipDurationDialog::slotPosUp()
119 int position = m_tc.getFrameCount(m_view.clip_position->text());
120 //if (duration >= m_clip->duration().frames(m_fps)) return;
122 m_view.clip_position->setText(m_tc.getTimecode(GenTime(position, m_fps)));
125 void ClipDurationDialog::slotPosDown()
127 int position = m_tc.getFrameCount(m_view.clip_position->text());
128 //if (duration >= m_clip->duration().frames(m_fps)) return;
130 m_view.clip_position->setText(m_tc.getTimecode(GenTime(position, m_fps)));
133 void ClipDurationDialog::slotDurUp()
135 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
136 int crop = m_tc.getFrameCount(m_view.crop_position->text());
137 if (m_clip->maxDuration() != GenTime() && duration + crop > m_clip->maxDuration().frames(m_fps)) return;
139 m_view.clip_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps)));
142 void ClipDurationDialog::slotDurDown()
144 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
145 if (duration <= 0) return;
147 m_view.clip_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps)));
150 void ClipDurationDialog::slotCropUp()
152 int crop = m_tc.getFrameCount(m_view.crop_position->text());
153 int duration = m_tc.getFrameCount(m_view.clip_duration->text());
154 if (m_clip->maxDuration() != GenTime() && duration + crop > m_clip->maxDuration().frames(m_fps)) return;
156 m_view.crop_position->setText(m_tc.getTimecode(GenTime(crop, m_fps)));
159 void ClipDurationDialog::slotCropDown()
161 int crop = m_tc.getFrameCount(m_view.crop_position->text());
162 if (crop <= 0) return;
164 m_view.crop_position->setText(m_tc.getTimecode(GenTime(crop, m_fps)));
167 GenTime ClipDurationDialog::startPos() const
169 int pos = m_tc.getFrameCount(m_view.clip_position->text());
170 return GenTime(pos, m_fps);
173 GenTime ClipDurationDialog::cropStart() const
175 int pos = m_tc.getFrameCount(m_view.crop_position->text());
176 return GenTime(pos, m_fps);
179 GenTime ClipDurationDialog::duration() const
181 int pos = m_tc.getFrameCount(m_view.clip_duration->text());
182 return GenTime(pos, m_fps);
185 void ClipDurationDialog::wheelEvent(QWheelEvent * event)
187 if (m_view.clip_position->underMouse()) {
188 if (event->delta() > 0)
192 } else if (m_view.clip_duration->underMouse()) {
193 if (event->delta() > 0)
197 } else if (m_view.crop_position->underMouse()) {
198 if (event->delta() > 0)
205 #include "clipdurationdialog.moc"