Start of the undo framework

svn path=/branches/KDE4/; revision=1792
parent 87a3fbf3
#ifndef ADDCLIPCOMMAND_H
#define ADDCLIPCOMMAND_H
#include <QUndoCommand>
#include <KDebug>
#include "projectlist.h"
class AddClipCommand : public QUndoCommand
{
public:
AddClipCommand(ProjectList *list, const QStringList &names, const QDomElement &xml, const int id, const KUrl &url, bool doIt)
: m_list(list), m_names(names), m_xml(xml), m_id(id), m_url(url), m_doIt(doIt) {
if (doIt) setText(i18n("Add clip"));
else setText(i18n("Delete clip"));
}
virtual void undo()
{
kDebug()<<"---- undoing action";
if (m_doIt) m_list->deleteClip(m_id);
else m_list->addClip(m_names, m_xml, m_id, m_url);
}
virtual void redo()
{
kDebug()<<"---- redoing action";
if (m_doIt) m_list->addClip(m_names, m_xml, m_id, m_url);
else m_list->deleteClip(m_id);
}
private:
ProjectList *m_list;
QStringList m_names;
QDomElement m_xml;
int m_id;
KUrl m_url;
bool m_doIt;
};
#endif
#ifndef DEFINITIONS_H
#define DEFINITIONS_H
#define FRAME_SIZE 90
#endif
......@@ -2,7 +2,7 @@
#include <QTextStream>
#include <QTimer>
#include <KApplication>
#include <KAction>
#include <KLocale>
......@@ -35,9 +35,11 @@ MainWindow::MainWindow(QWidget *parent)
m_monitorManager = new MonitorManager();
m_commandStack = new KUndoStack(this);
projectListDock = new QDockWidget(i18n("Project Tree"), this);
projectListDock->setObjectName("project_tree");
m_projectList = new ProjectList(this);
m_projectList = new ProjectList(m_commandStack, this);
projectListDock->setWidget(m_projectList);
addDockWidget(Qt::TopDockWidgetArea, projectListDock);
......@@ -137,12 +139,18 @@ void MainWindow::setupActions()
KStandardAction::openNew(this, SLOT(newFile()),
actionCollection());
KStandardAction::openNew(this, SLOT(newFile()),
/*KStandardAction::undo(this, SLOT(undo()),
actionCollection());
KStandardAction::redo(this, SLOT(redo()),
actionCollection());*/
KStandardAction::preferences(this, SLOT(slotPreferences()),
actionCollection());
QAction * redo = m_commandStack->createRedoAction(actionCollection());
QAction * undo = m_commandStack->createUndoAction(actionCollection());
setupGUI();
}
......@@ -175,7 +183,7 @@ void MainWindow::saveFileAs(const QString &outputFileName)
fileName = outputFileName;
}
void MainWindow::saveFileAs()
{
saveFileAs(KFileDialog::getSaveFileName());
......
......@@ -7,6 +7,7 @@
#include <KTextEdit>
#include <KListWidget>
#include <KTabWidget>
#include <KUndoStack>
#include "projectlist.h"
#include "monitor.h"
......@@ -46,6 +47,8 @@ class MainWindow : public KXmlGuiWindow
QDockWidget *projectMonitorDock;
Monitor *m_projectMonitor;
KUndoStack *m_commandStack;
private slots:
void newFile();
......
......@@ -32,15 +32,15 @@ void MonitorManager::initMonitors(Monitor *clipMonitor, Monitor *projectMonitor)
void MonitorManager::initClipMonitor()
{
m_clipMonitor->initMonitor();
// initProjectMonitor();
initProjectMonitor();
//QTimer::singleShot(1500, this, SLOT(initProjectMonitor()));
}
void MonitorManager::initProjectMonitor()
{
m_clipMonitor->stop();
m_projectMonitor->initMonitor();
activateMonitor("project");
// m_projectMonitor->initMonitor();
// activateMonitor("project");
emit connectMonitors();
}
......
......@@ -16,8 +16,8 @@
const int FullPathRole = NameRole + 2;
const int ClipTypeRole = NameRole + 3;
ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int type)
: QTreeWidgetItem(parent, strings, type), m_element(xml), m_clipType(DocClipBase::NONE)
ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId)
: QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_element(xml), m_clipType(DocClipBase::NONE), m_clipId(clipId)
{
setSizeHint(0, QSize(65, 45));
setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
......@@ -33,6 +33,20 @@ ProjectItem::~ProjectItem()
{
}
int ProjectItem::clipId()
{
return m_clipId;
}
QStringList ProjectItem::names()
{
QStringList result;
result.append(text(0));
result.append(text(1));
result.append(text(2));
return result;
}
QDomElement ProjectItem::toXml()
{
return m_element;
......
......@@ -12,18 +12,22 @@
class ProjectItem : public QTreeWidgetItem
{
public:
ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml = QDomElement(), int type = QTreeWidgetItem::UserType);
ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId);
~ProjectItem();
QDomElement toXml();
void setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata);
int clipId();
QStringList names();
private:
QDomElement m_element;
GenTime m_duration;
bool m_durationKnown;
DocClipBase::CLIPTYPE m_clipType;
int m_clipId;
void slotSetToolTip();
};
#endif
......@@ -15,6 +15,8 @@
#include "kdenlivesettings.h"
#include "ui_colorclip_ui.h"
#include "addclipcommand.h"
#include <QtGui>
const int NameRole = Qt::UserRole;
......@@ -65,13 +67,14 @@ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIn
};
ProjectList::ProjectList(QWidget *parent)
: QWidget(parent), m_render(NULL), m_fps(-1)
ProjectList::ProjectList(KUndoStack *commandStack, QWidget *parent)
: QWidget(parent), m_render(NULL), m_fps(-1), m_commandStack(commandStack)
{
QWidget *vbox = new QWidget;
listView = new QTreeWidget(this);;
QVBoxLayout *layout = new QVBoxLayout;
m_clipIdCounter = 0;
// setup toolbar
searchView = new KTreeWidgetSearchLine (this);
......@@ -140,9 +143,37 @@ void ProjectList::slotEditClip()
void ProjectList::slotRemoveClip()
{
kDebug()<<"////////// SLOT REMOVE";
if (!listView->currentItem()) return;
delete listView->currentItem();
ProjectItem *item = ((ProjectItem *)listView->currentItem());
AddClipCommand *command = new AddClipCommand(this, item->names(), item->toXml(), item->clipId(), KUrl(item->data(1, FullPathRole).toString()), false);
m_commandStack->push(command);
}
void ProjectList::addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url)
{
ProjectItem *item = new ProjectItem(listView, name, elem, clipId);
if (!url.isEmpty()) {
item->setData(1, FullPathRole, url.path());
emit getFileProperties(url, elem.attribute("frame_thumbnail", 0).toInt());
}
}
void ProjectList::deleteClip(const int clipId)
{
QTreeWidgetItem *parent = 0;
int count =
parent ? parent->childCount() : listView->topLevelItemCount();
for (int i = 0; i < count; i++)
{
QTreeWidgetItem *item =
parent ? parent->child(i) : listView->topLevelItem(i);
if (((ProjectItem *)item)->clipId() == clipId) {
delete item;
break;
}
}
}
void ProjectList::slotAddClip()
......@@ -152,17 +183,18 @@ void ProjectList::slotAddClip()
if (list.isEmpty()) return;
KUrl::List::Iterator it;
KUrl url;
ProjectItem *item;
// ProjectItem *item;
for (it = list.begin(); it != list.end(); it++) {
QStringList itemEntry;
itemEntry.append(QString::null);
itemEntry.append((*it).fileName());
item = new ProjectItem(listView, itemEntry, QDomElement());
item->setData(1, FullPathRole, (*it).path());
emit getFileProperties((*it), 0);
AddClipCommand *command = new AddClipCommand(this, itemEntry, QDomElement(), m_clipIdCounter++, *it, true);
m_commandStack->push(command);
//item = new ProjectItem(listView, itemEntry, QDomElement());
//item->setData(1, FullPathRole, (*it).path());
}
listView->setCurrentItem(item);
//listView->setCurrentItem(item);
}
void ProjectList::slotAddColorClip()
......@@ -187,11 +219,13 @@ void ProjectList::slotAddColorClip()
QStringList itemEntry;
itemEntry.append(QString::null);
itemEntry.append(dia_ui->clip_name->text());
ProjectItem *item = new ProjectItem(listView, itemEntry, element);
QPixmap pix(60, 40);
AddClipCommand *command = new AddClipCommand(this, itemEntry, element, m_clipIdCounter++, KUrl(), true);
m_commandStack->push(command);
//ProjectItem *item = new ProjectItem(listView, itemEntry, element);
/*QPixmap pix(60, 40);
pix.fill(dia_ui->clip_color->color());
item->setIcon(0, QIcon(pix));
listView->setCurrentItem(item);
item->setIcon(0, QIcon(pix));*/
//listView->setCurrentItem(item);
}
delete dia_ui;
......@@ -262,7 +296,7 @@ void ProjectList::slotReplyGetFileProperties(const QMap < QString, QString > &pr
void ProjectList::slotReplyGetImage(const KUrl &url, int pos, const QPixmap &pix, int w, int h)
{
QTreeWidgetItem *parent = 0;
QTreeWidgetItem *parent = 0;
int count =
parent ? parent->childCount() : listView->topLevelItemCount();
......@@ -272,7 +306,7 @@ void ProjectList::slotReplyGetImage(const KUrl &url, int pos, const QPixmap &pix
parent ? parent->child(i) : listView->topLevelItem(i);
if (item->data(1, FullPathRole).toString() == url.path()) {
item->setIcon(0,pix);
item->setIcon(0, pix);
break;
}
}
......@@ -291,10 +325,14 @@ void ProjectList::addProducer(QDomElement producer)
QStringList itemEntry;
itemEntry.append(QString::null);
itemEntry.append(resource.fileName());
ProjectItem *item = new ProjectItem(listView, itemEntry, producer);
AddClipCommand *command = new AddClipCommand(this, itemEntry, producer, producer.attribute("id").toInt(), resource, true);
m_commandStack->push(command);
/*ProjectItem *item = new ProjectItem(listView, itemEntry, producer);
item->setData(1, FullPathRole, resource.path());
item->setData(1, ClipTypeRole, (int) type);
emit getFileProperties(resource, producer.attribute("frame_thumbnail", 0).toInt());
item->setData(1, ClipTypeRole, (int) type);*/
}
}
else if (type == DocClipBase::COLOR) {
......@@ -305,9 +343,12 @@ void ProjectList::addProducer(QDomElement producer)
QStringList itemEntry;
itemEntry.append(QString::null);
itemEntry.append(producer.attribute("name"));
ProjectItem *item = new ProjectItem(listView, itemEntry, producer);
item->setIcon(0, QIcon(pix));
item->setData(1, ClipTypeRole, (int) type);
AddClipCommand *command = new AddClipCommand(this, itemEntry, producer, producer.attribute("id").toInt(), KUrl(), true);
m_commandStack->push(command);
//ProjectItem *item = new ProjectItem(listView, itemEntry, producer);
/*item->setIcon(0, QIcon(pix));
item->setData(1, ClipTypeRole, (int) type);*/
}
}
......
......@@ -3,8 +3,9 @@
#include <QDomNodeList>
#include <QToolBar>
#include <QTreeWidget>
#include <KUndoStack>
#include <KTreeWidgetSearchLine>
#include "docclipbase.h"
......@@ -17,11 +18,14 @@ class ProjectList : public QWidget
Q_OBJECT
public:
ProjectList(QWidget *parent=0);
ProjectList(KUndoStack *commandStack, QWidget *parent=0);
QDomElement producersList();
void setRenderer(Render *projectRender);
void addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url = KUrl());
void deleteClip(const int clipId);
public slots:
void setDocument(KdenliveDoc *doc);
void addProducer(QDomElement producer);
......@@ -36,6 +40,8 @@ class ProjectList : public QWidget
Timecode m_timecode;
double m_fps;
QToolBar *m_toolbar;
KUndoStack *m_commandStack;
int m_clipIdCounter;
private slots:
void slotAddClip();
......
......@@ -479,6 +479,7 @@ void Render::getFileProperties(const KUrl &url, uint framenb)
}
}
emit replyGetFileProperties(filePropertyMap, metadataPropertyMap);
kDebug()<<"REquested fuile info for: "<<url.path();
delete frame;
}
......@@ -709,7 +710,7 @@ void Render::stop()
kDebug()<<"///////////// RENDER STOP-------";
if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
m_mltConsumer->set("refresh", 0);
m_mltConsumer->stop();
// m_mltConsumer->stop();
}
kDebug()<<"///////////// RENDER STOP2-------";
isBlocked = true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment