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