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(m_timePos->height());
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::setMarkers(QList <CommentedTime> markers)
390 m_ruler->setMarkers(markers);
393 void Monitor::slotSeekToPreviousSnap()
395 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
398 void Monitor::slotSeekToNextSnap()
400 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
403 GenTime Monitor::position()
405 return render->seekPosition();
408 GenTime Monitor::getSnapForPos(bool previous)
410 QList <GenTime> snaps;
411 QList < GenTime > markers = m_currentClip->snapMarkers();
412 for (int i = 0; i < markers.size(); ++i) {
413 GenTime t = markers.at(i);
416 QPoint zone = m_ruler->zone();
417 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
418 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
419 snaps.append(GenTime());
420 snaps.append(m_currentClip->duration());
423 const GenTime pos = render->seekPosition();
424 for (int i = 0; i < snaps.size(); ++i) {
425 if (previous && snaps.at(i) >= pos) {
427 return snaps.at(i - 1);
428 } else if (!previous && snaps.at(i) > pos) {
435 void Monitor::slotZoneMoved(int start, int end)
437 m_ruler->setZone(start, end);
438 setClipZone(m_ruler->zone());
442 void Monitor::slotSetZoneStart()
444 m_ruler->setZoneStart();
445 emit zoneUpdated(m_ruler->zone());
446 setClipZone(m_ruler->zone());
450 void Monitor::slotSetZoneEnd()
452 m_ruler->setZoneEnd();
453 emit zoneUpdated(m_ruler->zone());
454 setClipZone(m_ruler->zone());
459 void Monitor::mousePressEvent(QMouseEvent * event)
461 if (event->button() != Qt::RightButton) {
462 if (videoBox->geometry().contains(event->pos()) && (!m_overlay || !m_overlay->underMouse())) {
463 m_dragStarted = true;
464 m_DragStartPosition = event->pos();
466 } else if (m_contextMenu && (!m_effectWidget || !m_effectWidget->isVisible())) {
467 m_contextMenu->popup(event->globalPos());
471 void Monitor::resizeEvent(QResizeEvent *event)
474 if (render && isVisible() && isActive()) render->doRefresh();
477 void Monitor::slotSwitchFullScreen()
479 videoBox->switchFullScreen();
483 void Monitor::mouseReleaseEvent(QMouseEvent * event)
485 if (m_dragStarted && event->button() != Qt::RightButton) {
486 if (videoBox->geometry().contains(event->pos()) && (!m_effectWidget || !m_effectWidget->isVisible())) {
487 if (isActive()) slotPlay();
488 else slotActivateMonitor();
489 } //else event->ignore(); //QWidget::mouseReleaseEvent(event);
491 m_dragStarted = false;
496 void Monitor::mouseMoveEvent(QMouseEvent *event)
498 if (!m_dragStarted || m_currentClip == NULL) return;
500 if ((event->pos() - m_DragStartPosition).manhattanLength()
501 < QApplication::startDragDistance())
505 QDrag *drag = new QDrag(this);
506 QMimeData *mimeData = new QMimeData;
509 list.append(m_currentClip->getId());
510 QPoint p = m_ruler->zone();
511 list.append(QString::number(p.x()));
512 list.append(QString::number(p.y()));
514 data.append(list.join(";").toUtf8());
515 mimeData->setData("kdenlive/clip", data);
516 drag->setMimeData(mimeData);
517 /*QPixmap pix = m_currentClip->thumbnail();
518 drag->setPixmap(pix);
519 drag->setHotSpot(QPoint(0, 50));*/
520 drag->start(Qt::MoveAction);
521 /*Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
522 Qt::DropAction dropAction;
523 dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);*/
525 //Qt::DropAction dropAction = drag->exec();
532 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
533 event->setDropAction(Qt::IgnoreAction);
534 event->setDropAction(Qt::MoveAction);
535 if (event->mimeData()->hasText()) {
536 event->acceptProposedAction();
540 Qt::DropActions Monitor::supportedDropActions() const {
541 // returns what actions are supported when dropping
542 return Qt::MoveAction;
545 QStringList Monitor::mimeTypes() const
547 QStringList qstrList;
548 // list of accepted mime types for drop
549 qstrList.append("kdenlive/clip");
554 void Monitor::wheelEvent(QWheelEvent * event)
556 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
560 void Monitor::mouseDoubleClickEvent(QMouseEvent * event)
562 if (!KdenliveSettings::openglmonitors()) {
563 videoBox->switchFullScreen();
568 void Monitor::slotMouseSeek(int eventDelta, bool fast)
571 int delta = m_monitorManager->timecode().fps();
572 if (eventDelta > 0) delta = 0 - delta;
573 if (render->requestedSeekPosition != SEEK_INACTIVE)
574 slotSeek(render->requestedSeekPosition - delta);
575 else slotSeek(render->seekFramePosition() - delta);
577 if (eventDelta >= 0) slotForwardOneFrame();
578 else slotRewindOneFrame();
582 void Monitor::slotSetThumbFrame()
584 if (m_currentClip == NULL) {
587 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
588 emit refreshClipThumbnail(m_currentClip->getId(), true);
591 void Monitor::slotExtractCurrentZone()
593 if (m_currentClip == NULL) return;
594 emit extractZone(m_currentClip->getId(), m_ruler->zone());
597 void Monitor::slotExtractCurrentFrame()
600 // check if we are using a proxy
601 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
602 // using proxy, use original clip url to get frame
603 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
605 else frame = render->extractFrame(render->seekFramePosition());
606 QPointer<KFileDialog> fs = new KFileDialog(KUrl(), "image/png", this);
607 fs->setOperationMode(KFileDialog::Saving);
608 fs->setMode(KFile::File);
609 fs->setConfirmOverwrite(true);
610 fs->setKeepLocation(true);
613 if (fs) path = fs->selectedFile();
615 if (!path.isEmpty()) {
620 void Monitor::setTimePos(const QString &pos)
622 m_timePos->setValue(pos);
626 void Monitor::slotSeek()
628 slotSeek(m_timePos->getValue());
631 void Monitor::slotSeek(int pos)
633 if (render == NULL) return;
634 slotActivateMonitor();
635 render->seekToFrame(pos);
639 void Monitor::checkOverlay()
641 if (m_overlay == NULL) return;
643 int pos = m_timePos->getValue();//render->seekFramePosition();
644 QPoint zone = m_ruler->zone();
646 overlayText = i18n("In Point");
647 else if (pos == zone.y())
648 overlayText = i18n("Out Point");
651 overlayText = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
652 if (!overlayText.isEmpty()) {
653 m_overlay->setOverlayText(overlayText, false);
658 if (m_overlay->isVisible() && overlayText.isEmpty()) m_overlay->setOverlayText(QString(), false);
659 else m_overlay->setOverlayText(overlayText);
662 void Monitor::slotStart()
664 slotActivateMonitor();
666 render->seekToFrame(0);
669 void Monitor::slotEnd()
671 slotActivateMonitor();
673 render->seekToFrame(render->getLength());
676 void Monitor::slotZoneStart()
678 slotActivateMonitor();
680 render->seekToFrame(m_ruler->zone().x());
683 void Monitor::slotZoneEnd()
685 slotActivateMonitor();
687 render->seekToFrame(m_ruler->zone().y());
690 void Monitor::slotRewind(double speed)
692 slotActivateMonitor();
694 double currentspeed = render->playSpeed();
695 if (currentspeed >= 0) render->play(-1);
696 else switch((int) currentspeed) {
709 } else render->play(speed);
710 //m_playAction->setChecked(true);
711 m_playAction->setIcon(m_pauseIcon);
714 void Monitor::slotForward(double speed)
716 slotActivateMonitor();
718 double currentspeed = render->playSpeed();
719 if (currentspeed <= 0) render->play(1);
720 else switch((int) currentspeed) {
733 } else render->play(speed);
734 //m_playAction->setChecked(true);
735 m_playAction->setIcon(m_pauseIcon);
738 void Monitor::slotRewindOneFrame(int diff)
740 slotActivateMonitor();
742 render->seekToFrameDiff(-diff);
746 void Monitor::slotForwardOneFrame(int diff)
748 slotActivateMonitor();
750 render->seekToFrameDiff(diff);
754 void Monitor::seekCursor(int pos)
756 if (m_ruler->slotNewValue(pos)) {
757 m_timePos->setValue(pos);
762 void Monitor::rendererStopped(int pos)
764 if (m_ruler->slotNewValue(pos)) {
765 m_timePos->setValue(pos);
768 m_playAction->setIcon(m_playIcon);
771 void Monitor::adjustRulerSize(int length)
773 if (length > 0) m_length = length;
774 m_ruler->adjustScale(m_length);
775 if (m_currentClip != NULL) {
776 QPoint zone = m_currentClip->zone();
777 m_ruler->setZone(zone.x(), zone.y());
783 if (render) render->stop();
786 void Monitor::start()
788 if (!isVisible() || !isActive()) return;
790 if (m_glWidget) m_glWidget->activateMonitor();
792 if (render) render->startConsumer();
795 void Monitor::refreshMonitor(bool visible)
797 if (visible && render) {
798 if (!slotActivateMonitor()) {
799 // the monitor was already active, simply refreshClipThumbnail
805 void Monitor::refreshMonitor()
812 void Monitor::pause()
814 if (render == NULL) return;
815 slotActivateMonitor();
817 //m_playAction->setChecked(true);
818 m_playAction->setIcon(m_playIcon);
821 void Monitor::unpause()
825 void Monitor::slotPlay()
827 if (render == NULL) return;
828 slotActivateMonitor();
829 if (render->isPlaying()) {
830 m_playAction->setIcon(m_playIcon);
831 render->switchPlay(false);
834 m_playAction->setIcon(m_pauseIcon);
835 render->switchPlay(true);
837 m_ruler->refreshRuler();
840 void Monitor::slotPlayZone()
842 if (render == NULL) return;
843 slotActivateMonitor();
844 QPoint p = m_ruler->zone();
845 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
846 //m_playAction->setChecked(true);
847 m_playAction->setIcon(m_pauseIcon);
850 void Monitor::slotLoopZone()
852 if (render == NULL) return;
853 slotActivateMonitor();
854 QPoint p = m_ruler->zone();
855 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
856 //m_playAction->setChecked(true);
857 m_playAction->setIcon(m_pauseIcon);
860 void Monitor::slotLoopClip()
862 if (render == NULL || m_selectedClip == NULL)
864 slotActivateMonitor();
865 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
866 //m_playAction->setChecked(true);
867 m_playAction->setIcon(m_pauseIcon);
870 void Monitor::updateClipProducer(Mlt::Producer *prod)
872 if (render == NULL) return;
873 render->setProducer(prod, render->seekFramePosition());
876 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
878 if (render == NULL) return;
879 if (clip == NULL && m_currentClip != NULL) {
880 m_currentClip->lastSeekPosition = render->seekFramePosition();
881 kDebug()<<"// SETTING NULL CLIP MONITOR";
882 m_currentClip = NULL;
884 render->setProducer(NULL, -1);
888 if (clip != m_currentClip || forceUpdate) {
889 if (m_currentClip) m_currentClip->lastSeekPosition = render->seekFramePosition();
890 m_currentClip = clip;
891 if (position == -1) position = clip->lastSeekPosition;
893 Mlt::Producer *prod = NULL;
894 if (clip) prod = clip->getCloneProducer();
895 if (render->setProducer(prod, position) == -1) {
896 // MLT CONSUMER is broken
897 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
901 slotActivateMonitor();
902 if (position == -1) position = render->seekFramePosition();
903 render->seek(position);
905 zone = m_currentClip->zone();
906 m_ruler->setZone(zone.x(), zone.y());
911 if (!zone.isNull()) {
912 m_ruler->setZone(zone.x(), zone.y());
913 render->seek(zone.x());
917 void Monitor::slotOpenFile(const QString &file)
919 if (render == NULL) return;
920 slotActivateMonitor();
921 render->loadUrl(file);
924 void Monitor::slotSaveZone()
926 if (render == NULL) return;
927 emit saveZone(render, m_ruler->zone(), m_currentClip);
929 //render->setSceneList(doc, 0);
932 void Monitor::setCustomProfile(const QString &profile, Timecode tc)
934 m_timePos->updateTimeCode(tc);
935 if (render == NULL) return;
936 if (!render->hasProfile(profile)) {
937 slotActivateMonitor();
938 render->resetProfile(profile);
940 if (m_glWidget) m_glWidget->setImageAspectRatio(render->dar());
945 void Monitor::resetProfile(const QString &profile)
947 m_timePos->updateTimeCode(m_monitorManager->timecode());
948 if (render == NULL) return;
949 if (!render->hasProfile(profile)) {
950 slotActivateMonitor();
951 render->resetProfile(profile);
953 if (m_glWidget) m_glWidget->setImageAspectRatio(render->dar());
957 m_effectWidget->resetProfile(render);
960 void Monitor::saveSceneList(QString path, QDomElement info)
962 if (render == NULL) return;
963 render->saveSceneList(path, info);
966 const QString Monitor::sceneList()
968 if (render == NULL) return QString();
969 return render->sceneList();
972 void Monitor::setClipZone(QPoint pos)
974 if (m_currentClip == NULL) return;
975 m_currentClip->setZone(pos);
978 void Monitor::slotSwitchDropFrames(bool show)
980 render->setDropFrames(show);
983 void Monitor::slotSwitchMonitorInfo(bool show)
985 KdenliveSettings::setDisplayMonitorInfo(show);
987 if (m_overlay) return;
988 if (videoSurface == NULL) {
989 // Using OpenGL display
991 if (m_glWidget->layout()) delete m_glWidget->layout();
992 m_overlay = new Overlay();
993 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
994 QVBoxLayout *layout = new QVBoxLayout;
995 layout->addStretch(10);
996 layout->addWidget(m_overlay);
997 m_glWidget->setLayout(layout);
1000 if (videoSurface->layout()) delete videoSurface->layout();
1001 m_overlay = new Overlay();
1002 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
1003 QVBoxLayout *layout = new QVBoxLayout;
1004 layout->addStretch(10);
1005 layout->addWidget(m_overlay);
1006 videoSurface->setLayout(layout);
1008 m_overlay->setHidden(true);
1017 void Monitor::slotEditMarker()
1019 if (m_editMarker) m_editMarker->trigger();
1022 void Monitor::updateTimecodeFormat()
1024 m_timePos->slotUpdateTimeCodeFormat();
1027 QStringList Monitor::getZoneInfo() const
1030 if (m_currentClip == NULL) return result;
1031 result << m_currentClip->getId();
1032 QPoint zone = m_ruler->zone();
1033 result << QString::number(zone.x()) << QString::number(zone.y());
1037 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
1040 m_loopClipAction->setEnabled(true);
1041 m_selectedClip = item;
1043 m_loopClipAction->setEnabled(false);
1047 void Monitor::slotSetSelectedClip(ClipItem* item)
1049 if (item || (!item && !m_loopClipTransition)) {
1050 m_loopClipTransition = false;
1051 slotSetSelectedClip((AbstractClipItem*)item);
1055 void Monitor::slotSetSelectedClip(Transition* item)
1057 if (item || (!item && m_loopClipTransition)) {
1058 m_loopClipTransition = true;
1059 slotSetSelectedClip((AbstractClipItem*)item);
1064 void Monitor::slotShowEffectScene(bool show, bool manuallyTriggered)
1066 if (m_id == Kdenlive::projectMonitor) {
1067 if (!m_effectWidget->getVisibilityAction()->isChecked())
1069 if (m_effectWidget->isVisible() == show)
1071 setUpdatesEnabled(false);
1074 videoSurface->setVisible(false);
1075 // Preview is handeled internally through the Render::showFrame method
1076 render->disablePreview(true);
1079 m_glWidget->setVisible(false);
1082 m_effectWidget->setVisible(true);
1083 m_effectWidget->getScene()->slotZoomFit();
1084 emit requestFrameForAnalysis(true);
1086 m_effectWidget->setVisible(false);
1087 emit requestFrameForAnalysis(false);
1089 videoSurface->setVisible(true);
1090 // Preview is handeled internally through the Render::showFrame method
1091 render->disablePreview(false);
1095 m_glWidget->setVisible(true);
1099 if (!manuallyTriggered)
1100 m_effectWidget->showVisibilityButton(show);
1101 setUpdatesEnabled(true);
1102 videoBox->setEnabled(show);
1103 //render->doRefresh();
1107 MonitorEditWidget* Monitor::getEffectEdit()
1109 return m_effectWidget;
1112 bool Monitor::effectSceneDisplayed()
1114 return m_effectWidget->isVisible();
1117 void Monitor::slotSetVolume(int volume)
1119 KdenliveSettings::setVolume(volume);
1121 if (volume == 0) icon = KIcon("audio-volume-muted");
1122 else icon = KIcon("audio-volume-medium");
1123 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1124 render->slotSetVolume(volume);
1127 void Monitor::slotShowVolume()
1129 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1130 int vol = render->volume();
1131 // Disable widget if we cannot get the volume
1132 m_volumePopup->setEnabled(vol != -1);
1133 m_audioSlider->blockSignals(true);
1134 m_audioSlider->setValue(vol);
1135 m_audioSlider->blockSignals(false);
1136 m_volumePopup->show();
1139 AbstractRender *Monitor::abstractRender()
1144 void Monitor::reloadProducer(const QString &id)
1146 if (!m_currentClip) return;
1147 if (m_currentClip->getId() == id)
1148 slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
1151 QString Monitor::getMarkerThumb(GenTime pos)
1153 if (!m_currentClip) return QString();
1154 if (!m_currentClip->getClipHash().isEmpty()) {
1155 QString url = m_monitorManager->getProjectFolder() + "thumbs/" + m_currentClip->getClipHash() + '#' + QString::number(pos.frames(m_monitorManager->timecode().fps())) + ".png";
1156 if (QFile::exists(url)) return url;
1161 void Monitor::setPalette ( const QPalette & p)
1163 QWidget::setPalette(p);
1164 if (m_ruler) m_ruler->updatePalette();
1168 Overlay::Overlay(QWidget* parent) :
1171 //setAttribute(Qt::WA_TransparentForMouseEvents);
1172 setAutoFillBackground(true);
1173 setBackgroundRole(QPalette::Base);
1174 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1175 setCursor(Qt::PointingHandCursor);
1180 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1186 void Overlay::mousePressEvent( QMouseEvent * event )
1192 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1198 void Overlay::setOverlayText(const QString &text, bool isZone)
1200 if (text.isEmpty()) {
1202 p.setColor(QPalette::Base, KdenliveSettings::window_background());
1211 p.setColor(QPalette::Text, Qt::white);
1212 if (isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1213 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1215 setText(' ' + text + ' ');
1220 #include "monitor.moc"