]> git.sesse.net Git - kdenlive/blob - src/markerdialog.cpp
Try to fix timecode error:
[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) :
30         QDialog(parent),
31         m_producer(NULL),
32         m_profile(NULL),
33         m_clip(clip)
34 {
35     setFont(KGlobalSettings::toolBarFont());
36     setupUi(this);
37     setWindowTitle(caption);
38
39     m_in = new TimecodeDisplay(tc, this);
40     inputLayout->addWidget(m_in);
41     m_in->setValue(t.time());
42
43     m_previewTimer = new QTimer(this);
44
45     if (m_clip != NULL) {
46         m_in->setRange(0, m_clip->duration().frames(tc.fps()));
47         m_previewTimer->setInterval(500);
48         connect(m_previewTimer, SIGNAL(timeout()), this, SLOT(slotUpdateThumb()));
49         m_profile = new Mlt::Profile((char*) KdenliveSettings::current_profile().data());
50         m_dar = m_profile->dar();
51         QDomDocument doc;
52         QDomElement mlt = doc.createElement("mlt");
53         QDomElement play = doc.createElement("mlt");
54         doc.appendChild(mlt);
55         mlt.appendChild(play);
56         play.appendChild(doc.importNode(clip->toXML(), true));
57         //char *tmp = doc.toString().toUtf8().data();
58         m_producer = new Mlt::Producer(*m_profile, "xml-string", doc.toString().toUtf8().data());
59         //delete[] tmp;
60         int width = 100.0 * m_dar;
61         if (width % 2 == 1) width++;
62         QPixmap p(width, 100);
63         QString colour = clip->getProperty("colour");
64
65         switch (m_clip->clipType()) {
66         case VIDEO:
67         case AV:
68         case SLIDESHOW:
69         case PLAYLIST:
70             connect(this, SIGNAL(updateThumb()), m_previewTimer, SLOT(start()));
71         case IMAGE:
72         case TEXT:
73             p = QPixmap::fromImage(KThumb::getFrame(m_producer, m_in->getValue(), width, 100));
74             break;
75         case COLOR:
76             colour = colour.replace(0, 2, "#");
77             p.fill(QColor(colour.left(7)));
78             break;
79         default:
80             p.fill(Qt::black);
81         }
82
83         if (!p.isNull()) {
84             clip_thumb->setFixedWidth(p.width());
85             clip_thumb->setFixedHeight(p.height());
86             clip_thumb->setPixmap(p);
87         }
88         connect(m_in, SIGNAL(editingFinished()), this, SIGNAL(updateThumb()));
89     } else {
90         clip_thumb->setHidden(true);
91     }
92
93     marker_comment->setText(t.comment());
94     marker_comment->selectAll();
95     marker_comment->setFocus();
96
97     adjustSize();
98 }
99
100 MarkerDialog::~MarkerDialog()
101 {
102     delete m_previewTimer;
103     delete m_producer;
104     delete m_profile;
105 }
106
107 void MarkerDialog::slotUpdateThumb()
108 {
109     m_previewTimer->stop();
110     int pos = m_in->getValue();
111     int width = 100.0 * m_dar;
112     if (width % 2 == 1) width++;
113     QPixmap p = QPixmap::fromImage(KThumb::getFrame(m_producer, pos, width, 100));
114     if (!p.isNull())
115         clip_thumb->setPixmap(p);
116     else
117         kDebug() << "!!!!!!!!!!!  ERROR CREATING THUMB";
118 }
119
120 CommentedTime MarkerDialog::newMarker()
121 {
122     return CommentedTime(m_in->gentime(), marker_comment->text());
123 }
124
125 #include "markerdialog.moc"
126
127