start of the clip tracks view

svn path=/branches/KDE4/; revision=1790
parent e44b49b3
......@@ -39,6 +39,8 @@ set(kdenlive_SRCS
timecode.cpp
monitormanager.cpp
documenttrack.cpp
documentvideotrack.cpp
documentaudiotrack.cpp
headertrack.cpp
)
......
......@@ -50,8 +50,7 @@
#define END_LABEL_X 4
#define END_LABEL_Y (END_LABEL_X + LABEL_SIZE - 2)
#define FRAME_SIZE 90
#include "definitions.h"
const int CustomRuler::comboScale[] =
{ 1, 2, 5, 10, 25, 50, 125, 250, 500, 725, 1500, 3000, 6000,
......
#include <QMouseEvent>
#include <QStylePainter>
#include <KDebug>
#include <QFrame>
#include <QWidget>
#include <QPainter>
#include "documentaudiotrack.h"
DocumentAudioTrack::DocumentAudioTrack(QDomElement xml, TrackView * view, QWidget *parent)
: DocumentTrack(xml, view, parent), m_trackView(view)
{
setFixedHeight(50);
}
// virtual
void DocumentAudioTrack::paintEvent(QPaintEvent *e )
{
QRect region = e->rect();
QPainter painter(this);
painter.fillRect(region, QBrush(Qt::green));
painter.drawLine(region.bottomLeft (), region.bottomRight ());
}
#include "documentaudiotrack.moc"
#ifndef DOCUMENTAUDIOTRACK_H
#define DOCUMENTAUDIOTRACK_H
#include "documenttrack.h"
#include "trackview.h"
class DocumentAudioTrack : public DocumentTrack
{
Q_OBJECT
public:
DocumentAudioTrack(QDomElement xml, TrackView * view, QWidget *parent=0);
protected:
virtual void paintEvent(QPaintEvent * /*e*/);
private:
TrackView *m_trackView;
public slots:
};
#endif
......@@ -10,10 +10,48 @@
#include "documenttrack.h"
DocumentTrack::DocumentTrack(QWidget *parent)
: QWidget(parent)
DocumentTrack::DocumentTrack(QDomElement xml, TrackView * view, QWidget *parent)
: QWidget(parent), m_xml(xml), m_trackDuration(0)
{
setFixedHeight(50);
parseXml();
}
void DocumentTrack::parseXml()
{
m_clipList.clear();
int position = 0;
for(QDomNode n = m_xml.firstChild(); !n.isNull(); n = n.nextSibling())
{
QDomElement elem = n.toElement();
if (elem.tagName() == "blank") {
position += elem.attribute("length", 0).toInt();
}
else if (elem.tagName() == "entry") {
TrackViewClip clip;
clip.startTime = position;
int in = elem.attribute("in", 0).toInt();
int out = elem.attribute("out", 0).toInt() - in;
clip.cropTime = in;
clip.duration = out;
position += out;
clip.producer = elem.attribute("producer", QString::null);
kDebug()<<"++++++++++++++\n\n / / /ADDING CLIP: "<<clip.cropTime<<", out: "<<clip.duration<<", Producer: "<<clip.producer<<"\n\n++++++++++++++++++++";
m_clipList.append(clip);
}
}
m_trackDuration = position;
}
int DocumentTrack::duration()
{
return m_trackDuration;
}
QList <TrackViewClip> DocumentTrack::clipList()
{
return m_clipList;
}
// virtual
......
#ifndef DOCUMENTTRACK_H
#define DOCUMENTTRACK_H
#include <QDomElement>
#include <QList>
class TrackView;
struct TrackViewClip {
int startTime;
int duration;
int cropTime;
QString producer;
};
class DocumentTrack : public QWidget
{
Q_OBJECT
public:
DocumentTrack(QWidget *parent=0);
DocumentTrack(QDomElement xml, TrackView * view, QWidget *parent=0);
QList <TrackViewClip> clipList();
int duration();
protected:
virtual void paintEvent(QPaintEvent * /*e*/);
private:
QDomElement m_xml;
QList <TrackViewClip> m_clipList;
void parseXml();
int m_trackDuration;
public slots:
......
#include <QMouseEvent>
#include <QStylePainter>
#include <KDebug>
#include <QFrame>
#include <QWidget>
#include <QPainter>
#include "documentvideotrack.h"
DocumentVideoTrack::DocumentVideoTrack(QDomElement xml, TrackView * view, QWidget *parent)
: DocumentTrack(xml, view, parent), m_trackView(view)
{
setFixedHeight(50);
}
// virtual
void DocumentVideoTrack::paintEvent(QPaintEvent *e )
{
QList <TrackViewClip> trackClipList = clipList();
double scale = m_trackView->zoomFactor();
QRect region = e->rect();
QPainter painter(this);
//painter.fillRect(region, QBrush(Qt::red));
painter.drawLine(region.bottomLeft (), region.bottomRight ());
for (int i = 0; i < trackClipList.size(); ++i) {
int start = (int) (trackClipList.at(i).startTime * scale);
int end = (int) (trackClipList.at(i).duration * scale);
QRect clipRect(start, region.top(), end, region.bottom());
QPainterPath path;
painter.setRenderHint(QPainter::Antialiasing);
painter.fillRect(clipRect, QBrush(Qt::red));
painter.drawRect(clipRect);
QRect textRect = painter.boundingRect ( clipRect, Qt::AlignCenter, " " + trackClipList.at(i).producer + " " );
painter.fillRect(textRect, QBrush(QColor(255, 255, 255, 100)));
painter.drawText(clipRect, Qt::AlignCenter, trackClipList.at(i).producer);
}
}
#include "documentvideotrack.moc"
#ifndef DOCUMENTVIDEOTRACK_H
#define DOCUMENTVIDEOTRACK_H
#include "documenttrack.h"
#include "trackview.h"
class DocumentVideoTrack : public DocumentTrack
{
Q_OBJECT
public:
DocumentVideoTrack(QDomElement xml, TrackView * view, QWidget *parent=0);
protected:
virtual void paintEvent(QPaintEvent * /*e*/);
private:
TrackView *m_trackView;
public slots:
};
#endif
......@@ -33,7 +33,8 @@
#include "kdenlivedoc.h"
KdenliveDoc::KdenliveDoc(KUrl url, double fps, int width, int height, QWidget *parent):QObject(parent), m_url(url), m_fps(fps), m_width(width), m_height(height), m_projectName(NULL)
KdenliveDoc::KdenliveDoc(KUrl url, double fps, int width, int height, QWidget *parent):QObject(parent), m_render(NULL), m_url(url), m_fps(fps), m_width(width), m_height(height), m_projectName(NULL)
{
if (!url.isEmpty()) {
QString tmpFile;
......@@ -52,7 +53,7 @@ KdenliveDoc::KdenliveDoc(KUrl url, double fps, int width, int height, QWidget *p
}
else {
// Creating new document
QDomElement westley = m_document.createElement("westley");
/*QDomElement westley = m_document.createElement("westley");
m_document.appendChild(westley);
QDomElement doc = m_document.createElement("kdenlivedoc");
doc.setAttribute("version", "0.6");
......@@ -61,7 +62,36 @@ KdenliveDoc::KdenliveDoc(KUrl url, double fps, int width, int height, QWidget *p
doc.setAttribute("width", m_width);
doc.setAttribute("height", m_height);
doc.setAttribute("projectfps", m_fps);
doc.appendChild(props);
doc.appendChild(props);*/
QDomElement westley = m_document.createElement("westley");
m_document.appendChild(westley);
QDomElement prod = m_document.createElement("producer");
prod.setAttribute("resource", "colour");
prod.setAttribute("colour", "red");
prod.setAttribute("id", "black");
prod.setAttribute("in", "0");
prod.setAttribute("out", "0");
QDomElement tractor = m_document.createElement("tractor");
QDomElement multitrack = m_document.createElement("multitrack");
QDomElement playlist1 = m_document.createElement("playlist");
playlist1.appendChild(prod);
multitrack.appendChild(playlist1);
QDomElement playlist2 = m_document.createElement("playlist");
multitrack.appendChild(playlist2);
QDomElement playlist3 = m_document.createElement("playlist");
multitrack.appendChild(playlist3);
QDomElement playlist4 = m_document.createElement("playlist");
playlist4.setAttribute("hide", "video");
multitrack.appendChild(playlist4);
QDomElement playlist5 = m_document.createElement("playlist");
playlist5.setAttribute("hide", "video");
multitrack.appendChild(playlist5);
tractor.appendChild(multitrack);
westley.appendChild(tractor);
}
if (fps == 30000.0 / 1001.0 ) m_timecode.setFormat(30, true);
......@@ -72,6 +102,20 @@ KdenliveDoc::~KdenliveDoc()
{
}
void KdenliveDoc::setRenderer(Render *render)
{
m_render = render;
if (m_render) m_render->setSceneList(m_document);
}
QDomDocument KdenliveDoc::generateSceneList()
{
QDomDocument doc;
QDomElement westley = doc.createElement("westley");
doc.appendChild(westley);
QDomElement prod = doc.createElement("producer");
}
QDomDocument KdenliveDoc::toXml()
{
return m_document;
......
......@@ -28,6 +28,7 @@
#include "gentime.h"
#include "timecode.h"
#include "renderer.h"
class KdenliveDoc:public QObject {
Q_OBJECT public:
......@@ -42,6 +43,7 @@ class KdenliveDoc:public QObject {
void setProducers(QDomElement doc);
Timecode timecode();
QDomDocument toXml();
void setRenderer(Render *render);
private:
KUrl m_url;
......@@ -51,6 +53,8 @@ class KdenliveDoc:public QObject {
int m_width;
int m_height;
Timecode m_timecode;
Render *m_render;
QDomDocument generateSceneList();
public slots:
......
......@@ -20,7 +20,6 @@
#include <mlt++/Mlt.h>
#include "mainwindow.h"
#include "trackview.h"
#include "kdenlivesettings.h"
#include "ui_configmisc_ui.h"
......@@ -83,12 +82,12 @@ MainWindow::MainWindow(QWidget *parent)
tabifyDockWidget (clipMonitorDock, projectMonitorDock);
connect(projectMonitorDock, SIGNAL(visibilityChanged (bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
connect(clipMonitorDock, SIGNAL(visibilityChanged (bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
connect(clipMonitorDock, SIGNAL(visibilityChanged (bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
connect(m_monitorManager, SIGNAL(connectMonitors ()), this, SLOT(slotConnectMonitors()));
connect(m_monitorManager, SIGNAL(raiseClipMonitor (bool)), this, SLOT(slotRaiseMonitor(bool)));
m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
newFile();
}
......@@ -153,14 +152,14 @@ void MainWindow::newFile()
TrackView *trackView = new TrackView(doc);
m_timelineArea->addTab(trackView, "New Project");
if (m_timelineArea->count() == 1)
connectDocument(doc);
connectDocument(trackView, doc);
}
void MainWindow::activateDocument()
{
TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
KdenliveDoc *currentDoc = currentTab->document();
connectDocument(currentDoc);
connectDocument(currentTab, currentDoc);
}
void MainWindow::saveFileAs(const QString &outputFileName)
......@@ -204,15 +203,20 @@ void MainWindow::openFile(const QString &inputFileName) //new
KdenliveDoc *doc = new KdenliveDoc(KUrl(inputFileName), 25, 720, 576);
TrackView *trackView = new TrackView(doc);
m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName()));
connectDocument(doc);
connectDocument(trackView, doc);
}
void MainWindow::connectDocument(KdenliveDoc *doc) //changed
void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //changed
{
if (m_activeDocument) m_activeDocument->setProducers(m_projectList->producersList());
//m_projectMonitor->stop();
if (m_activeDocument) {
m_activeDocument->setProducers(m_projectList->producersList());
m_activeDocument->setRenderer(NULL);
}
m_projectList->setDocument(doc);
m_monitorManager->setTimecode(doc->timecode());
doc->setRenderer(m_projectMonitor->render);
m_activeDocument = doc;
}
......
......@@ -12,6 +12,7 @@
#include "monitor.h"
#include "monitormanager.h"
#include "kdenlivedoc.h"
#include "trackview.h"
class MainWindow : public KXmlGuiWindow
{
......@@ -49,7 +50,7 @@ class MainWindow : public KXmlGuiWindow
private slots:
void newFile();
void activateDocument();
void connectDocument(KdenliveDoc*);
void connectDocument(TrackView*, KdenliveDoc*);
void openFile();
void saveFile();
void saveFileAs();
......
......@@ -24,13 +24,16 @@ void MonitorManager::initMonitors(Monitor *clipMonitor, Monitor *projectMonitor)
{
m_clipMonitor = clipMonitor;
m_projectMonitor = projectMonitor;
QTimer::singleShot(750, this, SLOT(initClipMonitor()));
//QTimer::singleShot(750, this, SLOT(initClipMonitor()));
initClipMonitor();
//initProjectMonitor();
}
void MonitorManager::initClipMonitor()
{
m_clipMonitor->initMonitor();
QTimer::singleShot(1500, this, SLOT(initProjectMonitor()));
// initProjectMonitor();
//QTimer::singleShot(1500, this, SLOT(initProjectMonitor()));
}
void MonitorManager::initProjectMonitor()
......
......@@ -144,8 +144,10 @@ void Render::createVideoXWindow(WId winid, WId externalMonitor)
m_mltConsumer->set("frequency", 48000);
m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
//m_mltConsumer->start();
initSceneList();
QTimer::singleShot(500, this, SLOT(initSceneList()));
//QTimer::singleShot(500, this, SLOT(initSceneList()));
//initSceneList();
// m_mltConsumer->listen("consumer-stopped", this, (mlt_listener) consumer_stopped);
// m_mltConsumer->set("buffer", 25);
......@@ -369,7 +371,7 @@ int Render::getLength()
if (m_mltProducer)
{
kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
// kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
return mlt_producer_get_playtime(m_mltProducer->get_producer());
}
return 0;
......@@ -515,7 +517,7 @@ void Render::initSceneList()
multitrack.appendChild(playlist5);
tractor.appendChild(multitrack);
westley.appendChild(tractor);
kDebug()<<doc.toString();
// kDebug()<<doc.toString();
/*
QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
setSceneList(doc, 0);
......@@ -525,14 +527,14 @@ void Render::initSceneList()
/** Create the producer from the Westley QDomDocument */
void Render::setSceneList(QDomDocument list, int position)
{
if (!m_winid == -1) return;
if (m_winid == -1) return;
m_generateScenelist = true;
kWarning()<<"////// RENDER, SET SCENE LIST";
Mlt::Playlist track;
char *tmp = decodedString(list.toString());
kDebug()<<" / / /STRING rESULT-----------: "<<tmp;
Mlt::Producer clip("westley-xml", tmp);
delete[] tmp;
......@@ -709,13 +711,14 @@ void Render::stop()
m_mltConsumer->set("refresh", 0);
m_mltConsumer->stop();
}
kDebug()<<"///////////// RENDER STOP2-------";
isBlocked = true;
if (m_mltProducer) {
m_mltProducer->set_speed(0.0);
m_mltProducer->set("out", m_mltProducer->get_length() - 1);
}
kDebug()<<"///////////// RENDER STOP3-------";
}
void Render::stop(const GenTime & startTime)
......
#include <QMouseEvent>
#include <QStylePainter>
#include <QScrollBar>
#include <KDebug>
#include "documenttrack.h"
#include "definitions.h"
#include "documentvideotrack.h"
#include "documentaudiotrack.h"
#include "headertrack.h"
#include "trackview.h"
TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
: QWidget(parent), m_doc(doc)
: QWidget(parent), m_doc(doc), m_scale(1.0)
{
view = new Ui::TimeLine_UI();
view->setupUi(this);
......@@ -25,10 +28,19 @@ TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
m_tracksLayout->addWidget(m_scrollArea);
m_scrollArea->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOn);
m_scrollArea->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
m_tracksAreaLayout = new QVBoxLayout;
m_scrollArea->setWidgetResizable( true );
m_scrollBox = new QFrame(m_scrollArea);
//m_scrollBox ->setFlat(false);
m_scrollBox ->setFocusPolicy(Qt::WheelFocus);
m_scrollBox->setSizePolicy( QSizePolicy::Preferred,QSizePolicy::Fixed );
m_tracksAreaLayout = new QVBoxLayout(m_scrollBox);
m_tracksAreaLayout->setContentsMargins (0, 0, 0, 0);
m_tracksAreaLayout->insertStretch (1000);
m_scrollArea->setLayout(m_tracksAreaLayout);
m_tracksAreaLayout->setSpacing(0);
//MyScroll->setGeometry(...);
m_scrollArea->setWidget(m_scrollBox);
view->tracks_frame->setLayout(m_tracksLayout);
m_headersLayout = new QVBoxLayout;
......@@ -42,16 +54,39 @@ TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
void TrackView::parseDocument(QDomDocument doc)
{
QDomNodeList tracks = doc.elementsByTagName("kdenlivetrack");
QDomNodeList tracks = doc.elementsByTagName("playlist");
m_projectDuration = 300;
int duration;
for (int i = 0; i < tracks.count(); i++)
{
slotAddTrack(i);
if (tracks.item(i).toElement().attribute("hide", QString::null) == "video") {
// this is an audio track
duration = slotAddAudioTrack(i, tracks.item(i).toElement());
}
else duration = slotAddVideoTrack(i, tracks.item(i).toElement());
if (duration > m_projectDuration) m_projectDuration = duration;
}
m_tracksAreaLayout->insertStretch (1000);
//m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
}
void TrackView::slotChangeZoom(int factor)
{
m_ruler->setPixelPerMark(factor);
m_scale = m_ruler->pixelPerMark();
for (int i = 0; i < documentTracks.count(); i++) {
kDebug()<<"------REPAINTING OBJECT";
documentTracks.at(i)->update();
//documentTracks.at(i)->setFixedWidth(300 * zoomFactor());
}
m_scrollBox->setFixedWidth(( m_projectDuration + 300) * zoomFactor());
/*m_scrollArea->horizontalScrollBar()->setMaximum(300 * zoomFactor());
m_scrollArea->horizontalScrollBar()->setPageStep(FRAME_SIZE * zoomFactor());*/
}
const double TrackView::zoomFactor() const
{
return m_scale * FRAME_SIZE;
}
KdenliveDoc *TrackView::document()
......@@ -59,12 +94,25 @@ KdenliveDoc *TrackView::document()
return m_doc;
}
void TrackView::slotAddTrack(int ix)
int TrackView::slotAddAudioTrack(int ix, QDomElement xml)
{
DocumentTrack *track = new DocumentAudioTrack(xml, this, m_scrollBox);
HeaderTrack *header = new HeaderTrack();
m_tracksAreaLayout->addWidget(track); //, ix, Qt::AlignTop);
m_headersLayout->addWidget(header); //, ix, Qt::AlignTop);
documentTracks.insert(ix, track);
return track->duration();
//track->show();
}
int TrackView::slotAddVideoTrack(int ix, QDomElement xml)
{
DocumentTrack *track = new DocumentTrack();
DocumentTrack *track = new DocumentVideoTrack(xml, this, m_scrollBox);
HeaderTrack *header = new HeaderTrack();
m_tracksAreaLayout->addWidget(track, ix, Qt::AlignTop);
m_headersLayout->addWidget(header, ix, Qt::AlignTop);
m_tracksAreaLayout->addWidget(track); //, ix, Qt::AlignTop);
m_headersLayout->addWidget(header); //, ix, Qt::AlignTop);
documentTracks.insert(ix, track);
return track->duration();
//track->show();
}
......
......@@ -4,10 +4,14 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <KRuler>
#include <QGroupBox>
#define FRAME_SIZE 90
#include "ui_timeline_ui.h"