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"
25 #include <KMessageBox>
27 #include <QWheelEvent>
29 ClipDurationDialog::ClipDurationDialog(AbstractClipItem *clip, Timecode tc, GenTime min, GenTime max, QWidget * parent):
35 setFont(KGlobalSettings::toolBarFont());
38 m_pos = new TimecodeDisplay(tc);
39 m_dur = new TimecodeDisplay(tc);
40 m_cropStart = new TimecodeDisplay(tc);
41 m_cropEnd = new TimecodeDisplay(tc);
43 clip_position_box->addWidget(m_pos);
44 clip_duration_box->addWidget(m_dur);
45 crop_start_box->addWidget(m_cropStart),
46 crop_end_box->addWidget(m_cropEnd);
48 bool allowCrop = true;
49 if (clip->type() == AVWIDGET) {
50 ClipItem *item = static_cast <ClipItem *>(clip);
51 int t = item->clipType();
52 if (t == COLOR || t == IMAGE || t == TEXT)
56 if (!allowCrop || clip->type() == TRANSITIONWIDGET) {
57 m_cropStart->setHidden(true);
59 m_cropEnd->setHidden(true),
63 m_crop = m_clip->cropStart();
65 m_pos->setValue(m_clip->startPos());
66 m_dur->setValue(m_clip->cropDuration());
67 m_cropStart->setValue(m_clip->cropStart());
68 m_cropEnd->setValue(m_clip->maxDuration() - m_clip->cropDuration() - m_clip->cropStart());
70 connect(m_pos, SIGNAL(editingFinished()), this, SLOT(slotCheckStart()));
71 connect(m_dur, SIGNAL(editingFinished()), this, SLOT(slotCheckDuration()));
72 connect(m_cropStart, SIGNAL(editingFinished()), this, SLOT(slotCheckCrop()));
73 connect(m_cropEnd, SIGNAL(editingFinished()), this, SLOT(slotCheckEnd()));
78 ClipDurationDialog::~ClipDurationDialog()
86 void ClipDurationDialog::slotCheckStart()
88 GenTime start = m_pos->gentime();
89 GenTime duration = m_dur->gentime();
90 if (m_min != GenTime() && start < m_min)
91 m_pos->setValue(m_min);
92 else if (m_max != GenTime() && start + duration > m_max)
93 m_pos->setValue(m_max - duration);
96 void ClipDurationDialog::slotCheckDuration()
98 GenTime start = m_pos->gentime();
99 GenTime duration = m_dur->gentime();
100 GenTime cropStart = m_cropStart->gentime();
103 if (m_clip->maxDuration() == GenTime())
106 maxDuration = m_max == GenTime() ? start + m_clip->maxDuration() - cropStart : qMin(m_max, start + m_clip->maxDuration() - cropStart);
108 if (maxDuration != GenTime() && start + duration > maxDuration) {
109 m_dur->blockSignals(true);
110 m_dur->setValue(maxDuration - start);
111 m_dur->blockSignals(false);
114 m_cropEnd->blockSignals(true);
115 m_cropEnd->setValue(m_clip->maxDuration() - m_dur->gentime() - cropStart);
116 m_cropEnd->blockSignals(false);
119 void ClipDurationDialog::slotCheckCrop()
121 GenTime duration = m_dur->gentime();
122 GenTime cropStart = m_cropStart->gentime();
123 GenTime maxDuration = m_clip->maxDuration();
125 GenTime diff = cropStart - m_crop;
126 if ((diff > GenTime() && diff < duration) || diff < GenTime()) {
129 m_cropStart->setValue(m_crop);
133 if (maxDuration != GenTime() && cropStart + duration > maxDuration) {
134 m_cropStart->setValue(m_crop);
137 m_dur->blockSignals(true);
138 m_dur->setValue(duration);
139 m_dur->blockSignals(false);
143 void ClipDurationDialog::slotCheckEnd()
145 GenTime cropStart = m_cropStart->gentime();
146 GenTime cropEnd = m_cropEnd->gentime();
147 GenTime duration = m_clip->maxDuration() - cropEnd - cropStart;
149 if (duration >= GenTime()) {
150 m_dur->setValue(duration);
153 m_cropEnd->blockSignals(true);
154 m_cropEnd->setValue(m_clip->maxDuration() - m_dur->gentime() - cropStart);
155 m_cropEnd->blockSignals(false);
159 GenTime ClipDurationDialog::startPos() const
161 return m_pos->gentime();
164 GenTime ClipDurationDialog::cropStart() const
166 return m_cropStart->gentime();
169 GenTime ClipDurationDialog::duration() const
171 return m_dur->gentime();
174 #include "clipdurationdialog.moc"