]> git.sesse.net Git - kdenlive/commitdiff
Fix document loading
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 27 May 2008 09:26:05 +0000 (09:26 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 27 May 2008 09:26:05 +0000 (09:26 +0000)
svn path=/branches/KDE4/; revision=2199

src/clipitem.cpp
src/kdenlivedoc.cpp
src/kdenlivedoc.h
src/trackview.cpp

index 097139c7d4abc0b65d305a4c319aef5ea698f956..3c811e7b1caca7181371f703f3af66ac50332430 100644 (file)
@@ -43,7 +43,7 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double scale, double fps)
         : AbstractClipItem(info, QRectF()), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), m_effectsCounter(1), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_thumbsRequested(0), m_hover(false) {
     QRectF rect((double) info.startPos.frames(fps) * scale, (double)(info.track * KdenliveSettings::trackheight() + 1), (double)(info.endPos - info.startPos).frames(fps) * scale, (double)(KdenliveSettings::trackheight() - 1));
     setRect(rect);
-    kDebug() << "/////  NEW CLIP RECT: " << rect;
+    //kDebug() << "/////  NEW CLIP RECT: " << rect;
     m_fps = fps;
     m_clipName = clip->name();
     m_producer = clip->getId();
index 8f271714ec6be798da60823c47f49a5869ad232d..03d06d49836c131556fb26bc1f35455be89c011e 100644 (file)
@@ -34,8 +34,9 @@
 #include "addfoldercommand.h"
 #include "editfoldercommand.h"
 #include "titlewidget.h"
+#include "mainwindow.h"
 
-KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, MltVideoProfile profile, QUndoGroup *undoGroup, QWidget *parent): QObject(parent), m_render(NULL), m_url(url), m_projectFolder(projectFolder), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new KUndoStack(undoGroup)), m_modified(false) {
+KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, MltVideoProfile profile, QUndoGroup *undoGroup, MainWindow *parent): QObject(parent), m_render(NULL), m_url(url), m_projectFolder(projectFolder), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new KUndoStack(undoGroup)), m_modified(false), m_documentLoadingProgress(0), m_documentLoadingStep(0.0) {
     m_clipManager = new ClipManager(this);
     if (!url.isEmpty()) {
         QString tmpFile;
@@ -50,12 +51,22 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, MltVideoPro
                 if (!profilePath.isEmpty()) setProfilePath(profilePath);
                 double version = infoXml.attribute("version").toDouble();
                 if (version < 0.7) convertDocument(version);
-                QDomNodeList producers = m_document.elementsByTagName("producer"); //infoXmlNode.childNodes();
+                QDomNodeList producers = m_document.elementsByTagName("producer");
                 QDomElement e;
-                for (int i = 0; i < producers.count(); i++) {
+                               const int max = producers.count();
+                               if (max > 0) {
+                                       m_documentLoadingStep = 100.0 / (max + m_document.elementsByTagName("entry").count());
+                                       parent->slotGotProgressInfo(i18n("Loading project clips"), (int) m_documentLoadingProgress);
+                               }
+
+                for (int i = 0; i < max; i++) {
                     e = producers.item(i).cloneNode().toElement();
+                                       if (m_documentLoadingStep > 0) {
+                                               m_documentLoadingProgress += m_documentLoadingStep;
+                                               parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
+                                               qApp->processEvents();
+                                       }
                     if (!e.isNull() && e.attribute("id") != "black") {
-                        //e.setTagName("producer");
                         addClip(e, e.attribute("id").toInt());
                     }
                 }
@@ -273,8 +284,8 @@ void KdenliveDoc::convertDocument(double version) {
     westley0.removeChild(westley);
 
     kDebug() << "/////////////////  CONVERTED DOC:";
-    kDebug() << m_document.toString();
-    kDebug() << "/////////////////  END CONVERTED DOC:";
+    //kDebug() << m_document.toString();
+    //kDebug() << "/////////////////  END CONVERTED DOC:";
 }
 
 QDomElement KdenliveDoc::documentInfoXml() {
@@ -324,8 +335,13 @@ void KdenliveDoc::setProfilePath(QString path) {
     else m_timecode.setFormat((int) m_fps);
 }
 
-void KdenliveDoc::setThumbsProgress(KUrl url, int progress) {
-    emit thumbsProgress(url, progress);
+void KdenliveDoc::setThumbsProgress(const QString &message, int progress) {
+    emit progressInfo(message, progress);
+}
+
+void KdenliveDoc::loadingProgressed() {
+       m_documentLoadingProgress += m_documentLoadingStep;
+       emit progressInfo(QString(), (int) m_documentLoadingProgress);
 }
 
 KUndoStack *KdenliveDoc::commandStack() {
index 8ddbce8362817a2740fe94d7a985b1482eacd0e0..0e50bd19de1e966966e6a018530ab4ebaa50dfd3 100644 (file)
 class Render;
 class ClipManager;
 class DocClipBase;
+class MainWindow;
 
 class KdenliveDoc: public QObject {
 Q_OBJECT public:
 
-    KdenliveDoc(const KUrl &url, const KUrl &projectFolder, MltVideoProfile profile, QUndoGroup *undoGroup, QWidget *parent = 0);
+    KdenliveDoc(const KUrl &url, const KUrl &projectFolder, MltVideoProfile profile, QUndoGroup *undoGroup, MainWindow *parent = 0);
     ~KdenliveDoc();
     QDomNodeList producersList();
     double fps() const;
@@ -77,7 +78,7 @@ Q_OBJECT public:
     void deleteProjectClip(QList <int> ids);
     void deleteProjectFolder(QMap <QString, int> map);
     /** Inform application of the audio thumbnails generation progress */
-    void setThumbsProgress(KUrl url, int progress);
+    void setThumbsProgress(const QString &message, int progress);
     QString profilePath() const;
     QString description() const;
     /** Returns the document format: PAL or NTSC */
@@ -92,7 +93,8 @@ Q_OBJECT public:
     bool isModified() const;
     /** Returns project folder, used to store project files (titles, effects,...) */
     KUrl projectFolder() const;
-
+       /** Used to inform main app of the current document loading progress */
+       void loadingProgressed();
 private:
     KUrl m_url;
     QDomDocument m_document;
@@ -111,6 +113,8 @@ private:
     bool m_modified;
     /** Project folder, used to store project files (titles, effects,...) */
     KUrl m_projectFolder;
+       double m_documentLoadingStep;
+       double m_documentLoadingProgress;
     void convertDocument(double version);
 
 public slots:
@@ -122,7 +126,7 @@ signals:
     void signalDeleteProjectClip(int);
     void updateClipDisplay(int);
     void deletTimelineClip(int);
-    void thumbsProgress(KUrl, int);
+    void progressInfo(const QString &, int);
     /** emited when the document state has been modified (= needs saving or not) */
     void docModified(bool);
     void refreshClipThumbnail(int);
index 9c45abbdba7641361d6eb64a80667deb0a62c2ba..bea6710257b88d27ef6ad9ed08581ed56732cd82 100644 (file)
@@ -152,11 +152,15 @@ void TrackView::parseDocument(QDomDocument doc) {
             videotrack = (e.attribute("hide") != "video");
             trackduration = slotAddProjectTrack(pos, p, videotrack);
             pos--;
-            kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
+            //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
             if (trackduration > duration) duration = trackduration;
         } else {
                        // background black track
-                       int black_clips = e.childNodes().count();
+            for (int j = 0; j < m_projectTracks; j++) {
+                p = playlists.item(j).toElement();
+                if (p.attribute("id") == playlist_name) break;
+            }
+                       int black_clips = p.childNodes().count();
                        for (int i = 0; i < black_clips; i++)
                                m_doc->loadingProgressed();
                        qApp->processEvents();
@@ -167,7 +171,7 @@ void TrackView::parseDocument(QDomDocument doc) {
     // parse transitions
     QDomNodeList transitions = doc.elementsByTagName("transition");
     int projectTransitions = transitions.count();
-    kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
+    //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
     for (int i = 0; i < projectTransitions; i++) {
         e = transitions.item(i).toElement();
         QDomNodeList transitionparams = e.childNodes();
@@ -181,7 +185,7 @@ void TrackView::parseDocument(QDomDocument doc) {
                 // do not add audio mixing transitions
                 if (p.attribute("name") == "internal_added" && p.text() == "237") {
                     transitionAdd = false;
-                    kDebug() << "//  TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
+                    //kDebug() << "//  TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
                     break;
                 } else if (p.attribute("name") == "a_track") a_track = p.text().toInt();
                 else if (p.attribute("name") == "b_track") b_track = m_projectTracks - 1 - p.text().toInt();
@@ -194,7 +198,7 @@ void TrackView::parseDocument(QDomDocument doc) {
             transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
             transitionInfo.endPos = GenTime(e.attribute("out").toInt(), m_doc->fps());
             transitionInfo.track = b_track;
-            kDebug() << "///////////////   +++++++++++  ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
+            //kDebug() << "///////////////   +++++++++++  ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
             Transition *tr = new Transition(transitionInfo, a_track, m_scale, m_doc->fps(), QDomElement());
             m_scene->addItem(tr);
         }
@@ -301,12 +305,12 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool videotrack) {
 
                 ItemInfo clipinfo;
                 clipinfo.startPos = GenTime(position, m_doc->fps());
-                clipinfo.endPos = clipinfo.startPos + GenTime(out, m_doc->fps());
+                clipinfo.endPos = clipinfo.startPos + GenTime(out - in, m_doc->fps());
                 clipinfo.track = ix;
-                kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
+                //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
                 ClipItem *item = new ClipItem(clip, clipinfo, m_scale, m_doc->fps());
                 m_scene->addItem(item);
-                position += out;
+                position += (out - in);
 
                 // parse clip effects
                 for (QDomNode n2 = elem.firstChild(); !n2.isNull(); n2 = n2.nextSibling()) {