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 ***************************************************************************/
23 #include "clipdurationdialog.h"
24 #include "kdenlivesettings.h"
25 #include <QWheelEvent>
27 ClipDurationDialog::ClipDurationDialog(AbstractClipItem *clip, Timecode tc, QWidget * parent): QDialog(parent), m_tc(tc), m_clip(clip) {
28 setFont(KGlobalSettings::toolBarFont());
32 if (clip->type() == TRANSITIONWIDGET) {
33 m_view.crop_up->hide();
34 m_view.crop_down->hide();
35 m_view.crop_position->hide();
36 m_view.crop_label->hide();
39 m_view.clip_position->setText(tc.getTimecode(m_clip->startPos(), m_fps));
40 m_view.crop_position->setText(tc.getTimecode(m_clip->cropStart(), m_fps));
41 m_view.clip_duration->setText(tc.getTimecode(m_clip->duration(), m_fps));
42 connect(m_view.position_up, SIGNAL(clicked()), this, SLOT(slotPosUp()));
43 connect(m_view.position_down, SIGNAL(clicked()), this, SLOT(slotPosDown()));
44 connect(m_view.crop_up, SIGNAL(clicked()), this, SLOT(slotCropUp()));
45 connect(m_view.crop_down, SIGNAL(clicked()), this, SLOT(slotCropDown()));
46 connect(m_view.duration_up, SIGNAL(clicked()), this, SLOT(slotDurUp()));
47 connect(m_view.duration_down, SIGNAL(clicked()), this, SLOT(slotDurDown()));
52 ClipDurationDialog::~ClipDurationDialog() {
55 void ClipDurationDialog::slotPosUp() {
56 int position = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
57 //if (duration >= m_clip->duration().frames(m_fps)) return;
59 m_view.clip_position->setText(m_tc.getTimecode(GenTime(position, m_fps), m_fps));
62 void ClipDurationDialog::slotPosDown() {
63 int position = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
64 //if (duration >= m_clip->duration().frames(m_fps)) return;
66 m_view.clip_position->setText(m_tc.getTimecode(GenTime(position, m_fps), m_fps));
69 void ClipDurationDialog::slotDurUp() {
70 int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
71 int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
72 if (duration + crop > m_clip->maxDuration().frames(m_fps)) return;
74 m_view.clip_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
77 void ClipDurationDialog::slotDurDown() {
78 int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
79 if (duration <= 0) return;
81 m_view.clip_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
84 void ClipDurationDialog::slotCropUp() {
85 int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
86 int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
87 if (duration + crop > m_clip->maxDuration().frames(m_fps)) return;
89 m_view.crop_position->setText(m_tc.getTimecode(GenTime(crop, m_fps), m_fps));
92 void ClipDurationDialog::slotCropDown() {
93 int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
94 if (crop <= 0) return;
96 m_view.crop_position->setText(m_tc.getTimecode(GenTime(crop, m_fps), m_fps));
99 GenTime ClipDurationDialog::startPos() const {
100 int pos = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
101 return GenTime(pos, m_fps);
104 GenTime ClipDurationDialog::cropStart() const {
105 int pos = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
106 return GenTime(pos, m_fps);
109 GenTime ClipDurationDialog::duration() const {
110 int pos = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
111 return GenTime(pos, m_fps);
114 void ClipDurationDialog::wheelEvent(QWheelEvent * event) {
116 if (m_view.clip_position->underMouse()) {
117 if (event->delta() > 0)
121 } else if (m_view.clip_duration->underMouse()) {
122 if (event->delta() > 0)
126 } else if (m_view.crop_position->underMouse()) {
127 if (event->delta() > 0)
134 #include "clipdurationdialog.moc"