From: Jean-Baptiste Mardelle Date: Sat, 5 Jan 2008 19:06:57 +0000 (+0000) Subject: Start of the undo framework X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=0137177547608649b1130434380ca42abc410a9e;p=kdenlive Start of the undo framework svn path=/branches/KDE4/; revision=1792 --- diff --git a/src/addclipcommand.h b/src/addclipcommand.h new file mode 100644 index 00000000..a8b05fa5 --- /dev/null +++ b/src/addclipcommand.h @@ -0,0 +1,39 @@ +#ifndef ADDCLIPCOMMAND_H +#define ADDCLIPCOMMAND_H + +#include +#include + +#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 + diff --git a/src/definitions.h b/src/definitions.h new file mode 100644 index 00000000..b1e6f226 --- /dev/null +++ b/src/definitions.h @@ -0,0 +1,6 @@ +#ifndef DEFINITIONS_H +#define DEFINITIONS_H + +#define FRAME_SIZE 90 + +#endif diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 86240214..8befa8fc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2,7 +2,7 @@ #include #include - + #include #include #include @@ -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()); diff --git a/src/mainwindow.h b/src/mainwindow.h index 41086b54..5a9d74b3 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -7,6 +7,7 @@ #include #include #include +#include #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(); diff --git a/src/monitormanager.cpp b/src/monitormanager.cpp index c6475dca..6ef4bd80 100644 --- a/src/monitormanager.cpp +++ b/src/monitormanager.cpp @@ -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(); } diff --git a/src/projectitem.cpp b/src/projectitem.cpp index eb2c3c95..3c5dfc84 100644 --- a/src/projectitem.cpp +++ b/src/projectitem.cpp @@ -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; diff --git a/src/projectitem.h b/src/projectitem.h index e38d30b4..3422a5b7 100644 --- a/src/projectitem.h +++ b/src/projectitem.h @@ -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 diff --git a/src/projectlist.cpp b/src/projectlist.cpp index dd9b3ea5..baeafea6 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -15,6 +15,8 @@ #include "kdenlivesettings.h" #include "ui_colorclip_ui.h" +#include "addclipcommand.h" + #include 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);*/ } } diff --git a/src/projectlist.h b/src/projectlist.h index 3a7daf92..ced014da 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -3,8 +3,9 @@ #include #include - #include + +#include #include #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(); diff --git a/src/renderer.cpp b/src/renderer.cpp index 93059de1..02f048ac 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -479,6 +479,7 @@ void Render::getFileProperties(const KUrl &url, uint framenb) } } emit replyGetFileProperties(filePropertyMap, metadataPropertyMap); + kDebug()<<"REquested fuile info for: "<is_stopped()) { m_mltConsumer->set("refresh", 0); - m_mltConsumer->stop(); + // m_mltConsumer->stop(); } kDebug()<<"///////////// RENDER STOP2-------"; isBlocked = true;