]> git.sesse.net Git - kdenlive/blob - src/clipdurationdialog.cpp
Fix clip and transition move / resize through the double click move / resize widget
[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 <KDebug>
22
23 #include "clipdurationdialog.h"
24 #include "kdenlivesettings.h"
25 #include <QWheelEvent>
26
27 ClipDurationDialog::ClipDurationDialog(AbstractClipItem *clip, Timecode tc, QWidget * parent): QDialog(parent), m_tc(tc), m_clip(clip) {
28     setFont(KGlobalSettings::toolBarFont());
29     m_fps = m_tc.fps();
30     m_view.setupUi(this);
31
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();
37     }
38
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()));
48
49     adjustSize();
50 }
51
52 ClipDurationDialog::~ClipDurationDialog() {
53 }
54
55 void ClipDurationDialog::setMargins(GenTime min, GenTime max) {
56     m_min = min;
57     m_max = max;
58     connect(m_view.clip_position, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckStart()));
59     connect(m_view.clip_duration, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckDuration()));
60 }
61
62 void ClipDurationDialog::slotCheckStart() {
63     int pos = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
64     int dur = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
65     GenTime start(pos, m_fps);
66     GenTime duration(dur, m_fps);
67     if (start < m_min) {
68         m_view.clip_position->setText(m_tc.getTimecode(m_min, m_fps));
69     } else if (start + duration > m_max) {
70         m_view.clip_position->setText(m_tc.getTimecode(m_max - duration, m_fps));
71     }
72 }
73
74 void ClipDurationDialog::slotCheckDuration() {
75     int pos = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
76     int dur = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
77     GenTime start(pos, m_fps);
78     GenTime duration(dur, m_fps);
79     if (start + duration > m_max) {
80         m_view.clip_duration->setText(m_tc.getTimecode(m_max - start, m_fps));
81     }
82 }
83
84 void ClipDurationDialog::slotPosUp() {
85     int position = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
86     //if (duration >= m_clip->duration().frames(m_fps)) return;
87     position ++;
88     m_view.clip_position->setText(m_tc.getTimecode(GenTime(position, m_fps), m_fps));
89 }
90
91 void ClipDurationDialog::slotPosDown() {
92     int position = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
93     //if (duration >= m_clip->duration().frames(m_fps)) return;
94     position --;
95     m_view.clip_position->setText(m_tc.getTimecode(GenTime(position, m_fps), m_fps));
96 }
97
98 void ClipDurationDialog::slotDurUp() {
99     int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
100     int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
101     if (duration + crop > m_clip->maxDuration().frames(m_fps)) return;
102     duration ++;
103     m_view.clip_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
104 }
105
106 void ClipDurationDialog::slotDurDown() {
107     int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
108     if (duration <= 0) return;
109     duration --;
110     m_view.clip_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
111 }
112
113 void ClipDurationDialog::slotCropUp() {
114     int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
115     int duration = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
116     if (duration + crop > m_clip->maxDuration().frames(m_fps)) return;
117     crop ++;
118     m_view.crop_position->setText(m_tc.getTimecode(GenTime(crop, m_fps), m_fps));
119 }
120
121 void ClipDurationDialog::slotCropDown() {
122     int crop = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
123     if (crop <= 0) return;
124     crop --;
125     m_view.crop_position->setText(m_tc.getTimecode(GenTime(crop, m_fps), m_fps));
126 }
127
128 GenTime ClipDurationDialog::startPos() const {
129     int pos = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
130     return GenTime(pos, m_fps);
131 }
132
133 GenTime ClipDurationDialog::cropStart() const {
134     int pos = m_tc.getFrameCount(m_view.crop_position->text(), m_fps);
135     return GenTime(pos, m_fps);
136 }
137
138 GenTime ClipDurationDialog::duration() const {
139     int pos = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
140     return GenTime(pos, m_fps);
141 }
142
143 void ClipDurationDialog::wheelEvent(QWheelEvent * event) {
144     if (m_view.clip_position->underMouse()) {
145         if (event->delta() > 0)
146             slotPosUp();
147         else
148             slotPosDown();
149     } else if (m_view.clip_duration->underMouse()) {
150         if (event->delta() > 0)
151             slotDurUp();
152         else
153             slotDurDown();
154     } else if (m_view.crop_position->underMouse()) {
155         if (event->delta() > 0)
156             slotCropUp();
157         else
158             slotCropDown();
159     }
160 }
161
162 #include "clipdurationdialog.moc"
163
164