1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
22 #include "smallruler.h"
23 #include "docclipbase.h"
24 #include "abstractclipitem.h"
25 #include "monitorscene.h"
26 #include "monitoreditwidget.h"
27 #include "kdenlivesettings.h"
31 #include <KFileDialog>
32 #include <KApplication>
33 #include <KMessageBox>
34 #include <KSelectAction>
36 #include <QMouseEvent>
37 #include <QStylePainter>
39 #include <QToolButton>
41 #include <QDesktopWidget>
43 #include <QIntValidator>
44 #include <QVBoxLayout>
48 #define SEEK_INACTIVE (-1)
51 Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profile, QWidget *parent) :
52 AbstractMonitor(id, manager, parent)
58 , m_dragStarted(false)
59 , m_loopClipAction(NULL)
61 , m_effectWidget(NULL)
62 , m_selectedClip(NULL)
63 , m_loopClipTransition(true)
69 QVBoxLayout *layout = new QVBoxLayout;
70 layout->setContentsMargins(0, 0, 0, 0);
71 layout->setSpacing(0);
73 // Video widget holder
74 layout->addWidget(videoBox, 10);
77 // Get base size for icons
78 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
82 m_toolbar = new QToolBar(this);
83 m_toolbar->setIconSize(QSize(s, s));
85 m_playIcon = KIcon("media-playback-start");
86 m_pauseIcon = KIcon("media-playback-pause");
89 if (id != Kdenlive::dvdMonitor) {
90 m_toolbar->addAction(KIcon("kdenlive-zone-start"), i18n("Set zone start"), this, SLOT(slotSetZoneStart()));
91 m_toolbar->addAction(KIcon("kdenlive-zone-end"), i18n("Set zone end"), this, SLOT(slotSetZoneEnd()));
94 m_toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"), this, SLOT(slotRewind()));
95 //m_toolbar->addAction(KIcon("media-skip-backward"), i18n("Rewind 1 frame"), this, SLOT(slotRewindOneFrame()));
97 QToolButton *playButton = new QToolButton(m_toolbar);
98 m_playMenu = new QMenu(i18n("Play..."), this);
99 m_playAction = m_playMenu->addAction(m_playIcon, i18n("Play"));
100 //m_playAction->setCheckable(true);
101 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
103 playButton->setMenu(m_playMenu);
104 playButton->setPopupMode(QToolButton::MenuButtonPopup);
105 m_toolbar->addWidget(playButton);
107 //m_toolbar->addAction(KIcon("media-skip-forward"), i18n("Forward 1 frame"), this, SLOT(slotForwardOneFrame()));
108 m_toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"), this, SLOT(slotForward()));
110 playButton->setDefaultAction(m_playAction);
112 if (id != Kdenlive::dvdMonitor) {
113 QToolButton *configButton = new QToolButton(m_toolbar);
114 m_configMenu = new QMenu(i18n("Misc..."), this);
115 configButton->setIcon(KIcon("system-run"));
116 configButton->setMenu(m_configMenu);
117 configButton->setPopupMode(QToolButton::QToolButton::InstantPopup);
118 m_toolbar->addWidget(configButton);
120 if (id == Kdenlive::clipMonitor) {
121 m_markerMenu = new QMenu(i18n("Go to marker..."), this);
122 m_markerMenu->setEnabled(false);
123 m_configMenu->addMenu(m_markerMenu);
124 connect(m_markerMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotGoToMarker(QAction*)));
126 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (100%)"), this, SLOT(slotSetSizeOneToOne()));
127 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (50%)"), this, SLOT(slotSetSizeOneToTwo()));
130 // Create Volume slider popup
131 m_volumePopup = new QFrame(this, Qt::Popup);
132 QVBoxLayout *poplayout = new QVBoxLayout;
133 poplayout->setContentsMargins(0, 0, 0, 0);
134 m_audioSlider = new QSlider(Qt::Vertical);
135 m_audioSlider->setRange(0, 100);
136 poplayout->addWidget(m_audioSlider);
137 m_volumePopup->setLayout(poplayout);
139 if (KdenliveSettings::volume() == 0) icon = KIcon("audio-volume-muted");
140 else icon = KIcon("audio-volume-medium");
142 m_volumeWidget = m_toolbar->widgetForAction(m_toolbar->addAction(icon, i18n("Audio volume"), this, SLOT(slotShowVolume())));
144 // we need to show / hide the popup once so that it's geometry can be calculated in slotShowVolume
145 m_volumePopup->show();
146 m_volumePopup->hide();
148 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
150 setMinimumHeight(200);
152 if (profile.isEmpty())
153 profile = KdenliveSettings::current_profile();
155 bool monitorCreated = false;
157 createOpenGlWidget(videoBox, profile);
158 monitorCreated = true;
159 //m_glWidget->setFixedSize(width, height);
160 #elif defined(USE_OPENGL)
161 if (KdenliveSettings::openglmonitors()) {
162 monitorCreated = createOpenGlWidget(videoBox, profile);
165 if (!monitorCreated) {
166 createVideoSurface();
167 render = new Render(m_id, (int) videoSurface->winId(), profile, this);
168 connect(videoSurface, SIGNAL(refreshMonitor()), render, SLOT(doRefresh()));
171 else if (m_glWidget) {
172 QVBoxLayout *lay = new QVBoxLayout;
173 lay->setContentsMargins(0, 0, 0, 0);
174 lay->addWidget(m_glWidget);
175 videoBox->setLayout(lay);
180 m_ruler = new SmallRuler(this, render);
181 if (id == Kdenlive::dvdMonitor) m_ruler->setZone(-3, -2);
182 layout->addWidget(m_ruler);
184 connect(m_audioSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetVolume(int)));
185 connect(render, SIGNAL(durationChanged(int)), this, SLOT(adjustRulerSize(int)));
186 connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int)));
187 connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
189 if (id != Kdenlive::clipMonitor) {
190 connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int)));
191 connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int)));
192 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SIGNAL(zoneUpdated(QPoint)));
194 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SLOT(setClipZone(QPoint)));
197 if (videoSurface) videoSurface->show();
199 if (id == Kdenlive::projectMonitor) {
200 m_effectWidget = new MonitorEditWidget(render, videoBox);
201 connect(m_effectWidget, SIGNAL(showEdit(bool,bool)), this, SLOT(slotShowEffectScene(bool,bool)));
202 m_toolbar->addAction(m_effectWidget->getVisibilityAction());
203 videoBox->layout()->addWidget(m_effectWidget);
204 m_effectWidget->hide();
207 QWidget *spacer = new QWidget(this);
208 spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
209 m_toolbar->addWidget(spacer);
210 m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this);
211 m_toolbar->addWidget(m_timePos);
212 connect(m_timePos, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotSeek()));
213 m_toolbar->setMaximumHeight(m_timePos->height());
214 layout->addWidget(m_toolbar);
223 delete m_effectWidget;
227 QWidget *Monitor::container()
233 bool Monitor::createOpenGlWidget(QWidget *parent, const QString &profile)
235 render = new Render(id(), 0, profile, this);
236 m_glWidget = new VideoGLWidget(parent);
237 if (m_glWidget == NULL) {
238 // Creation failed, we are in trouble...
241 m_glWidget->setImageAspectRatio(render->dar());
242 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
243 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
248 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
250 m_contextMenu = new QMenu(this);
251 m_contextMenu->addMenu(m_playMenu);
253 m_contextMenu->addMenu(goMenu);
255 m_contextMenu->addMenu(markerMenu);
256 QList <QAction *>list = markerMenu->actions();
257 for (int i = 0; i < list.count(); ++i) {
258 if (list.at(i)->data().toString() == "edit_marker") {
259 m_editMarker = list.at(i);
265 m_playMenu->addAction(playZone);
266 m_playMenu->addAction(loopZone);
268 m_loopClipAction = loopClip;
269 m_playMenu->addAction(loopClip);
272 //TODO: add save zone to timeline monitor when fixed
273 if (m_id == Kdenlive::clipMonitor) {
274 m_contextMenu->addMenu(m_markerMenu);
275 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
276 QAction *extractZone = m_configMenu->addAction(KIcon("document-new"), i18n("Extract Zone"), this, SLOT(slotExtractCurrentZone()));
277 m_contextMenu->addAction(extractZone);
279 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
280 m_contextMenu->addAction(extractFrame);
282 if (m_id != Kdenlive::clipMonitor) {
283 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
284 splitView->setCheckable(true);
285 m_configMenu->addAction(splitView);
287 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
288 m_configMenu->addAction(setThumbFrame);
291 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
292 showTips->setCheckable(true);
293 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
294 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
296 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
297 dropFrames->setCheckable(true);
298 dropFrames->setChecked(true);
299 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
301 m_configMenu->addAction(showTips);
302 m_configMenu->addAction(dropFrames);
305 void Monitor::slotGoToMarker(QAction *action)
307 int pos = action->data().toInt();
311 void Monitor::slotSetSizeOneToOne()
313 QRect r = QApplication::desktop()->screenGeometry();
314 const int maxWidth = r.width() - 20;
315 const int maxHeight = r.height() - 20;
316 int width = render->renderWidth();
317 int height = render->renderHeight();
318 kDebug() << "// render info: " << width << "x" << height;
319 while (width >= maxWidth || height >= maxHeight) {
321 height = height * 0.8;
323 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
324 videoBox->setFixedSize(width, height);
327 //m_ui.video_frame->setMinimumSize(0, 0);
328 emit adjustMonitorSize();
331 void Monitor::slotSetSizeOneToTwo()
333 QRect r = QApplication::desktop()->screenGeometry();
334 const int maxWidth = r.width() - 20;
335 const int maxHeight = r.height() - 20;
336 int width = render->renderWidth() / 2;
337 int height = render->renderHeight() / 2;
338 kDebug() << "// render info: " << width << "x" << height;
339 while (width >= maxWidth || height >= maxHeight) {
341 height = height * 0.8;
343 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
344 videoBox->setFixedSize(width, height);
347 //m_ui.video_frame->setMinimumSize(0, 0);
348 emit adjustMonitorSize();
351 void Monitor::resetSize()
353 videoBox->setMinimumSize(0, 0);
356 QString Monitor::getTimecodeFromFrames(int pos)
358 return m_monitorManager->timecode().getTimecodeFromFrames(pos);
361 double Monitor::fps() const
363 return m_monitorManager->timecode().fps();
366 DocClipBase *Monitor::activeClip()
368 return m_currentClip;
371 void Monitor::updateMarkers(DocClipBase *source)
373 if (source == m_currentClip && source != NULL) {
374 m_markerMenu->clear();
375 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
376 if (!markers.isEmpty()) {
378 for (int i = 0; i < markers.count(); ++i) {
379 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
381 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
382 QAction *go = m_markerMenu->addAction(position);
386 m_ruler->setMarkers(markers);
387 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
391 void Monitor::setMarkers(const QList<CommentedTime> &markers)
393 m_ruler->setMarkers(markers);
396 void Monitor::slotSeekToPreviousSnap()
398 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
401 void Monitor::slotSeekToNextSnap()
403 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
406 GenTime Monitor::position()
408 return render->seekPosition();
411 GenTime Monitor::getSnapForPos(bool previous)
413 QList <GenTime> snaps;
414 QList < GenTime > markers = m_currentClip->snapMarkers();
415 for (int i = 0; i < markers.size(); ++i) {
416 GenTime t = markers.at(i);
419 QPoint zone = m_ruler->zone();
420 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
421 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
422 snaps.append(GenTime());
423 snaps.append(m_currentClip->duration());
426 const GenTime pos = render->seekPosition();
427 for (int i = 0; i < snaps.size(); ++i) {
428 if (previous && snaps.at(i) >= pos) {
430 return snaps.at(i - 1);
431 } else if (!previous && snaps.at(i) > pos) {
438 void Monitor::slotZoneMoved(int start, int end)
440 m_ruler->setZone(start, end);
441 setClipZone(m_ruler->zone());
445 void Monitor::slotSetZoneStart()
447 m_ruler->setZoneStart();
448 emit zoneUpdated(m_ruler->zone());
449 setClipZone(m_ruler->zone());
453 void Monitor::slotSetZoneEnd()
455 m_ruler->setZoneEnd();
456 emit zoneUpdated(m_ruler->zone());
457 setClipZone(m_ruler->zone());
462 void Monitor::mousePressEvent(QMouseEvent * event)
464 if (render) render->setActiveMonitor();
465 if (event->button() != Qt::RightButton) {
466 if (videoBox->geometry().contains(event->pos()) && (!m_overlay || !m_overlay->underMouse())) {
467 m_dragStarted = true;
468 m_DragStartPosition = event->pos();
470 } else if (m_contextMenu && (!m_effectWidget || !m_effectWidget->isVisible())) {
471 m_contextMenu->popup(event->globalPos());
475 void Monitor::resizeEvent(QResizeEvent *event)
478 if (render && isVisible() && isActive()) render->doRefresh();
481 void Monitor::slotSwitchFullScreen()
483 videoBox->switchFullScreen();
487 void Monitor::mouseReleaseEvent(QMouseEvent * event)
489 if (m_dragStarted && event->button() != Qt::RightButton) {
490 if (videoBox->geometry().contains(event->pos()) && (!m_effectWidget || !m_effectWidget->isVisible())) {
491 if (isActive()) slotPlay();
492 else slotActivateMonitor();
493 } //else event->ignore(); //QWidget::mouseReleaseEvent(event);
495 m_dragStarted = false;
500 void Monitor::mouseMoveEvent(QMouseEvent *event)
502 if (!m_dragStarted || m_currentClip == NULL) return;
504 if ((event->pos() - m_DragStartPosition).manhattanLength()
505 < QApplication::startDragDistance())
509 QDrag *drag = new QDrag(this);
510 QMimeData *mimeData = new QMimeData;
513 list.append(m_currentClip->getId());
514 QPoint p = m_ruler->zone();
515 list.append(QString::number(p.x()));
516 list.append(QString::number(p.y()));
518 data.append(list.join(";").toUtf8());
519 mimeData->setData("kdenlive/clip", data);
520 drag->setMimeData(mimeData);
521 /*QPixmap pix = m_currentClip->thumbnail();
522 drag->setPixmap(pix);
523 drag->setHotSpot(QPoint(0, 50));*/
524 drag->start(Qt::MoveAction);
525 /*Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
526 Qt::DropAction dropAction;
527 dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);*/
529 //Qt::DropAction dropAction = drag->exec();
536 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
537 event->setDropAction(Qt::IgnoreAction);
538 event->setDropAction(Qt::MoveAction);
539 if (event->mimeData()->hasText()) {
540 event->acceptProposedAction();
544 Qt::DropActions Monitor::supportedDropActions() const {
545 // returns what actions are supported when dropping
546 return Qt::MoveAction;
549 QStringList Monitor::mimeTypes() const
551 QStringList qstrList;
552 // list of accepted mime types for drop
553 qstrList.append("kdenlive/clip");
558 void Monitor::wheelEvent(QWheelEvent * event)
560 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
564 void Monitor::mouseDoubleClickEvent(QMouseEvent * event)
566 if (!KdenliveSettings::openglmonitors()) {
567 videoBox->switchFullScreen();
572 void Monitor::slotMouseSeek(int eventDelta, bool fast)
575 int delta = m_monitorManager->timecode().fps();
576 if (eventDelta > 0) delta = 0 - delta;
577 if (render->requestedSeekPosition != SEEK_INACTIVE)
578 slotSeek(render->requestedSeekPosition - delta);
579 else slotSeek(render->seekFramePosition() - delta);
581 if (eventDelta >= 0) slotForwardOneFrame();
582 else slotRewindOneFrame();
586 void Monitor::slotSetThumbFrame()
588 if (m_currentClip == NULL) {
591 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
592 emit refreshClipThumbnail(m_currentClip->getId(), true);
595 void Monitor::slotExtractCurrentZone()
597 if (m_currentClip == NULL) return;
598 emit extractZone(m_currentClip->getId(), m_ruler->zone());
601 void Monitor::slotExtractCurrentFrame()
604 // check if we are using a proxy
605 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
606 // using proxy, use original clip url to get frame
607 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
609 else frame = render->extractFrame(render->seekFramePosition());
610 QPointer<KFileDialog> fs = new KFileDialog(KUrl(), "image/png", this);
611 fs->setOperationMode(KFileDialog::Saving);
612 fs->setMode(KFile::File);
613 fs->setConfirmOverwrite(true);
614 fs->setKeepLocation(true);
616 QString path = fs->selectedFile();
617 if (!path.isEmpty()) {
624 void Monitor::setTimePos(const QString &pos)
626 m_timePos->setValue(pos);
630 void Monitor::slotSeek()
632 slotSeek(m_timePos->getValue());
635 void Monitor::slotSeek(int pos)
637 if (render == NULL) return;
638 slotActivateMonitor();
639 render->seekToFrame(pos);
643 void Monitor::checkOverlay()
645 if (m_overlay == NULL) return;
647 int pos = m_timePos->getValue();//render->seekFramePosition();
648 QPoint zone = m_ruler->zone();
650 overlayText = i18n("In Point");
651 else if (pos == zone.y())
652 overlayText = i18n("Out Point");
655 overlayText = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
656 if (!overlayText.isEmpty()) {
657 m_overlay->setOverlayText(overlayText, false);
662 if (m_overlay->isVisible() && overlayText.isEmpty()) m_overlay->setOverlayText(QString(), false);
663 else m_overlay->setOverlayText(overlayText);
666 void Monitor::slotStart()
668 slotActivateMonitor();
670 render->seekToFrame(0);
673 void Monitor::slotEnd()
675 slotActivateMonitor();
677 render->seekToFrame(render->getLength());
680 void Monitor::slotZoneStart()
682 slotActivateMonitor();
684 render->seekToFrame(m_ruler->zone().x());
687 void Monitor::slotZoneEnd()
689 slotActivateMonitor();
691 render->seekToFrame(m_ruler->zone().y());
694 void Monitor::slotRewind(double speed)
696 slotActivateMonitor();
698 double currentspeed = render->playSpeed();
699 if (currentspeed >= 0) render->play(-1);
700 else switch((int) currentspeed) {
713 } else render->play(speed);
714 //m_playAction->setChecked(true);
715 m_playAction->setIcon(m_pauseIcon);
718 void Monitor::slotForward(double speed)
720 slotActivateMonitor();
722 double currentspeed = render->playSpeed();
723 if (currentspeed <= 0) render->play(1);
724 else switch((int) currentspeed) {
737 } else render->play(speed);
738 //m_playAction->setChecked(true);
739 m_playAction->setIcon(m_pauseIcon);
742 void Monitor::slotRewindOneFrame(int diff)
744 slotActivateMonitor();
746 render->seekToFrameDiff(-diff);
750 void Monitor::slotForwardOneFrame(int diff)
752 slotActivateMonitor();
754 render->seekToFrameDiff(diff);
758 void Monitor::seekCursor(int pos)
760 if (m_ruler->slotNewValue(pos)) {
761 m_timePos->setValue(pos);
766 void Monitor::rendererStopped(int pos)
768 if (m_ruler->slotNewValue(pos)) {
769 m_timePos->setValue(pos);
772 m_playAction->setIcon(m_playIcon);
775 void Monitor::adjustRulerSize(int length)
777 if (length > 0) m_length = length;
778 m_ruler->adjustScale(m_length);
779 if (m_currentClip != NULL) {
780 QPoint zone = m_currentClip->zone();
781 m_ruler->setZone(zone.x(), zone.y());
787 if (render) render->stop();
790 void Monitor::start()
792 if (!isVisible() || !isActive()) return;
794 if (m_glWidget) m_glWidget->activateMonitor();
796 if (render) render->startConsumer();
799 void Monitor::refreshMonitor(bool visible)
801 if (visible && render) {
802 if (!slotActivateMonitor()) {
803 // the monitor was already active, simply refreshClipThumbnail
809 void Monitor::refreshMonitor()
816 void Monitor::pause()
818 if (render == NULL) return;
819 slotActivateMonitor();
821 //m_playAction->setChecked(true);
822 m_playAction->setIcon(m_playIcon);
825 void Monitor::unpause()
829 void Monitor::slotPlay()
831 if (render == NULL) return;
832 slotActivateMonitor();
833 if (render->isPlaying()) {
834 m_playAction->setIcon(m_playIcon);
835 render->switchPlay(false);
838 m_playAction->setIcon(m_pauseIcon);
839 render->switchPlay(true);
841 m_ruler->refreshRuler();
844 void Monitor::slotPlayZone()
846 if (render == NULL) return;
847 slotActivateMonitor();
848 QPoint p = m_ruler->zone();
849 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
850 //m_playAction->setChecked(true);
851 m_playAction->setIcon(m_pauseIcon);
854 void Monitor::slotLoopZone()
856 if (render == NULL) return;
857 slotActivateMonitor();
858 QPoint p = m_ruler->zone();
859 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
860 //m_playAction->setChecked(true);
861 m_playAction->setIcon(m_pauseIcon);
864 void Monitor::slotLoopClip()
866 if (render == NULL || m_selectedClip == NULL)
868 slotActivateMonitor();
869 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
870 //m_playAction->setChecked(true);
871 m_playAction->setIcon(m_pauseIcon);
874 void Monitor::updateClipProducer(Mlt::Producer *prod)
876 if (render == NULL) return;
877 render->setProducer(prod, render->seekFramePosition());
880 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
882 if (render == NULL) return;
883 if (clip == NULL && m_currentClip != NULL) {
884 m_currentClip->lastSeekPosition = render->seekFramePosition();
885 m_currentClip = NULL;
887 render->setProducer(NULL, -1);
891 if (clip != m_currentClip || forceUpdate) {
892 if (m_currentClip) m_currentClip->lastSeekPosition = render->seekFramePosition();
893 m_currentClip = clip;
894 if (position == -1) position = clip->lastSeekPosition;
896 Mlt::Producer *prod = NULL;
897 if (clip) prod = clip->getCloneProducer();
898 if (render->setProducer(prod, position) == -1) {
899 // MLT CONSUMER is broken
900 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
904 slotActivateMonitor();
905 if (position == -1) position = render->seekFramePosition();
906 render->seek(position);
908 zone = m_currentClip->zone();
909 m_ruler->setZone(zone.x(), zone.y());
914 if (!zone.isNull()) {
915 m_ruler->setZone(zone.x(), zone.y());
916 render->seek(zone.x());
920 void Monitor::slotOpenFile(const QString &file)
922 if (render == NULL) return;
923 slotActivateMonitor();
924 render->loadUrl(file);
927 void Monitor::slotSaveZone()
929 if (render == NULL) return;
930 emit saveZone(render, m_ruler->zone(), m_currentClip);
932 //render->setSceneList(doc, 0);
935 void Monitor::setCustomProfile(const QString &profile, const Timecode &tc)
937 m_timePos->updateTimeCode(tc);
938 if (render == NULL) return;
939 if (!render->hasProfile(profile)) {
940 slotActivateMonitor();
941 render->resetProfile(profile);
943 if (m_glWidget) m_glWidget->setImageAspectRatio(render->dar());
948 void Monitor::resetProfile(const QString &profile)
950 m_timePos->updateTimeCode(m_monitorManager->timecode());
951 if (render == NULL) return;
952 if (!render->hasProfile(profile)) {
953 slotActivateMonitor();
954 render->resetProfile(profile);
956 if (m_glWidget) m_glWidget->setImageAspectRatio(render->dar());
960 m_effectWidget->resetProfile(render);
963 void Monitor::saveSceneList(const QString &path, const QDomElement &info)
965 if (render == NULL) return;
966 render->saveSceneList(path, info);
969 const QString Monitor::sceneList()
971 if (render == NULL) return QString();
972 return render->sceneList();
975 void Monitor::setClipZone(const QPoint &pos)
977 if (m_currentClip == NULL) return;
978 m_currentClip->setZone(pos);
981 void Monitor::slotSwitchDropFrames(bool show)
983 render->setDropFrames(show);
986 void Monitor::slotSwitchMonitorInfo(bool show)
988 KdenliveSettings::setDisplayMonitorInfo(show);
990 if (m_overlay) return;
991 if (videoSurface == NULL) {
992 // Using OpenGL display
994 if (m_glWidget->layout()) delete m_glWidget->layout();
995 m_overlay = new Overlay();
996 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
997 QVBoxLayout *layout = new QVBoxLayout;
998 layout->addStretch(10);
999 layout->addWidget(m_overlay);
1000 m_glWidget->setLayout(layout);
1003 if (videoSurface->layout()) delete videoSurface->layout();
1004 m_overlay = new Overlay();
1005 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
1006 QVBoxLayout *layout = new QVBoxLayout;
1007 layout->addStretch(10);
1008 layout->addWidget(m_overlay);
1009 videoSurface->setLayout(layout);
1011 m_overlay->setHidden(true);
1020 void Monitor::slotEditMarker()
1022 if (m_editMarker) m_editMarker->trigger();
1025 void Monitor::updateTimecodeFormat()
1027 m_timePos->slotUpdateTimeCodeFormat();
1030 QStringList Monitor::getZoneInfo() const
1033 if (m_currentClip == NULL) return result;
1034 result << m_currentClip->getId();
1035 QPoint zone = m_ruler->zone();
1036 result << QString::number(zone.x()) << QString::number(zone.y());
1040 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
1043 if (m_loopClipAction) m_loopClipAction->setEnabled(true);
1044 m_selectedClip = item;
1046 if (m_loopClipAction) m_loopClipAction->setEnabled(false);
1050 void Monitor::slotSetSelectedClip(ClipItem* item)
1052 if (item || (!item && !m_loopClipTransition)) {
1053 m_loopClipTransition = false;
1054 slotSetSelectedClip((AbstractClipItem*)item);
1058 void Monitor::slotSetSelectedClip(Transition* item)
1060 if (item || (!item && m_loopClipTransition)) {
1061 m_loopClipTransition = true;
1062 slotSetSelectedClip((AbstractClipItem*)item);
1067 void Monitor::slotShowEffectScene(bool show, bool manuallyTriggered)
1069 if (m_id == Kdenlive::projectMonitor) {
1070 if (!m_effectWidget->getVisibilityAction()->isChecked())
1072 if (m_effectWidget->isVisible() == show)
1074 setUpdatesEnabled(false);
1077 videoSurface->setVisible(false);
1078 // Preview is handeled internally through the Render::showFrame method
1079 render->disablePreview(true);
1082 m_glWidget->setVisible(false);
1085 m_effectWidget->setVisible(true);
1086 m_effectWidget->getScene()->slotZoomFit();
1087 emit requestFrameForAnalysis(true);
1089 m_effectWidget->setVisible(false);
1090 emit requestFrameForAnalysis(false);
1092 videoSurface->setVisible(true);
1093 // Preview is handeled internally through the Render::showFrame method
1094 render->disablePreview(false);
1098 m_glWidget->setVisible(true);
1102 if (!manuallyTriggered)
1103 m_effectWidget->showVisibilityButton(show);
1104 setUpdatesEnabled(true);
1105 videoBox->setEnabled(show);
1106 //render->doRefresh();
1110 MonitorEditWidget* Monitor::getEffectEdit()
1112 return m_effectWidget;
1115 bool Monitor::effectSceneDisplayed()
1117 return m_effectWidget->isVisible();
1120 void Monitor::slotSetVolume(int volume)
1122 KdenliveSettings::setVolume(volume);
1124 if (volume == 0) icon = KIcon("audio-volume-muted");
1125 else icon = KIcon("audio-volume-medium");
1126 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1127 render->slotSetVolume(volume);
1130 void Monitor::slotShowVolume()
1132 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1133 int vol = render->volume();
1134 // Disable widget if we cannot get the volume
1135 m_volumePopup->setEnabled(vol != -1);
1136 m_audioSlider->blockSignals(true);
1137 m_audioSlider->setValue(vol);
1138 m_audioSlider->blockSignals(false);
1139 m_volumePopup->show();
1142 AbstractRender *Monitor::abstractRender()
1147 void Monitor::reloadProducer(const QString &id)
1149 if (!m_currentClip) return;
1150 if (m_currentClip->getId() == id)
1151 slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
1154 QString Monitor::getMarkerThumb(GenTime pos)
1156 if (!m_currentClip) return QString();
1157 if (!m_currentClip->getClipHash().isEmpty()) {
1158 QString url = m_monitorManager->getProjectFolder() + "thumbs/" + m_currentClip->getClipHash() + '#' + QString::number((int) pos.frames(m_monitorManager->timecode().fps())) + ".png";
1159 if (QFile::exists(url)) return url;
1164 void Monitor::setPalette ( const QPalette & p)
1166 QWidget::setPalette(p);
1167 if (m_ruler) m_ruler->updatePalette();
1171 Overlay::Overlay(QWidget* parent) :
1174 //setAttribute(Qt::WA_TransparentForMouseEvents);
1175 setAutoFillBackground(true);
1176 setBackgroundRole(QPalette::Base);
1177 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1178 setCursor(Qt::PointingHandCursor);
1183 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1189 void Overlay::mousePressEvent( QMouseEvent * event )
1195 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1201 void Overlay::setOverlayText(const QString &text, bool isZone)
1203 if (text.isEmpty()) {
1205 p.setColor(QPalette::Base, KdenliveSettings::window_background());
1214 p.setColor(QPalette::Text, Qt::white);
1215 if (isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1216 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1218 setText(' ' + text + ' ');
1223 #include "monitor.moc"