]> git.sesse.net Git - kdenlive/blob - src/markerdialog.cpp
64bc1ee9eeeb8eca84cc4f30a57c62f1bb2f83fc
[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         m_frameDisplay(KdenliveSettings::frametimecode())
36 {
37     setFont(KGlobalSettings::toolBarFont());
38     m_fps = m_tc.fps();
39     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 mlt = doc.createElement("mlt");
50         QDomElement play = doc.createElement("mlt");
51         doc.appendChild(mlt);
52         mlt.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, "xml-string", doc.toString().toUtf8().data());
56         //delete[] tmp;
57         int width = 100.0 * m_dar;
58         if (width % 2 == 1) width++;
59         QPixmap p(width, 100);
60         QString colour = clip->getProperty("colour");
61         switch (m_clip->clipType()) {
62         case VIDEO:
63         case AV:
64         case SLIDESHOW:
65         case PLAYLIST:
66             connect(this, SIGNAL(updateThumb()), m_previewTimer, SLOT(start()));
67         case IMAGE:
68         case TEXT:
69             p = QPixmap::fromImage(KThumb::getFrame(m_producer, t.time().frames(m_fps), width, 100));
70             break;
71         case COLOR:
72             colour = colour.replace(0, 2, "#");
73             p.fill(QColor(colour.left(7)));
74             break;
75         default:
76             p.fill(Qt::black);
77         }
78         if (!p.isNull()) {
79             clip_thumb->setFixedWidth(p.width());
80             clip_thumb->setFixedHeight(p.height());
81             clip_thumb->setPixmap(p);
82         }
83         connect(marker_position, SIGNAL(textChanged(const QString &)), this, SIGNAL(updateThumb()));
84     } else clip_thumb->setHidden(true);
85
86     if (m_frameDisplay) {
87         QValidator *valid = new QIntValidator(this);
88         marker_position->setInputMask("");
89         marker_position->setValidator(valid);
90     }
91     marker_position->setText(tc.getDisplayTimecode(t.time(), m_frameDisplay));
92
93     marker_comment->setText(t.comment());
94     marker_comment->selectAll();
95     marker_comment->setFocus();
96
97     connect(position_up, SIGNAL(clicked()), this, SLOT(slotTimeUp()));
98     connect(position_down, SIGNAL(clicked()), this, SLOT(slotTimeDown()));
99
100     adjustSize();
101 }
102
103 MarkerDialog::~MarkerDialog()
104 {
105     delete m_previewTimer;
106     delete m_producer;
107     delete m_profile;
108 }
109
110 void MarkerDialog::slotUpdateThumb()
111 {
112     m_previewTimer->stop();
113     int pos = m_tc.getDisplayFrameCount(marker_position->text(), m_frameDisplay);
114     int width = 100.0 * m_dar;
115     if (width % 2 == 1) width++;
116     QPixmap p = QPixmap::fromImage(KThumb::getFrame(m_producer, pos, width, 100));
117     if (!p.isNull()) clip_thumb->setPixmap(p);
118     else kDebug() << "!!!!!!!!!!!  ERROR CREATING THUMB";
119 }
120
121 void MarkerDialog::slotTimeUp()
122 {
123     int duration = m_tc.getDisplayFrameCount(marker_position->text(), m_frameDisplay);
124     if (m_clip && duration >= m_clip->duration().frames(m_fps)) return;
125     duration ++;
126     marker_position->setText(m_tc.getDisplayTimecode(GenTime(duration, m_fps), m_frameDisplay));
127 }
128
129 void MarkerDialog::slotTimeDown()
130 {
131     int duration = m_tc.getDisplayFrameCount(marker_position->text(), m_frameDisplay);
132     if (duration <= 0) return;
133     duration --;
134     marker_position->setText(m_tc.getDisplayTimecode(GenTime(duration, m_fps), m_frameDisplay));
135 }
136
137 CommentedTime MarkerDialog::newMarker()
138 {
139     return CommentedTime(GenTime(m_tc.getDisplayFrameCount(marker_position->text(), m_frameDisplay), m_fps), marker_comment->text());
140 }
141
142 void MarkerDialog::wheelEvent(QWheelEvent * event)
143 {
144     if (marker_position->underMouse() || clip_thumb->underMouse()) {
145         if (event->delta() > 0)
146             slotTimeUp();
147         else
148             slotTimeDown();
149     }
150 }
151
152 #include "markerdialog.moc"
153
154