]> git.sesse.net Git - kdenlive/commitdiff
Use QImage instead of QPixmap where possible, rework the clip loading stuff
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 14 Sep 2009 16:42:05 +0000 (16:42 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 14 Sep 2009 16:42:05 +0000 (16:42 +0000)
svn path=/trunk/kdenlive/; revision=3890

13 files changed:
src/customtrackview.cpp
src/dvdwizardvob.cpp
src/kdenlivedoc.cpp
src/kthumb.cpp
src/kthumb.h
src/mainwindow.cpp
src/markerdialog.cpp
src/monitor.cpp
src/projectlist.cpp
src/projectlist.h
src/renderer.cpp
src/renderer.h
src/titlewidget.cpp

index c262c9cdc1dd0aa0f37c3254ab8e27feec04cf83..99abfc64d6d2a115d5fc4a91793279f29f923541 100644 (file)
@@ -3076,11 +3076,11 @@ void CustomTrackView::deleteSelectedClips()
             emit transitionItemSelected(NULL);
         }
     }
-    if (groupCount > 0 && clipCount == transitionCount == 0)
+    if (groupCount > 0 && (clipCount == transitionCount == 0))
         deleteSelected->setText(i18np("Delete selected group", "Delete selected groups", groupCount));
-    else if (clipCount > 0 && groupCount == transitionCount == 0)
+    else if (clipCount > 0 && (groupCount == transitionCount == 0))
         deleteSelected->setText(i18np("Delete selected clip", "Delete selected clips", clipCount));
-    else if (transitionCount > 0 && groupCount == clipCount == 0)
+    else if (transitionCount > 0 && (groupCount == clipCount == 0))
         deleteSelected->setText(i18np("Delete selected transition", "Delete selected transitions", transitionCount));
     else deleteSelected->setText(i18n("Delete selected items"));
     m_commandStack->push(deleteSelected);
index b5ef75993252c3cf273997ae90d371fe50e70084..c982917321728ed1d0b3a813b200779893024a23 100644 (file)
@@ -125,8 +125,7 @@ void DvdWizardVob::slotAddVobFile(KUrl url, const QString &chapters)
     if (producer->is_blank() == false) {
         int width = 45.0 * profile.dar();
         if (width % 2 == 1) width++;
-        pix = KThumb::getFrame(producer, 0, width, 45);
-        item->setIcon(0, pix);
+        item->setIcon(0, QPixmap::fromImage(KThumb::getFrame(producer, 0, width, 45)));
         int playTime = producer->get_playtime();
         item->setText(1, Timecode::getStringTimecode(playTime, profile.fps()));
         item->setData(1, Qt::UserRole, playTime);
index f3591cc82af6695ac2d9b1afea26aa5e5760ec0e..ad0ab37c8416eb718b86b62afe6dea94decbf022 100644 (file)
@@ -933,8 +933,7 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
 
     if (createClipItem) {
         emit addProjectClip(clip);
-        qApp->processEvents();
-        m_render->getFileProperties(clip->toXML(), clip->getId(), true);
+        //qApp->processEvents();
     }
 }
 
index e8b15d8d35706535888e7e49b340f9c5a05f5985..8d15736749f784f9d763652812faa4e89c48723f 100644 (file)
@@ -190,18 +190,18 @@ void KThumb::extractImage(int frame, int frame2)
     const int theight = KdenliveSettings::trackheight();
 
     if (frame != -1) {
-        QPixmap pix = getFrame(m_producer, frame, twidth, theight);
+        QPixmap pix = QPixmap::fromImage(getFrame(m_producer, frame, twidth, theight));
         emit thumbReady(frame, pix);
     }
     if (frame2 != -1) {
-        QPixmap pix = getFrame(m_producer, frame2, twidth, theight);
+        QPixmap pix = QPixmap::fromImage(getFrame(m_producer, frame2, twidth, theight));
         emit thumbReady(frame2, pix);
     }
 }
 
 QPixmap KThumb::extractImage(int frame, int width, int height)
 {
-    return getFrame(m_producer, frame, width, height);
+    return QPixmap::fromImage(getFrame(m_producer, frame, width, height));
 }
 
 //static
