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