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(m_monitorManager, 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(s * 1.5);
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 DocClipBase *Monitor::activeClip()
355 return m_currentClip;
358 void Monitor::updateMarkers(DocClipBase *source)
360 if (source == m_currentClip && source != NULL) {
361 m_markerMenu->clear();
362 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
363 if (!markers.isEmpty()) {
365 for (int i = 0; i < markers.count(); i++) {
366 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
368 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
369 QAction *go = m_markerMenu->addAction(position);
373 m_ruler->setMarkers(markers);
374 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
378 void Monitor::slotSeekToPreviousSnap()
380 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
383 void Monitor::slotSeekToNextSnap()
385 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
388 GenTime Monitor::position()
390 return render->seekPosition();
393 GenTime Monitor::getSnapForPos(bool previous)
395 QList <GenTime> snaps;
396 QList < GenTime > markers = m_currentClip->snapMarkers();
397 for (int i = 0; i < markers.size(); ++i) {
398 GenTime t = markers.at(i);
401 QPoint zone = m_ruler->zone();
402 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
403 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
404 snaps.append(GenTime());
405 snaps.append(m_currentClip->duration());
408 const GenTime pos = render->seekPosition();
409 for (int i = 0; i < snaps.size(); ++i) {
410 if (previous && snaps.at(i) >= pos) {
412 return snaps.at(i - 1);
413 } else if (!previous && snaps.at(i) > pos) {
420 void Monitor::slotZoneMoved(int start, int end)
422 m_ruler->setZone(start, end);
423 setClipZone(m_ruler->zone());
427 void Monitor::slotSetZoneStart()
429 m_ruler->setZoneStart();
430 emit zoneUpdated(m_ruler->zone());
431 setClipZone(m_ruler->zone());
435 void Monitor::slotSetZoneEnd()
437 m_ruler->setZoneEnd();
438 emit zoneUpdated(m_ruler->zone());
439 setClipZone(m_ruler->zone());
444 void Monitor::mousePressEvent(QMouseEvent * event)
446 if (event->button() != Qt::RightButton) {
447 if (videoBox->geometry().contains(event->pos()) && (!m_overlay || !m_overlay->underMouse())) {
448 m_dragStarted = true;
449 m_DragStartPosition = event->pos();
451 } else if (m_contextMenu && (!m_effectWidget || !m_effectWidget->isVisible())) {
452 m_contextMenu->popup(event->globalPos());
456 void Monitor::resizeEvent(QResizeEvent *event)
459 if (render && isVisible() && isActive()) render->doRefresh();
462 void Monitor::slotSwitchFullScreen()
464 videoBox->switchFullScreen();
468 void Monitor::mouseReleaseEvent(QMouseEvent * event)
470 if (m_dragStarted && event->button() != Qt::RightButton) {
471 if (videoBox->geometry().contains(event->pos()) && (!m_effectWidget || !m_effectWidget->isVisible())) {
472 if (isActive()) slotPlay();
473 else slotActivateMonitor();
474 } //else event->ignore(); //QWidget::mouseReleaseEvent(event);
476 m_dragStarted = false;
481 void Monitor::mouseMoveEvent(QMouseEvent *event)
483 if (!m_dragStarted || m_currentClip == NULL) return;
485 if ((event->pos() - m_DragStartPosition).manhattanLength()
486 < QApplication::startDragDistance())
490 QDrag *drag = new QDrag(this);
491 QMimeData *mimeData = new QMimeData;
494 list.append(m_currentClip->getId());
495 QPoint p = m_ruler->zone();
496 list.append(QString::number(p.x()));
497 list.append(QString::number(p.y()));
499 data.append(list.join(";").toUtf8());
500 mimeData->setData("kdenlive/clip", data);
501 drag->setMimeData(mimeData);
502 /*QPixmap pix = m_currentClip->thumbnail();
503 drag->setPixmap(pix);
504 drag->setHotSpot(QPoint(0, 50));*/
505 drag->start(Qt::MoveAction);
506 /*Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
507 Qt::DropAction dropAction;
508 dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);*/
510 //Qt::DropAction dropAction = drag->exec();
517 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
518 event->setDropAction(Qt::IgnoreAction);
519 event->setDropAction(Qt::MoveAction);
520 if (event->mimeData()->hasText()) {
521 event->acceptProposedAction();
525 Qt::DropActions Monitor::supportedDropActions() const {
526 // returns what actions are supported when dropping
527 return Qt::MoveAction;
530 QStringList Monitor::mimeTypes() const
532 QStringList qstrList;
533 // list of accepted mime types for drop
534 qstrList.append("kdenlive/clip");
539 void Monitor::wheelEvent(QWheelEvent * event)
541 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
545 void Monitor::mouseDoubleClickEvent(QMouseEvent * event)
547 if (!KdenliveSettings::openglmonitors()) {
548 videoBox->switchFullScreen();
553 void Monitor::slotMouseSeek(int eventDelta, bool fast)
556 int delta = m_monitorManager->timecode().fps();
557 if (eventDelta > 0) delta = 0 - delta;
558 if (render->requestedSeekPosition != SEEK_INACTIVE)
559 slotSeek(render->requestedSeekPosition - delta);
560 else slotSeek(render->seekFramePosition() - delta);
562 if (eventDelta >= 0) slotForwardOneFrame();
563 else slotRewindOneFrame();
567 void Monitor::slotSetThumbFrame()
569 if (m_currentClip == NULL) {
572 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
573 emit refreshClipThumbnail(m_currentClip->getId(), true);
576 void Monitor::slotExtractCurrentZone()
578 if (m_currentClip == NULL) return;
579 emit extractZone(m_currentClip->getId(), m_ruler->zone());
582 void Monitor::slotExtractCurrentFrame()
585 // check if we are using a proxy
586 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
587 // using proxy, use original clip url to get frame
588 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
590 else frame = render->extractFrame(render->seekFramePosition());
591 QPointer<KFileDialog> fs = new KFileDialog(KUrl(), "image/png", this);
592 fs->setOperationMode(KFileDialog::Saving);
593 fs->setMode(KFile::File);
594 fs->setConfirmOverwrite(true);
595 fs->setKeepLocation(true);
598 if (fs) path = fs->selectedFile();
600 if (!path.isEmpty()) {
605 void Monitor::setTimePos(const QString &pos)
607 m_timePos->setValue(pos);
611 void Monitor::slotSeek()
613 slotSeek(m_timePos->getValue());
616 void Monitor::slotSeek(int pos)
618 if (render == NULL) return;
619 slotActivateMonitor();
620 render->seekToFrame(pos);
624 void Monitor::checkOverlay()
626 if (m_overlay == NULL) return;
628 int pos = m_timePos->getValue();//render->seekFramePosition();
629 QPoint zone = m_ruler->zone();
631 overlayText = i18n("In Point");
632 else if (pos == zone.y())
633 overlayText = i18n("Out Point");
636 overlayText = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
637 if (!overlayText.isEmpty()) {
638 m_overlay->setOverlayText(overlayText, false);
643 if (m_overlay->isVisible() && overlayText.isEmpty()) m_overlay->setOverlayText(QString(), false);
644 else m_overlay->setOverlayText(overlayText);
647 void Monitor::slotStart()
649 slotActivateMonitor();
651 render->seekToFrame(0);
654 void Monitor::slotEnd()
656 slotActivateMonitor();
658 render->seekToFrame(render->getLength());
661 void Monitor::slotZoneStart()
663 slotActivateMonitor();
665 render->seekToFrame(m_ruler->zone().x());
668 void Monitor::slotZoneEnd()
670 slotActivateMonitor();
672 render->seekToFrame(m_ruler->zone().y());
675 void Monitor::slotRewind(double speed)
677 slotActivateMonitor();
679 double currentspeed = render->playSpeed();
680 if (currentspeed >= 0) render->play(-1);
681 else switch((int) currentspeed) {
694 } else render->play(speed);
695 //m_playAction->setChecked(true);
696 m_playAction->setIcon(m_pauseIcon);
699 void Monitor::slotForward(double speed)
701 slotActivateMonitor();
703 double currentspeed = render->playSpeed();
704 if (currentspeed <= 0) render->play(1);
705 else switch((int) currentspeed) {
718 } else render->play(speed);
719 //m_playAction->setChecked(true);
720 m_playAction->setIcon(m_pauseIcon);
723 void Monitor::slotRewindOneFrame(int diff)
725 slotActivateMonitor();
727 render->seekToFrameDiff(-diff);
731 void Monitor::slotForwardOneFrame(int diff)
733 slotActivateMonitor();
735 render->seekToFrameDiff(diff);
739 void Monitor::seekCursor(int pos)
741 if (m_ruler->slotNewValue(pos)) {
742 m_timePos->setValue(pos);
747 void Monitor::rendererStopped(int pos)
749 if (m_ruler->slotNewValue(pos)) {
750 m_timePos->setValue(pos);
753 m_playAction->setIcon(m_playIcon);
756 void Monitor::adjustRulerSize(int length)
758 if (length > 0) m_length = length;
759 m_ruler->adjustScale(m_length);
760 if (m_currentClip != NULL) {
761 QPoint zone = m_currentClip->zone();
762 m_ruler->setZone(zone.x(), zone.y());
768 if (render) render->stop();
771 void Monitor::start()
773 if (!isVisible() || !isActive()) return;
775 if (m_glWidget) m_glWidget->activateMonitor();
777 if (render) render->startConsumer();
780 void Monitor::refreshMonitor(bool visible)
782 if (visible && render) {
783 if (!slotActivateMonitor()) {
784 // the monitor was already active, simply refreshClipThumbnail
790 void Monitor::refreshMonitor()
797 void Monitor::pause()
799 if (render == NULL) return;
800 slotActivateMonitor();
802 //m_playAction->setChecked(true);
803 m_playAction->setIcon(m_playIcon);
806 void Monitor::unpause()
810 void Monitor::slotPlay()
812 if (render == NULL) return;
813 slotActivateMonitor();
814 if (render->isPlaying()) {
815 m_playAction->setIcon(m_playIcon);
816 render->switchPlay(false);
819 m_playAction->setIcon(m_pauseIcon);
820 render->switchPlay(true);
822 m_ruler->refreshRuler();
825 void Monitor::slotPlayZone()
827 if (render == NULL) return;
828 slotActivateMonitor();
829 QPoint p = m_ruler->zone();
830 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
831 //m_playAction->setChecked(true);
832 m_playAction->setIcon(m_pauseIcon);
835 void Monitor::slotLoopZone()
837 if (render == NULL) return;
838 slotActivateMonitor();
839 QPoint p = m_ruler->zone();
840 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
841 //m_playAction->setChecked(true);
842 m_playAction->setIcon(m_pauseIcon);
845 void Monitor::slotLoopClip()
847 if (render == NULL || m_selectedClip == NULL)
849 slotActivateMonitor();
850 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
851 //m_playAction->setChecked(true);
852 m_playAction->setIcon(m_pauseIcon);
855 void Monitor::updateClipProducer(Mlt::Producer *prod)
857 if (render == NULL) return;
858 render->setProducer(prod, render->seekFramePosition());
861 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
863 if (render == NULL) return;
864 if (clip == NULL && m_currentClip != NULL) {
865 m_currentClip->lastSeekPosition = render->seekFramePosition();
866 kDebug()<<"// SETTING NULL CLIP MONITOR";
867 m_currentClip = NULL;
869 render->setProducer(NULL, -1);
873 if (clip != m_currentClip || forceUpdate) {
874 if (m_currentClip) m_currentClip->lastSeekPosition = render->seekFramePosition();
875 m_currentClip = clip;
876 if (position == -1) position = clip->lastSeekPosition;
878 Mlt::Producer *prod = NULL;
879 if (clip) prod = clip->getCloneProducer();
880 if (render->setProducer(prod, position) == -1) {
881 // MLT CONSUMER is broken
882 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
886 slotActivateMonitor();
887 if (position == -1) position = render->seekFramePosition();
888 render->seek(position);
891 if (!zone.isNull()) {
892 m_ruler->setZone(zone.x(), zone.y());
893 render->seek(zone.x());
897 void Monitor::slotOpenFile(const QString &file)
899 if (render == NULL) return;
900 slotActivateMonitor();
901 render->loadUrl(file);
904 void Monitor::slotSaveZone()
906 if (render == NULL) return;
907 emit saveZone(render, m_ruler->zone(), m_currentClip);
909 //render->setSceneList(doc, 0);
912 void Monitor::setCustomProfile(const QString &profile, Timecode tc)
914 m_timePos->updateTimeCode(tc);
915 if (render == NULL) return;
916 if (!render->hasProfile(profile)) {
917 slotActivateMonitor();
918 render->resetProfile(profile);
920 if (m_glWidget) m_glWidget->setImageAspectRatio(render->dar());
925 void Monitor::resetProfile(const QString &profile)
927 m_timePos->updateTimeCode(m_monitorManager->timecode());
928 if (render == NULL) return;
929 if (!render->hasProfile(profile)) {
930 slotActivateMonitor();
931 render->resetProfile(profile);
933 if (m_glWidget) m_glWidget->setImageAspectRatio(render->dar());
937 m_effectWidget->resetProfile(render);
940 void Monitor::saveSceneList(QString path, QDomElement info)
942 if (render == NULL) return;
943 render->saveSceneList(path, info);
946 const QString Monitor::sceneList()
948 if (render == NULL) return QString();
949 return render->sceneList();
952 void Monitor::setClipZone(QPoint pos)
954 if (m_currentClip == NULL) return;
955 m_currentClip->setZone(pos);
958 void Monitor::slotSwitchDropFrames(bool show)
960 render->setDropFrames(show);
963 void Monitor::slotSwitchMonitorInfo(bool show)
965 KdenliveSettings::setDisplayMonitorInfo(show);
967 if (m_overlay) return;
968 if (videoSurface == NULL) {
969 // Using OpenGL display
971 if (m_glWidget->layout()) delete m_glWidget->layout();
972 m_overlay = new Overlay();
973 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
974 QVBoxLayout *layout = new QVBoxLayout;
975 layout->addStretch(10);
976 layout->addWidget(m_overlay);
977 m_glWidget->setLayout(layout);
980 if (videoSurface->layout()) delete videoSurface->layout();
981 m_overlay = new Overlay();
982 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
983 QVBoxLayout *layout = new QVBoxLayout;
984 layout->addStretch(10);
985 layout->addWidget(m_overlay);
986 videoSurface->setLayout(layout);
988 m_overlay->setHidden(true);
997 void Monitor::slotEditMarker()
999 if (m_editMarker) m_editMarker->trigger();
1002 void Monitor::updateTimecodeFormat()
1004 m_timePos->slotUpdateTimeCodeFormat();
1007 QStringList Monitor::getZoneInfo() const
1010 if (m_currentClip == NULL) return result;
1011 result << m_currentClip->getId();
1012 QPoint zone = m_ruler->zone();
1013 result << QString::number(zone.x()) << QString::number(zone.y());
1017 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
1020 m_loopClipAction->setEnabled(true);
1021 m_selectedClip = item;
1023 m_loopClipAction->setEnabled(false);
1027 void Monitor::slotSetSelectedClip(ClipItem* item)
1029 if (item || (!item && !m_loopClipTransition)) {
1030 m_loopClipTransition = false;
1031 slotSetSelectedClip((AbstractClipItem*)item);
1035 void Monitor::slotSetSelectedClip(Transition* item)
1037 if (item || (!item && m_loopClipTransition)) {
1038 m_loopClipTransition = true;
1039 slotSetSelectedClip((AbstractClipItem*)item);
1044 void Monitor::slotShowEffectScene(bool show, bool manuallyTriggered)
1046 if (m_id == Kdenlive::projectMonitor) {
1047 if (!m_effectWidget->getVisibilityAction()->isChecked())
1049 if (m_effectWidget->isVisible() == show)
1051 setUpdatesEnabled(false);
1054 videoSurface->setVisible(false);
1055 // Preview is handeled internally through the Render::showFrame method
1056 render->disablePreview(true);
1059 m_glWidget->setVisible(false);
1062 m_effectWidget->setVisible(true);
1063 m_effectWidget->getScene()->slotZoomFit();
1064 emit requestFrameForAnalysis(true);
1066 m_effectWidget->setVisible(false);
1067 emit requestFrameForAnalysis(false);
1069 videoSurface->setVisible(true);
1070 // Preview is handeled internally through the Render::showFrame method
1071 render->disablePreview(false);
1075 m_glWidget->setVisible(true);
1079 if (!manuallyTriggered)
1080 m_effectWidget->showVisibilityButton(show);
1081 setUpdatesEnabled(true);
1082 videoBox->setEnabled(show);
1083 //render->doRefresh();
1087 MonitorEditWidget* Monitor::getEffectEdit()
1089 return m_effectWidget;
1092 bool Monitor::effectSceneDisplayed()
1094 return m_effectWidget->isVisible();
1097 void Monitor::slotSetVolume(int volume)
1099 KdenliveSettings::setVolume(volume);
1101 if (volume == 0) icon = KIcon("audio-volume-muted");
1102 else icon = KIcon("audio-volume-medium");
1103 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1104 render->slotSetVolume(volume);
1107 void Monitor::slotShowVolume()
1109 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1110 int vol = render->volume();
1111 // Disable widget if we cannot get the volume
1112 m_volumePopup->setEnabled(vol != -1);
1113 m_audioSlider->blockSignals(true);
1114 m_audioSlider->setValue(vol);
1115 m_audioSlider->blockSignals(false);
1116 m_volumePopup->show();
1119 AbstractRender *Monitor::abstractRender()
1124 void Monitor::reloadProducer(const QString &id)
1126 if (!m_currentClip) return;
1127 if (m_currentClip->getId() == id)
1128 slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
1131 void Monitor::setPalette ( const QPalette & p)
1133 QWidget::setPalette(p);
1134 if (m_ruler) m_ruler->updatePalette();
1138 Overlay::Overlay(QWidget* parent) :
1141 //setAttribute(Qt::WA_TransparentForMouseEvents);
1142 setAutoFillBackground(true);
1143 setBackgroundRole(QPalette::Base);
1144 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1145 setCursor(Qt::PointingHandCursor);
1150 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1156 void Overlay::mousePressEvent( QMouseEvent * event )
1162 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1168 void Overlay::setOverlayText(const QString &text, bool isZone)
1170 if (text.isEmpty()) {
1172 p.setColor(QPalette::Base, KdenliveSettings::window_background());
1181 p.setColor(QPalette::Text, Qt::white);
1182 if (isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1183 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1185 setText(' ' + text + ' ');
1190 #include "monitor.moc"