@@ -219,16 +219,16 @@ QPixmap KThumb::getImage(KUrl url, int frame, int width, int height)
     Mlt::Producer *producer = new Mlt::Producer(profile, tmp);
     delete[] tmp;
 
-    pix = getFrame(producer, frame, width, height);
+    pix = QPixmap::fromImage(getFrame(producer, frame, width, height));
     delete producer;
     return pix;
 }
 
 
 //static
-QPixmap KThumb::getFrame(Mlt::Producer *producer, int framepos, int width, int height)
+QImage KThumb::getFrame(Mlt::Producer *producer, int framepos, int width, int height)
 {
-    QPixmap p(width, height);
+    QImage p(width, height, QImage::Format_ARGB32);
     if (producer == NULL) {
         p.fill(Qt::red);
         return p;
@@ -257,7 +257,7 @@ QPixmap KThumb::getFrame(Mlt::Producer *producer, int framepos, int width, int h
     //mlt_service_unlock(service.get_service());
 
     if (!image.isNull()) {
-        p = QPixmap::fromImage(image.rgbSwapped());
+        p = image.rgbSwapped();
     } else
         p.fill(Qt::red);
 
index 82290d204a247a8ea905eb3620b3f4034b2ed43a..eb3f61a1373965ee187b836b3aaae8d56ea10e7d 100644 (file)
@@ -100,7 +100,7 @@ public slots:
     void removeAudioThumb();
     void getAudioThumbs(int channel, double frame, double frameLength, int arrayWidth);
     static QPixmap getImage(KUrl url, int frame, int width, int height);
-    static QPixmap getFrame(Mlt::Producer *producer, int framepos, int width, int height);
+    static QImage getFrame(Mlt::Producer *producer, int framepos, int width, int height);
 
 private slots:
     void slotAudioThumbProgress(const int progress);
index ad836cad8081c29c4a4b0494a4238b69cff9e431..867f6ccd3e30bcb895a0332bbab70fcc2bc1bc8e 100644 (file)
@@ -1763,6 +1763,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //cha
             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
+            disconnect(m_projectList, SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
             m_effectStack->clear();
         }
         //m_activeDocument->setRenderer(NULL);
@@ -1828,7 +1829,9 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //cha
     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
     connect(trackView, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
+    connect(m_projectList, SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
 
+    
     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu, m_clipTypeGroup);
     m_activeTimeline = trackView;
     if (m_renderWidget) {
index d72716c020d2e5354319b99dd0235e38d111cb22..a0f62d58c11771938db229029436db54ac5a6352 100644 (file)
@@ -65,7 +65,7 @@ MarkerDialog::MarkerDialog(DocClipBase *clip, CommentedTime t, Timecode tc, cons
             connect(this, SIGNAL(updateThumb()), m_previewTimer, SLOT(start()));
         case IMAGE:
         case TEXT:
-            p = KThumb::getFrame(m_producer, t.time().frames(m_fps), width, 100);
+            p = QPixmap::fromImage(KThumb::getFrame(m_producer, t.time().frames(m_fps), width, 100));
             break;
         case COLOR:
             colour = colour.replace(0, 2, "#");
@@ -107,7 +107,7 @@ void MarkerDialog::slotUpdateThumb()
     int pos = m_tc.getFrameCount(marker_position->text());
     int width = 100.0 * m_dar;
     if (width % 2 == 1) width++;
-    QPixmap p = KThumb::getFrame(m_producer, pos, width, 100);
+    QPixmap p = QPixmap::fromImage(KThumb::getFrame(m_producer, pos, width, 100));
     if (!p.isNull()) clip_thumb->setPixmap(p);
     else kDebug() << "!!!!!!!!!!!  ERROR CREATING THUMB";
 }
index 73d3448f28faf1e3d83b50e78ebe7a2318e17379..78acd3d76c4b334018592ddb2337fb18207c3e6d 100644 (file)
@@ -450,11 +450,17 @@ void Monitor::slotSetThumbFrame()
 
 void Monitor::slotExtractCurrentFrame()
 {
-    QPixmap frame = render->extractFrame(render->seekFramePosition());
-    QString outputFile = KFileDialog::getSaveFileName(KUrl(), "image/png");
-    if (!outputFile.isEmpty()) {
-        if (QFile::exists(outputFile) && KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it?")) == KMessageBox::No) return;
-        frame.save(outputFile);
+    QImage frame = render->extractFrame(render->seekFramePosition());
+    KFileDialog *fs = new KFileDialog(KUrl(), "image/png",this);
+    fs->setOperationMode(KFileDialog::Saving);
+    fs->setMode(KFile::File);
+    fs->setConfirmOverwrite(true);
+    fs->setKeepLocation(true);
+    fs->exec();
+    QString path = fs->selectedFile();
+    delete fs;
+    if (!path.isEmpty()) {
+        frame.save(path);
     }
 }
 
index 44583f763c1ed9a25c422abe875ea258bd744013..73c30fd5f1b19a3581322604dc7b0e0736d7ffb6 100644 (file)
@@ -498,9 +498,12 @@ void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
 
 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
 {
+    m_listView->setEnabled(false);
     if (getProperties) {
-        m_listView->setEnabled(false);
         m_listView->blockSignals(true);
+        m_refreshed = false;
+        m_infoQueue.insert(clip->getId(), clip->toXML());
+        //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
     }
     const QString parent = clip->getProperty("groupid");
     kDebug() << "Adding clip with groupid: " << parent;
@@ -536,7 +539,8 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
         if (!annotation.isEmpty()) item->setText(2, annotation);
         item->setText(3, QString::number(f.rating()));
     }
-    if (getProperties) m_listView->blockSignals(false);
+    if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
+    if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
 }
 
 void ProjectList::slotResetProjectList()
@@ -550,9 +554,8 @@ void ProjectList::slotResetProjectList()
 
 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
 {
+    m_refreshed = false;
     m_infoQueue.insert(id, xml);
-    m_listView->setEnabled(false);
-    if (!m_queueTimer.isActive()) m_queueTimer.start();
     //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
 }
 
@@ -570,7 +573,8 @@ void ProjectList::slotProcessNextClipInQueue()
         m_infoQueue.remove(j.key());
         emit getFileProperties(dom, id, false);
     }
-    if (!m_infoQueue.isEmpty()) m_queueTimer.start();
+
+    if (!m_infoQueue.isEmpty() && !m_queueTimer.isActive()) m_queueTimer.start();
 }
 
 void ProjectList::slotUpdateClip(const QString &id)
@@ -606,12 +610,14 @@ void ProjectList::updateAllClips()
                 }
             }
             item->setData(1, UsageRole, QString::number(item->numReferences()));
-            qApp->processEvents();
+            //qApp->processEvents();
         }
         ++it;
     }
