]> git.sesse.net Git - kdenlive/blob - src/markerdialog.cpp
Reindent the codebase using 'linux' bracket placement.
[kdenlive] / src / markerdialog.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 "markerdialog.h"
22 #include "kthumb.h"
23 #include "kdenlivesettings.h"
24
25 #include <QWheelEvent>
26 #include <KDebug>
27
28
29 MarkerDialog::MarkerDialog(DocClipBase *clip, CommentedTime t, Timecode tc, const QString &caption, QWidget * parent): QDialog(parent), m_tc(tc), m_clip(clip), m_marker(t), m_producer(NULL), m_profile(NULL)
30 {
31     setFont(KGlobalSettings::toolBarFont());
32     m_fps = m_tc.fps();
33     m_view.setupUi(this);
34     setWindowTitle(caption);
35     m_previewTimer = new QTimer(this);
36
37     if (m_clip != NULL) {
38         m_previewTimer->setInterval(500);
39         connect(m_previewTimer, SIGNAL(timeout()), this, SLOT(slotUpdateThumb()));
40         m_profile = new Mlt::Profile((char*) KdenliveSettings::current_profile().data());
41         m_dar = m_profile->dar();
42         QDomDocument doc;
43         QDomElement westley = doc.createElement("westley");
44         QDomElement play = doc.createElement("playlist");
45         doc.appendChild(westley);
46         westley.appendChild(play);
47         play.appendChild(doc.importNode(clip->toXML(), true));
48         //char *tmp = doc.toString().toUtf8().data();
49         m_producer = new Mlt::Producer(*m_profile, "westley-xml", doc.toString().toUtf8().data());
50         //delete[] tmp;
51
52         QPixmap p((int)(100 * m_dar), 100);
53         QString colour = clip->getProperty("colour");
54         switch (m_clip->clipType()) {
55         case VIDEO:
56         case AV:
57         case SLIDESHOW:
58         case PLAYLIST:
59             connect(this, SIGNAL(updateThumb()), m_previewTimer, SLOT(start()));
60         case IMAGE:
61         case TEXT:
62             p = KThumb::getFrame(m_producer, t.time().frames(m_fps), (int)(100 * m_dar), 100);
63             break;
64         case COLOR:
65             colour = colour.replace(0, 2, "#");
66             p.fill(QColor(colour.left(7)));
67             break;
68         default:
69             p.fill(Qt::black);
70         }
71         if (!p.isNull()) {
72             m_view.clip_thumb->setFixedWidth(p.width());
73             m_view.clip_thumb->setFixedHeight(p.height());
74             m_view.clip_thumb->setPixmap(p);
75         }
76         connect(m_view.marker_position, SIGNAL(textChanged(const QString &)), this, SIGNAL(updateThumb()));
77     } else m_view.clip_thumb->setHidden(true);
78
79     m_view.marker_position->setText(tc.getTimecode(t.time(), m_fps));
80
81     m_view.marker_comment->setText(t.comment());
82     m_view.marker_comment->selectAll();
83     m_view.marker_comment->setFocus();
84
85     connect(m_view.position_up, SIGNAL(clicked()), this, SLOT(slotTimeUp()));
86     connect(m_view.position_down, SIGNAL(clicked()), this, SLOT(slotTimeDown()));
87
88     adjustSize();
89 }
90
91 MarkerDialog::~MarkerDialog()
92 {
93     delete m_previewTimer;
94     if (m_producer) delete m_producer;
95     if (m_profile) delete m_profile;
96 }
97
98 void MarkerDialog::slotUpdateThumb()
99 {
100     m_previewTimer->stop();
101     int pos = m_tc.getFrameCount(m_view.marker_position->text(), m_fps);
102     QPixmap p = KThumb::getFrame(m_producer, pos, (int)(100 * m_dar), 100);
103     if (!p.isNull()) m_view.clip_thumb->setPixmap(p);
104     else kDebug() << "!!!!!!!!!!!  ERROR CREATING THUMB";
105 }
106
107 void MarkerDialog::slotTimeUp()
108 {
109     int duration = m_tc.getFrameCount(m_view.marker_position->text(), m_fps);
110     if (m_clip && duration >= m_clip->duration().frames(m_fps)) return;
111     duration ++;
112     m_view.marker_position->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
113 }
114
115 void MarkerDialog::slotTimeDown()
116 {
117     int duration = m_tc.getFrameCount(m_view.marker_position->text(), m_fps);
118     if (duration <= 0) return;
119     duration --;
120     m_view.marker_position->setText(m_tc.getTimecode(GenTime(duration, m_fps), m_fps));
121 }
122
123 CommentedTime MarkerDialog::newMarker()
124 {
125     return CommentedTime(GenTime(m_tc.getFrameCount(m_view.marker_position->text(), m_fps), m_fps), m_view.marker_comment->text());
126 }
127
128 void MarkerDialog::wheelEvent(QWheelEvent * event)
129 {
130     if (m_view.marker_position->underMouse() || m_view.clip_thumb->underMouse()) {
131         if (event->delta() > 0)
132             slotTimeUp();
133         else
134             slotTimeDown();
135     }
136 }
137
138 #include "markerdialog.moc"
139
140