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 m_toolbar->addAction(m_effectWidget->getVisibilityAction());
191 videoBox->layout()->addWidget(m_effectWidget);
192 m_effectWidget->hide();
195 QWidget *spacer = new QWidget(this);
196 spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
197 m_toolbar->addWidget(spacer);
198 m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this);
199 m_toolbar->addWidget(m_timePos);
200 connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotSeek()));
201 m_toolbar->setMaximumHeight(s * 1.5);
202 layout->addWidget(m_toolbar);
211 delete m_effectWidget;
215 QWidget *Monitor::container()
221 bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile)
223 render = new Render(id(), 0, profile, this);
224 m_glWidget = new VideoGLWidget(parent);
225 if (m_glWidget == NULL) {
226 // Creation failed, we are in trouble...
229 m_glWidget->setImageAspectRatio(render->dar());
230 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
231 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
236 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
238 m_contextMenu = new QMenu(this);
239 m_contextMenu->addMenu(m_playMenu);
241 m_contextMenu->addMenu(goMenu);
243 m_contextMenu->addMenu(markerMenu);
244 QList <QAction *>list = markerMenu->actions();
245 for (int i = 0; i < list.count(); i++) {
246 if (list.at(i)->data().toString() == "edit_marker") {
247 m_editMarker = list.at(i);
253 m_playMenu->addAction(playZone);
254 m_playMenu->addAction(loopZone);
256 m_loopClipAction = loopClip;
257 m_playMenu->addAction(loopClip);
260 //TODO: add save zone to timeline monitor when fixed
261 if (m_id == Kdenlive::clipMonitor) {
262 m_contextMenu->addMenu(m_markerMenu);
263 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
264 QAction *extractZone = m_configMenu->addAction(KIcon("document-new"), i18n("Extract Zone"), this, SLOT(slotExtractCurrentZone()));
265 m_contextMenu->addAction(extractZone);
267 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
268 m_contextMenu->addAction(extractFrame);
270 if (m_id != Kdenlive::clipMonitor) {
271 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
272 splitView->setCheckable(true);
273 m_configMenu->addAction(splitView);
275 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
276 m_configMenu->addAction(setThumbFrame);
279 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
280 showTips->setCheckable(true);
281 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
282 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
284 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
285 dropFrames->setCheckable(true);
286 dropFrames->setChecked(true);
287 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
289 m_configMenu->addAction(showTips);
290 m_configMenu->addAction(dropFrames);
294 void Monitor::slotGoToMarker(QAction *action)
296 int pos = action->data().toInt();
300 void Monitor::slotSetSizeOneToOne()
302 QRect r = QApplication::desktop()->screenGeometry();
303 const int maxWidth = r.width() - 20;
304 const int maxHeight = r.height() - 20;
305 int width = render->renderWidth();
306 int height = render->renderHeight();
307 kDebug() << "// render info: " << width << "x" << height;
308 while (width >= maxWidth || height >= maxHeight) {
310 height = height * 0.8;
312 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
313 videoBox->setFixedSize(width, height);
316 //m_ui.video_frame->setMinimumSize(0, 0);
317 emit adjustMonitorSize();
320 void Monitor::slotSetSizeOneToTwo()
322 QRect r = QApplication::desktop()->screenGeometry();
323 const int maxWidth = r.width() - 20;
324 const int maxHeight = r.height() - 20;
325 int width = render->renderWidth() / 2;
326 int height = render->renderHeight() / 2;
327 kDebug() << "// render info: " << width << "x" << height;
328 while (width >= maxWidth || height >= maxHeight) {
330 height = height * 0.8;
332 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
333 videoBox->setFixedSize(width, height);
336 //m_ui.video_frame->setMinimumSize(0, 0);
337 emit adjustMonitorSize();
340 void Monitor::resetSize()
342 videoBox->setMinimumSize(0, 0);
345 DocClipBase *Monitor::activeClip()
347 return m_currentClip;
350 void Monitor::updateMarkers(DocClipBase *source)
352 if (source == m_currentClip && source != NULL) {
353 m_markerMenu->clear();
354 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
355 if (!markers.isEmpty()) {
357 for (int i = 0; i < markers.count(); i++) {
358 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
360 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
361 QAction *go = m_markerMenu->addAction(position);
364 m_ruler->setMarkers(marks);
365 } else m_ruler->setMarkers(QList <int>());
366 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
370 void Monitor::slotSeekToPreviousSnap()
372 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
375 void Monitor::slotSeekToNextSnap()
377 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
380 GenTime Monitor::position()
382 return render->seekPosition();
385 GenTime Monitor::getSnapForPos(bool previous)
387 QList <GenTime> snaps;
388 QList < GenTime > markers = m_currentClip->snapMarkers();
389 for (int i = 0; i < markers.size(); ++i) {
390 GenTime t = markers.at(i);
393 QPoint zone = m_ruler->zone();
394 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
395 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
396 snaps.append(GenTime());
397 snaps.append(m_currentClip->duration());
400 const GenTime pos = render->seekPosition();
401 for (int i = 0; i < snaps.size(); ++i) {
402 if (previous && snaps.at(i) >= pos) {
404 return snaps.at(i - 1);
405 } else if (!previous && snaps.at(i) > pos) {
412 void Monitor::slotZoneMoved(int start, int end)
414 m_ruler->setZone(start, end);
416 setClipZone(m_ruler->zone());
419 void Monitor::slotSetZoneStart()
421 m_ruler->setZone(m_ruler->position(), -1);
422 emit zoneUpdated(m_ruler->zone());
424 setClipZone(m_ruler->zone());
427 void Monitor::slotSetZoneEnd()
429 m_ruler->setZone(-1, m_ruler->position());
430 emit zoneUpdated(m_ruler->zone());
432 setClipZone(m_ruler->zone());
436 void Monitor::mousePressEvent(QMouseEvent * event)
438 if (event->button() != Qt::RightButton) {
439 if (videoBox->geometry().contains(event->pos()) && (!m_overlay || !m_overlay->underMouse())) {
440 m_dragStarted = true;
441 m_DragStartPosition = event->pos();
443 } else if (m_contextMenu && (!m_effectWidget || !m_effectWidget->isVisible())) {
444 m_contextMenu->popup(event->globalPos());
448 void Monitor::resizeEvent(QResizeEvent *event)
451 if (render && isVisible() && isActive()) render->doRefresh();
454 void Monitor::slotSwitchFullScreen()
456 videoBox->switchFullScreen();
460 void Monitor::mouseReleaseEvent(QMouseEvent * event)
462 if (m_dragStarted && event->button() != Qt::RightButton) {
463 if (videoBox->geometry().contains(event->pos()) && (!m_effectWidget || !m_effectWidget->isVisible())) {
464 if (isActive()) slotPlay();
465 else slotActivateMonitor();
466 } //else event->ignore(); //QWidget::mouseReleaseEvent(event);
467 m_dragStarted = false;
472 void Monitor::mouseMoveEvent(QMouseEvent *event)
474 if (!m_dragStarted || m_currentClip == NULL) return;
476 if ((event->pos() - m_DragStartPosition).manhattanLength()
477 < QApplication::startDragDistance())
481 QDrag *drag = new QDrag(this);
482 QMimeData *mimeData = new QMimeData;
485 list.append(m_currentClip->getId());
486 QPoint p = m_ruler->zone();
487 list.append(QString::number(p.x()));
488 list.append(QString::number(p.y()));
490 data.append(list.join(";").toUtf8());
491 mimeData->setData("kdenlive/clip", data);
492 drag->setMimeData(mimeData);
493 /*QPixmap pix = m_currentClip->thumbnail();
494 drag->setPixmap(pix);
495 drag->setHotSpot(QPoint(0, 50));*/
496 drag->start(Qt::MoveAction);
498 //Qt::DropAction dropAction;
499 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
501 //Qt::DropAction dropAction = drag->exec();
507 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
508 event->setDropAction(Qt::IgnoreAction);
509 event->setDropAction(Qt::MoveAction);
510 if (event->mimeData()->hasText()) {
511 event->acceptProposedAction();
515 Qt::DropActions Monitor::supportedDropActions() const {
516 // returns what actions are supported when dropping
517 return Qt::MoveAction;
520 QStringList Monitor::mimeTypes() const
522 QStringList qstrList;
523 // list of accepted mime types for drop
524 qstrList.append("kdenlive/clip");
529 void Monitor::wheelEvent(QWheelEvent * event)
531 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
535 void Monitor::mouseDoubleClickEvent(QMouseEvent * event)
537 if (!KdenliveSettings::openglmonitors()) {
538 videoBox->switchFullScreen();
543 void Monitor::slotMouseSeek(int eventDelta, bool fast)
546 int delta = m_monitorManager->timecode().fps();
547 if (eventDelta > 0) delta = 0 - delta;
548 slotSeek(m_ruler->position() - delta);
550 if (eventDelta >= 0) slotForwardOneFrame();
551 else slotRewindOneFrame();
555 void Monitor::slotSetThumbFrame()
557 if (m_currentClip == NULL) {
560 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
561 emit refreshClipThumbnail(m_currentClip->getId(), true);
564 void Monitor::slotExtractCurrentZone()
566 if (m_currentClip == NULL) return;
567 emit extractZone(m_currentClip->getId(), m_ruler->zone());
570 void Monitor::slotExtractCurrentFrame()
573 // check if we are using a proxy
574 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
575 // using proxy, use original clip url to get frame
576 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
578 else frame = render->extractFrame(render->seekFramePosition());
579 KFileDialog *fs = new KFileDialog(KUrl(), "image/png", this);
580 fs->setOperationMode(KFileDialog::Saving);
581 fs->setMode(KFile::File);
582 fs->setConfirmOverwrite(true);
583 fs->setKeepLocation(true);
585 QString path = fs->selectedFile();
587 if (!path.isEmpty()) {
592 void Monitor::setTimePos(const QString &pos)
594 m_timePos->setValue(pos);
598 void Monitor::slotSeek()
600 slotSeek(m_timePos->getValue());
603 void Monitor::slotSeek(int pos)
605 if (render == NULL) return;
606 slotActivateMonitor();
607 render->seekToFrame(pos);
610 void Monitor::checkOverlay()
612 if (m_overlay == NULL) return;
614 int pos = m_ruler->position();
615 QPoint zone = m_ruler->zone();
617 overlayText = i18n("In Point");
618 else if (pos == zone.y())
619 overlayText = i18n("Out Point");
622 overlayText = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
623 if (!overlayText.isEmpty()) {
624 m_overlay->setOverlayText(overlayText, false);
629 if (m_overlay->isVisible() && overlayText.isEmpty()) m_overlay->setOverlayText(QString(), false);
630 else m_overlay->setOverlayText(overlayText);
633 void Monitor::slotStart()
635 slotActivateMonitor();
637 render->seekToFrame(0);
640 void Monitor::slotEnd()
642 slotActivateMonitor();
644 render->seekToFrame(render->getLength());
647 void Monitor::slotZoneStart()
649 slotActivateMonitor();
651 render->seekToFrame(m_ruler->zone().x());
654 void Monitor::slotZoneEnd()
656 slotActivateMonitor();
658 render->seekToFrame(m_ruler->zone().y());
661 void Monitor::slotRewind(double speed)
663 slotActivateMonitor();
665 double currentspeed = render->playSpeed();
666 if (currentspeed >= 0) render->play(-2);
667 else render->play(currentspeed * 2);
668 } else render->play(speed);
669 //m_playAction->setChecked(true);
670 m_playAction->setIcon(m_pauseIcon);
673 void Monitor::slotForward(double speed)
675 slotActivateMonitor();
677 double currentspeed = render->playSpeed();
678 if (currentspeed <= 1) render->play(2);
679 else render->play(currentspeed * 2);
680 } else render->play(speed);
681 //m_playAction->setChecked(true);
682 m_playAction->setIcon(m_pauseIcon);
685 void Monitor::slotRewindOneFrame(int diff)
687 slotActivateMonitor();
689 render->seekToFrameDiff(-diff);
692 void Monitor::slotForwardOneFrame(int diff)
694 slotActivateMonitor();
696 render->seekToFrameDiff(diff);
699 void Monitor::seekCursor(int pos)
701 //slotActivateMonitor();
702 if (m_ruler->slotNewValue(pos)) {
704 m_timePos->setValue(pos);
708 void Monitor::rendererStopped(int pos)
710 if (m_ruler->slotNewValue(pos)) {
712 m_timePos->setValue(pos);
714 m_playAction->setIcon(m_playIcon);
717 void Monitor::adjustRulerSize(int length)
719 if (length > 0) m_length = length;
720 m_ruler->adjustScale(m_length);
721 if (m_currentClip != NULL) {
722 QPoint zone = m_currentClip->zone();
723 m_ruler->setZone(zone.x(), zone.y());
729 if (render) render->stop();
732 void Monitor::start()
734 if (!isVisible() || !isActive()) return;
735 if (render) render->doRefresh();// start();
738 void Monitor::refreshMonitor(bool visible)
740 if (visible && render) {
741 if (!slotActivateMonitor()) {
742 // the monitor was already active, simply refreshClipThumbnail
748 void Monitor::refreshMonitor()
755 void Monitor::pause()
757 if (render == NULL) return;
758 slotActivateMonitor();
760 //m_playAction->setChecked(true);
761 m_playAction->setIcon(m_playIcon);
764 void Monitor::unpause()
768 void Monitor::slotPlay()
770 if (render == NULL) return;
771 slotActivateMonitor();
772 if (render->playSpeed() == 0.0) {
773 m_playAction->setIcon(m_pauseIcon);
774 render->switchPlay(true);
776 m_playAction->setIcon(m_playIcon);
777 render->switchPlay(false);
781 void Monitor::slotPlayZone()
783 if (render == NULL) return;
784 slotActivateMonitor();
785 QPoint p = m_ruler->zone();
786 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
787 //m_playAction->setChecked(true);
788 m_playAction->setIcon(m_pauseIcon);
791 void Monitor::slotLoopZone()
793 if (render == NULL) return;
794 slotActivateMonitor();
795 QPoint p = m_ruler->zone();
796 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
797 //m_playAction->setChecked(true);
798 m_playAction->setIcon(m_pauseIcon);
801 void Monitor::slotLoopClip()
803 if (render == NULL || m_selectedClip == NULL)
805 slotActivateMonitor();
806 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
807 //m_playAction->setChecked(true);
808 m_playAction->setIcon(m_pauseIcon);
811 void Monitor::updateClipProducer(Mlt::Producer *prod)
813 if (render == NULL) return;
814 render->setProducer(prod, render->seekFramePosition());
817 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
819 if (render == NULL) return;
820 if (clip == NULL && m_currentClip != NULL) {
821 kDebug()<<"// SETTING NULL CLIP MONITOR";
822 m_currentClip = NULL;
824 render->setProducer(NULL, -1);
828 if (clip != m_currentClip || forceUpdate) {
829 m_currentClip = clip;
830 if (m_currentClip) slotActivateMonitor();
832 Mlt::Producer *prod = NULL;
833 if (clip) prod = clip->getCloneProducer();
834 if (render->setProducer(prod, position) == -1) {
835 // MLT CONSUMER is broken
836 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
840 slotActivateMonitor();
841 if (position == -1) position = render->seekFramePosition();
842 render->seek(position);
845 if (!zone.isNull()) {
846 m_ruler->setZone(zone.x(), zone.y());
847 render->seek(zone.x());
851 void Monitor::slotOpenFile(const QString &file)
853 if (render == NULL) return;
854 slotActivateMonitor();
856 QDomElement mlt = doc.createElement("mlt");
857 doc.appendChild(mlt);
858 QDomElement prod = doc.createElement("producer");
859 mlt.appendChild(prod);
860 prod.setAttribute("mlt_service", "avformat");
861 prod.setAttribute("resource", file);
862 render->setSceneList(doc, 0);
865 void Monitor::slotSaveZone()
867 if (render == NULL) return;
868 emit saveZone(render, m_ruler->zone(), m_currentClip);
870 //render->setSceneList(doc, 0);
873 void Monitor::resetProfile(const QString &profile)
875 m_timePos->updateTimeCode(m_monitorManager->timecode());
876 if (render == NULL) return;
877 if (!render->hasProfile(profile)) {
878 slotActivateMonitor();
879 render->resetProfile(profile);
882 m_effectWidget->resetProfile(render);
885 void Monitor::saveSceneList(QString path, QDomElement info)
887 if (render == NULL) return;
888 render->saveSceneList(path, info);
891 const QString Monitor::sceneList()
893 if (render == NULL) return QString();
894 return render->sceneList();
897 void Monitor::setClipZone(QPoint pos)
899 if (m_currentClip == NULL) return;
900 m_currentClip->setZone(pos);
903 void Monitor::slotSwitchDropFrames(bool show)
905 render->setDropFrames(show);
908 void Monitor::slotSwitchMonitorInfo(bool show)
910 KdenliveSettings::setDisplayMonitorInfo(show);
912 if (m_overlay) return;
913 if (videoSurface == NULL) {
914 // Using OpenGL display
916 if (m_glWidget->layout()) delete m_glWidget->layout();
917 m_overlay = new Overlay();
918 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
919 QVBoxLayout *layout = new QVBoxLayout;
920 layout->addStretch(10);
921 layout->addWidget(m_overlay);
922 m_glWidget->setLayout(layout);
925 if (videoSurface->layout()) delete videoSurface->layout();
926 m_overlay = new Overlay();
927 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
928 QVBoxLayout *layout = new QVBoxLayout;
929 layout->addStretch(10);
930 layout->addWidget(m_overlay);
931 videoSurface->setLayout(layout);
933 m_overlay->setHidden(true);
942 void Monitor::slotEditMarker()
944 if (m_editMarker) m_editMarker->trigger();
947 void Monitor::updateTimecodeFormat()
949 m_timePos->slotUpdateTimeCodeFormat();
952 QStringList Monitor::getZoneInfo() const
955 if (m_currentClip == NULL) return result;
956 result << m_currentClip->getId();
957 QPoint zone = m_ruler->zone();
958 result << QString::number(zone.x()) << QString::number(zone.y());
962 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
965 m_loopClipAction->setEnabled(true);
966 m_selectedClip = item;
968 m_loopClipAction->setEnabled(false);
972 void Monitor::slotSetSelectedClip(ClipItem* item)
974 if (item || (!item && !m_loopClipTransition)) {
975 m_loopClipTransition = false;
976 slotSetSelectedClip((AbstractClipItem*)item);
980 void Monitor::slotSetSelectedClip(Transition* item)
982 if (item || (!item && m_loopClipTransition)) {
983 m_loopClipTransition = true;
984 slotSetSelectedClip((AbstractClipItem*)item);
989 void Monitor::slotShowEffectScene(bool show)
991 if (m_id == Kdenlive::projectMonitor) {
992 if (m_effectWidget->isVisible() == show) return;
994 videoSurface->setVisible(!show);
997 m_glWidget->setVisible(!show);
1000 m_effectWidget->setVisible(show);
1001 m_effectWidget->getVisibilityAction()->setChecked(show);
1002 emit requestFrameForAnalysis(show);
1004 m_effectWidget->getScene()->slotZoomFit();
1006 videoBox->setEnabled(show);
1007 render->doRefresh();
1011 MonitorEditWidget* Monitor::getEffectEdit()
1013 return m_effectWidget;
1016 bool Monitor::effectSceneDisplayed()
1018 return m_effectWidget->isVisible();
1021 void Monitor::slotSetVolume(int volume)
1023 KdenliveSettings::setVolume(volume);
1025 if (volume == 0) icon = KIcon("audio-volume-muted");
1026 else icon = KIcon("audio-volume-medium");
1027 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1028 render->slotSetVolume(volume);
1031 void Monitor::slotShowVolume()
1033 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1034 int vol = render->volume();
1035 // Disable widget if we cannot get the volume
1036 m_volumePopup->setEnabled(vol != -1);
1037 m_audioSlider->blockSignals(true);
1038 m_audioSlider->setValue(vol);
1039 m_audioSlider->blockSignals(false);
1040 m_volumePopup->show();
1043 AbstractRender *Monitor::abstractRender()
1048 void Monitor::reloadProducer(const QString &id)
1050 if (!m_currentClip) return;
1051 if (m_currentClip->getId() == id)
1052 slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
1055 void Monitor::setPalette ( const QPalette & p)
1057 QWidget::setPalette(p);
1058 if (m_ruler) m_ruler->updatePalette();
1062 Overlay::Overlay(QWidget* parent) :
1065 //setAttribute(Qt::WA_TransparentForMouseEvents);
1066 setAutoFillBackground(true);
1067 setBackgroundRole(QPalette::Base);
1068 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1069 setCursor(Qt::PointingHandCursor);
1073 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1079 void Overlay::mousePressEvent( QMouseEvent * event )
1085 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1091 void Overlay::setOverlayText(const QString &text, bool isZone)
1093 if (text.isEmpty()) {
1095 p.setColor(QPalette::Base, KdenliveSettings::window_background());
1104 p.setColor(QPalette::Text, Qt::white);
1105 if (isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1106 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1108 setText(' ' + text + ' ');
1113 #include "monitor.moc"