+    qApp->processEvents();
+    if (!m_queueTimer.isActive()) m_queueTimer.start();
 
-    m_listView->blockSignals(false);
+    if (m_listView->isEnabled()) m_listView->blockSignals(false);
     m_listView->setSortingEnabled(true);
     if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
 }
@@ -809,7 +815,10 @@ void ProjectList::slotCheckForEmptyQueue()
     if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
         m_refreshed = true;
         emit loadingIsOver();
-    } else QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
+        emit displayMessage(QString(), DefaultMessage);
+        m_listView->blockSignals(false);
+        m_listView->setEnabled(true);
+    } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
 }
 
 void ProjectList::reloadClipThumbnails()
@@ -832,7 +841,6 @@ void ProjectList::requestClipThumbnail(const QString id)
 void ProjectList::slotProcessNextThumbnail()
 {
     if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
-        m_listView->setEnabled(true);
         slotCheckForEmptyQueue();
         return;
     }
@@ -841,6 +849,10 @@ void ProjectList::slotProcessNextThumbnail()
         return;
     }
     slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
+    if (m_thumbnailQueue.count() > 1) {
+        emit displayMessage(i18n("Loading clips (%1)", m_thumbnailQueue.count()), InformationMessage);
+        qApp->processEvents();
+    }
 }
 
 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
