X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmonitor.cpp;h=2b8cd627b7276942a20936f2e85647b526e3978d;hb=edb2e9a073ba73424d17da6e0821d0e1c0281a19;hp=3242e71eaa53bdd50d034c971279f90538085884;hpb=166bcc9f67827ac012c26e39621714516ccc1ac3;p=kdenlive diff --git a/src/monitor.cpp b/src/monitor.cpp index 3242e71e..2b8cd627 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -23,14 +23,16 @@ #include "docclipbase.h" #include "abstractclipitem.h" #include "monitorscene.h" -#include "monitoreditwidget.h" +#include "widgets/monitoreditwidget.h" +#include "widgets/videosurface.h" #include "kdenlivesettings.h" #include -#include +#include #include #include #include +#include #include #include @@ -41,24 +43,29 @@ #include #include #include +#include #define SEEK_INACTIVE (-1) -Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profile, QWidget *parent) : - AbstractMonitor(id, manager, parent), - render(NULL), - m_currentClip(NULL), - m_overlay(NULL), - m_scale(1), - m_length(0), - m_dragStarted(false), - m_contextMenu(NULL), - m_effectWidget(NULL), - m_selectedClip(NULL), - m_loopClipTransition(true), - m_editMarker(NULL) +Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QString profile, QWidget *parent) : + AbstractMonitor(id, manager, parent) + , render(NULL) + , m_currentClip(NULL) + , m_overlay(NULL) + , m_scale(1) + , m_length(2) + , m_dragStarted(false) + , m_loopClipAction(NULL) + , m_contextMenu(NULL) + , m_effectWidget(NULL) + , m_selectedClip(NULL) + , m_loopClipTransition(true) +#ifdef USE_OPENGL + , m_glWidget(NULL) +#endif + , m_editMarker(NULL) { QVBoxLayout *layout = new QVBoxLayout; layout->setContentsMargins(0, 0, 0, 0); @@ -80,7 +87,7 @@ Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profil m_pauseIcon = KIcon("media-playback-pause"); - if (id != Kdenlive::dvdMonitor) { + if (id != Kdenlive::DvdMonitor) { m_toolbar->addAction(KIcon("kdenlive-zone-start"), i18n("Set zone start"), this, SLOT(slotSetZoneStart())); m_toolbar->addAction(KIcon("kdenlive-zone-end"), i18n("Set zone end"), this, SLOT(slotSetZoneEnd())); } @@ -103,7 +110,7 @@ Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profil playButton->setDefaultAction(m_playAction); - if (id != Kdenlive::dvdMonitor) { + if (id != Kdenlive::DvdMonitor) { QToolButton *configButton = new QToolButton(m_toolbar); m_configMenu = new QMenu(i18n("Misc..."), this); configButton->setIcon(KIcon("system-run")); @@ -111,11 +118,11 @@ Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profil configButton->setPopupMode(QToolButton::QToolButton::InstantPopup); m_toolbar->addWidget(configButton); - if (id == Kdenlive::clipMonitor) { + if (id == Kdenlive::ClipMonitor) { m_markerMenu = new QMenu(i18n("Go to marker..."), this); m_markerMenu->setEnabled(false); m_configMenu->addMenu(m_markerMenu); - connect(m_markerMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToMarker(QAction *))); + connect(m_markerMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotGoToMarker(QAction*))); } m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (100%)"), this, SLOT(slotSetSizeOneToOne())); m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (50%)"), this, SLOT(slotSetSizeOneToTwo())); @@ -143,7 +150,8 @@ Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profil setLayout(layout); setMinimumHeight(200); - if (profile.isEmpty()) profile = KdenliveSettings::current_profile(); + if (profile.isEmpty()) + profile = KdenliveSettings::current_profile(); bool monitorCreated = false; #ifdef Q_WS_MAC @@ -170,8 +178,8 @@ Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profil #endif // Monitor ruler - m_ruler = new SmallRuler(m_monitorManager, render); - if (id == Kdenlive::dvdMonitor) m_ruler->setZone(-3, -2); + m_ruler = new SmallRuler(this, render); + if (id == Kdenlive::DvdMonitor) m_ruler->setZone(-3, -2); layout->addWidget(m_ruler); connect(m_audioSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetVolume(int))); @@ -179,7 +187,7 @@ Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profil connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int))); connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int))); - if (id != Kdenlive::clipMonitor) { + if (id != Kdenlive::ClipMonitor) { connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int))); connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int))); connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SIGNAL(zoneUpdated(QPoint))); @@ -189,9 +197,9 @@ Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profil if (videoSurface) videoSurface->show(); - if (id == Kdenlive::projectMonitor) { + if (id == Kdenlive::ProjectMonitor) { m_effectWidget = new MonitorEditWidget(render, videoBox); - connect(m_effectWidget, SIGNAL(showEdit(bool, bool)), this, SLOT(slotShowEffectScene(bool, bool))); + connect(m_effectWidget, SIGNAL(showEdit(bool,bool)), this, SLOT(slotShowEffectScene(bool,bool))); m_toolbar->addAction(m_effectWidget->getVisibilityAction()); videoBox->layout()->addWidget(m_effectWidget); m_effectWidget->hide(); @@ -203,7 +211,7 @@ Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profil m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this); m_toolbar->addWidget(m_timePos); connect(m_timePos, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotSeek())); - m_toolbar->setMaximumHeight(s * 1.5); + m_toolbar->setMaximumHeight(m_timePos->height()); layout->addWidget(m_toolbar); } @@ -223,10 +231,9 @@ QWidget *Monitor::container() } #ifdef USE_OPENGL -bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile) +bool Monitor::createOpenGlWidget(QWidget *parent, const QString &profile) { render = new Render(id(), 0, profile, this); - kDebug()<<"+++++++++++++\nCREATED OPENGL WIDG\n++++++++++++++"; m_glWidget = new VideoGLWidget(parent); if (m_glWidget == NULL) { // Creation failed, we are in trouble... @@ -248,7 +255,7 @@ void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMe if (markerMenu) { m_contextMenu->addMenu(markerMenu); QList list = markerMenu->actions(); - for (int i = 0; i < list.count(); i++) { + for (int i = 0; i < list.count(); ++i) { if (list.at(i)->data().toString() == "edit_marker") { m_editMarker = list.at(i); break; @@ -264,7 +271,7 @@ void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMe } //TODO: add save zone to timeline monitor when fixed - if (m_id == Kdenlive::clipMonitor) { + if (m_id == Kdenlive::ClipMonitor) { m_contextMenu->addMenu(m_markerMenu); m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone())); QAction *extractZone = m_configMenu->addAction(KIcon("document-new"), i18n("Extract Zone"), this, SLOT(slotExtractCurrentZone())); @@ -273,7 +280,7 @@ void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMe QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame())); m_contextMenu->addAction(extractFrame); - if (m_id != Kdenlive::clipMonitor) { + if (m_id != Kdenlive::ClipMonitor) { QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool))); splitView->setCheckable(true); m_configMenu->addAction(splitView); @@ -291,10 +298,9 @@ void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMe dropFrames->setCheckable(true); dropFrames->setChecked(true); connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool))); - + m_configMenu->addAction(showTips); m_configMenu->addAction(dropFrames); - } void Monitor::slotGoToMarker(QAction *action) @@ -348,6 +354,16 @@ void Monitor::resetSize() videoBox->setMinimumSize(0, 0); } +QString Monitor::getTimecodeFromFrames(int pos) +{ + return m_monitorManager->timecode().getTimecodeFromFrames(pos); +} + +double Monitor::fps() const +{ + return m_monitorManager->timecode().fps(); +} + DocClipBase *Monitor::activeClip() { return m_currentClip; @@ -360,7 +376,7 @@ void Monitor::updateMarkers(DocClipBase *source) QList markers = m_currentClip->commentedSnapMarkers(); if (!markers.isEmpty()) { QList marks; - for (int i = 0; i < markers.count(); i++) { + for (int i = 0; i < markers.count(); ++i) { int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps()); marks.append(pos); QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment(); @@ -373,6 +389,11 @@ void Monitor::updateMarkers(DocClipBase *source) } } +void Monitor::setMarkers(const QList &markers) +{ + m_ruler->setMarkers(markers); +} + void Monitor::slotSeekToPreviousSnap() { if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps())); @@ -418,29 +439,30 @@ GenTime Monitor::getSnapForPos(bool previous) void Monitor::slotZoneMoved(int start, int end) { m_ruler->setZone(start, end); - checkOverlay(); setClipZone(m_ruler->zone()); + checkOverlay(); } void Monitor::slotSetZoneStart() { m_ruler->setZoneStart(); emit zoneUpdated(m_ruler->zone()); - checkOverlay(); setClipZone(m_ruler->zone()); + checkOverlay(); } void Monitor::slotSetZoneEnd() { m_ruler->setZoneEnd(); emit zoneUpdated(m_ruler->zone()); - checkOverlay(); setClipZone(m_ruler->zone()); + checkOverlay(); } // virtual void Monitor::mousePressEvent(QMouseEvent * event) { + if (render) render->setActiveMonitor(); if (event->button() != Qt::RightButton) { if (videoBox->geometry().contains(event->pos()) && (!m_overlay || !m_overlay->underMouse())) { m_dragStarted = true; @@ -453,7 +475,7 @@ void Monitor::mousePressEvent(QMouseEvent * event) void Monitor::resizeEvent(QResizeEvent *event) { - Q_UNUSED(event); + Q_UNUSED(event) if (render && isVisible() && isActive()) render->doRefresh(); } @@ -470,8 +492,9 @@ void Monitor::mouseReleaseEvent(QMouseEvent * event) if (isActive()) slotPlay(); else slotActivateMonitor(); } //else event->ignore(); //QWidget::mouseReleaseEvent(event); - m_dragStarted = false; } + m_dragStarted = false; + event->accept(); } // virtual @@ -500,9 +523,9 @@ void Monitor::mouseMoveEvent(QMouseEvent *event) drag->setPixmap(pix); drag->setHotSpot(QPoint(0, 50));*/ drag->start(Qt::MoveAction); - - //Qt::DropAction dropAction; - //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction); + /*Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction); + Qt::DropAction dropAction; + dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);*/ //Qt::DropAction dropAction = drag->exec(); @@ -510,6 +533,7 @@ void Monitor::mouseMoveEvent(QMouseEvent *event) //event->accept(); } + /*void Monitor::dragMoveEvent(QDragMoveEvent * event) { event->setDropAction(Qt::IgnoreAction); event->setDropAction(Qt::MoveAction); @@ -589,13 +613,13 @@ void Monitor::slotExtractCurrentFrame() fs->setMode(KFile::File); fs->setConfirmOverwrite(true); fs->setKeepLocation(true); - fs->exec(); - QString path; - if (fs) path = fs->selectedFile(); - delete fs; - if (!path.isEmpty()) { - frame.save(path); + if (fs->exec()) { + QString path = fs->selectedFile(); + if (!path.isEmpty()) { + frame.save(path); + } } + delete fs; } void Monitor::setTimePos(const QString &pos) @@ -621,7 +645,7 @@ void Monitor::checkOverlay() { if (m_overlay == NULL) return; QString overlayText; - int pos = render->seekFramePosition(); + int pos = m_timePos->getValue();//render->seekFramePosition(); QPoint zone = m_ruler->zone(); if (pos == zone.x()) overlayText = i18n("In Point"); @@ -735,16 +759,16 @@ void Monitor::slotForwardOneFrame(int diff) void Monitor::seekCursor(int pos) { if (m_ruler->slotNewValue(pos)) { - checkOverlay(); m_timePos->setValue(pos); + checkOverlay(); } } void Monitor::rendererStopped(int pos) { if (m_ruler->slotNewValue(pos)) { - checkOverlay(); m_timePos->setValue(pos); + checkOverlay(); } m_playAction->setIcon(m_playIcon); } @@ -767,6 +791,9 @@ void Monitor::stop() void Monitor::start() { if (!isVisible() || !isActive()) return; +#ifdef USE_OPENGL + if (m_glWidget) m_glWidget->activateMonitor(); +#endif if (render) render->startConsumer(); } @@ -804,12 +831,13 @@ void Monitor::slotPlay() { if (render == NULL) return; slotActivateMonitor(); - if (render->playSpeed() == 0.0) { + if (render->isPlaying()) { + m_playAction->setIcon(m_playIcon); + render->switchPlay(false); + } + else { m_playAction->setIcon(m_pauseIcon); render->switchPlay(true); - } else { - m_playAction->setIcon(m_playIcon); - render->switchPlay(false); } m_ruler->refreshRuler(); } @@ -847,7 +875,7 @@ void Monitor::slotLoopClip() void Monitor::updateClipProducer(Mlt::Producer *prod) { if (render == NULL) return; - render->setProducer(prod, render->seekFramePosition()); + render->setProducer(prod, render->seekFramePosition()); } void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position) @@ -855,7 +883,6 @@ void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpda if (render == NULL) return; if (clip == NULL && m_currentClip != NULL) { m_currentClip->lastSeekPosition = render->seekFramePosition(); - kDebug()<<"// SETTING NULL CLIP MONITOR"; m_currentClip = NULL; m_length = -1; render->setProducer(NULL, -1); @@ -872,12 +899,17 @@ void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpda if (render->setProducer(prod, position) == -1) { // MLT CONSUMER is broken kDebug(QtWarningMsg) << "ERROR, Cannot start monitor"; - } + } else start(); } else { if (m_currentClip) { slotActivateMonitor(); if (position == -1) position = render->seekFramePosition(); render->seek(position); + if (zone.isNull()) { + zone = m_currentClip->zone(); + m_ruler->setZone(zone.x(), zone.y()); + return; + } } } if (!zone.isNull()) { @@ -890,14 +922,7 @@ void Monitor::slotOpenFile(const QString &file) { if (render == NULL) return; slotActivateMonitor(); - QDomDocument doc; - QDomElement mlt = doc.createElement("mlt"); - doc.appendChild(mlt); - QDomElement prod = doc.createElement("producer"); - mlt.appendChild(prod); - prod.setAttribute("mlt_service", "avformat"); - prod.setAttribute("resource", file); - render->setSceneList(doc, 0); + render->loadUrl(file); } void Monitor::slotSaveZone() @@ -908,6 +933,19 @@ void Monitor::slotSaveZone() //render->setSceneList(doc, 0); } +void Monitor::setCustomProfile(const QString &profile, const Timecode &tc) +{ + m_timePos->updateTimeCode(tc); + if (render == NULL) return; + if (!render->hasProfile(profile)) { + slotActivateMonitor(); + render->resetProfile(profile); +#ifdef USE_OPENGL + if (m_glWidget) m_glWidget->setImageAspectRatio(render->dar()); +#endif + } +} + void Monitor::resetProfile(const QString &profile) { m_timePos->updateTimeCode(m_monitorManager->timecode()); @@ -915,12 +953,15 @@ void Monitor::resetProfile(const QString &profile) if (!render->hasProfile(profile)) { slotActivateMonitor(); render->resetProfile(profile); +#ifdef USE_OPENGL + if (m_glWidget) m_glWidget->setImageAspectRatio(render->dar()); +#endif } if (m_effectWidget) m_effectWidget->resetProfile(render); } -void Monitor::saveSceneList(QString path, QDomElement info) +void Monitor::saveSceneList(const QString &path, const QDomElement &info) { if (render == NULL) return; render->saveSceneList(path, info); @@ -932,7 +973,7 @@ const QString Monitor::sceneList() return render->sceneList(); } -void Monitor::setClipZone(QPoint pos) +void Monitor::setClipZone(const QPoint &pos) { if (m_currentClip == NULL) return; m_currentClip->setZone(pos); @@ -1000,10 +1041,10 @@ QStringList Monitor::getZoneInfo() const void Monitor::slotSetSelectedClip(AbstractClipItem* item) { if (item) { - m_loopClipAction->setEnabled(true); + if (m_loopClipAction) m_loopClipAction->setEnabled(true); m_selectedClip = item; } else { - m_loopClipAction->setEnabled(false); + if (m_loopClipAction) m_loopClipAction->setEnabled(false); } } @@ -1026,7 +1067,7 @@ void Monitor::slotSetSelectedClip(Transition* item) void Monitor::slotShowEffectScene(bool show, bool manuallyTriggered) { - if (m_id == Kdenlive::projectMonitor) { + if (m_id == Kdenlive::ProjectMonitor) { if (!m_effectWidget->getVisibilityAction()->isChecked()) show = false; if (m_effectWidget->isVisible() == show) @@ -1111,6 +1152,16 @@ void Monitor::reloadProducer(const QString &id) slotSetClipProducer(m_currentClip, m_currentClip->zone(), true); } +QString Monitor::getMarkerThumb(GenTime pos) +{ + if (!m_currentClip) return QString(); + if (!m_currentClip->getClipHash().isEmpty()) { + QString url = m_monitorManager->getProjectFolder() + "thumbs/" + m_currentClip->getClipHash() + '#' + QString::number((int) pos.frames(m_monitorManager->timecode().fps())) + ".png"; + if (QFile::exists(url)) return url; + } + return QString(); +} + void Monitor::setPalette ( const QPalette & p) { QWidget::setPalette(p); @@ -1126,6 +1177,7 @@ Overlay::Overlay(QWidget* parent) : setBackgroundRole(QPalette::Base); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); setCursor(Qt::PointingHandCursor); + } // virtual @@ -1150,11 +1202,11 @@ void Overlay::mouseDoubleClickEvent ( QMouseEvent * event ) void Overlay::setOverlayText(const QString &text, bool isZone) { if (text.isEmpty()) { - QPalette p; + /*QPalette p; p.setColor(QPalette::Base, KdenliveSettings::window_background()); setPalette(p); setText(QString()); - repaint(); + repaint();*/ setHidden(true); return; }