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>
35 #include <QMouseEvent>
36 #include <QStylePainter>
38 #include <QToolButton>
40 #include <QDesktopWidget>
42 #include <QIntValidator>
43 #include <QVBoxLayout>
46 #define SEEK_INACTIVE (-1)
49 Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profile, QWidget *parent) :
50 AbstractMonitor(id, manager, parent),
60 m_loopClipTransition(true),
66 QVBoxLayout *layout = new QVBoxLayout;
67 layout->setContentsMargins(0, 0, 0, 0);
68 layout->setSpacing(0);
70 // Video widget holder
71 layout->addWidget(videoBox, 10);
74 // Get base size for icons
75 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
79 m_toolbar = new QToolBar(this);
80 m_toolbar->setIconSize(QSize(s, s));
82 m_playIcon = KIcon("media-playback-start");
83 m_pauseIcon = KIcon("media-playback-pause");
86 if (id != Kdenlive::dvdMonitor) {
87 m_toolbar->addAction(KIcon("kdenlive-zone-start"), i18n("Set zone start"), this, SLOT(slotSetZoneStart()));
88 m_toolbar->addAction(KIcon("kdenlive-zone-end"), i18n("Set zone end"), this, SLOT(slotSetZoneEnd()));
91 m_toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"), this, SLOT(slotRewind()));
92 //m_toolbar->addAction(KIcon("media-skip-backward"), i18n("Rewind 1 frame"), this, SLOT(slotRewindOneFrame()));
94 QToolButton *playButton = new QToolButton(m_toolbar);
95 m_playMenu = new QMenu(i18n("Play..."), this);
96 m_playAction = m_playMenu->addAction(m_playIcon, i18n("Play"));
97 //m_playAction->setCheckable(true);
98 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
100 playButton->setMenu(m_playMenu);
101 playButton->setPopupMode(QToolButton::MenuButtonPopup);
102 m_toolbar->addWidget(playButton);
104 //m_toolbar->addAction(KIcon("media-skip-forward"), i18n("Forward 1 frame"), this, SLOT(slotForwardOneFrame()));
105 m_toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"), this, SLOT(slotForward()));
107 playButton->setDefaultAction(m_playAction);
109 if (id != Kdenlive::dvdMonitor) {
110 QToolButton *configButton = new QToolButton(m_toolbar);
111 m_configMenu = new QMenu(i18n("Misc..."), this);
112 configButton->setIcon(KIcon("system-run"));
113 configButton->setMenu(m_configMenu);
114 configButton->setPopupMode(QToolButton::QToolButton::InstantPopup);
115 m_toolbar->addWidget(configButton);
117 if (id == Kdenlive::clipMonitor) {
118 m_markerMenu = new QMenu(i18n("Go to marker..."), this);
119 m_markerMenu->setEnabled(false);
120 m_configMenu->addMenu(m_markerMenu);
121 connect(m_markerMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToMarker(QAction *)));
123 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (100%)"), this, SLOT(slotSetSizeOneToOne()));
124 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (50%)"), this, SLOT(slotSetSizeOneToTwo()));
127 // Create Volume slider popup
128 m_volumePopup = new QFrame(this, Qt::Popup);
129 QVBoxLayout *poplayout = new QVBoxLayout;
130 poplayout->setContentsMargins(0, 0, 0, 0);
131 m_audioSlider = new QSlider(Qt::Vertical);
132 m_audioSlider->setRange(0, 100);
133 poplayout->addWidget(m_audioSlider);
134 m_volumePopup->setLayout(poplayout);
136 if (KdenliveSettings::volume() == 0) icon = KIcon("audio-volume-muted");
137 else icon = KIcon("audio-volume-medium");
139 m_volumeWidget = m_toolbar->widgetForAction(m_toolbar->addAction(icon, i18n("Audio volume"), this, SLOT(slotShowVolume())));
141 // we need to show / hide the popup once so that it's geometry can be calculated in slotShowVolume
142 m_volumePopup->show();
143 m_volumePopup->hide();
145 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
147 setMinimumHeight(200);
149 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
151 bool monitorCreated = false;
153 createOpenGlWidget(videoBox, profile);
154 monitorCreated = true;
155 //m_glWidget->setFixedSize(width, height);
156 #elif defined(USE_OPENGL)
157 if (KdenliveSettings::openglmonitors()) {
158 monitorCreated = createOpenGlWidget(videoBox, profile);
161 if (!monitorCreated) {
162 createVideoSurface();
163 render = new Render(m_id, (int) videoSurface->winId(), profile, this);
164 connect(videoSurface, SIGNAL(refreshMonitor()), render, SLOT(doRefresh()));
167 else if (m_glWidget) {
168 QVBoxLayout *lay = new QVBoxLayout;
169 lay->setContentsMargins(0, 0, 0, 0);
170 lay->addWidget(m_glWidget);
171 videoBox->setLayout(lay);
176 m_ruler = new SmallRuler(this, render);
177 if (id == Kdenlive::dvdMonitor) m_ruler->setZone(-3, -2);
178 layout->addWidget(m_ruler);
180 connect(m_audioSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetVolume(int)));
181 connect(render, SIGNAL(durationChanged(int)), this, SLOT(adjustRulerSize(int)));
182 connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int)));
183 connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
185 if (id != Kdenlive::clipMonitor) {
186 connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int)));
187 connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int)));
188 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SIGNAL(zoneUpdated(QPoint)));
190 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SLOT(setClipZone(QPoint)));
193 if (videoSurface) videoSurface->show();
195 if (id == Kdenlive::projectMonitor) {
196 m_effectWidget = new MonitorEditWidget(render, videoBox);
197 connect(m_effectWidget, SIGNAL(showEdit(bool, bool)), this, SLOT(slotShowEffectScene(bool, bool)));
198 m_toolbar->addAction(m_effectWidget->getVisibilityAction());
199 videoBox->layout()->addWidget(m_effectWidget);
200 m_effectWidget->hide();
203 QWidget *spacer = new QWidget(this);
204 spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
205 m_toolbar->addWidget(spacer);
206 m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this);
207 m_toolbar->addWidget(m_timePos);
208 connect(m_timePos, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotSeek()));
209 m_toolbar->setMaximumHeight(s * 1.5);
210 layout->addWidget(m_toolbar);
219 delete m_effectWidget;
223 QWidget *Monitor::container()
229 bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile)
231 render = new Render(id(), 0, profile, this);
232 m_glWidget = new VideoGLWidget(parent);
233 if (m_glWidget == NULL) {
234 // Creation failed, we are in trouble...
237 m_glWidget->setImageAspectRatio(render->dar());
238 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
239 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
244 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
246 m_contextMenu = new QMenu(this);
247 m_contextMenu->addMenu(m_playMenu);
249 m_contextMenu->addMenu(goMenu);
251 m_contextMenu->addMenu(markerMenu);
252 QList <QAction *>list = markerMenu->actions();
253 for (int i = 0; i < list.count(); i++) {
254 if (list.at(i)->data().toString() == "edit_marker") {
255 m_editMarker = list.at(i);
261 m_playMenu->addAction(playZone);
262 m_playMenu->addAction(loopZone);
264 m_loopClipAction = loopClip;
265 m_playMenu->addAction(loopClip);
268 //TODO: add save zone to timeline monitor when fixed
269 if (m_id == Kdenlive::clipMonitor) {
270 m_contextMenu->addMenu(m_markerMenu);
271 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
272 QAction *extractZone = m_configMenu->addAction(KIcon("document-new"), i18n("Extract Zone"), this, SLOT(slotExtractCurrentZone()));
273 m_contextMenu->addAction(extractZone);
275 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
276 m_contextMenu->addAction(extractFrame);
278 if (m_id != Kdenlive::clipMonitor) {
279 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
280 splitView->setCheckable(true);
281 m_configMenu->addAction(splitView);
283 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
284 m_configMenu->addAction(setThumbFrame);
287 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
288 showTips->setCheckable(true);
289 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
290 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
292 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
293 dropFrames->setCheckable(true);
294 dropFrames->setChecked(true);
295 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
297 m_configMenu->addAction(showTips);
298 m_configMenu->addAction(dropFrames);
302 void Monitor::slotGoToMarker(QAction *action)
304 int pos = action->data().toInt();
308 void Monitor::slotSetSizeOneToOne()
310 QRect r = QApplication::desktop()->screenGeometry();
311 const int maxWidth = r.width() - 20;
312 const int maxHeight = r.height() - 20;
313 int width = render->renderWidth();
314 int height = render->renderHeight();
315 kDebug() << "// render info: " << width << "x" << height;
316 while (width >= maxWidth || height >= maxHeight) {
318 height = height * 0.8;
320 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
321 videoBox->setFixedSize(width, height);
324 //m_ui.video_frame->setMinimumSize(0, 0);
325 emit adjustMonitorSize();
328 void Monitor::slotSetSizeOneToTwo()
330 QRect r = QApplication::desktop()->screenGeometry();
331 const int maxWidth = r.width() - 20;
332 const int maxHeight = r.height() - 20;
333 int width = render->renderWidth() / 2;
334 int height = render->renderHeight() / 2;
335 kDebug() << "// render info: " << width << "x" << height;
336 while (width >= maxWidth || height >= maxHeight) {
338 height = height * 0.8;
340 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
341 videoBox->setFixedSize(width, height);
344 //m_ui.video_frame->setMinimumSize(0, 0);
345 emit adjustMonitorSize();
348 void Monitor::resetSize()
350 videoBox->setMinimumSize(0, 0);
353 QString Monitor::getTimecodeFromFrames(int pos)
355 return m_monitorManager->timecode().getTimecodeFromFrames(pos);
358 double Monitor::fps() const
360 return m_monitorManager->timecode().fps();
363 DocClipBase *Monitor::activeClip()
365 return m_currentClip;
368 void Monitor::updateMarkers(DocClipBase *source)
370 if (source == m_currentClip && source != NULL) {
371 m_markerMenu->clear();
372 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
373 if (!markers.isEmpty()) {
375 for (int i = 0; i < markers.count(); i++) {
376 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
378 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
379 QAction *go = m_markerMenu->addAction(position);
383 m_ruler->setMarkers(markers);
384 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
388 void Monitor::slotSeekToPreviousSnap()
390 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
393 void Monitor::slotSeekToNextSnap()
395 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
398 GenTime Monitor::position()
400 return render->seekPosition();
403 GenTime Monitor::getSnapForPos(bool previous)
405 QList <GenTime> snaps;
406 QList < GenTime > markers = m_currentClip->snapMarkers();
407 for (int i = 0; i < markers.size(); ++i) {
408 GenTime t = markers.at(i);
411 QPoint zone = m_ruler->zone();
412 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
413 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
414 snaps.append(GenTime());
415 snaps.append(m_currentClip->duration());
418 const GenTime pos = render->seekPosition();
419 for (int i = 0; i < snaps.size(); ++i) {
420 if (previous && snaps.at(i) >= pos) {
422 return snaps.at(i - 1);
423 } else if (!previous && snaps.at(i) > pos) {
430 void Monitor::slotZoneMoved(int start, int end)
432 m_ruler->setZone(start, end);
433 setClipZone(m_ruler->zone());
437 void Monitor::slotSetZoneStart()
439 m_ruler->setZoneStart();
440 emit zoneUpdated(m_ruler->zone());
441 setClipZone(m_ruler->zone());
445 void Monitor::slotSetZoneEnd()
447 m_ruler->setZoneEnd();
448 emit zoneUpdated(m_ruler->zone());
449 setClipZone(m_ruler->zone());
454 void Monitor::mousePressEvent(QMouseEvent * event)
456 if (event->button() != Qt::RightButton) {
457 if (videoBox->geometry().contains(event->pos()) && (!m_overlay || !m_overlay->underMouse())) {
458 m_dragStarted = true;
459 m_DragStartPosition = event->pos();
461 } else if (m_contextMenu && (!m_effectWidget || !m_effectWidget->isVisible())) {
462 m_contextMenu->popup(event->globalPos());
466 void Monitor::resizeEvent(QResizeEvent *event)
469 if (render && isVisible() && isActive()) render->doRefresh();
472 void Monitor::slotSwitchFullScreen()
474 videoBox->switchFullScreen();
478 void Monitor::mouseReleaseEvent(QMouseEvent * event)
480 if (m_dragStarted && event->button() != Qt::RightButton) {
481 if (videoBox->geometry().contains(event->pos()) && (!m_effectWidget || !m_effectWidget->isVisible())) {
482 if (isActive()) slotPlay();
483 else slotActivateMonitor();
484 } //else event->ignore(); //QWidget::mouseReleaseEvent(event);
486 m_dragStarted = false;
491 void Monitor::mouseMoveEvent(QMouseEvent *event)
493 if (!m_dragStarted || m_currentClip == NULL) return;
495 if ((event->pos() - m_DragStartPosition).manhattanLength()
496 < QApplication::startDragDistance())
500 QDrag *drag = new QDrag(this);
501 QMimeData *mimeData = new QMimeData;
504 list.append(m_currentClip->getId());
505 QPoint p = m_ruler->zone();
506 list.append(QString::number(p.x()));
507 list.append(QString::number(p.y()));
509 data.append(list.join(";").toUtf8());
510 mimeData->setData("kdenlive/clip", data);
511 drag->setMimeData(mimeData);
512 /*QPixmap pix = m_currentClip->thumbnail();
513 drag->setPixmap(pix);
514 drag->setHotSpot(QPoint(0, 50));*/
515 drag->start(Qt::MoveAction);
516 /*Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
517 Qt::DropAction dropAction;
518 dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);*/
520 //Qt::DropAction dropAction = drag->exec();
527 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
528 event->setDropAction(Qt::IgnoreAction);
529 event->setDropAction(Qt::MoveAction);
530 if (event->mimeData()->hasText()) {
531 event->acceptProposedAction();
535 Qt::DropActions Monitor::supportedDropActions() const {
536 // returns what actions are supported when dropping
537 return Qt::MoveAction;
540 QStringList Monitor::mimeTypes() const
542 QStringList qstrList;
543 // list of accepted mime types for drop
544 qstrList.append("kdenlive/clip");
549 void Monitor::wheelEvent(QWheelEvent * event)
551 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
555 void Monitor::mouseDoubleClickEvent(QMouseEvent * event)
557 if (!KdenliveSettings::openglmonitors()) {
558 videoBox->switchFullScreen();
563 void Monitor::slotMouseSeek(int eventDelta, bool fast)
566 int delta = m_monitorManager->timecode().fps();
567 if (eventDelta > 0) delta = 0 - delta;
568 if (render->requestedSeekPosition != SEEK_INACTIVE)
569 slotSeek(render->requestedSeekPosition - delta);
570 else slotSeek(render->seekFramePosition() - delta);
572 if (eventDelta >= 0) slotForwardOneFrame();
573 else slotRewindOneFrame();
577 void Monitor::slotSetThumbFrame()
579 if (m_currentClip == NULL) {
582 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
583 emit refreshClipThumbnail(m_currentClip->getId(), true);
586 void Monitor::slotExtractCurrentZone()
588 if (m_currentClip == NULL) return;
589 emit extractZone(m_currentClip->getId(), m_ruler->zone());
592 void Monitor::slotExtractCurrentFrame()
595 // check if we are using a proxy
596 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
597 // using proxy, use original clip url to get frame
598 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
600 else frame = render->extractFrame(render->seekFramePosition());
601 QPointer<KFileDialog> fs = new KFileDialog(KUrl(), "image/png", this);
602 fs->setOperationMode(KFileDialog::Saving);
603 fs->setMode(KFile::File);
604 fs->setConfirmOverwrite(true);
605 fs->setKeepLocation(true);
608 if (fs) path = fs->selectedFile();
610 if (!path.isEmpty()) {
615 void Monitor::setTimePos(const QString &pos)
617 m_timePos->setValue(pos);
621 void Monitor::slotSeek()
623 slotSeek(m_timePos->getValue());
626 void Monitor::slotSeek(int pos)
628 if (render == NULL) return;
629 slotActivateMonitor();
630 render->seekToFrame(pos);
634 void Monitor::checkOverlay()
636 if (m_overlay == NULL) return;
638 int pos = m_timePos->getValue();//render->seekFramePosition();
639 QPoint zone = m_ruler->zone();
641 overlayText = i18n("In Point");
642 else if (pos == zone.y())
643 overlayText = i18n("Out Point");
646 overlayText = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
647 if (!overlayText.isEmpty()) {
648 m_overlay->setOverlayText(overlayText, false);
653 if (m_overlay->isVisible() && overlayText.isEmpty()) m_overlay->setOverlayText(QString(), false);
654 else m_overlay->setOverlayText(overlayText);
657 void Monitor::slotStart()
659 slotActivateMonitor();
661 render->seekToFrame(0);
664 void Monitor::slotEnd()
666 slotActivateMonitor();
668 render->seekToFrame(render->getLength());
671 void Monitor::slotZoneStart()
673 slotActivateMonitor();
675 render->seekToFrame(m_ruler->zone().x());
678 void Monitor::slotZoneEnd()
680 slotActivateMonitor();
682 render->seekToFrame(m_ruler->zone().y());
685 void Monitor::slotRewind(double speed)
687 slotActivateMonitor();
689 double currentspeed = render->playSpeed();
690 if (currentspeed >= 0) render->play(-1);
691 else switch((int) currentspeed) {
704 } else render->play(speed);
705 //m_playAction->setChecked(true);
706 m_playAction->setIcon(m_pauseIcon);
709 void Monitor::slotForward(double speed)
711 slotActivateMonitor();
713 double currentspeed = render->playSpeed();
714 if (currentspeed <= 0) render->play(1);
715 else switch((int) currentspeed) {
728 } else render->play(speed);
729 //m_playAction->setChecked(true);
730 m_playAction->setIcon(m_pauseIcon);
733 void Monitor::slotRewindOneFrame(int diff)
735 slotActivateMonitor();
737 render->seekToFrameDiff(-diff);
741 void Monitor::slotForwardOneFrame(int diff)
743 slotActivateMonitor();
745 render->seekToFrameDiff(diff);
749 void Monitor::seekCursor(int pos)
751 if (m_ruler->slotNewValue(pos)) {
752 m_timePos->setValue(pos);
757 void Monitor::rendererStopped(int pos)
759 if (m_ruler->slotNewValue(pos)) {
760 m_timePos->setValue(pos);
763 m_playAction->setIcon(m_playIcon);
766 void Monitor::adjustRulerSize(int length)
768 if (length > 0) m_length = length;
769 m_ruler->adjustScale(m_length);
770 if (m_currentClip != NULL) {
771 QPoint zone = m_currentClip->zone();
772 m_ruler->setZone(zone.x(), zone.y());
778 if (render) render->stop();
781 void Monitor::start()
783 if (!isVisible() || !isActive()) return;
785 if (m_glWidget) m_glWidget->activateMonitor();
787 if (render) render->startConsumer();
790 void Monitor::refreshMonitor(bool visible)
792 if (visible && render) {
793 if (!slotActivateMonitor()) {
794 // the monitor was already active, simply refreshClipThumbnail
800 void Monitor::refreshMonitor()
807 void Monitor::pause()
809 if (render == NULL) return;
810 slotActivateMonitor();
812 //m_playAction->setChecked(true);
813 m_playAction->setIcon(m_playIcon);
816 void Monitor::unpause()
820 void Monitor::slotPlay()
822 if (render == NULL) return;
823 slotActivateMonitor();
824 if (render->isPlaying()) {
825 m_playAction->setIcon(m_playIcon);
826 render->switchPlay(false);
829 m_playAction->setIcon(m_pauseIcon);
830 render->switchPlay(true);
832 m_ruler->refreshRuler();
835 void Monitor::slotPlayZone()
837 if (render == NULL) return;
838 slotActivateMonitor();
839 QPoint p = m_ruler->zone();
840 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
841 //m_playAction->setChecked(true);
842 m_playAction->setIcon(m_pauseIcon);
845 void Monitor::slotLoopZone()
847 if (render == NULL) return;
848 slotActivateMonitor();
849 QPoint p = m_ruler->zone();
850 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
851 //m_playAction->setChecked(true);
852 m_playAction->setIcon(m_pauseIcon);
855 void Monitor::slotLoopClip()
857 if (render == NULL || m_selectedClip == NULL)
859 slotActivateMonitor();
860 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
861 //m_playAction->setChecked(true);
862 m_playAction->setIcon(m_pauseIcon);
865 void Monitor::updateClipProducer(Mlt::Producer *prod)
867 if (render == NULL) return;
868 render->setProducer(prod, render->seekFramePosition());
871 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
873 if (render == NULL) return;
874 if (clip == NULL && m_currentClip != NULL) {
875 m_currentClip->lastSeekPosition = render->seekFramePosition();
876 kDebug()<<"// SETTING NULL CLIP MONITOR";
877 m_currentClip = NULL;
879 render->setProducer(NULL, -1);
883 if (clip != m_currentClip || forceUpdate) {
884 if (m_currentClip) m_currentClip->lastSeekPosition = render->seekFramePosition();
885 m_currentClip = clip;
886 if (position == -1) position = clip->lastSeekPosition;
888 Mlt::Producer *prod = NULL;
889 if (clip) prod = clip->getCloneProducer();
890 if (render->setProducer(prod, position) == -1) {
891 // MLT CONSUMER is broken
892 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
896 slotActivateMonitor();
897 if (position == -1) position = render->seekFramePosition();
898 render->seek(position);
901 if (!zone.isNull()) {
902 m_ruler->setZone(zone.x(), zone.y());
903 render->seek(zone.x());
907 void Monitor::slotOpenFile(const QString &file)
909 if (render == NULL) return;
910 slotActivateMonitor();
911 render->loadUrl(file);
914 void Monitor::slotSaveZone()
916 if (render == NULL) return;
917 emit saveZone(render, m_ruler->zone(), m_currentClip);
919 //render->setSceneList(doc, 0);
922 void Monitor::setCustomProfile(const QString &profile, Timecode tc)
924 m_timePos->updateTimeCode(tc);
925 if (render == NULL) return;
926 if (!render->hasProfile(profile)) {
927 slotActivateMonitor();
928 render->resetProfile(profile);
930 if (m_glWidget) m_glWidget->setImageAspectRatio(render->dar());
935 void Monitor::resetProfile(const QString &profile)
937 m_timePos->updateTimeCode(m_monitorManager->timecode());
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());
947 m_effectWidget->resetProfile(render);
950 void Monitor::saveSceneList(QString path, QDomElement info)
952 if (render == NULL) return;
953 render->saveSceneList(path, info);
956 const QString Monitor::sceneList()
958 if (render == NULL) return QString();
959 return render->sceneList();
962 void Monitor::setClipZone(QPoint pos)
964 if (m_currentClip == NULL) return;
965 m_currentClip->setZone(pos);
968 void Monitor::slotSwitchDropFrames(bool show)
970 render->setDropFrames(show);
973 void Monitor::slotSwitchMonitorInfo(bool show)
975 KdenliveSettings::setDisplayMonitorInfo(show);
977 if (m_overlay) return;
978 if (videoSurface == NULL) {
979 // Using OpenGL display
981 if (m_glWidget->layout()) delete m_glWidget->layout();
982 m_overlay = new Overlay();
983 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
984 QVBoxLayout *layout = new QVBoxLayout;
985 layout->addStretch(10);
986 layout->addWidget(m_overlay);
987 m_glWidget->setLayout(layout);
990 if (videoSurface->layout()) delete videoSurface->layout();
991 m_overlay = new Overlay();
992 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
993 QVBoxLayout *layout = new QVBoxLayout;
994 layout->addStretch(10);
995 layout->addWidget(m_overlay);
996 videoSurface->setLayout(layout);
998 m_overlay->setHidden(true);
1007 void Monitor::slotEditMarker()
1009 if (m_editMarker) m_editMarker->trigger();
1012 void Monitor::updateTimecodeFormat()
1014 m_timePos->slotUpdateTimeCodeFormat();
1017 QStringList Monitor::getZoneInfo() const
1020 if (m_currentClip == NULL) return result;
1021 result << m_currentClip->getId();
1022 QPoint zone = m_ruler->zone();
1023 result << QString::number(zone.x()) << QString::number(zone.y());
1027 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
1030 m_loopClipAction->setEnabled(true);
1031 m_selectedClip = item;
1033 m_loopClipAction->setEnabled(false);
1037 void Monitor::slotSetSelectedClip(ClipItem* item)
1039 if (item || (!item && !m_loopClipTransition)) {
1040 m_loopClipTransition = false;
1041 slotSetSelectedClip((AbstractClipItem*)item);
1045 void Monitor::slotSetSelectedClip(Transition* item)
1047 if (item || (!item && m_loopClipTransition)) {
1048 m_loopClipTransition = true;
1049 slotSetSelectedClip((AbstractClipItem*)item);
1054 void Monitor::slotShowEffectScene(bool show, bool manuallyTriggered)
1056 if (m_id == Kdenlive::projectMonitor) {
1057 if (!m_effectWidget->getVisibilityAction()->isChecked())
1059 if (m_effectWidget->isVisible() == show)
1061 setUpdatesEnabled(false);
1064 videoSurface->setVisible(false);
1065 // Preview is handeled internally through the Render::showFrame method
1066 render->disablePreview(true);
1069 m_glWidget->setVisible(false);
1072 m_effectWidget->setVisible(true);
1073 m_effectWidget->getScene()->slotZoomFit();
1074 emit requestFrameForAnalysis(true);
1076 m_effectWidget->setVisible(false);
1077 emit requestFrameForAnalysis(false);
1079 videoSurface->setVisible(true);
1080 // Preview is handeled internally through the Render::showFrame method
1081 render->disablePreview(false);
1085 m_glWidget->setVisible(true);
1089 if (!manuallyTriggered)
1090 m_effectWidget->showVisibilityButton(show);
1091 setUpdatesEnabled(true);
1092 videoBox->setEnabled(show);
1093 //render->doRefresh();
1097 MonitorEditWidget* Monitor::getEffectEdit()
1099 return m_effectWidget;
1102 bool Monitor::effectSceneDisplayed()
1104 return m_effectWidget->isVisible();
1107 void Monitor::slotSetVolume(int volume)
1109 KdenliveSettings::setVolume(volume);
1111 if (volume == 0) icon = KIcon("audio-volume-muted");
1112 else icon = KIcon("audio-volume-medium");
1113 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1114 render->slotSetVolume(volume);
1117 void Monitor::slotShowVolume()
1119 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1120 int vol = render->volume();
1121 // Disable widget if we cannot get the volume
1122 m_volumePopup->setEnabled(vol != -1);
1123 m_audioSlider->blockSignals(true);
1124 m_audioSlider->setValue(vol);
1125 m_audioSlider->blockSignals(false);
1126 m_volumePopup->show();
1129 AbstractRender *Monitor::abstractRender()
1134 void Monitor::reloadProducer(const QString &id)
1136 if (!m_currentClip) return;
1137 if (m_currentClip->getId() == id)
1138 slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
1141 QString Monitor::getMarkerThumb(GenTime pos)
1143 if (!m_currentClip) return QString();
1144 if (!m_currentClip->getClipHash().isEmpty()) {
1145 QString url = m_monitorManager->getProjectFolder() + "thumbs/" + m_currentClip->getClipHash() + '#' + QString::number(pos.frames(m_monitorManager->timecode().fps())) + ".png";
1146 if (QFile::exists(url)) return url;
1151 void Monitor::setPalette ( const QPalette & p)
1153 QWidget::setPalette(p);
1154 if (m_ruler) m_ruler->updatePalette();
1158 Overlay::Overlay(QWidget* parent) :
1161 //setAttribute(Qt::WA_TransparentForMouseEvents);
1162 setAutoFillBackground(true);
1163 setBackgroundRole(QPalette::Base);
1164 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1165 setCursor(Qt::PointingHandCursor);
1170 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1176 void Overlay::mousePressEvent( QMouseEvent * event )
1182 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1188 void Overlay::setOverlayText(const QString &text, bool isZone)
1190 if (text.isEmpty()) {
1192 p.setColor(QPalette::Base, KdenliveSettings::window_background());
1201 p.setColor(QPalette::Text, Qt::white);
1202 if (isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1203 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1205 setText(' ' + text + ' ');
1210 #include "monitor.moc"