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