@@ -862,12 +874,12 @@ void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
         int height = 50;
         int width = (int)(height  * m_render->dar());
         if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
-        else if (clip->clipType() == IMAGE) pix = KThumb::getFrame(item->referencedClip()->producer(), 0, width, height);
+        else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
         else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
         if (!pix.isNull()) {
             m_listView->blockSignals(true);
             item->setIcon(0, pix);
-            m_listView->blockSignals(false);
+            if (m_listView->isEnabled()) m_listView->blockSignals(false);
             m_doc->cachePixmap(item->getClipHash(), pix);
         }
         if (update) emit projectModified();
@@ -894,7 +906,7 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
             emit receivedClipDuration(clipId);
             delete producer;
         }*/
-        m_listView->blockSignals(false);
+        if (m_listView->isEnabled()) m_listView->blockSignals(false);
         if (item->icon(0).isNull()) {
             requestClipThumbnail(clipId);
         }
@@ -910,7 +922,7 @@ void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
         m_listView->blockSignals(true);
         item->setIcon(0, pix);
         m_doc->cachePixmap(item->getClipHash(), pix);
-        m_listView->blockSignals(false);
+        if (m_listView->isEnabled()) m_listView->blockSignals(false);
     }
 }
 
index 5d19d328010510e1f5f7863e8155690c2f30880b..10c51d6ecd73eaff69321fa74ed83dbe68eaab71 100644 (file)
@@ -208,6 +208,7 @@ signals:
     void showClipProperties(DocClipBase *);
     void projectModified();
     void loadingIsOver();
+    void displayMessage(const QString, MessageType);
     void clipNameChanged(const QString, const QString);
     void refreshClip();
 };
index 153ff140f9f789c013fe850eeb3d3fab81ae6465..e39a71d4fd0f253a50edfeb00d0deac7be636f07 100644 (file)
@@ -349,14 +349,15 @@ int Render::renderHeight() const
     return m_mltProfile->height();
 }
 
-QPixmap Render::extractFrame(int frame_position, int width, int height)
+QImage Render::extractFrame(int frame_position, int width, int height)
 {
     if (width == -1) {
         width = renderWidth();
         height = renderHeight();
     } else if (width % 2 == 1) width++;
-    QPixmap pix(width, height);
+
     if (!m_mltProducer) {
+        QImage pix(width, height, QImage::Format_RGB32);
         pix.fill(Qt::black);
         return pix;
     }
index 406e251288af080e6373bcabc989fddc65dcf4ae..8414f633e07f82b65050df223b9e041e2229ee52 100644 (file)
@@ -127,7 +127,7 @@ Q_OBJECT public:
     void stop(const GenTime & startTime);
     void setVolume(double volume);
 
-    QPixmap extractFrame(int frame_position, int width = -1, int height = -1);
+    QImage extractFrame(int frame_position, int width = -1, int height = -1);
     /** Wraps the VEML command of the same name. Tells the renderer to
     play the current scene at the speed specified, relative to normal
     playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play
index 142260ba8e8f9c29c0da30904bcee4d6a6888372..9d7f3f4866aa6f2909bd63a3819afbc736f65211 100644 (file)
@@ -545,7 +545,7 @@ void TitleWidget::displayBackgroundFrame()
         p.end();
         m_frameImage->setPixmap(bg);
     } else {
-        m_frameImage->setPixmap(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2));
+        m_frameImage->setPixmap(QPixmap::fromImage(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2)));
     }
 }