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>
26 #include <KGlobalSettings>
28 #include <QWheelEvent>
30 ClipDurationDialog::ClipDurationDialog(AbstractClipItem *clip, const Timecode &tc, const GenTime &min, const GenTime &max, QWidget * parent):
36 setFont(KGlobalSettings::toolBarFont());
39 m_pos = new TimecodeDisplay(tc);
40 m_cropStart = new TimecodeDisplay(tc);
41 m_dur = new TimecodeDisplay(tc);
42 m_cropEnd = new TimecodeDisplay(tc);
44 clip_position_box->addWidget(m_pos);
45 crop_start_box->addWidget(m_cropStart);
46 clip_duration_box->addWidget(m_dur);
47 crop_end_box->addWidget(m_cropEnd);
49 bool allowCrop = true;
50 if (clip->type() == AVWIDGET) {
51 ClipItem *item = static_cast <ClipItem *>(clip);
52 int t = item->clipType();
53 if (t == COLOR || t == IMAGE || t == TEXT)
57 if (!allowCrop || clip->type() == TRANSITIONWIDGET) {
58 m_cropStart->setHidden(true);
60 m_cropEnd->setHidden(true),
64 m_crop = m_clip->cropStart();
66 m_pos->setValue(m_clip->startPos());
67 m_dur->setValue(m_clip->cropDuration());
68 m_cropStart->setValue(m_clip->cropStart());
69 m_cropEnd->setValue(m_clip->maxDuration() - m_clip->cropDuration() - m_clip->cropStart());
71 connect(m_pos, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotCheckStart()));
72 connect(m_dur, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotCheckDuration()));
73 connect(m_cropStart, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotCheckCrop()));
74 connect(m_cropEnd, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotCheckEnd()));
79 ClipDurationDialog::~ClipDurationDialog()
87 void ClipDurationDialog::slotCheckStart()
89 GenTime start = m_pos->gentime();
90 GenTime duration = m_dur->gentime();
91 if (m_min != GenTime() && start < m_min)
92 m_pos->setValue(m_min);
93 else if (m_max != GenTime() && start + duration > m_max)
94 m_pos->setValue(m_max - duration);
97 void ClipDurationDialog::slotCheckDuration()
99 GenTime start = m_pos->gentime();
100 GenTime duration = m_dur->gentime();
101 GenTime cropStart = m_cropStart->gentime();
104 if (m_clip->maxDuration() == GenTime())
107 maxDuration = m_max == GenTime() ? start + m_clip->maxDuration() - cropStart : qMin(m_max, start + m_clip->maxDuration() - cropStart);
109 if (maxDuration != GenTime() && start + duration > maxDuration) {
110 m_dur->blockSignals(true);
111 m_dur->setValue(maxDuration - start);
112 m_dur->blockSignals(false);
115 m_cropEnd->blockSignals(true);
116 m_cropEnd->setValue(m_clip->maxDuration() - m_dur->gentime() - cropStart);
117 m_cropEnd->blockSignals(false);
120 void ClipDurationDialog::slotCheckCrop()
122 GenTime duration = m_dur->gentime();
123 GenTime cropStart = m_cropStart->gentime();
124 GenTime maxDuration = m_clip->maxDuration();
126 GenTime diff = cropStart - m_crop;
127 if ((diff > GenTime() && diff < duration) || diff < GenTime()) {
130 m_cropStart->setValue(m_crop);
134 if (maxDuration != GenTime() && cropStart + duration > maxDuration) {
135 m_cropStart->setValue(m_crop);
138 m_dur->blockSignals(true);
139 m_dur->setValue(duration);
140 m_dur->blockSignals(false);
144 void ClipDurationDialog::slotCheckEnd()
146 GenTime cropStart = m_cropStart->gentime();
147 GenTime cropEnd = m_cropEnd->gentime();
148 GenTime duration = m_clip->maxDuration() - cropEnd - cropStart;
150 if (duration >= GenTime()) {
151 m_dur->setValue(duration);
154 m_cropEnd->blockSignals(true);
155 m_cropEnd->setValue(m_clip->maxDuration() - m_dur->gentime() - cropStart);
156 m_cropEnd->blockSignals(false);
160 GenTime ClipDurationDialog::startPos() const
162 return m_pos->gentime();
165 GenTime ClipDurationDialog::cropStart() const
167 return m_cropStart->gentime();
170 GenTime ClipDurationDialog::duration() const
172 return m_dur->gentime();
175 #include "clipdurationdialog.moc"