]> git.sesse.net Git - kdenlive/blob - src/clipdurationdialog.cpp
Krazy fixes: cleanup all headers
[kdenlive] / src / clipdurationdialog.cpp
1 /***************************************************************************
2  *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #include "clipdurationdialog.h"
22 #include "clipitem.h"
23 #include "kdenlivesettings.h"
24
25 #include <KDebug>
26
27 #include <QWheelEvent>
28
29 ClipDurationDialog::ClipDurationDialog(AbstractClipItem *clip, Timecode tc, QWidget * parent): QDialog(parent), m_tc(tc), m_clip(clip) {
30     setFont(KGlobalSettings::toolBarFont());
31     m_fps = m_tc.fps();
32     m_view.setupUi(this);
33
34     bool allowCrop = true;
35     if (clip->type() == AVWIDGET) {
36         ClipItem *item = static_cast <ClipItem *>(clip);
37         int t = item->clipType();
38         if (t == COLOR || t == IMAGE || t == TEXT) allowCrop = false;
39     }
40
41     if (!allowCrop || clip->type() == TRANSITIONWIDGET) {
42         m_view.crop_up->hide();
43         m_view.crop_down->hide();
44         m_view.crop_position->hide();
45         m_view.crop_label->hide();
46     }
47
48     m_view.clip_position->setText(tc.getTimecode(m_clip->startPos(), m_fps));
49     m_view.crop_position->setText(tc.getTimecode(m_clip->cropStart(), m_fps));
50     m_view.clip_duration->setText(tc.getTimecode(m_clip->duration(), m_fps));
51     connect(m_view.position_up, SIGNAL(clicked()), this, SLOT(slotPosUp()));
52     connect(m_view.position_down, SIGNAL(clicked()), this, SLOT(slotPosDown()));
53     connect(m_view.crop_up, SIGNAL(clicked()), this, SLOT(slotCropUp()));
54     connect(m_view.crop_down, SIGNAL(clicked()), this, SLOT(slotCropDown()));
55     connect(m_view.duration_up, SIGNAL(clicked()), this, SLOT(slotDurUp()));
56     connect(m_view.duration_down, SIGNAL(clicked()), this, SLOT(slotDurDown()));
57     connect(m_view.crop_position, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckCrop()));
58     adjustSize();
59 }
60
61 ClipDurationDialog::~ClipDurationDialog() {
62 }
63
64 void ClipDurationDialog::setMargins(GenTime min, GenTime max) {
65     m_min = min;
66     m_max = max;
67     connect(m_view.clip_position, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckStart()));
68     connect(m_view.clip_duration, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckDuration()));
69 }
70
71 void ClipDurationDialog::slotCheckStart() {
72     int pos = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
73     int dur = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
74     GenTime start(pos, m_fps);
75     GenTime duration(dur, m_fps);
76     if (start < m_min) {
77         m_view.clip_position->setText(m_tc.getTimecode(m_min, m_fps));
78     } else if (start + duration > m_max) {
79         m_view.clip_position->setText(m_tc.getTimecode(m_max - duration, m_fps));
80     }
81 }
82
83 void ClipDurationDialog::slotCheckDuration() {
84     int pos = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
85     int dur = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
86     GenTime start(pos, m_fps);
87     GenTime duration(dur, m_fps);
88     GenTime maxDuration = m_max == GenTime() ? start + m_clip->maxDuration() : qMin(m_max, start + m_clip->maxDuration());
89     if (start + duration > maxDuration) {
90         m_view.clip_duration->setText(m_tc.getTimecode(maxDuration - start, m_fps));
91     }
92 }
93
94 void ClipDurationDialog::slotCheckCrop() {
95     int dur = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
96     int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
97     GenTime duration(dur, m_fps);
98     GenTime cropStart(crop, m_fps);
99     GenTime maxDuration = m_clip->maxDuration();
100     if (cropStart + duration > maxDuration) {
101         m_view.crop_position->setText(m_tc.getTimecode(maxDuration - duration, m_fps));
102     }
103 }
104
105 void ClipDurationDialog::slotPosUp() {
106     int position = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
107     //if (duration >= m_clip->duration().frames(m_fps)) return;
108     position ++;
109     m_view.clip_position->setText(m_tc.getTimecode(GenTime(position, m_fps), m_fps));
110 }
111
112 void ClipDurationDialog::slotPosDown() {
113     int position = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
114     //if (duration >= m_clip->duration().frames(m_fps)) return;
115     position --;
116     m_view.clip_position->setText(m_tc.getTimecode(GenTime(position, m_fps), m_fps));
117 }
118
119 void ClipDurationDialog::slotDurUp() {
120     int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
121     int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
122     if (duration + crop > m_clip->maxDuration().frames(m_fps)) return;
123     duration ++;
124     m_view.clip_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
125 }
126
127 void ClipDurationDialog::slotDurDown() {
128     int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
129     if (duration <= 0) return;
130     duration --;
131     m_view.clip_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
132 }
133
134 void ClipDurationDialog::slotCropUp() {
135     int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
136     int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
137     if (duration + crop > m_clip->maxDuration().frames(m_fps)) return;
138     crop ++;
139     m_view.crop_position->setText(m_tc.getTimecode(GenTime(crop, m_fps), m_fps));
140 }
141
142 void ClipDurationDialog::slotCropDown() {
143     int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
144     if (crop <= 0) return;
145     crop --;
146     m_view.crop_position->setText(m_tc.getTimecode(GenTime(crop, m_fps), m_fps));
147 }
148
149 GenTime ClipDurationDialog::startPos() const {
150     int pos = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
151     return GenTime(pos, m_fps);
152 }
153
154 GenTime ClipDurationDialog::cropStart() const {
155     int pos = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
156     return GenTime(pos, m_fps);
157 }
158
159 GenTime ClipDurationDialog::duration() const {
160     int pos = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
161     return GenTime(pos, m_fps);
162 }
163
164 void ClipDurationDialog::wheelEvent(QWheelEvent * event) {
165     if (m_view.clip_position->underMouse()) {
166         if (event->delta() > 0)
167             slotPosUp();
168         else
169             slotPosDown();
170     } else if (m_view.clip_duration->underMouse()) {
171         if (event->delta() > 0)
172             slotDurUp();
173         else
174             slotDurDown();
175     } else if (m_view.crop_position->underMouse()) {
176         if (event->delta() > 0)
177             slotCropUp();
178         else
179             slotCropDown();
180     }
181 }
182
183 #include "clipdurationdialog.moc"
184
185