From: Jean-Baptiste Mardelle Date: Mon, 14 Sep 2009 16:42:05 +0000 (+0000) Subject: Use QImage instead of QPixmap where possible, rework the clip loading stuff X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=20355351f224646a58f0fc0baecaa647d0f765b3;p=kdenlive Use QImage instead of QPixmap where possible, rework the clip loading stuff svn path=/trunk/kdenlive/; revision=3890 --- diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index c262c9cd..99abfc64 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -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); diff --git a/src/dvdwizardvob.cpp b/src/dvdwizardvob.cpp index b5ef7599..c9829173 100644 --- a/src/dvdwizardvob.cpp +++ b/src/dvdwizardvob.cpp @@ -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); diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index f3591cc8..ad0ab37c 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -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(); } } diff --git a/src/kthumb.cpp b/src/kthumb.cpp index e8b15d8d..8d157367 100644 --- a/src/kthumb.cpp +++ b/src/kthumb.cpp @@ -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); diff --git a/src/kthumb.h b/src/kthumb.h index 82290d20..eb3f61a1 100644 --- a/src/kthumb.h +++ b/src/kthumb.h @@ -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); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ad836cad..867f6ccd 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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) { diff --git a/src/markerdialog.cpp b/src/markerdialog.cpp index d72716c0..a0f62d58 100644 --- a/src/markerdialog.cpp +++ b/src/markerdialog.cpp @@ -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"; } diff --git a/src/monitor.cpp b/src/monitor.cpp index 73d3448f..78acd3d7 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -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); } } diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 44583f76..73c30fd5 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -498,9 +498,12 @@ void ProjectList::deleteProjectFolder(QMap 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); } } diff --git a/src/projectlist.h b/src/projectlist.h index 5d19d328..10c51d6e 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -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(); }; diff --git a/src/renderer.cpp b/src/renderer.cpp index 153ff140..e39a71d4 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -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; } diff --git a/src/renderer.h b/src/renderer.h index 406e2512..8414f633 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -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 diff --git a/src/titlewidget.cpp b/src/titlewidget.cpp index 142260ba..9d7f3f48 100644 --- a/src/titlewidget.cpp +++ b/src/titlewidget.cpp @@ -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))); } }