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 ***************************************************************************/
21 #include "markerdialog.h"
23 #include "kdenlivesettings.h"
25 #include <QWheelEvent>
29 MarkerDialog::MarkerDialog(DocClipBase *clip, CommentedTime t, Timecode tc, const QString &caption, QWidget * parent) :
36 setFont(KGlobalSettings::toolBarFont());
39 setWindowTitle(caption);
40 m_previewTimer = new QTimer(this);
43 m_previewTimer->setInterval(500);
44 connect(m_previewTimer, SIGNAL(timeout()), this, SLOT(slotUpdateThumb()));
45 m_profile = new Mlt::Profile((char*) KdenliveSettings::current_profile().data());
46 m_dar = m_profile->dar();
48 QDomElement mlt = doc.createElement("mlt");
49 QDomElement play = doc.createElement("mlt");
51 mlt.appendChild(play);
52 play.appendChild(doc.importNode(clip->toXML(), true));
53 //char *tmp = doc.toString().toUtf8().data();
54 m_producer = new Mlt::Producer(*m_profile, "xml-string", doc.toString().toUtf8().data());
56 int width = 100.0 * m_dar;
57 if (width % 2 == 1) width++;
58 QPixmap p(width, 100);
59 QString colour = clip->getProperty("colour");
60 switch (m_clip->clipType()) {
65 connect(this, SIGNAL(updateThumb()), m_previewTimer, SLOT(start()));
68 p = QPixmap::fromImage(KThumb::getFrame(m_producer, t.time().frames(m_fps), width, 100));
71 colour = colour.replace(0, 2, "#");
72 p.fill(QColor(colour.left(7)));
78 clip_thumb->setFixedWidth(p.width());
79 clip_thumb->setFixedHeight(p.height());
80 clip_thumb->setPixmap(p);
82 connect(marker_position, SIGNAL(textChanged(const QString &)), this, SIGNAL(updateThumb()));
83 } else clip_thumb->setHidden(true);
85 if (KdenliveSettings::frametimecode()) {
86 marker_position->setInputMask("000000000000");
87 marker_position->setText(QString::number((int) t.time().frames(m_fps)));
88 } else marker_position->setText(tc.getTimecode(t.time()));
90 marker_comment->setText(t.comment());
91 marker_comment->selectAll();
92 marker_comment->setFocus();
94 connect(position_up, SIGNAL(clicked()), this, SLOT(slotTimeUp()));
95 connect(position_down, SIGNAL(clicked()), this, SLOT(slotTimeDown()));
100 MarkerDialog::~MarkerDialog()
102 delete m_previewTimer;
107 void MarkerDialog::slotUpdateThumb()
109 m_previewTimer->stop();
111 if (KdenliveSettings::frametimecode()) pos = marker_position->text().toInt();
112 else pos = m_tc.getFrameCount(marker_position->text());
113 int width = 100.0 * m_dar;
114 if (width % 2 == 1) width++;
115 QPixmap p = QPixmap::fromImage(KThumb::getFrame(m_producer, pos, width, 100));
116 if (!p.isNull()) clip_thumb->setPixmap(p);
117 else kDebug() << "!!!!!!!!!!! ERROR CREATING THUMB";
120 void MarkerDialog::slotTimeUp()
123 if (KdenliveSettings::frametimecode()) duration = marker_position->text().toInt();
124 else duration = m_tc.getFrameCount(marker_position->text());
125 if (m_clip && duration >= m_clip->duration().frames(m_fps)) return;
127 if (KdenliveSettings::frametimecode()) marker_position->setText(QString::number(duration));
128 else marker_position->setText(m_tc.getTimecode(GenTime(duration, m_fps)));
131 void MarkerDialog::slotTimeDown()
134 if (KdenliveSettings::frametimecode()) duration = marker_position->text().toInt();
135 else duration = m_tc.getFrameCount(marker_position->text());
136 if (duration <= 0) return;
138 if (KdenliveSettings::frametimecode()) marker_position->setText(QString::number(duration));
139 else marker_position->setText(m_tc.getTimecode(GenTime(duration, m_fps)));
142 CommentedTime MarkerDialog::newMarker()
144 if (KdenliveSettings::frametimecode()) return CommentedTime(GenTime(marker_position->text().toInt(), m_fps), marker_comment->text());
145 return CommentedTime(GenTime(m_tc.getFrameCount(marker_position->text()), m_fps), marker_comment->text());
148 void MarkerDialog::wheelEvent(QWheelEvent * event)
150 if (marker_position->underMouse() || clip_thumb->underMouse()) {
151 if (event->delta() > 0)
158 #include "markerdialog.moc"