]> git.sesse.net Git - kdenlive/blob - src/markerdialog.cpp
* Fix aspect ratio of thumbnails to correctly use the project's arpect ratio
[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 {
35     setFont(KGlobalSettings::toolBarFont());
36     setupUi(this);
37     setWindowTitle(caption);
38
39     m_in = new TimecodeDisplay(tc, this);
40     inputLayout->addWidget(m_in);
41     m_in->setValue(t.time());
42
43     m_previewTimer = new QTimer(this);
44
45     if (m_clip != NULL) {
46         m_in->setRange(0, m_clip->duration().frames(tc.fps()));
47         m_previewTimer->setInterval(500);
48         connect(m_previewTimer, SIGNAL(timeout()), this, SLOT(slotUpdateThumb()));
49         m_profile = new Mlt::Profile((char*) KdenliveSettings::current_profile().data());
50         m_dar = m_profile->dar();
51         QDomDocument doc;
52         QDomElement mlt = doc.createElement("mlt");
53         QDomElement play = doc.createElement("mlt");
54         doc.appendChild(mlt);
55         mlt.appendChild(play);
56         play.appendChild(doc.importNode(clip->toXML(), true));
57         //char *tmp = doc.toString().toUtf8().data();
58         m_producer = new Mlt::Producer(*m_profile, "xml-string", doc.toString().toUtf8().data());
59         //delete[] tmp;
60         int width = 100.0 * m_dar;
61         if (width % 2 == 1) width++;
62         QPixmap p(width, 100);
63         QString colour = clip->getProperty("colour");
64         int swidth = (int) (100.0 * m_profile->width() / m_profile->height() + 0.5);
65
66         switch (m_clip->clipType()) {
67         case VIDEO:
68         case AV:
69         case SLIDESHOW:
70         case PLAYLIST:
71             connect(this, SIGNAL(updateThumb()), m_previewTimer, SLOT(start()));
72         case IMAGE:
73         case TEXT:
74             p = QPixmap::fromImage(KThumb::getFrame(m_producer, m_in->getValue(), swidth, width, 100));
75             break;
76         case COLOR:
77             colour = colour.replace(0, 2, "#");
78             p.fill(QColor(colour.left(7)));
79             break;
80         default:
81             p.fill(Qt::black);
82         }
83
84         if (!p.isNull()) {
85             clip_thumb->setFixedWidth(p.width());
86             clip_thumb->setFixedHeight(p.height());
87             clip_thumb->setPixmap(p);
88         }
89         connect(m_in, SIGNAL(editingFinished()), this, SIGNAL(updateThumb()));
90     } else {
91         clip_thumb->setHidden(true);
92     }
93
94     marker_comment->setText(t.comment());
95     marker_comment->selectAll();
96     marker_comment->setFocus();
97
98     adjustSize();
99 }
100
101 MarkerDialog::~MarkerDialog()
102 {
103     delete m_previewTimer;
104     delete m_producer;
105     delete m_profile;
106 }
107
108 void MarkerDialog::slotUpdateThumb()
109 {
110     m_previewTimer->stop();
111     int pos = m_in->getValue();
112     int width = 100.0 * m_dar;
113     int swidth = (int) (100.0 * m_profile->width() / m_profile->height() + 0.5);
114     if (width % 2 == 1) width++;
115     QPixmap p = QPixmap::fromImage(KThumb::getFrame(m_producer, pos, swidth, width, 100));
116     if (!p.isNull())
117         clip_thumb->setPixmap(p);
118     else
119         kDebug() << "!!!!!!!!!!!  ERROR CREATING THUMB";
120 }
121
122 CommentedTime MarkerDialog::newMarker()
123 {
124     return CommentedTime(m_in->gentime(), marker_comment->text());
125 }
126
127 #include "markerdialog.moc"
128
129