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