]> git.sesse.net Git - kdenlive/blob - src/spacerdialog.cpp
c0756fc7d18386618ba0f2f00848bea32c3ae7f7
[kdenlive] / src / spacerdialog.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 "spacerdialog.h"
22 #include "kthumb.h"
23 #include "kdenlivesettings.h"
24
25 #include <QWheelEvent>
26 #include <KDebug>
27
28
29 SpacerDialog::SpacerDialog(const GenTime duration, Timecode tc, int track, int trackNumber, QWidget * parent) :
30         QDialog(parent),
31         m_tc(tc)
32 {
33     setFont(KGlobalSettings::toolBarFont());
34     m_fps = m_tc.fps();
35     m_view.setupUi(this);
36     m_view.space_duration->setText(tc.getTimecode(duration, m_fps));
37     QStringList tracks;
38     tracks << i18n("All tracks");
39     for (int i = 0; i < trackNumber - 1; i++) {
40         tracks << QString::number(i);
41     }
42     m_view.track_number->addItems(tracks);
43     m_view.track_number->setCurrentIndex(track);
44
45     connect(m_view.position_up, SIGNAL(clicked()), this, SLOT(slotTimeUp()));
46     connect(m_view.position_down, SIGNAL(clicked()), this, SLOT(slotTimeDown()));
47
48     adjustSize();
49 }
50
51 SpacerDialog::~SpacerDialog()
52 {
53 }
54
55 void SpacerDialog::slotTimeUp()
56 {
57     int duration = m_tc.getFrameCount(m_view.space_duration->text(), m_fps);
58     duration ++;
59     m_view.space_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
60 }
61
62 void SpacerDialog::slotTimeDown()
63 {
64     int duration = m_tc.getFrameCount(m_view.space_duration->text(), m_fps);
65     if (duration <= 0) return;
66     duration --;
67     m_view.space_duration->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
68 }
69
70 GenTime SpacerDialog::selectedDuration()
71 {
72     return GenTime(m_tc.getFrameCount(m_view.space_duration->text(), m_fps), m_fps);
73 }
74
75 void SpacerDialog::wheelEvent(QWheelEvent * event)
76 {
77     if (m_view.space_duration->underMouse()) {
78         if (event->delta() > 0)
79             slotTimeUp();
80         else
81             slotTimeDown();
82     }
83 }
84
85 int SpacerDialog::selectedTrack()
86 {
87     return m_view.track_number->currentIndex() - 1;
88 }
89
90 #include "spacerdialog.moc"
91
92