]> git.sesse.net Git - kdenlive/blob - src/markerdialog.cpp
Cleaning code style of Definitions.
[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, const CommentedTime &t, const Timecode &tc, const QString &caption, QWidget * parent)
30     : QDialog(parent)
31     , m_producer(NULL)
32     , m_profile(NULL)
33     , m_clip(clip)
34     , m_dar(4.0 / 3.0)
35 {
36     setFont(KGlobalSettings::toolBarFont());
37     setupUi(this);
38     setWindowTitle(caption);
39
40     // Set  up categories
41     for (int i = 0; i < 5; ++i) {
42         marker_type->insertItem(i, i18n("Category %1", i));
43         marker_type->setItemData(i, CommentedTime::markerColor(i), Qt::DecorationRole);
44     }
45     marker_type->setCurrentIndex(t.markerType());
46
47     m_in = new TimecodeDisplay(tc, this);
48     inputLayout->addWidget(m_in);
49     m_in->setValue(t.time());
50
51     m_previewTimer = new QTimer(this);
52
53     if (m_clip != NULL) {
54         m_in->setRange(0, m_clip->duration().frames(tc.fps()));
55         m_previewTimer->setInterval(500);
56         connect(m_previewTimer, SIGNAL(timeout()), this, SLOT(slotUpdateThumb()));
57         m_profile = new Mlt::Profile((char*) KdenliveSettings::current_profile().data());
58         m_dar = m_profile->dar();
59         QDomDocument doc;
60         QDomElement mlt = doc.createElement("mlt");
61         QDomElement play = doc.createElement("mlt");
62         doc.appendChild(mlt);
63         mlt.appendChild(play);
64         play.appendChild(doc.importNode(clip->toXML(), true));
65         //char *tmp = doc.toString().toUtf8().data();
66         m_producer = new Mlt::Producer(*m_profile, "xml-string", doc.toString().toUtf8().data());
67         //delete[] tmp;
68         int width = Kdenlive::DefaultThumbHeight * m_dar;
69         if (width % 2 == 1) width++;
70         QPixmap p(width, 100);
71         QString colour = clip->getProperty("colour");
72         int swidth = (int) (Kdenlive::DefaultThumbHeight * m_profile->width() / m_profile->height() + 0.5);
73
74         switch (m_clip->clipType()) {
75         case Video:
76         case AV:
77         case SlideShow:
78         case Playlist:
79             connect(this, SIGNAL(updateThumb()), m_previewTimer, SLOT(start()));
80             break;
81         case Image:
82         case Text:
83             m_image = KThumb::getFrame(m_producer, m_in->getValue(), swidth, width, Kdenlive::DefaultThumbHeight);
84             p = QPixmap::fromImage(m_image);
85             break;
86         case Color:
87             colour = colour.replace(0, 2, "#");
88             p.fill(QColor(colour.left(7)));
89             break;
90         //UNKNOWN, AUDIO, VIRTUAL:
91         default:
92             p.fill(Qt::black);
93         }
94
95         if (!p.isNull()) {
96             clip_thumb->setFixedWidth(p.width());
97             clip_thumb->setFixedHeight(p.height());
98             clip_thumb->setPixmap(p);
99         }
100         connect(m_in, SIGNAL(timeCodeEditingFinished()), this, SIGNAL(updateThumb()));
101     } else {
102         clip_thumb->setHidden(true);
103         label_category->setHidden(true);
104         marker_type->setHidden(true);
105     }
106
107     marker_comment->setText(t.comment());
108     marker_comment->selectAll();
109     marker_comment->setFocus();
110
111     adjustSize();
112 }
113
114 MarkerDialog::~MarkerDialog()
115 {
116     delete m_previewTimer;
117     delete m_producer;
118     delete m_profile;
119 }
120
121 void MarkerDialog::slotUpdateThumb()
122 {
123     m_previewTimer->stop();
124     int pos = m_in->getValue();
125     int width = 100.0 * m_dar;
126     int swidth = (int) (100.0 * m_profile->width() / m_profile->height() + 0.5);
127     if (width % 2 == 1)
128         width++;
129
130     m_image = KThumb::getFrame(m_producer, pos, swidth, width, 100);
131     const QPixmap p = QPixmap::fromImage(m_image);
132     if (!p.isNull())
133         clip_thumb->setPixmap(p);
134     else
135         kDebug() << "!!!!!!!!!!!  ERROR CREATING THUMB";
136 }
137
138 QImage MarkerDialog::markerImage() const
139 {
140     return m_image;
141 }
142
143 CommentedTime MarkerDialog::newMarker()
144 {
145     KdenliveSettings::setDefault_marker_type(marker_type->currentIndex());
146     return CommentedTime(m_in->gentime(), marker_comment->text(), marker_type->currentIndex());
147 }
148
149 #include "markerdialog.moc"
150
151