Progress in clip monitor and project switching

svn path=/branches/KDE4/; revision=1780
parent 4935314b
......@@ -27,6 +27,7 @@ set(kdenlive_SRCS
main.cpp
mainwindow.cpp
customruler.cpp
smallruler.cpp
projectlist.cpp
projectitem.cpp
monitor.cpp
......@@ -36,6 +37,7 @@ set(kdenlive_SRCS
trackview.cpp
docclipbase.cpp
timecode.cpp
monitormanager.cpp
)
kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
......
......@@ -57,8 +57,8 @@ const int CustomRuler::comboScale[] =
{ 1, 2, 5, 10, 25, 50, 125, 250, 500, 725, 1500, 3000, 6000,
12000 };
CustomRuler::CustomRuler(QWidget *parent)
: KRuler(parent)
CustomRuler::CustomRuler(Timecode tc, QWidget *parent)
: KRuler(parent), m_timecode(tc)
{
slotNewOffset(0);
setRulerMetricStyle(KRuler::Pixel);
......@@ -145,7 +145,10 @@ void CustomRuler::paintEvent(QPaintEvent * /*e*/)
fend = pixelPerMark()*littleMarkDistance();
if (fend > 5) for ( f=offsetmin; f<offsetmax; f+=fend ) {
p.drawLine((int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2);
if (fend > 30) p.drawText( (int)f + 2, LABEL_SIZE, QString::number((f - offsetmin) / pixelPerMark() / FRAME_SIZE) );
if (fend > 60) {
QString lab = m_timecode.getTimecodeFromFrames((int) ((f - offsetmin) / pixelPerMark() / FRAME_SIZE + 0.5));
p.drawText( (int)f + 2, LABEL_SIZE, lab );
}
}
}
if (showMediumMarks()) {
......@@ -153,7 +156,10 @@ void CustomRuler::paintEvent(QPaintEvent * /*e*/)
fend = pixelPerMark()*mediumMarkDistance();
if (fend > 5) for ( f=offsetmin; f<offsetmax; f+=fend ) {
p.drawLine((int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2);
if (fend > 30) p.drawText( (int)f + 2, LABEL_SIZE, QString::number((f - offsetmin) / pixelPerMark() / FRAME_SIZE) );
if (fend > 60) {
QString lab = m_timecode.getTimecodeFromFrames((int) ((f - offsetmin) / pixelPerMark() / FRAME_SIZE + 0.5) );
p.drawText( (int)f + 2, LABEL_SIZE, lab );
}
}
}
if (showBigMarks()) {
......@@ -161,7 +167,14 @@ void CustomRuler::paintEvent(QPaintEvent * /*e*/)
fend = pixelPerMark()*bigMarkDistance();
if (fend > 5) for ( f=offsetmin; f<offsetmax; f+=fend ) {
p.drawLine((int)f, BIG_MARK_X1, (int)f, BIG_MARK_X2);
if (fend > 30) p.drawText( (int)f + 2, LABEL_SIZE, QString::number((f - offsetmin) / pixelPerMark() / FRAME_SIZE) );
if (fend > 60) {
QString lab = m_timecode.getTimecodeFromFrames((int) ((f - offsetmin) / pixelPerMark() / FRAME_SIZE + 0.5) );
p.drawText( (int)f + 2, LABEL_SIZE, lab );
}
else if (((int) (f - offsetmin)) % ((int)(fend * 5)) == 0) {
QString lab = m_timecode.getTimecodeFromFrames((int) ((f - offsetmin) / pixelPerMark() / FRAME_SIZE + 0.5) );
p.drawText( (int)f + 2, LABEL_SIZE, lab );
}
}
}
/* if (d->showem) {
......
......@@ -3,12 +3,14 @@
#include <KRuler>
#include <timecode.h>
class CustomRuler : public KRuler
{
Q_OBJECT
public:
CustomRuler(QWidget *parent=0);
CustomRuler(Timecode tc, QWidget *parent=0);
virtual void mousePressEvent ( QMouseEvent * event );
void setPixelPerMark (double rate);
static const int comboScale[];
......@@ -17,6 +19,7 @@ class CustomRuler : public KRuler
private:
int m_cursorPosition;
Timecode m_timecode;
public slots:
void slotNewValue ( int _value );
......
......@@ -33,31 +33,51 @@
#include "kdenlivedoc.h"
KdenliveDoc::KdenliveDoc(KUrl url, double fps, int width, int height, QWidget *parent):QObject(parent), m_url(url), m_projectName(NULL)
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)
{
if (!url.isEmpty()) {
QString tmpFile;
if(KIO::NetAccess::download(url.path(), tmpFile, parent))
{
QFile file(tmpFile);
m_document.setContent(&file, false);
file.close();
m_projectName = url.fileName();
{
QFile file(tmpFile);
m_document.setContent(&file, false);
file.close();
m_projectName = url.fileName();
KIO::NetAccess::removeTempFile(tmpFile);
}
else
{
KMessageBox::error(parent,
KIO::NetAccess::lastErrorString());
KIO::NetAccess::removeTempFile(tmpFile);
}
else
{
KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
}
}
else {
// Creating new document
QDomElement westley = m_document.createElement("westley");
m_document.appendChild(westley);
QDomElement doc = m_document.createElement("kdenlivedoc");
doc.setAttribute("version", "0.6");
westley.appendChild(doc);
QDomElement props = m_document.createElement("properties");
doc.setAttribute("width", m_width);
doc.setAttribute("height", m_height);
doc.setAttribute("projectfps", m_fps);
doc.appendChild(props);
}
if (fps == 30000.0 / 1001.0 ) m_timecode.setFormat(30, true);
else m_timecode.setFormat((int) fps);
}
KdenliveDoc::~KdenliveDoc()
{
}
Timecode KdenliveDoc::timecode()
{
return m_timecode;
}
QString KdenliveDoc::documentName()
{
return m_projectName;
......@@ -68,5 +88,45 @@ QDomNodeList KdenliveDoc::producersList()
return m_document.elementsByTagName("producer");
}
void KdenliveDoc::setProducers(QDomElement doc)
{
QDomNode kdenlivedocument = m_document.elementsByTagName("kdenlivedoc").item(0);
QDomNodeList list = m_document.elementsByTagName("producer");
int ct = list.count();
kDebug()<<"DELETING CHILD PRODUCERS: "<<ct;
for (int i = 0; i < ct; i++) {
kdenlivedocument.removeChild(list.item(0));
}
QDomNode n = doc.firstChild();
ct = 0;
while(!n.isNull()) {
QDomElement e = n.toElement(); // try to convert the node to an element.
if(!e.isNull() && e.tagName() == "producer") {
kdenlivedocument.appendChild(m_document.importNode(e, true));
ct++;
}
n = n.nextSibling();
}
kDebug()<<"ADDING CHILD PRODS: "<<ct<<"\n";
//kDebug()<<m_document.toString();
}
double KdenliveDoc::fps()
{
return m_fps;
}
int KdenliveDoc::width()
{
return m_width;
}
int KdenliveDoc::height()
{
return m_height;
}
#include "kdenlivedoc.moc"
......@@ -27,7 +27,7 @@
#include <kurl.h>
#include "gentime.h"
#include "timecode.h"
class KdenliveDoc:public QObject {
Q_OBJECT public:
......@@ -36,11 +36,20 @@ class KdenliveDoc:public QObject {
~KdenliveDoc();
QString documentName();
QDomNodeList producersList();
double fps();
int width();
int height();
void setProducers(QDomElement doc);
Timecode timecode();
private:
KUrl m_url;
QDomDocument m_document;
QString m_projectName;
double m_fps;
int m_width;
int m_height;
Timecode m_timecode;
public slots:
......
#include <QTextStream>
#include <QTimer>
#include <KApplication>
#include <KAction>
......@@ -25,7 +26,7 @@
MainWindow::MainWindow(QWidget *parent)
: KXmlGuiWindow(parent),
fileName(QString())
fileName(QString()), m_activeDocument(NULL)
{
m_timelineArea = new KTabWidget(this);
m_timelineArea->setHoverCloseButton(true);
......@@ -33,26 +34,28 @@ MainWindow::MainWindow(QWidget *parent)
connect(m_timelineArea, SIGNAL(currentChanged (int)), this, SLOT(activateDocument()));
setCentralWidget(m_timelineArea);
m_monitorManager = new MonitorManager();
projectListDock = new QDockWidget(i18n("Project Tree"), this);
projectListDock->setObjectName("project_tree");
m_projectList = new ProjectList(NULL, this);
m_projectList = new ProjectList(this);
projectListDock->setWidget(m_projectList);
addDockWidget(Qt::TopDockWidgetArea, projectListDock);
effectListDock = new QDockWidget(i18n("Effect List"), this);
effectListDock->setObjectName("project_tree");
effectListDock->setObjectName("effect_list");
effectList = new KListWidget(this);
effectListDock->setWidget(effectList);
addDockWidget(Qt::TopDockWidgetArea, effectListDock);
effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
effectStackDock->setObjectName("project_tree");
effectStackDock->setObjectName("effect_stack");
effectStack = new KListWidget(this);
effectStackDock->setWidget(effectStack);
addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
transitionConfigDock = new QDockWidget(i18n("Transition"), this);
transitionConfigDock->setObjectName("project_tree");
transitionConfigDock->setObjectName("transition");
transitionConfig = new KListWidget(this);
transitionConfigDock->setWidget(transitionConfig);
addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
......@@ -60,34 +63,56 @@ MainWindow::MainWindow(QWidget *parent)
Mlt::Factory::init(NULL);
clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
clipMonitorDock->setObjectName("project_tree");
m_clipMonitor = new Monitor("clip", this);
clipMonitorDock->setObjectName("clip_monitor");
m_clipMonitor = new Monitor("clip", m_monitorManager, this);
clipMonitorDock->setWidget(m_clipMonitor);
addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
projectMonitorDock->setObjectName("project_tree");
m_projectMonitor = new Monitor("project", this);
projectMonitorDock->setObjectName("project_monitor");
m_projectMonitor = new Monitor("project", m_monitorManager, this);
projectMonitorDock->setWidget(m_projectMonitor);
addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
setupActions();
tabifyDockWidget (effectListDock, projectListDock);
tabifyDockWidget (effectListDock, effectStackDock);
tabifyDockWidget (effectListDock, transitionConfigDock);
tabifyDockWidget (projectListDock, effectListDock);
tabifyDockWidget (projectListDock, effectStackDock);
tabifyDockWidget (projectListDock, transitionConfigDock);
projectListDock->raise();
tabifyDockWidget (clipMonitorDock, projectMonitorDock);
connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_projectMonitor, SLOT(slotSetXml(const QDomElement &)));
connect(projectMonitorDock, SIGNAL(visibilityChanged (bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
connect(clipMonitorDock, SIGNAL(visibilityChanged (bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
connect(m_projectList, SIGNAL(getFileProperties(const KUrl &, uint)), m_projectMonitor->render, SLOT(getFileProperties(const KUrl &, uint)));
connect(m_projectMonitor->render, SIGNAL(replyGetImage(const KUrl &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const KUrl &, int, const QPixmap &, int, int)));
m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
connect(m_monitorManager, SIGNAL(connectMonitors ()), this, SLOT(slotConnectMonitors()));
connect(m_monitorManager, SIGNAL(raiseClipMonitor (bool)), this, SLOT(slotRaiseMonitor(bool)));
}
connect(m_projectMonitor->render, SIGNAL(replyGetFileProperties(const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QMap < QString, QString > &, const QMap < QString, QString > &)));
void MainWindow::slotRaiseMonitor(bool clipMonitor)
{
if (clipMonitor) clipMonitorDock->raise();
else projectMonitorDock->raise();
}
void MainWindow::slotConnectMonitors()
{
m_projectList->setRenderer(m_clipMonitor->render);
connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
connect(m_projectList, SIGNAL(getFileProperties(const KUrl &, uint)), m_clipMonitor->render, SLOT(getFileProperties(const KUrl &, uint)));
connect(m_clipMonitor->render, SIGNAL(replyGetImage(const KUrl &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const KUrl &, int, const QPixmap &, int, int)));
connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QMap < QString, QString > &, const QMap < QString, QString > &)));
}
void MainWindow::setupActions()
{
KAction* clearAction = new KAction(this);
......@@ -127,6 +152,8 @@ void MainWindow::newFile()
KdenliveDoc *doc = new KdenliveDoc(KUrl(), 25, 720, 576);
TrackView *trackView = new TrackView(doc);
m_timelineArea->addTab(trackView, "New Project");
if (m_timelineArea->count() == 1)
connectDocument(doc);
}
void MainWindow::activateDocument()
......@@ -183,8 +210,9 @@ void MainWindow::openFile(const QString &inputFileName) //new
void MainWindow::connectDocument(KdenliveDoc *doc) //changed
{
m_projectList->populate(doc->producersList());
//connect(doc, SIGNAL(addClip(QDomElement &)), m_projectList, SLOT(slotAddClip(QDomElement &)));
if (m_activeDocument) m_activeDocument->setProducers(m_projectList->producersList());
m_projectList->setDocument(doc);
m_activeDocument = doc;
}
......
......@@ -10,6 +10,7 @@
#include "projectlist.h"
#include "monitor.h"
#include "monitormanager.h"
#include "kdenlivedoc.h"
class MainWindow : public KXmlGuiWindow
......@@ -24,6 +25,8 @@ class MainWindow : public KXmlGuiWindow
KTabWidget* m_timelineArea;
void setupActions();
QString fileName;
KdenliveDoc *m_activeDocument;
MonitorManager *m_monitorManager;
QDockWidget *projectListDock;
ProjectList *m_projectList;
......@@ -52,6 +55,8 @@ class MainWindow : public KXmlGuiWindow
void saveFileAs();
void saveFileAs(const QString &outputFileName);
void slotPreferences();
void slotConnectMonitors();
void slotRaiseMonitor(bool clipMonitor);
};
#endif
......@@ -8,49 +8,149 @@
#include "gentime.h"
#include "monitor.h"
Monitor::Monitor(QString name, QWidget *parent)
: QWidget(parent)
Monitor::Monitor(QString name, MonitorManager *manager, QWidget *parent)
: QWidget(parent), render(NULL), m_monitorManager(manager), m_name(name)
{
ui.setupUi(this);
if (name == "project") {
render = new Render(name, this);
render->createVideoXWindow(ui.video_frame->winId(), -1);
m_scale = 1;
m_ruler = new SmallRuler();
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget( m_ruler);
ui.ruler_frame->setLayout( layout );
//m_ruler->setPixelPerMark(3);
connect(m_ruler, SIGNAL(seekRenderer(int)), this, SLOT(slotSeek(int)));
connect(ui.button_play, SIGNAL(clicked()), this, SLOT(slotOpen()));
connect(ui.button_rew, SIGNAL(clicked()), this, SLOT(slotRewind()));
connect(ui.button_play_2, SIGNAL(clicked()), this, SLOT(slotPlay()));
}
}
void Monitor::slotOpen()
// virtual
void Monitor::mousePressEvent ( QMouseEvent * event )
{
slotPlay();
}
// virtual
void Monitor::wheelEvent ( QWheelEvent * event )
{
render->play(0);
if (event->delta() > 0) m_position++;
else m_position--;
render->seekToFrame(m_position);
}
render->mltInsertClip(2, GenTime(1, 25), QString("<westley><producer mlt_service=\"colour\" colour=\"red\" in=\"1\" out=\"30\" /></westley>"));
render->mltInsertClip(2, GenTime(0, 25), QString("<westley><producer mlt_service=\"avformat\" resource=\"/home/one/.vids/clip3e.mpg\" in=\"1\" out=\"300\" /></westley>"));
void Monitor::slotSeek(int pos)
{
if ( render == NULL ) return;
int realPos = ((double) pos) / m_scale;
render->seekToFrame(realPos);
}
void Monitor::seekCursor(int pos)
{
int rulerPos = (int) (pos * m_scale);
m_position = pos;
//kDebug()<<"seek: "<<pos<<", scale: "<<m_scale<<
m_ruler->slotNewValue(rulerPos);
}
void Monitor::rendererStopped(int pos)
{
int rulerPos = (int) (pos * m_scale);
m_ruler->slotNewValue(rulerPos);
ui.button_play_2->setChecked(false);
}
void Monitor::initMonitor()
{
if ( render ) return;
render = new Render(m_name, this);
render->createVideoXWindow(ui.video_frame->winId(), -1);
connect(render, SIGNAL(playListDuration(int)), this, SLOT(adjustRulerSize(int)));
connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int)));
int width = m_ruler->width();
m_ruler->setLength(width);
m_ruler->setMaximum(width);
m_length = 0;
}
// virtual
void Monitor::resizeEvent ( QResizeEvent * event )
{
adjustRulerSize(-1);
if (render) render->askForRefresh();
}
void Monitor::adjustRulerSize(int length)
{
int width = m_ruler->width();
m_ruler->setLength(width);
if (length > 0) m_length = length;
m_scale = (double) width / m_length;
if (m_scale == 0) m_scale = 1;
kDebug()<<"RULER WIDT: "<<width<<", RENDER LENGT: "<<m_length<<", SCALE: "<<m_scale;
m_ruler->setPixelPerMark(m_scale);
m_ruler->setMaximum(width);
//m_ruler->setLength(length);
}
void Monitor::stop()
{
if (render) render->stop();
}
void Monitor::start()
{
if (render) render->start();
}
void Monitor::refreshMonitor(bool visible)
{
if (visible && render) render->askForRefresh();
}
void Monitor::slotOpen()
{
if ( render == NULL ) return;
render->mltInsertClip(2, GenTime(1, 25), QString("<westley><producer mlt_service=\"colour\" colour=\"red\" in=\"1\" out=\"30\" /></westley>"));
render->mltInsertClip(2, GenTime(0, 25), QString("<westley><producer mlt_service=\"avformat\" resource=\"/home/one/.vids/clip3e.mpg\" in=\"1\" out=\"300\" /></westley>"));
}
void Monitor::slotRewind()
{
if ( render == NULL ) return;
m_monitorManager->activateMonitor(m_name);
render->seek(GenTime(0));
}
void Monitor::slotPlay()
{
if ( render == NULL ) return;
m_monitorManager->activateMonitor(m_name);
render->switchPlay();
ui.button_play_2->setChecked(true);
}
void Monitor::slotSetXml(const QDomElement &e)
{
if ( render == NULL ) return;
m_monitorManager->activateMonitor(m_name);
QDomDocument doc;
QDomElement westley = doc.createElement("westley");
doc.appendChild(westley);
westley.appendChild(e);
render->setSceneList(doc, 0);
m_ruler->slotNewValue(0);
m_position = 0;
}
void Monitor::slotOpenFile(const QString &file)
{
if ( render == NULL ) return;
m_monitorManager->activateMonitor(m_name);
QDomDocument doc;
QDomElement westley = doc.createElement("westley");
doc.appendChild(westley);
......
#ifndef MONITOR_H
#define MONITOR_H
#include <KListWidget>
#include "ui_monitor_ui.h"
#include "renderer.h"
#include "monitormanager.h"
#include "smallruler.h"
class MonitorManager;
class Monitor : public QWidget
{
Q_OBJECT
public:
Monitor(QString name, QWidget *parent=0);
Monitor(QString name, MonitorManager *manager, QWidget *parent=0);
Render *render;
virtual void resizeEvent ( QResizeEvent * event );
protected:
virtual void mousePressEvent ( QMouseEvent * event );
virtual void wheelEvent ( QWheelEvent * event );
private:
Ui::Monitor_UI ui;
MonitorManager *m_monitorManager;
QString m_name;
double m_scale;
int m_length;
int m_position;
SmallRuler *m_ruler;
private slots:
void slotPlay();
void slotOpen();
void slotRewind();
void adjustRulerSize(int length);
void seekCursor(int pos);
void rendererStopped(int pos);
void slotSeek(int pos);
public slots:
void slotOpenFile(const QString &);
void slotSetXml(const QDomElement &e);
void initMonitor();
void refreshMonitor(bool visible);
void stop();
void start();
};
#endif
#include <QObject>
#include <QTimer>
#include "monitormanager.h"
MonitorManager::MonitorManager(QWidget *parent)
: QObject(parent)
{
}
void MonitorManager::initMonitors(Monitor *clipMonitor, Monitor *projectMonitor)
{
m_clipMonitor = clipMonitor;
m_projectMonitor = projectMonitor;
QTimer::singleShot(750, this, SLOT(initClipMonitor()));
}
void MonitorManager::initClipMonitor()
{
m_clipMonitor->initMonitor();
QTimer::singleShot(1500, this, SLOT(initProjectMonitor()));
}
void MonitorManager::initProjectMonitor()
{
m_clipMonitor->stop();
m_projectMonitor->initMonitor();
activateMonitor("project");
emit connectMonitors();
}