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)),
58 m_loopClipTransition(true),
61 QVBoxLayout *layout = new QVBoxLayout;
62 layout->setContentsMargins(0, 0, 0, 0);
63 layout->setSpacing(0);
65 // Video widget holder
66 layout->addWidget(videoBox, 10);
69 // Get base size for icons
70 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
73 layout->addWidget(m_ruler);
75 m_toolbar = new QToolBar(this);
76 m_toolbar->setIconSize(QSize(s, s));
78 m_playIcon = KIcon("media-playback-start");
79 m_pauseIcon = KIcon("media-playback-pause");
81 if (id != Kdenlive::dvdMonitor) {
82 m_toolbar->addAction(KIcon("kdenlive-zone-start"), i18n("Set zone start"), this, SLOT(slotSetZoneStart()));
83 m_toolbar->addAction(KIcon("kdenlive-zone-end"), i18n("Set zone end"), this, SLOT(slotSetZoneEnd()));
85 m_ruler->setZone(-3, -2);
88 m_toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"), this, SLOT(slotRewind()));
89 //m_toolbar->addAction(KIcon("media-skip-backward"), i18n("Rewind 1 frame"), this, SLOT(slotRewindOneFrame()));
91 QToolButton *playButton = new QToolButton(m_toolbar);
92 m_playMenu = new QMenu(i18n("Play..."), this);
93 m_playAction = m_playMenu->addAction(m_playIcon, i18n("Play"));
94 //m_playAction->setCheckable(true);
95 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
97 playButton->setMenu(m_playMenu);
98 playButton->setPopupMode(QToolButton::MenuButtonPopup);
99 m_toolbar->addWidget(playButton);
101 //m_toolbar->addAction(KIcon("media-skip-forward"), i18n("Forward 1 frame"), this, SLOT(slotForwardOneFrame()));
102 m_toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"), this, SLOT(slotForward()));
104 playButton->setDefaultAction(m_playAction);
106 if (id != Kdenlive::dvdMonitor) {
107 QToolButton *configButton = new QToolButton(m_toolbar);
108 m_configMenu = new QMenu(i18n("Misc..."), this);
109 configButton->setIcon(KIcon("system-run"));
110 configButton->setMenu(m_configMenu);
111 configButton->setPopupMode(QToolButton::QToolButton::InstantPopup);
112 m_toolbar->addWidget(configButton);
114 if (id == Kdenlive::clipMonitor) {
115 m_markerMenu = new QMenu(i18n("Go to marker..."), this);
116 m_markerMenu->setEnabled(false);
117 m_configMenu->addMenu(m_markerMenu);
118 connect(m_markerMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToMarker(QAction *)));
120 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (100%)"), this, SLOT(slotSetSizeOneToOne()));
121 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (50%)"), this, SLOT(slotSetSizeOneToTwo()));
124 // Create Volume slider popup
125 m_volumePopup = new QFrame(this, Qt::Popup);
126 QVBoxLayout *poplayout = new QVBoxLayout;
127 poplayout->setContentsMargins(0, 0, 0, 0);
128 m_audioSlider = new QSlider(Qt::Vertical);
129 m_audioSlider->setRange(0, 100);
130 poplayout->addWidget(m_audioSlider);
131 m_volumePopup->setLayout(poplayout);
133 if (KdenliveSettings::volume() == 0) icon = KIcon("audio-volume-muted");
134 else icon = KIcon("audio-volume-medium");
136 m_volumeWidget = m_toolbar->widgetForAction(m_toolbar->addAction(icon, i18n("Audio volume"), this, SLOT(slotShowVolume())));
138 // we need to show / hide the popup once so that it's geometry can be calculated in slotShowVolume
139 m_volumePopup->show();
140 m_volumePopup->hide();
142 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
144 setMinimumHeight(200);
146 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
148 bool monitorCreated = false;
150 createOpenGlWidget(videoBox, profile);
151 monitorCreated = true;
152 //m_glWidget->setFixedSize(width, height);
153 #elif defined(USE_OPENGL)
154 if (KdenliveSettings::openglmonitors()) {
155 monitorCreated = createOpenGlWidget(videoBox, profile);
158 if (!monitorCreated) {
159 createVideoSurface();
160 render = new Render(m_id, (int) videoSurface->winId(), profile, this);
161 connect(videoSurface, SIGNAL(refreshMonitor()), render, SLOT(doRefresh()));
164 else if (m_glWidget) {
165 QVBoxLayout *lay = new QVBoxLayout;
166 lay->setContentsMargins(0, 0, 0, 0);
167 lay->addWidget(m_glWidget);
168 videoBox->setLayout(lay);
172 connect(m_audioSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetVolume(int)));
173 connect(m_ruler, SIGNAL(seekRenderer(int)), this, SLOT(slotSeek(int)));
174 connect(render, SIGNAL(durationChanged(int)), this, SLOT(adjustRulerSize(int)));
175 connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int)));
176 connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
178 if (id != Kdenlive::clipMonitor) {
179 connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int)));
180 connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int)));
181 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SIGNAL(zoneUpdated(QPoint)));
183 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SLOT(setClipZone(QPoint)));
186 if (videoSurface) videoSurface->show();
188 if (id == Kdenlive::projectMonitor) {
189 m_effectWidget = new MonitorEditWidget(render, videoBox);
190 connect(m_effectWidget, SIGNAL(showEdit(bool, bool)), this, SLOT(slotShowEffectScene(bool, bool)));
191 m_toolbar->addAction(m_effectWidget->getVisibilityAction());
192 videoBox->layout()->addWidget(m_effectWidget);
193 m_effectWidget->hide();
196 QWidget *spacer = new QWidget(this);
197 spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
198 m_toolbar->addWidget(spacer);
199 m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this);
200 m_toolbar->addWidget(m_timePos);
201 connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotSeek()));
202 m_toolbar->setMaximumHeight(s * 1.5);
203 layout->addWidget(m_toolbar);
212 delete m_effectWidget;
216 QWidget *Monitor::container()
222 bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile)
224 render = new Render(id(), 0, profile, this);
225 m_glWidget = new VideoGLWidget(parent);
226 if (m_glWidget == NULL) {
227 // Creation failed, we are in trouble...
230 m_glWidget->setImageAspectRatio(render->dar());
231 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
232 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
237 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
239 m_contextMenu = new QMenu(this);
240 m_contextMenu->addMenu(m_playMenu);
242 m_contextMenu->addMenu(goMenu);
244 m_contextMenu->addMenu(markerMenu);
245 QList <QAction *>list = markerMenu->actions();
246 for (int i = 0; i < list.count(); i++) {
247 if (list.at(i)->data().toString() == "edit_marker") {
248 m_editMarker = list.at(i);
254 m_playMenu->addAction(playZone);
255 m_playMenu->addAction(loopZone);
257 m_loopClipAction = loopClip;
258 m_playMenu->addAction(loopClip);
261 //TODO: add save zone to timeline monitor when fixed
262 if (m_id == Kdenlive::clipMonitor) {
263 m_contextMenu->addMenu(m_markerMenu);
264 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
265 QAction *extractZone = m_configMenu->addAction(KIcon("document-new"), i18n("Extract Zone"), this, SLOT(slotExtractCurrentZone()));
266 m_contextMenu->addAction(extractZone);
268 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
269 m_contextMenu->addAction(extractFrame);
271 if (m_id != Kdenlive::clipMonitor) {
272 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
273 splitView->setCheckable(true);
274 m_configMenu->addAction(splitView);
276 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
277 m_configMenu->addAction(setThumbFrame);
280 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
281 showTips->setCheckable(true);
282 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
283 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
285 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
286 dropFrames->setCheckable(true);
287 dropFrames->setChecked(true);
288 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
290 m_configMenu->addAction(showTips);
291 m_configMenu->addAction(dropFrames);
295 void Monitor::slotGoToMarker(QAction *action)
297 int pos = action->data().toInt();
301 void Monitor::slotSetSizeOneToOne()
303 QRect r = QApplication::desktop()->screenGeometry();
304 const int maxWidth = r.width() - 20;
305 const int maxHeight = r.height() - 20;
306 int width = render->renderWidth();
307 int height = render->renderHeight();
308 kDebug() << "// render info: " << width << "x" << height;
309 while (width >= maxWidth || height >= maxHeight) {
311 height = height * 0.8;
313 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
314 videoBox->setFixedSize(width, height);
317 //m_ui.video_frame->setMinimumSize(0, 0);
318 emit adjustMonitorSize();
321 void Monitor::slotSetSizeOneToTwo()
323 QRect r = QApplication::desktop()->screenGeometry();
324 const int maxWidth = r.width() - 20;
325 const int maxHeight = r.height() - 20;
326 int width = render->renderWidth() / 2;
327 int height = render->renderHeight() / 2;
328 kDebug() << "// render info: " << width << "x" << height;
329 while (width >= maxWidth || height >= maxHeight) {
331 height = height * 0.8;
333 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
334 videoBox->setFixedSize(width, height);
337 //m_ui.video_frame->setMinimumSize(0, 0);
338 emit adjustMonitorSize();
341 void Monitor::resetSize()
343 videoBox->setMinimumSize(0, 0);
346 DocClipBase *Monitor::activeClip()
348 return m_currentClip;
351 void Monitor::updateMarkers(DocClipBase *source)
353 if (source == m_currentClip && source != NULL) {
354 m_markerMenu->clear();
355 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
356 if (!markers.isEmpty()) {
358 for (int i = 0; i < markers.count(); i++) {
359 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
361 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
362 QAction *go = m_markerMenu->addAction(position);
365 m_ruler->setMarkers(marks);
366 } else m_ruler->setMarkers(QList <int>());
367 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
371 void Monitor::slotSeekToPreviousSnap()
373 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
376 void Monitor::slotSeekToNextSnap()
378 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
381 GenTime Monitor::position()
383 return render->seekPosition();
386 GenTime Monitor::getSnapForPos(bool previous)
388 QList <GenTime> snaps;
389 QList < GenTime > markers = m_currentClip->snapMarkers();
390 for (int i = 0; i < markers.size(); ++i) {
391 GenTime t = markers.at(i);
394 QPoint zone = m_ruler->zone();
395 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
396 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
397 snaps.append(GenTime());
398 snaps.append(m_currentClip->duration());
401 const GenTime pos = render->seekPosition();
402 for (int i = 0; i < snaps.size(); ++i) {
403 if (previous && snaps.at(i) >= pos) {
405 return snaps.at(i - 1);
406 } else if (!previous && snaps.at(i) > pos) {
413 void Monitor::slotZoneMoved(int start, int end)
415 m_ruler->setZone(start, end);
417 setClipZone(m_ruler->zone());
420 void Monitor::slotSetZoneStart()
422 m_ruler->setZone(m_ruler->position(), -1);
423 emit zoneUpdated(m_ruler->zone());
425 setClipZone(m_ruler->zone());
428 void Monitor::slotSetZoneEnd()
430 m_ruler->setZone(-1, m_ruler->position());
431 emit zoneUpdated(m_ruler->zone());
433 setClipZone(m_ruler->zone());
437 void Monitor::mousePressEvent(QMouseEvent * event)
439 if (event->button() != Qt::RightButton) {
440 if (videoBox->geometry().contains(event->pos()) && (!m_overlay || !m_overlay->underMouse())) {
441 m_dragStarted = true;
442 m_DragStartPosition = event->pos();
444 } else if (m_contextMenu && (!m_effectWidget || !m_effectWidget->isVisible())) {
445 m_contextMenu->popup(event->globalPos());
449 void Monitor::resizeEvent(QResizeEvent *event)
452 if (render && isVisible() && isActive()) render->doRefresh();
455 void Monitor::slotSwitchFullScreen()
457 videoBox->switchFullScreen();
461 void Monitor::mouseReleaseEvent(QMouseEvent * event)
463 if (m_dragStarted && event->button() != Qt::RightButton) {
464 if (videoBox->geometry().contains(event->pos()) && (!m_effectWidget || !m_effectWidget->isVisible())) {
465 if (isActive()) slotPlay();
466 else slotActivateMonitor();
467 } //else event->ignore(); //QWidget::mouseReleaseEvent(event);
468 m_dragStarted = false;
473 void Monitor::mouseMoveEvent(QMouseEvent *event)
475 if (!m_dragStarted || m_currentClip == NULL) return;
477 if ((event->pos() - m_DragStartPosition).manhattanLength()
478 < QApplication::startDragDistance())
482 QDrag *drag = new QDrag(this);
483 QMimeData *mimeData = new QMimeData;
486 list.append(m_currentClip->getId());
487 QPoint p = m_ruler->zone();
488 list.append(QString::number(p.x()));
489 list.append(QString::number(p.y()));
491 data.append(list.join(";").toUtf8());
492 mimeData->setData("kdenlive/clip", data);
493 drag->setMimeData(mimeData);
494 /*QPixmap pix = m_currentClip->thumbnail();
495 drag->setPixmap(pix);
496 drag->setHotSpot(QPoint(0, 50));*/
497 drag->start(Qt::MoveAction);
499 //Qt::DropAction dropAction;
500 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
502 //Qt::DropAction dropAction = drag->exec();
508 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
509 event->setDropAction(Qt::IgnoreAction);
510 event->setDropAction(Qt::MoveAction);
511 if (event->mimeData()->hasText()) {
512 event->acceptProposedAction();
516 Qt::DropActions Monitor::supportedDropActions() const {
517 // returns what actions are supported when dropping
518 return Qt::MoveAction;
521 QStringList Monitor::mimeTypes() const
523 QStringList qstrList;
524 // list of accepted mime types for drop
525 qstrList.append("kdenlive/clip");
530 void Monitor::wheelEvent(QWheelEvent * event)
532 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
536 void Monitor::mouseDoubleClickEvent(QMouseEvent * event)
538 if (!KdenliveSettings::openglmonitors()) {
539 videoBox->switchFullScreen();
544 void Monitor::slotMouseSeek(int eventDelta, bool fast)
547 int delta = m_monitorManager->timecode().fps();
548 if (eventDelta > 0) delta = 0 - delta;
549 slotSeek(m_ruler->position() - delta);
551 if (eventDelta >= 0) slotForwardOneFrame();
552 else slotRewindOneFrame();
556 void Monitor::slotSetThumbFrame()
558 if (m_currentClip == NULL) {
561 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
562 emit refreshClipThumbnail(m_currentClip->getId(), true);
565 void Monitor::slotExtractCurrentZone()
567 if (m_currentClip == NULL) return;
568 emit extractZone(m_currentClip->getId(), m_ruler->zone());
571 void Monitor::slotExtractCurrentFrame()
574 // check if we are using a proxy
575 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
576 // using proxy, use original clip url to get frame
577 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
579 else frame = render->extractFrame(render->seekFramePosition());
580 QPointer<KFileDialog> fs = new KFileDialog(KUrl(), "image/png", this);
581 fs->setOperationMode(KFileDialog::Saving);
582 fs->setMode(KFile::File);
583 fs->setConfirmOverwrite(true);
584 fs->setKeepLocation(true);
586 QString path = fs->selectedFile();
588 if (!path.isEmpty()) {
593 void Monitor::setTimePos(const QString &pos)
595 m_timePos->setValue(pos);
599 void Monitor::slotSeek()
601 slotSeek(m_timePos->getValue());
604 void Monitor::slotSeek(int pos)
606 if (render == NULL) return;
607 slotActivateMonitor();
608 render->seekToFrame(pos);
611 void Monitor::checkOverlay()
613 if (m_overlay == NULL) return;
615 int pos = m_ruler->position();
616 QPoint zone = m_ruler->zone();
618 overlayText = i18n("In Point");
619 else if (pos == zone.y())
620 overlayText = i18n("Out Point");
623 overlayText = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
624 if (!overlayText.isEmpty()) {
625 m_overlay->setOverlayText(overlayText, false);
630 if (m_overlay->isVisible() && overlayText.isEmpty()) m_overlay->setOverlayText(QString(), false);
631 else m_overlay->setOverlayText(overlayText);
634 void Monitor::slotStart()
636 slotActivateMonitor();
638 render->seekToFrame(0);
641 void Monitor::slotEnd()
643 slotActivateMonitor();
645 render->seekToFrame(render->getLength());
648 void Monitor::slotZoneStart()
650 slotActivateMonitor();
652 render->seekToFrame(m_ruler->zone().x());
655 void Monitor::slotZoneEnd()
657 slotActivateMonitor();
659 render->seekToFrame(m_ruler->zone().y());
662 void Monitor::slotRewind(double speed)
664 slotActivateMonitor();
666 double currentspeed = render->playSpeed();
667 if (currentspeed >= 0) render->play(-2);
668 else render->play(currentspeed * 2);
669 } else render->play(speed);
670 //m_playAction->setChecked(true);
671 m_playAction->setIcon(m_pauseIcon);
674 void Monitor::slotForward(double speed)
676 slotActivateMonitor();
678 double currentspeed = render->playSpeed();
679 if (currentspeed <= 1) render->play(2);
680 else render->play(currentspeed * 2);
681 } else render->play(speed);
682 //m_playAction->setChecked(true);
683 m_playAction->setIcon(m_pauseIcon);
686 void Monitor::slotRewindOneFrame(int diff)
688 slotActivateMonitor();
690 render->seekToFrameDiff(-diff);
693 void Monitor::slotForwardOneFrame(int diff)
695 slotActivateMonitor();
697 render->seekToFrameDiff(diff);
700 void Monitor::seekCursor(int pos)
702 //slotActivateMonitor();
703 if (m_ruler->slotNewValue(pos)) {
705 m_timePos->setValue(pos);
709 void Monitor::rendererStopped(int pos)
711 if (m_ruler->slotNewValue(pos)) {
713 m_timePos->setValue(pos);
715 m_playAction->setIcon(m_playIcon);
718 void Monitor::adjustRulerSize(int length)
720 if (length > 0) m_length = length;
721 m_ruler->adjustScale(m_length);
722 if (m_currentClip != NULL) {
723 QPoint zone = m_currentClip->zone();
724 m_ruler->setZone(zone.x(), zone.y());
730 if (render) render->stop();
733 void Monitor::start()
735 if (!isVisible() || !isActive()) return;
736 if (render) render->doRefresh();// start();
739 void Monitor::refreshMonitor(bool visible)
741 if (visible && render) {
742 if (!slotActivateMonitor()) {
743 // the monitor was already active, simply refreshClipThumbnail
749 void Monitor::refreshMonitor()
756 void Monitor::pause()
758 if (render == NULL) return;
759 slotActivateMonitor();
761 //m_playAction->setChecked(true);
762 m_playAction->setIcon(m_playIcon);
765 void Monitor::unpause()
769 void Monitor::slotPlay()
771 if (render == NULL) return;
772 slotActivateMonitor();
773 if (render->playSpeed() == 0.0) {
774 m_playAction->setIcon(m_pauseIcon);
775 render->switchPlay(true);
777 m_playAction->setIcon(m_playIcon);
778 render->switchPlay(false);
782 void Monitor::slotPlayZone()
784 if (render == NULL) return;
785 slotActivateMonitor();
786 QPoint p = m_ruler->zone();
787 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
788 //m_playAction->setChecked(true);
789 m_playAction->setIcon(m_pauseIcon);
792 void Monitor::slotLoopZone()
794 if (render == NULL) return;
795 slotActivateMonitor();
796 QPoint p = m_ruler->zone();
797 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
798 //m_playAction->setChecked(true);
799 m_playAction->setIcon(m_pauseIcon);
802 void Monitor::slotLoopClip()
804 if (render == NULL || m_selectedClip == NULL)
806 slotActivateMonitor();
807 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
808 //m_playAction->setChecked(true);
809 m_playAction->setIcon(m_pauseIcon);
812 void Monitor::updateClipProducer(Mlt::Producer *prod)
814 if (render == NULL) return;
815 render->setProducer(prod, render->seekFramePosition());
818 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
820 if (render == NULL) return;
821 if (clip == NULL && m_currentClip != NULL) {
822 kDebug()<<"// SETTING NULL CLIP MONITOR";
823 m_currentClip = NULL;
825 render->setProducer(NULL, -1);
829 if (clip != m_currentClip || forceUpdate) {
830 m_currentClip = clip;
831 if (m_currentClip) slotActivateMonitor();
833 Mlt::Producer *prod = NULL;
834 if (clip) prod = clip->getCloneProducer();
835 if (render->setProducer(prod, position) == -1) {
836 // MLT CONSUMER is broken
837 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
841 slotActivateMonitor();
842 if (position == -1) position = render->seekFramePosition();
843 render->seek(position);
846 if (!zone.isNull()) {
847 m_ruler->setZone(zone.x(), zone.y());
848 render->seek(zone.x());
852 void Monitor::slotOpenFile(const QString &file)
854 if (render == NULL) return;
855 slotActivateMonitor();
857 QDomElement mlt = doc.createElement("mlt");
858 doc.appendChild(mlt);
859 QDomElement prod = doc.createElement("producer");
860 mlt.appendChild(prod);
861 prod.setAttribute("mlt_service", "avformat");
862 prod.setAttribute("resource", file);
863 render->setSceneList(doc, 0);
866 void Monitor::slotSaveZone()
868 if (render == NULL) return;
869 emit saveZone(render, m_ruler->zone(), m_currentClip);
871 //render->setSceneList(doc, 0);
874 void Monitor::resetProfile(const QString &profile)
876 m_timePos->updateTimeCode(m_monitorManager->timecode());
877 if (render == NULL) return;
878 if (!render->hasProfile(profile)) {
879 slotActivateMonitor();
880 render->resetProfile(profile);
883 m_effectWidget->resetProfile(render);
886 void Monitor::saveSceneList(QString path, QDomElement info)
888 if (render == NULL) return;
889 render->saveSceneList(path, info);
892 const QString Monitor::sceneList()
894 if (render == NULL) return QString();
895 return render->sceneList();
898 void Monitor::setClipZone(QPoint pos)
900 if (m_currentClip == NULL) return;
901 m_currentClip->setZone(pos);
904 void Monitor::slotSwitchDropFrames(bool show)
906 render->setDropFrames(show);
909 void Monitor::slotSwitchMonitorInfo(bool show)
911 KdenliveSettings::setDisplayMonitorInfo(show);
913 if (m_overlay) return;
914 if (videoSurface == NULL) {
915 // Using OpenGL display
917 if (m_glWidget->layout()) delete m_glWidget->layout();
918 m_overlay = new Overlay();
919 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
920 QVBoxLayout *layout = new QVBoxLayout;
921 layout->addStretch(10);
922 layout->addWidget(m_overlay);
923 m_glWidget->setLayout(layout);
926 if (videoSurface->layout()) delete videoSurface->layout();
927 m_overlay = new Overlay();
928 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
929 QVBoxLayout *layout = new QVBoxLayout;
930 layout->addStretch(10);
931 layout->addWidget(m_overlay);
932 videoSurface->setLayout(layout);
934 m_overlay->setHidden(true);
943 void Monitor::slotEditMarker()
945 if (m_editMarker) m_editMarker->trigger();
948 void Monitor::updateTimecodeFormat()
950 m_timePos->slotUpdateTimeCodeFormat();
953 QStringList Monitor::getZoneInfo() const
956 if (m_currentClip == NULL) return result;
957 result << m_currentClip->getId();
958 QPoint zone = m_ruler->zone();
959 result << QString::number(zone.x()) << QString::number(zone.y());
963 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
966 m_loopClipAction->setEnabled(true);
967 m_selectedClip = item;
969 m_loopClipAction->setEnabled(false);
973 void Monitor::slotSetSelectedClip(ClipItem* item)
975 if (item || (!item && !m_loopClipTransition)) {
976 m_loopClipTransition = false;
977 slotSetSelectedClip((AbstractClipItem*)item);
981 void Monitor::slotSetSelectedClip(Transition* item)
983 if (item || (!item && m_loopClipTransition)) {
984 m_loopClipTransition = true;
985 slotSetSelectedClip((AbstractClipItem*)item);
990 void Monitor::slotShowEffectScene(bool show, bool manuallyTriggered)
992 if (m_id == Kdenlive::projectMonitor) {
993 if (!m_effectWidget->getVisibilityAction()->isChecked())
995 if (m_effectWidget->isVisible() == show)
997 setUpdatesEnabled(false);
1000 videoSurface->setVisible(false);
1001 // Preview is handeled internally through the Render::showFrame method
1002 render->disablePreview(true);
1005 m_glWidget->setVisible(false);
1008 m_effectWidget->setVisible(true);
1009 m_effectWidget->getScene()->slotZoomFit();
1010 emit requestFrameForAnalysis(true);
1012 m_effectWidget->setVisible(false);
1013 emit requestFrameForAnalysis(false);
1015 videoSurface->setVisible(true);
1016 // Preview is handeled internally through the Render::showFrame method
1017 render->disablePreview(false);
1021 m_glWidget->setVisible(true);
1025 if (!manuallyTriggered)
1026 m_effectWidget->showVisibilityButton(show);
1027 setUpdatesEnabled(true);
1028 videoBox->setEnabled(show);
1029 //render->doRefresh();
1033 MonitorEditWidget* Monitor::getEffectEdit()
1035 return m_effectWidget;
1038 bool Monitor::effectSceneDisplayed()
1040 return m_effectWidget->isVisible();
1043 void Monitor::slotSetVolume(int volume)
1045 KdenliveSettings::setVolume(volume);
1047 if (volume == 0) icon = KIcon("audio-volume-muted");
1048 else icon = KIcon("audio-volume-medium");
1049 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1050 render->slotSetVolume(volume);
1053 void Monitor::slotShowVolume()
1055 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1056 int vol = render->volume();
1057 // Disable widget if we cannot get the volume
1058 m_volumePopup->setEnabled(vol != -1);
1059 m_audioSlider->blockSignals(true);
1060 m_audioSlider->setValue(vol);
1061 m_audioSlider->blockSignals(false);
1062 m_volumePopup->show();
1065 AbstractRender *Monitor::abstractRender()
1070 void Monitor::reloadProducer(const QString &id)
1072 if (!m_currentClip) return;
1073 if (m_currentClip->getId() == id)
1074 slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
1077 void Monitor::setPalette ( const QPalette & p)
1079 QWidget::setPalette(p);
1080 if (m_ruler) m_ruler->updatePalette();
1084 Overlay::Overlay(QWidget* parent) :
1087 //setAttribute(Qt::WA_TransparentForMouseEvents);
1088 setAutoFillBackground(true);
1089 setBackgroundRole(QPalette::Base);
1090 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1091 setCursor(Qt::PointingHandCursor);
1095 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1101 void Overlay::mousePressEvent( QMouseEvent * event )
1107 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1113 void Overlay::setOverlayText(const QString &text, bool isZone)
1115 if (text.isEmpty()) {
1117 p.setColor(QPalette::Base, KdenliveSettings::window_background());
1126 p.setColor(QPalette::Text, Qt::white);
1127 if (isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1128 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1130 setText(' ' + text + ' ');
1135 #include "monitor.moc"