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