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),
63 QVBoxLayout *layout = new QVBoxLayout;
64 layout->setContentsMargins(0, 0, 0, 0);
65 layout->setSpacing(0);
67 // Video widget holder
68 layout->addWidget(videoBox, 10);
71 // Get base size for icons
72 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
76 m_toolbar = new QToolBar(this);
77 m_toolbar->setIconSize(QSize(s, s));
79 m_playIcon = KIcon("media-playback-start");
80 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()));
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);
173 m_ruler = new SmallRuler(m_monitorManager, render);
174 if (id == Kdenlive::dvdMonitor) m_ruler->setZone(-3, -2);
175 layout->addWidget(m_ruler);
177 connect(m_audioSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetVolume(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 (videoSurface) videoSurface->show();
192 if (id == Kdenlive::projectMonitor) {
193 m_effectWidget = new MonitorEditWidget(render, videoBox);
194 connect(m_effectWidget, SIGNAL(showEdit(bool, bool)), this, SLOT(slotShowEffectScene(bool, bool)));
195 m_toolbar->addAction(m_effectWidget->getVisibilityAction());
196 videoBox->layout()->addWidget(m_effectWidget);
197 m_effectWidget->hide();
200 QWidget *spacer = new QWidget(this);
201 spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
202 m_toolbar->addWidget(spacer);
203 m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this);
204 m_toolbar->addWidget(m_timePos);
205 connect(m_timePos, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotSeek()));
206 m_toolbar->setMaximumHeight(s * 1.5);
207 layout->addWidget(m_toolbar);
216 delete m_effectWidget;
220 QWidget *Monitor::container()
226 bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile)
228 render = new Render(id(), 0, profile, this);
229 kDebug()<<"+++++++++++++\nCREATED OPENGL WIDG\n++++++++++++++";
230 m_glWidget = new VideoGLWidget(parent);
231 if (m_glWidget == NULL) {
232 // Creation failed, we are in trouble...
235 m_glWidget->setImageAspectRatio(render->dar());
236 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
237 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
242 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
244 m_contextMenu = new QMenu(this);
245 m_contextMenu->addMenu(m_playMenu);
247 m_contextMenu->addMenu(goMenu);
249 m_contextMenu->addMenu(markerMenu);
250 QList <QAction *>list = markerMenu->actions();
251 for (int i = 0; i < list.count(); i++) {
252 if (list.at(i)->data().toString() == "edit_marker") {
253 m_editMarker = list.at(i);
259 m_playMenu->addAction(playZone);
260 m_playMenu->addAction(loopZone);
262 m_loopClipAction = loopClip;
263 m_playMenu->addAction(loopClip);
266 //TODO: add save zone to timeline monitor when fixed
267 if (m_id == Kdenlive::clipMonitor) {
268 m_contextMenu->addMenu(m_markerMenu);
269 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
270 QAction *extractZone = m_configMenu->addAction(KIcon("document-new"), i18n("Extract Zone"), this, SLOT(slotExtractCurrentZone()));
271 m_contextMenu->addAction(extractZone);
273 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
274 m_contextMenu->addAction(extractFrame);
276 if (m_id != Kdenlive::clipMonitor) {
277 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
278 splitView->setCheckable(true);
279 m_configMenu->addAction(splitView);
281 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
282 m_configMenu->addAction(setThumbFrame);
285 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
286 showTips->setCheckable(true);
287 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
288 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
290 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
291 dropFrames->setCheckable(true);
292 dropFrames->setChecked(true);
293 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
295 m_configMenu->addAction(showTips);
296 m_configMenu->addAction(dropFrames);
300 void Monitor::slotGoToMarker(QAction *action)
302 int pos = action->data().toInt();
306 void Monitor::slotSetSizeOneToOne()
308 QRect r = QApplication::desktop()->screenGeometry();
309 const int maxWidth = r.width() - 20;
310 const int maxHeight = r.height() - 20;
311 int width = render->renderWidth();
312 int height = render->renderHeight();
313 kDebug() << "// render info: " << width << "x" << height;
314 while (width >= maxWidth || height >= maxHeight) {
316 height = height * 0.8;
318 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
319 videoBox->setFixedSize(width, height);
322 //m_ui.video_frame->setMinimumSize(0, 0);
323 emit adjustMonitorSize();
326 void Monitor::slotSetSizeOneToTwo()
328 QRect r = QApplication::desktop()->screenGeometry();
329 const int maxWidth = r.width() - 20;
330 const int maxHeight = r.height() - 20;
331 int width = render->renderWidth() / 2;
332 int height = render->renderHeight() / 2;
333 kDebug() << "// render info: " << width << "x" << height;
334 while (width >= maxWidth || height >= maxHeight) {
336 height = height * 0.8;
338 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
339 videoBox->setFixedSize(width, height);
342 //m_ui.video_frame->setMinimumSize(0, 0);
343 emit adjustMonitorSize();
346 void Monitor::resetSize()
348 videoBox->setMinimumSize(0, 0);
351 DocClipBase *Monitor::activeClip()
353 return m_currentClip;
356 void Monitor::updateMarkers(DocClipBase *source)
358 if (source == m_currentClip && source != NULL) {
359 m_markerMenu->clear();
360 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
361 if (!markers.isEmpty()) {
363 for (int i = 0; i < markers.count(); i++) {
364 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
366 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
367 QAction *go = m_markerMenu->addAction(position);
371 m_ruler->setMarkers(markers);
372 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
376 void Monitor::slotSeekToPreviousSnap()
378 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
381 void Monitor::slotSeekToNextSnap()
383 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
386 GenTime Monitor::position()
388 return render->seekPosition();
391 GenTime Monitor::getSnapForPos(bool previous)
393 QList <GenTime> snaps;
394 QList < GenTime > markers = m_currentClip->snapMarkers();
395 for (int i = 0; i < markers.size(); ++i) {
396 GenTime t = markers.at(i);
399 QPoint zone = m_ruler->zone();
400 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
401 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
402 snaps.append(GenTime());
403 snaps.append(m_currentClip->duration());
406 const GenTime pos = render->seekPosition();
407 for (int i = 0; i < snaps.size(); ++i) {
408 if (previous && snaps.at(i) >= pos) {
410 return snaps.at(i - 1);
411 } else if (!previous && snaps.at(i) > pos) {
418 void Monitor::slotZoneMoved(int start, int end)
420 m_ruler->setZone(start, end);
421 setClipZone(m_ruler->zone());
425 void Monitor::slotSetZoneStart()
427 m_ruler->setZoneStart();
428 emit zoneUpdated(m_ruler->zone());
429 setClipZone(m_ruler->zone());
433 void Monitor::slotSetZoneEnd()
435 m_ruler->setZoneEnd();
436 emit zoneUpdated(m_ruler->zone());
437 setClipZone(m_ruler->zone());
442 void Monitor::mousePressEvent(QMouseEvent * event)
444 if (event->button() != Qt::RightButton) {
445 if (videoBox->geometry().contains(event->pos()) && (!m_overlay || !m_overlay->underMouse())) {
446 m_dragStarted = true;
447 m_DragStartPosition = event->pos();
449 } else if (m_contextMenu && (!m_effectWidget || !m_effectWidget->isVisible())) {
450 m_contextMenu->popup(event->globalPos());
454 void Monitor::resizeEvent(QResizeEvent *event)
457 if (render && isVisible() && isActive()) render->doRefresh();
460 void Monitor::slotSwitchFullScreen()
462 videoBox->switchFullScreen();
466 void Monitor::mouseReleaseEvent(QMouseEvent * event)
468 if (m_dragStarted && event->button() != Qt::RightButton) {
469 if (videoBox->geometry().contains(event->pos()) && (!m_effectWidget || !m_effectWidget->isVisible())) {
470 if (isActive()) slotPlay();
471 else slotActivateMonitor();
472 } //else event->ignore(); //QWidget::mouseReleaseEvent(event);
474 m_dragStarted = false;
479 void Monitor::mouseMoveEvent(QMouseEvent *event)
481 if (!m_dragStarted || m_currentClip == NULL) return;
483 if ((event->pos() - m_DragStartPosition).manhattanLength()
484 < QApplication::startDragDistance())
488 QDrag *drag = new QDrag(this);
489 QMimeData *mimeData = new QMimeData;
492 list.append(m_currentClip->getId());
493 QPoint p = m_ruler->zone();
494 list.append(QString::number(p.x()));
495 list.append(QString::number(p.y()));
497 data.append(list.join(";").toUtf8());
498 mimeData->setData("kdenlive/clip", data);
499 drag->setMimeData(mimeData);
500 /*QPixmap pix = m_currentClip->thumbnail();
501 drag->setPixmap(pix);
502 drag->setHotSpot(QPoint(0, 50));*/
503 drag->start(Qt::MoveAction);
504 /*Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
505 Qt::DropAction dropAction;
506 dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);*/
508 //Qt::DropAction dropAction = drag->exec();
515 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
516 event->setDropAction(Qt::IgnoreAction);
517 event->setDropAction(Qt::MoveAction);
518 if (event->mimeData()->hasText()) {
519 event->acceptProposedAction();
523 Qt::DropActions Monitor::supportedDropActions() const {
524 // returns what actions are supported when dropping
525 return Qt::MoveAction;
528 QStringList Monitor::mimeTypes() const
530 QStringList qstrList;
531 // list of accepted mime types for drop
532 qstrList.append("kdenlive/clip");
537 void Monitor::wheelEvent(QWheelEvent * event)
539 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
543 void Monitor::mouseDoubleClickEvent(QMouseEvent * event)
545 if (!KdenliveSettings::openglmonitors()) {
546 videoBox->switchFullScreen();
551 void Monitor::slotMouseSeek(int eventDelta, bool fast)
554 int delta = m_monitorManager->timecode().fps();
555 if (eventDelta > 0) delta = 0 - delta;
556 if (render->requestedSeekPosition != SEEK_INACTIVE)
557 slotSeek(render->requestedSeekPosition - delta);
558 else slotSeek(render->seekFramePosition() - delta);
560 if (eventDelta >= 0) slotForwardOneFrame();
561 else slotRewindOneFrame();
565 void Monitor::slotSetThumbFrame()
567 if (m_currentClip == NULL) {
570 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
571 emit refreshClipThumbnail(m_currentClip->getId(), true);
574 void Monitor::slotExtractCurrentZone()
576 if (m_currentClip == NULL) return;
577 emit extractZone(m_currentClip->getId(), m_ruler->zone());
580 void Monitor::slotExtractCurrentFrame()
583 // check if we are using a proxy
584 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
585 // using proxy, use original clip url to get frame
586 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
588 else frame = render->extractFrame(render->seekFramePosition());
589 QPointer<KFileDialog> fs = new KFileDialog(KUrl(), "image/png", this);
590 fs->setOperationMode(KFileDialog::Saving);
591 fs->setMode(KFile::File);
592 fs->setConfirmOverwrite(true);
593 fs->setKeepLocation(true);
596 if (fs) path = fs->selectedFile();
598 if (!path.isEmpty()) {
603 void Monitor::setTimePos(const QString &pos)
605 m_timePos->setValue(pos);
609 void Monitor::slotSeek()
611 slotSeek(m_timePos->getValue());
614 void Monitor::slotSeek(int pos)
616 if (render == NULL) return;
617 slotActivateMonitor();
618 render->seekToFrame(pos);
622 void Monitor::checkOverlay()
624 if (m_overlay == NULL) return;
626 int pos = m_timePos->getValue();//render->seekFramePosition();
627 QPoint zone = m_ruler->zone();
629 overlayText = i18n("In Point");
630 else if (pos == zone.y())
631 overlayText = i18n("Out Point");
634 overlayText = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
635 if (!overlayText.isEmpty()) {
636 m_overlay->setOverlayText(overlayText, false);
641 if (m_overlay->isVisible() && overlayText.isEmpty()) m_overlay->setOverlayText(QString(), false);
642 else m_overlay->setOverlayText(overlayText);
645 void Monitor::slotStart()
647 slotActivateMonitor();
649 render->seekToFrame(0);
652 void Monitor::slotEnd()
654 slotActivateMonitor();
656 render->seekToFrame(render->getLength());
659 void Monitor::slotZoneStart()
661 slotActivateMonitor();
663 render->seekToFrame(m_ruler->zone().x());
666 void Monitor::slotZoneEnd()
668 slotActivateMonitor();
670 render->seekToFrame(m_ruler->zone().y());
673 void Monitor::slotRewind(double speed)
675 slotActivateMonitor();
677 double currentspeed = render->playSpeed();
678 if (currentspeed >= 0) render->play(-1);
679 else switch((int) currentspeed) {
692 } else render->play(speed);
693 //m_playAction->setChecked(true);
694 m_playAction->setIcon(m_pauseIcon);
697 void Monitor::slotForward(double speed)
699 slotActivateMonitor();
701 double currentspeed = render->playSpeed();
702 if (currentspeed <= 0) render->play(1);
703 else switch((int) currentspeed) {
716 } else render->play(speed);
717 //m_playAction->setChecked(true);
718 m_playAction->setIcon(m_pauseIcon);
721 void Monitor::slotRewindOneFrame(int diff)
723 slotActivateMonitor();
725 render->seekToFrameDiff(-diff);
729 void Monitor::slotForwardOneFrame(int diff)
731 slotActivateMonitor();
733 render->seekToFrameDiff(diff);
737 void Monitor::seekCursor(int pos)
739 if (m_ruler->slotNewValue(pos)) {
740 m_timePos->setValue(pos);
745 void Monitor::rendererStopped(int pos)
747 if (m_ruler->slotNewValue(pos)) {
748 m_timePos->setValue(pos);
751 m_playAction->setIcon(m_playIcon);
754 void Monitor::adjustRulerSize(int length)
756 if (length > 0) m_length = length;
757 m_ruler->adjustScale(m_length);
758 if (m_currentClip != NULL) {
759 QPoint zone = m_currentClip->zone();
760 m_ruler->setZone(zone.x(), zone.y());
766 if (render) render->stop();
769 void Monitor::start()
771 if (!isVisible() || !isActive()) return;
772 if (render) render->startConsumer();
775 void Monitor::refreshMonitor(bool visible)
777 if (visible && render) {
778 if (!slotActivateMonitor()) {
779 // the monitor was already active, simply refreshClipThumbnail
785 void Monitor::refreshMonitor()
792 void Monitor::pause()
794 if (render == NULL) return;
795 slotActivateMonitor();
797 //m_playAction->setChecked(true);
798 m_playAction->setIcon(m_playIcon);
801 void Monitor::unpause()
805 void Monitor::slotPlay()
807 if (render == NULL) return;
808 slotActivateMonitor();
809 if (render->isPlaying()) {
810 m_playAction->setIcon(m_playIcon);
811 render->switchPlay(false);
814 m_playAction->setIcon(m_pauseIcon);
815 render->switchPlay(true);
817 m_ruler->refreshRuler();
820 void Monitor::slotPlayZone()
822 if (render == NULL) return;
823 slotActivateMonitor();
824 QPoint p = m_ruler->zone();
825 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
826 //m_playAction->setChecked(true);
827 m_playAction->setIcon(m_pauseIcon);
830 void Monitor::slotLoopZone()
832 if (render == NULL) return;
833 slotActivateMonitor();
834 QPoint p = m_ruler->zone();
835 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
836 //m_playAction->setChecked(true);
837 m_playAction->setIcon(m_pauseIcon);
840 void Monitor::slotLoopClip()
842 if (render == NULL || m_selectedClip == NULL)
844 slotActivateMonitor();
845 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
846 //m_playAction->setChecked(true);
847 m_playAction->setIcon(m_pauseIcon);
850 void Monitor::updateClipProducer(Mlt::Producer *prod)
852 if (render == NULL) return;
853 render->setProducer(prod, render->seekFramePosition());
856 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
858 if (render == NULL) return;
859 if (clip == NULL && m_currentClip != NULL) {
860 m_currentClip->lastSeekPosition = render->seekFramePosition();
861 kDebug()<<"// SETTING NULL CLIP MONITOR";
862 m_currentClip = NULL;
864 render->setProducer(NULL, -1);
868 if (clip != m_currentClip || forceUpdate) {
869 if (m_currentClip) m_currentClip->lastSeekPosition = render->seekFramePosition();
870 m_currentClip = clip;
871 if (position == -1) position = clip->lastSeekPosition;
873 Mlt::Producer *prod = NULL;
874 if (clip) prod = clip->getCloneProducer();
875 if (render->setProducer(prod, position) == -1) {
876 // MLT CONSUMER is broken
877 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
881 slotActivateMonitor();
882 if (position == -1) position = render->seekFramePosition();
883 render->seek(position);
886 if (!zone.isNull()) {
887 m_ruler->setZone(zone.x(), zone.y());
888 render->seek(zone.x());
892 void Monitor::slotOpenFile(const QString &file)
894 if (render == NULL) return;
895 slotActivateMonitor();
897 QDomElement mlt = doc.createElement("mlt");
898 doc.appendChild(mlt);
899 QDomElement prod = doc.createElement("producer");
900 mlt.appendChild(prod);
901 prod.setAttribute("mlt_service", "avformat");
902 prod.setAttribute("resource", file);
903 render->setSceneList(doc, 0);
906 void Monitor::slotSaveZone()
908 if (render == NULL) return;
909 emit saveZone(render, m_ruler->zone(), m_currentClip);
911 //render->setSceneList(doc, 0);
914 void Monitor::resetProfile(const QString &profile)
916 m_timePos->updateTimeCode(m_monitorManager->timecode());
917 if (render == NULL) return;
918 if (!render->hasProfile(profile)) {
919 slotActivateMonitor();
920 render->resetProfile(profile);
923 m_effectWidget->resetProfile(render);
926 void Monitor::saveSceneList(QString path, QDomElement info)
928 if (render == NULL) return;
929 render->saveSceneList(path, info);
932 const QString Monitor::sceneList()
934 if (render == NULL) return QString();
935 return render->sceneList();
938 void Monitor::setClipZone(QPoint pos)
940 if (m_currentClip == NULL) return;
941 m_currentClip->setZone(pos);
944 void Monitor::slotSwitchDropFrames(bool show)
946 render->setDropFrames(show);
949 void Monitor::slotSwitchMonitorInfo(bool show)
951 KdenliveSettings::setDisplayMonitorInfo(show);
953 if (m_overlay) return;
954 if (videoSurface == NULL) {
955 // Using OpenGL display
957 if (m_glWidget->layout()) delete m_glWidget->layout();
958 m_overlay = new Overlay();
959 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
960 QVBoxLayout *layout = new QVBoxLayout;
961 layout->addStretch(10);
962 layout->addWidget(m_overlay);
963 m_glWidget->setLayout(layout);
966 if (videoSurface->layout()) delete videoSurface->layout();
967 m_overlay = new Overlay();
968 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
969 QVBoxLayout *layout = new QVBoxLayout;
970 layout->addStretch(10);
971 layout->addWidget(m_overlay);
972 videoSurface->setLayout(layout);
974 m_overlay->setHidden(true);
983 void Monitor::slotEditMarker()
985 if (m_editMarker) m_editMarker->trigger();
988 void Monitor::updateTimecodeFormat()
990 m_timePos->slotUpdateTimeCodeFormat();
993 QStringList Monitor::getZoneInfo() const
996 if (m_currentClip == NULL) return result;
997 result << m_currentClip->getId();
998 QPoint zone = m_ruler->zone();
999 result << QString::number(zone.x()) << QString::number(zone.y());
1003 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
1006 m_loopClipAction->setEnabled(true);
1007 m_selectedClip = item;
1009 m_loopClipAction->setEnabled(false);
1013 void Monitor::slotSetSelectedClip(ClipItem* item)
1015 if (item || (!item && !m_loopClipTransition)) {
1016 m_loopClipTransition = false;
1017 slotSetSelectedClip((AbstractClipItem*)item);
1021 void Monitor::slotSetSelectedClip(Transition* item)
1023 if (item || (!item && m_loopClipTransition)) {
1024 m_loopClipTransition = true;
1025 slotSetSelectedClip((AbstractClipItem*)item);
1030 void Monitor::slotShowEffectScene(bool show, bool manuallyTriggered)
1032 if (m_id == Kdenlive::projectMonitor) {
1033 if (!m_effectWidget->getVisibilityAction()->isChecked())
1035 if (m_effectWidget->isVisible() == show)
1037 setUpdatesEnabled(false);
1040 videoSurface->setVisible(false);
1041 // Preview is handeled internally through the Render::showFrame method
1042 render->disablePreview(true);
1045 m_glWidget->setVisible(false);
1048 m_effectWidget->setVisible(true);
1049 m_effectWidget->getScene()->slotZoomFit();
1050 emit requestFrameForAnalysis(true);
1052 m_effectWidget->setVisible(false);
1053 emit requestFrameForAnalysis(false);
1055 videoSurface->setVisible(true);
1056 // Preview is handeled internally through the Render::showFrame method
1057 render->disablePreview(false);
1061 m_glWidget->setVisible(true);
1065 if (!manuallyTriggered)
1066 m_effectWidget->showVisibilityButton(show);
1067 setUpdatesEnabled(true);
1068 videoBox->setEnabled(show);
1069 //render->doRefresh();
1073 MonitorEditWidget* Monitor::getEffectEdit()
1075 return m_effectWidget;
1078 bool Monitor::effectSceneDisplayed()
1080 return m_effectWidget->isVisible();
1083 void Monitor::slotSetVolume(int volume)
1085 KdenliveSettings::setVolume(volume);
1087 if (volume == 0) icon = KIcon("audio-volume-muted");
1088 else icon = KIcon("audio-volume-medium");
1089 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1090 render->slotSetVolume(volume);
1093 void Monitor::slotShowVolume()
1095 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1096 int vol = render->volume();
1097 // Disable widget if we cannot get the volume
1098 m_volumePopup->setEnabled(vol != -1);
1099 m_audioSlider->blockSignals(true);
1100 m_audioSlider->setValue(vol);
1101 m_audioSlider->blockSignals(false);
1102 m_volumePopup->show();
1105 AbstractRender *Monitor::abstractRender()
1110 void Monitor::reloadProducer(const QString &id)
1112 if (!m_currentClip) return;
1113 if (m_currentClip->getId() == id)
1114 slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
1117 void Monitor::setPalette ( const QPalette & p)
1119 QWidget::setPalette(p);
1120 if (m_ruler) m_ruler->updatePalette();
1124 Overlay::Overlay(QWidget* parent) :
1127 //setAttribute(Qt::WA_TransparentForMouseEvents);
1128 setAutoFillBackground(true);
1129 setBackgroundRole(QPalette::Base);
1130 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1131 setCursor(Qt::PointingHandCursor);
1136 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1142 void Overlay::mousePressEvent( QMouseEvent * event )
1148 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1154 void Overlay::setOverlayText(const QString &text, bool isZone)
1156 if (text.isEmpty()) {
1158 p.setColor(QPalette::Base, KdenliveSettings::window_background());
1167 p.setColor(QPalette::Text, Qt::white);
1168 if (isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1169 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1171 setText(' ' + text + ' ');
1176 #include "monitor.moc"