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