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 Monitor::Monitor(Kdenlive::MONITORID id, MonitorManager *manager, QString profile, QWidget *parent) :
47 AbstractMonitor(id, manager, parent),
50 m_ruler(new SmallRuler(m_monitorManager)),
55 m_monitorRefresh(NULL),
59 m_loopClipTransition(true),
62 QVBoxLayout *layout = new QVBoxLayout;
63 layout->setContentsMargins(0, 0, 0, 0);
64 layout->setSpacing(0);
66 // Video widget holder
67 m_videoBox = new VideoContainer(this);
68 layout->addWidget(m_videoBox, 10);
71 // Get base size for icons
72 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
75 layout->addWidget(m_ruler);
77 m_toolbar = new QToolBar(this);
78 m_toolbar->setIconSize(QSize(s, s));
80 m_playIcon = KIcon("media-playback-start");
81 m_pauseIcon = KIcon("media-playback-pause");
83 if (id != Kdenlive::dvdMonitor) {
84 m_toolbar->addAction(KIcon("kdenlive-zone-start"), i18n("Set zone start"), this, SLOT(slotSetZoneStart()));
85 m_toolbar->addAction(KIcon("kdenlive-zone-end"), i18n("Set zone end"), this, SLOT(slotSetZoneEnd()));
87 m_ruler->setZone(-3, -2);
90 m_toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"), this, SLOT(slotRewind()));
91 //m_toolbar->addAction(KIcon("media-skip-backward"), i18n("Rewind 1 frame"), this, SLOT(slotRewindOneFrame()));
93 QToolButton *playButton = new QToolButton(m_toolbar);
94 m_playMenu = new QMenu(i18n("Play..."), this);
95 m_playAction = m_playMenu->addAction(m_playIcon, i18n("Play"));
96 //m_playAction->setCheckable(true);
97 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
99 playButton->setMenu(m_playMenu);
100 playButton->setPopupMode(QToolButton::MenuButtonPopup);
101 m_toolbar->addWidget(playButton);
103 //m_toolbar->addAction(KIcon("media-skip-forward"), i18n("Forward 1 frame"), this, SLOT(slotForwardOneFrame()));
104 m_toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"), this, SLOT(slotForward()));
106 playButton->setDefaultAction(m_playAction);
108 if (id != Kdenlive::dvdMonitor) {
109 QToolButton *configButton = new QToolButton(m_toolbar);
110 m_configMenu = new QMenu(i18n("Misc..."), this);
111 configButton->setIcon(KIcon("system-run"));
112 configButton->setMenu(m_configMenu);
113 configButton->setPopupMode(QToolButton::QToolButton::InstantPopup);
114 m_toolbar->addWidget(configButton);
116 if (id == Kdenlive::clipMonitor) {
117 m_markerMenu = new QMenu(i18n("Go to marker..."), this);
118 m_markerMenu->setEnabled(false);
119 m_configMenu->addMenu(m_markerMenu);
120 connect(m_markerMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToMarker(QAction *)));
122 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (100%)"), this, SLOT(slotSetSizeOneToOne()));
123 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (50%)"), this, SLOT(slotSetSizeOneToTwo()));
126 // Create Volume slider popup
127 m_volumePopup = new QFrame(this, Qt::Popup);
128 QVBoxLayout *poplayout = new QVBoxLayout;
129 poplayout->setContentsMargins(0, 0, 0, 0);
130 m_audioSlider = new QSlider(Qt::Vertical);
131 m_audioSlider->setRange(0, 100);
132 poplayout->addWidget(m_audioSlider);
133 m_volumePopup->setLayout(poplayout);
135 if (KdenliveSettings::volume() == 0) icon = KIcon("audio-volume-muted");
136 else icon = KIcon("audio-volume-medium");
138 m_volumeWidget = m_toolbar->widgetForAction(m_toolbar->addAction(icon, i18n("Audio volume"), this, SLOT(slotShowVolume())));
140 // we need to show / hide the popup once so that it's geometry can be calculated in slotShowVolume
141 m_volumePopup->show();
142 m_volumePopup->hide();
144 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
146 setMinimumHeight(200);
148 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
150 bool monitorCreated = false;
152 createOpenGlWidget(m_videoBox, profile);
153 monitorCreated = true;
154 //m_glWidget->setFixedSize(width, height);
155 #elif defined(USE_OPENGL)
156 if (KdenliveSettings::openglmonitors()) {
157 monitorCreated = createOpenGlWidget(m_videoBox, profile);
160 QVBoxLayout *lay = new QVBoxLayout;
161 lay->setContentsMargins(0, 0, 0, 0);
162 if (!monitorCreated) {
163 m_monitorRefresh = new MonitorRefresh;
164 lay->addWidget(m_monitorRefresh);
165 m_videoBox->setLayout(lay);
166 render = new Render(m_id, (int) m_monitorRefresh->winId(), profile, this);
167 m_monitorRefresh->setRenderer(render);
170 else if (m_glWidget) {
171 lay->addWidget(m_glWidget);
172 m_videoBox->setLayout(lay);
176 connect(m_audioSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetVolume(int)));
177 connect(m_ruler, SIGNAL(seekRenderer(int)), this, SLOT(slotSeek(int)));
178 connect(render, SIGNAL(durationChanged(int)), this, SLOT(adjustRulerSize(int)));
179 connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int)));
180 connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
182 if (id != Kdenlive::clipMonitor) {
183 connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int)));
184 connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int)));
185 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SIGNAL(zoneUpdated(QPoint)));
187 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SLOT(setClipZone(QPoint)));
190 if (m_monitorRefresh) m_monitorRefresh->show();
192 if (id == Kdenlive::projectMonitor) {
193 m_effectWidget = new MonitorEditWidget(render, m_videoBox);
194 m_toolbar->addAction(m_effectWidget->getVisibilityAction());
195 lay->addWidget(m_effectWidget);
196 m_effectWidget->hide();
199 QWidget *spacer = new QWidget(this);
200 spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
201 m_toolbar->addWidget(spacer);
202 m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this);
203 m_toolbar->addWidget(m_timePos);
204 connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotSeek()));
205 m_toolbar->setMaximumHeight(s * 1.5);
206 layout->addWidget(m_toolbar);
215 delete m_effectWidget;
216 delete m_monitorRefresh;
220 QWidget *Monitor::container()
226 bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile)
228 render = new Render(id(), 0, profile, this);
229 m_glWidget = new VideoGLWidget(parent);
230 if (m_glWidget == NULL) {
231 // Creation failed, we are in trouble...
234 m_glWidget->setImageAspectRatio(render->dar());
235 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
236 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
241 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
243 m_contextMenu = new QMenu(this);
244 m_contextMenu->addMenu(m_playMenu);
246 m_contextMenu->addMenu(goMenu);
248 m_contextMenu->addMenu(markerMenu);
249 QList <QAction *>list = markerMenu->actions();
250 for (int i = 0; i < list.count(); i++) {
251 if (list.at(i)->data().toString() == "edit_marker") {
252 m_editMarker = list.at(i);
258 m_playMenu->addAction(playZone);
259 m_playMenu->addAction(loopZone);
261 m_loopClipAction = loopClip;
262 m_playMenu->addAction(loopClip);
265 //TODO: add save zone to timeline monitor when fixed
266 if (m_id == Kdenlive::clipMonitor) {
267 m_contextMenu->addMenu(m_markerMenu);
268 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
269 QAction *extractZone = m_configMenu->addAction(KIcon("document-new"), i18n("Extract Zone"), this, SLOT(slotExtractCurrentZone()));
270 m_contextMenu->addAction(extractZone);
272 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
273 m_contextMenu->addAction(extractFrame);
275 if (m_id != Kdenlive::clipMonitor) {
276 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
277 splitView->setCheckable(true);
278 m_configMenu->addAction(splitView);
280 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
281 m_configMenu->addAction(setThumbFrame);
284 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
285 showTips->setCheckable(true);
286 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
287 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
289 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
290 dropFrames->setCheckable(true);
291 dropFrames->setChecked(true);
292 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
294 m_configMenu->addAction(showTips);
295 m_configMenu->addAction(dropFrames);
299 void Monitor::slotGoToMarker(QAction *action)
301 int pos = action->data().toInt();
305 void Monitor::slotSetSizeOneToOne()
307 QRect r = QApplication::desktop()->screenGeometry();
308 const int maxWidth = r.width() - 20;
309 const int maxHeight = r.height() - 20;
310 int width = render->renderWidth();
311 int height = render->renderHeight();
312 kDebug() << "// render info: " << width << "x" << height;
313 while (width >= maxWidth || height >= maxHeight) {
315 height = height * 0.8;
317 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
318 m_videoBox->setFixedSize(width, height);
321 //m_ui.video_frame->setMinimumSize(0, 0);
322 emit adjustMonitorSize();
325 void Monitor::slotSetSizeOneToTwo()
327 QRect r = QApplication::desktop()->screenGeometry();
328 const int maxWidth = r.width() - 20;
329 const int maxHeight = r.height() - 20;
330 int width = render->renderWidth() / 2;
331 int height = render->renderHeight() / 2;
332 kDebug() << "// render info: " << width << "x" << height;
333 while (width >= maxWidth || height >= maxHeight) {
335 height = height * 0.8;
337 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
338 m_videoBox->setFixedSize(width, height);
341 //m_ui.video_frame->setMinimumSize(0, 0);
342 emit adjustMonitorSize();
345 void Monitor::resetSize()
347 m_videoBox->setMinimumSize(0, 0);
350 DocClipBase *Monitor::activeClip()
352 return m_currentClip;
355 void Monitor::updateMarkers(DocClipBase *source)
357 if (source == m_currentClip && source != NULL) {
358 m_markerMenu->clear();
359 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
360 if (!markers.isEmpty()) {
362 for (int i = 0; i < markers.count(); i++) {
363 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
365 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
366 QAction *go = m_markerMenu->addAction(position);
369 m_ruler->setMarkers(marks);
370 } else m_ruler->setMarkers(QList <int>());
371 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
375 void Monitor::slotSeekToPreviousSnap()
377 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
380 void Monitor::slotSeekToNextSnap()
382 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
385 GenTime Monitor::position()
387 return render->seekPosition();
390 GenTime Monitor::getSnapForPos(bool previous)
392 QList <GenTime> snaps;
393 QList < GenTime > markers = m_currentClip->snapMarkers();
394 for (int i = 0; i < markers.size(); ++i) {
395 GenTime t = markers.at(i);
398 QPoint zone = m_ruler->zone();
399 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
400 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
401 snaps.append(GenTime());
402 snaps.append(m_currentClip->duration());
405 const GenTime pos = render->seekPosition();
406 for (int i = 0; i < snaps.size(); ++i) {
407 if (previous && snaps.at(i) >= pos) {
409 return snaps.at(i - 1);
410 } else if (!previous && snaps.at(i) > pos) {
417 void Monitor::slotZoneMoved(int start, int end)
419 m_ruler->setZone(start, end);
421 setClipZone(m_ruler->zone());
424 void Monitor::slotSetZoneStart()
426 m_ruler->setZone(m_ruler->position(), -1);
427 emit zoneUpdated(m_ruler->zone());
429 setClipZone(m_ruler->zone());
432 void Monitor::slotSetZoneEnd()
434 m_ruler->setZone(-1, m_ruler->position());
435 emit zoneUpdated(m_ruler->zone());
437 setClipZone(m_ruler->zone());
441 void Monitor::mousePressEvent(QMouseEvent * event)
443 if (event->button() != Qt::RightButton) {
444 if (m_videoBox->geometry().contains(event->pos()) && (!m_overlay || !m_overlay->underMouse())) {
445 m_dragStarted = true;
446 m_DragStartPosition = event->pos();
448 } else if (m_contextMenu && (!m_effectWidget || !m_effectWidget->isVisible())) {
449 m_contextMenu->popup(event->globalPos());
453 void Monitor::resizeEvent(QResizeEvent *event)
456 if (render && isVisible() && isActive()) render->doRefresh();
460 void Monitor::slotSwitchFullScreen()
462 m_videoBox->switchFullScreen();
466 void Monitor::mouseReleaseEvent(QMouseEvent * event)
468 if (m_dragStarted && event->button() != Qt::RightButton) {
469 if (m_videoBox->geometry().contains(event->pos()) && (!m_effectWidget || !m_effectWidget->isVisible())) {
470 if (isActive()) slotPlay();
471 else slotActivateMonitor();
472 } //else event->ignore(); //QWidget::mouseReleaseEvent(event);
473 m_dragStarted = false;
478 void Monitor::mouseMoveEvent(QMouseEvent *event)
480 if (!m_dragStarted || m_currentClip == NULL) return;
482 if ((event->pos() - m_DragStartPosition).manhattanLength()
483 < QApplication::startDragDistance())
487 QDrag *drag = new QDrag(this);
488 QMimeData *mimeData = new QMimeData;
491 list.append(m_currentClip->getId());
492 QPoint p = m_ruler->zone();
493 list.append(QString::number(p.x()));
494 list.append(QString::number(p.y()));
496 data.append(list.join(";").toUtf8());
497 mimeData->setData("kdenlive/clip", data);
498 drag->setMimeData(mimeData);
499 /*QPixmap pix = m_currentClip->thumbnail();
500 drag->setPixmap(pix);
501 drag->setHotSpot(QPoint(0, 50));*/
502 drag->start(Qt::MoveAction);
504 //Qt::DropAction dropAction;
505 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
507 //Qt::DropAction dropAction = drag->exec();
513 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
514 event->setDropAction(Qt::IgnoreAction);
515 event->setDropAction(Qt::MoveAction);
516 if (event->mimeData()->hasText()) {
517 event->acceptProposedAction();
521 Qt::DropActions Monitor::supportedDropActions() const {
522 // returns what actions are supported when dropping
523 return Qt::MoveAction;
526 QStringList Monitor::mimeTypes() const
528 QStringList qstrList;
529 // list of accepted mime types for drop
530 qstrList.append("kdenlive/clip");
535 void Monitor::wheelEvent(QWheelEvent * event)
537 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
541 void Monitor::mouseDoubleClickEvent(QMouseEvent * event)
543 if (!KdenliveSettings::openglmonitors()) {
544 m_videoBox->switchFullScreen();
549 void Monitor::slotMouseSeek(int eventDelta, bool fast)
552 int delta = m_monitorManager->timecode().fps();
553 if (eventDelta > 0) delta = 0 - delta;
554 slotSeek(m_ruler->position() - delta);
556 if (eventDelta >= 0) slotForwardOneFrame();
557 else slotRewindOneFrame();
561 void Monitor::slotSetThumbFrame()
563 if (m_currentClip == NULL) {
566 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
567 emit refreshClipThumbnail(m_currentClip->getId(), true);
570 void Monitor::slotExtractCurrentZone()
572 if (m_currentClip == NULL) return;
573 emit extractZone(m_currentClip->getId(), m_ruler->zone());
576 void Monitor::slotExtractCurrentFrame()
579 // check if we are using a proxy
580 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
581 // using proxy, use original clip url to get frame
582 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
584 else frame = render->extractFrame(render->seekFramePosition());
585 KFileDialog *fs = new KFileDialog(KUrl(), "image/png", this);
586 fs->setOperationMode(KFileDialog::Saving);
587 fs->setMode(KFile::File);
588 fs->setConfirmOverwrite(true);
589 fs->setKeepLocation(true);
591 QString path = fs->selectedFile();
593 if (!path.isEmpty()) {
598 void Monitor::setTimePos(const QString &pos)
600 m_timePos->setValue(pos);
604 void Monitor::slotSeek()
606 slotSeek(m_timePos->getValue());
609 void Monitor::slotSeek(int pos)
611 if (render == NULL) return;
612 slotActivateMonitor();
613 render->seekToFrame(pos);
616 void Monitor::checkOverlay()
618 if (m_overlay == NULL) return;
619 int pos = m_ruler->position();
620 QPoint zone = m_ruler->zone();
622 m_overlay->setOverlayText(i18n("In Point"));
623 else if (pos == zone.y())
624 m_overlay->setOverlayText(i18n("Out Point"));
627 QString markerComment = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
628 if (markerComment.isEmpty())
629 m_overlay->setHidden(true);
631 m_overlay->setOverlayText(markerComment, false);
632 } else m_overlay->setHidden(true);
636 void Monitor::slotStart()
638 slotActivateMonitor();
640 render->seekToFrame(0);
643 void Monitor::slotEnd()
645 slotActivateMonitor();
647 render->seekToFrame(render->getLength());
650 void Monitor::slotZoneStart()
652 slotActivateMonitor();
654 render->seekToFrame(m_ruler->zone().x());
657 void Monitor::slotZoneEnd()
659 slotActivateMonitor();
661 render->seekToFrame(m_ruler->zone().y());
664 void Monitor::slotRewind(double speed)
666 slotActivateMonitor();
668 double currentspeed = render->playSpeed();
669 if (currentspeed >= 0) render->play(-2);
670 else render->play(currentspeed * 2);
671 } else render->play(speed);
672 //m_playAction->setChecked(true);
673 m_playAction->setIcon(m_pauseIcon);
676 void Monitor::slotForward(double speed)
678 slotActivateMonitor();
680 double currentspeed = render->playSpeed();
681 if (currentspeed <= 1) render->play(2);
682 else render->play(currentspeed * 2);
683 } else render->play(speed);
684 //m_playAction->setChecked(true);
685 m_playAction->setIcon(m_pauseIcon);
688 void Monitor::slotRewindOneFrame(int diff)
690 slotActivateMonitor();
692 render->seekToFrameDiff(-diff);
695 void Monitor::slotForwardOneFrame(int diff)
697 slotActivateMonitor();
699 render->seekToFrameDiff(diff);
702 void Monitor::seekCursor(int pos)
704 //slotActivateMonitor();
705 if (m_ruler->slotNewValue(pos)) {
707 m_timePos->setValue(pos);
711 void Monitor::rendererStopped(int pos)
713 if (m_ruler->slotNewValue(pos)) {
715 m_timePos->setValue(pos);
717 m_playAction->setIcon(m_playIcon);
720 void Monitor::adjustRulerSize(int length)
722 if (length > 0) m_length = length;
723 m_ruler->adjustScale(m_length);
724 if (m_currentClip != NULL) {
725 QPoint zone = m_currentClip->zone();
726 m_ruler->setZone(zone.x(), zone.y());
732 if (render) render->stop();
735 void Monitor::start()
737 if (!isVisible()) return;
738 if (render) render->start();
741 void Monitor::refreshMonitor(bool visible)
743 if (visible && render) {
744 if (!slotActivateMonitor()) {
745 // the monitor was already active, simply refreshClipThumbnail
751 void Monitor::refreshMonitor()
758 void Monitor::pause()
760 if (render == NULL) return;
761 slotActivateMonitor();
763 //m_playAction->setChecked(true);
764 m_playAction->setIcon(m_playIcon);
767 void Monitor::unpause()
771 void Monitor::slotPlay()
773 if (render == NULL) return;
774 slotActivateMonitor();
775 if (render->playSpeed() == 0.0) {
776 m_playAction->setIcon(m_pauseIcon);
777 render->switchPlay(true);
779 m_playAction->setIcon(m_playIcon);
780 render->switchPlay(false);
784 void Monitor::slotPlayZone()
786 if (render == NULL) return;
787 slotActivateMonitor();
788 QPoint p = m_ruler->zone();
789 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
790 //m_playAction->setChecked(true);
791 m_playAction->setIcon(m_pauseIcon);
794 void Monitor::slotLoopZone()
796 if (render == NULL) return;
797 slotActivateMonitor();
798 QPoint p = m_ruler->zone();
799 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
800 //m_playAction->setChecked(true);
801 m_playAction->setIcon(m_pauseIcon);
804 void Monitor::slotLoopClip()
806 if (render == NULL || m_selectedClip == NULL)
808 slotActivateMonitor();
809 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
810 //m_playAction->setChecked(true);
811 m_playAction->setIcon(m_pauseIcon);
814 void Monitor::updateClipProducer(Mlt::Producer *prod)
816 if (render == NULL) return;
817 render->setProducer(prod, render->seekFramePosition());
820 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
822 if (render == NULL) return;
823 if (clip == NULL && m_currentClip != NULL) {
824 kDebug()<<"// SETTING NULL CLIP MONITOR";
825 m_currentClip = NULL;
827 render->setProducer(NULL, -1);
831 if (clip != m_currentClip || forceUpdate) {
832 m_currentClip = clip;
833 if (m_currentClip) slotActivateMonitor();
835 Mlt::Producer *prod = NULL;
836 if (clip) prod = clip->getCloneProducer();
837 if (render->setProducer(prod, position) == -1) {
838 // MLT CONSUMER is broken
839 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
843 slotActivateMonitor();
844 if (position == -1) position = render->seekFramePosition();
845 render->seek(position);
848 if (!zone.isNull()) {
849 m_ruler->setZone(zone.x(), zone.y());
850 render->seek(zone.x());
854 void Monitor::slotOpenFile(const QString &file)
856 if (render == NULL) return;
857 slotActivateMonitor();
859 QDomElement mlt = doc.createElement("mlt");
860 doc.appendChild(mlt);
861 QDomElement prod = doc.createElement("producer");
862 mlt.appendChild(prod);
863 prod.setAttribute("mlt_service", "avformat");
864 prod.setAttribute("resource", file);
865 render->setSceneList(doc, 0);
868 void Monitor::slotSaveZone()
870 if (render == NULL) return;
871 emit saveZone(render, m_ruler->zone(), m_currentClip);
873 //render->setSceneList(doc, 0);
876 void Monitor::resetProfile(const QString &profile)
878 m_timePos->updateTimeCode(m_monitorManager->timecode());
879 if (render == NULL) return;
880 if (!render->hasProfile(profile)) {
881 slotActivateMonitor();
882 render->resetProfile(profile);
885 m_effectWidget->resetProfile(render);
888 void Monitor::saveSceneList(QString path, QDomElement info)
890 if (render == NULL) return;
891 render->saveSceneList(path, info);
894 const QString Monitor::sceneList()
896 if (render == NULL) return QString();
897 return render->sceneList();
900 void Monitor::setClipZone(QPoint pos)
902 if (m_currentClip == NULL) return;
903 m_currentClip->setZone(pos);
906 void Monitor::slotSwitchDropFrames(bool show)
908 render->setDropFrames(show);
911 void Monitor::slotSwitchMonitorInfo(bool show)
913 KdenliveSettings::setDisplayMonitorInfo(show);
915 if (m_overlay) return;
916 if (m_monitorRefresh == NULL) {
917 // Using OpenGL display
919 if (m_glWidget->layout()) delete m_glWidget->layout();
920 m_overlay = new Overlay();
921 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
922 QVBoxLayout *layout = new QVBoxLayout;
923 layout->addStretch(10);
924 layout->addWidget(m_overlay);
925 m_glWidget->setLayout(layout);
928 if (m_monitorRefresh->layout()) delete m_monitorRefresh->layout();
929 m_overlay = new Overlay();
930 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
931 QVBoxLayout *layout = new QVBoxLayout;
932 layout->addStretch(10);
933 layout->addWidget(m_overlay);
934 m_monitorRefresh->setLayout(layout);
936 m_overlay->setHidden(true);
945 void Monitor::slotEditMarker()
947 if (m_editMarker) m_editMarker->trigger();
950 void Monitor::updateTimecodeFormat()
952 m_timePos->slotUpdateTimeCodeFormat();
955 QStringList Monitor::getZoneInfo() const
958 if (m_currentClip == NULL) return result;
959 result << m_currentClip->getId();
960 QPoint zone = m_ruler->zone();
961 result << QString::number(zone.x()) << QString::number(zone.y());
965 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
968 m_loopClipAction->setEnabled(true);
969 m_selectedClip = item;
971 m_loopClipAction->setEnabled(false);
975 void Monitor::slotSetSelectedClip(ClipItem* item)
977 if (item || (!item && !m_loopClipTransition)) {
978 m_loopClipTransition = false;
979 slotSetSelectedClip((AbstractClipItem*)item);
983 void Monitor::slotSetSelectedClip(Transition* item)
985 if (item || (!item && m_loopClipTransition)) {
986 m_loopClipTransition = true;
987 slotSetSelectedClip((AbstractClipItem*)item);
992 void Monitor::slotEffectScene(bool show)
994 if (m_id == Kdenlive::projectMonitor) {
995 if (m_monitorRefresh) {
996 m_monitorRefresh->setVisible(!show);
999 m_glWidget->setVisible(!show);
1002 m_effectWidget->setVisible(show);
1003 m_effectWidget->getVisibilityAction()->setChecked(show);
1004 emit requestFrameForAnalysis(show);
1006 m_effectWidget->getScene()->slotZoomFit();
1008 m_videoBox->setEnabled(show);
1009 render->doRefresh();
1013 MonitorEditWidget* Monitor::getEffectEdit()
1015 return m_effectWidget;
1018 bool Monitor::effectSceneDisplayed()
1020 return m_effectWidget->isVisible();
1023 void Monitor::slotSetVolume(int volume)
1025 KdenliveSettings::setVolume(volume);
1027 if (volume == 0) icon = KIcon("audio-volume-muted");
1028 else icon = KIcon("audio-volume-medium");
1029 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1030 render->slotSetVolume(volume);
1033 void Monitor::slotShowVolume()
1035 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1036 int vol = render->volume();
1037 // Disable widget if we cannot get the volume
1038 m_volumePopup->setEnabled(vol != -1);
1039 m_audioSlider->blockSignals(true);
1040 m_audioSlider->setValue(vol);
1041 m_audioSlider->blockSignals(false);
1042 m_volumePopup->show();
1045 AbstractRender *Monitor::abstractRender()
1050 void Monitor::reloadProducer(const QString &id)
1052 if (!m_currentClip) return;
1053 if (m_currentClip->getId() == id)
1054 slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
1057 MonitorRefresh::MonitorRefresh(QWidget* parent) :
1061 // MonitorRefresh is used as container for the SDL display (it's window id is passed to SDL)
1062 setAttribute(Qt::WA_PaintOnScreen);
1063 setAttribute(Qt::WA_OpaquePaintEvent);
1064 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
1065 //setAttribute(Qt::WA_NoSystemBackground);
1068 void MonitorRefresh::setRenderer(Render* render)
1070 m_renderer = render;
1074 Overlay::Overlay(QWidget* parent) :
1077 //setAttribute(Qt::WA_TransparentForMouseEvents);
1078 setAutoFillBackground(true);
1079 setBackgroundRole(QPalette::Base);
1080 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1081 setCursor(Qt::PointingHandCursor);
1085 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1091 void Overlay::mousePressEvent( QMouseEvent * event )
1097 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1103 void Overlay::setOverlayText(const QString &text, bool isZone)
1108 p.setColor(QPalette::Text, Qt::white);
1109 if (m_isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1110 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1112 setText(' ' + text + ' ');
1118 #include "monitor.moc"