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 "widgets/monitoreditwidget.h"
27 #include "widgets/videosurface.h"
28 #include "kdenlivesettings.h"
31 #include <KLocalizedString>
32 #include <KFileDialog>
33 #include <KApplication>
34 #include <KMessageBox>
35 #include <KSelectAction>
37 #include <QMouseEvent>
38 #include <QStylePainter>
40 #include <QToolButton>
42 #include <QDesktopWidget>
44 #include <QIntValidator>
45 #include <QVBoxLayout>
49 #define SEEK_INACTIVE (-1)
52 Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QString profile, QWidget *parent) :
53 AbstractMonitor(id, manager, parent)
59 , m_dragStarted(false)
60 , m_loopClipAction(NULL)
62 , m_effectWidget(NULL)
63 , m_selectedClip(NULL)
64 , m_loopClipTransition(true)
70 QVBoxLayout *layout = new QVBoxLayout;
71 layout->setContentsMargins(0, 0, 0, 0);
72 layout->setSpacing(0);
74 // Video widget holder
75 layout->addWidget(videoBox, 10);
78 // Get base size for icons
79 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
83 m_toolbar = new QToolBar(this);
84 m_toolbar->setIconSize(QSize(s, s));
86 m_playIcon = KIcon("media-playback-start");
87 m_pauseIcon = KIcon("media-playback-pause");
90 if (id != Kdenlive::DvdMonitor) {
91 m_toolbar->addAction(KIcon("kdenlive-zone-start"), i18n("Set zone start"), this, SLOT(slotSetZoneStart()));
92 m_toolbar->addAction(KIcon("kdenlive-zone-end"), i18n("Set zone end"), this, SLOT(slotSetZoneEnd()));
95 m_toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"), this, SLOT(slotRewind()));
96 //m_toolbar->addAction(KIcon("media-skip-backward"), i18n("Rewind 1 frame"), this, SLOT(slotRewindOneFrame()));
98 QToolButton *playButton = new QToolButton(m_toolbar);
99 m_playMenu = new QMenu(i18n("Play..."), this);
100 m_playAction = m_playMenu->addAction(m_playIcon, i18n("Play"));
101 //m_playAction->setCheckable(true);
102 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
104 playButton->setMenu(m_playMenu);
105 playButton->setPopupMode(QToolButton::MenuButtonPopup);
106 m_toolbar->addWidget(playButton);
108 //m_toolbar->addAction(KIcon("media-skip-forward"), i18n("Forward 1 frame"), this, SLOT(slotForwardOneFrame()));
109 m_toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"), this, SLOT(slotForward()));
111 playButton->setDefaultAction(m_playAction);
113 if (id != Kdenlive::DvdMonitor) {
114 QToolButton *configButton = new QToolButton(m_toolbar);
115 m_configMenu = new QMenu(i18n("Misc..."), this);
116 configButton->setIcon(KIcon("system-run"));
117 configButton->setMenu(m_configMenu);
118 configButton->setPopupMode(QToolButton::QToolButton::InstantPopup);
119 m_toolbar->addWidget(configButton);
121 if (id == Kdenlive::ClipMonitor) {
122 m_markerMenu = new QMenu(i18n("Go to marker..."), this);
123 m_markerMenu->setEnabled(false);
124 m_configMenu->addMenu(m_markerMenu);
125 connect(m_markerMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotGoToMarker(QAction*)));
127 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (100%)"), this, SLOT(slotSetSizeOneToOne()));
128 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (50%)"), this, SLOT(slotSetSizeOneToTwo()));
131 // Create Volume slider popup
132 m_volumePopup = new QFrame(this, Qt::Popup);
133 QVBoxLayout *poplayout = new QVBoxLayout;
134 poplayout->setContentsMargins(0, 0, 0, 0);
135 m_audioSlider = new QSlider(Qt::Vertical);
136 m_audioSlider->setRange(0, 100);
137 poplayout->addWidget(m_audioSlider);
138 m_volumePopup->setLayout(poplayout);
140 if (KdenliveSettings::volume() == 0) icon = KIcon("audio-volume-muted");
141 else icon = KIcon("audio-volume-medium");
143 m_volumeWidget = m_toolbar->widgetForAction(m_toolbar->addAction(icon, i18n("Audio volume"), this, SLOT(slotShowVolume())));
145 // we need to show / hide the popup once so that it's geometry can be calculated in slotShowVolume
146 m_volumePopup->show();
147 m_volumePopup->hide();
149 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
151 setMinimumHeight(200);
153 if (profile.isEmpty())
154 profile = KdenliveSettings::current_profile();
156 bool monitorCreated = false;
158 createOpenGlWidget(videoBox, profile);
159 monitorCreated = true;
160 //m_glWidget->setFixedSize(width, height);
161 #elif defined(USE_OPENGL)
162 if (KdenliveSettings::openglmonitors()) {
163 monitorCreated = createOpenGlWidget(videoBox, profile);
166 if (!monitorCreated) {
167 createVideoSurface();
168 render = new Render(m_id, (int) videoSurface->winId(), profile, this);
169 connect(videoSurface, SIGNAL(refreshMonitor()), render, SLOT(doRefresh()));
172 else if (m_glWidget) {
173 QVBoxLayout *lay = new QVBoxLayout;
174 lay->setContentsMargins(0, 0, 0, 0);
175 lay->addWidget(m_glWidget);
176 videoBox->setLayout(lay);
181 m_ruler = new SmallRuler(this, render);
182 if (id == Kdenlive::DvdMonitor) m_ruler->setZone(-3, -2);
183 layout->addWidget(m_ruler);
185 connect(m_audioSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetVolume(int)));
186 connect(render, SIGNAL(durationChanged(int)), this, SLOT(adjustRulerSize(int)));
187 connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int)));
188 connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
190 if (id != Kdenlive::ClipMonitor) {
191 connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int)));
192 connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int)));
193 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SIGNAL(zoneUpdated(QPoint)));
195 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SLOT(setClipZone(QPoint)));
198 if (videoSurface) videoSurface->show();
200 if (id == Kdenlive::ProjectMonitor) {
201 m_effectWidget = new MonitorEditWidget(render, videoBox);
202 connect(m_effectWidget, SIGNAL(showEdit(bool,bool)), this, SLOT(slotShowEffectScene(bool,bool)));
203 m_toolbar->addAction(m_effectWidget->getVisibilityAction());
204 videoBox->layout()->addWidget(m_effectWidget);
205 m_effectWidget->hide();
208 QWidget *spacer = new QWidget(this);
209 spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
210 m_toolbar->addWidget(spacer);
211 m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this);
212 m_toolbar->addWidget(m_timePos);
213 connect(m_timePos, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotSeek()));
214 m_toolbar->setMaximumHeight(m_timePos->height());
215 layout->addWidget(m_toolbar);
224 delete m_effectWidget;
228 QWidget *Monitor::container()
234 bool Monitor::createOpenGlWidget(QWidget *parent, const QString &profile)
236 render = new Render(id(), 0, profile, this);
237 m_glWidget = new VideoGLWidget(parent);
238 if (m_glWidget == NULL) {
239 // Creation failed, we are in trouble...
242 m_glWidget->setImageAspectRatio(render->dar());
243 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
244 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
249 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
251 m_contextMenu = new QMenu(this);
252 m_contextMenu->addMenu(m_playMenu);
254 m_contextMenu->addMenu(goMenu);
256 m_contextMenu->addMenu(markerMenu);
257 QList <QAction *>list = markerMenu->actions();
258 for (int i = 0; i < list.count(); ++i) {
259 if (list.at(i)->data().toString() == "edit_marker") {
260 m_editMarker = list.at(i);
266 m_playMenu->addAction(playZone);
267 m_playMenu->addAction(loopZone);
269 m_loopClipAction = loopClip;
270 m_playMenu->addAction(loopClip);
273 //TODO: add save zone to timeline monitor when fixed
274 if (m_id == Kdenlive::ClipMonitor) {
275 m_contextMenu->addMenu(m_markerMenu);
276 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
277 QAction *extractZone = m_configMenu->addAction(KIcon("document-new"), i18n("Extract Zone"), this, SLOT(slotExtractCurrentZone()));
278 m_contextMenu->addAction(extractZone);
280 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
281 m_contextMenu->addAction(extractFrame);
283 if (m_id != Kdenlive::ClipMonitor) {
284 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
285 splitView->setCheckable(true);
286 m_configMenu->addAction(splitView);
288 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
289 m_configMenu->addAction(setThumbFrame);
292 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
293 showTips->setCheckable(true);
294 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
295 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
297 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
298 dropFrames->setCheckable(true);
299 dropFrames->setChecked(true);
300 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
302 m_configMenu->addAction(showTips);
303 m_configMenu->addAction(dropFrames);
306 void Monitor::slotGoToMarker(QAction *action)
308 int pos = action->data().toInt();
312 void Monitor::slotSetSizeOneToOne()
314 QRect r = QApplication::desktop()->screenGeometry();
315 const int maxWidth = r.width() - 20;
316 const int maxHeight = r.height() - 20;
317 int width = render->renderWidth();
318 int height = render->renderHeight();
319 kDebug() << "// render info: " << width << "x" << height;
320 while (width >= maxWidth || height >= maxHeight) {
322 height = height * 0.8;
324 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
325 videoBox->setFixedSize(width, height);
328 //m_ui.video_frame->setMinimumSize(0, 0);
329 emit adjustMonitorSize();
332 void Monitor::slotSetSizeOneToTwo()
334 QRect r = QApplication::desktop()->screenGeometry();
335 const int maxWidth = r.width() - 20;
336 const int maxHeight = r.height() - 20;
337 int width = render->renderWidth() / 2;
338 int height = render->renderHeight() / 2;
339 kDebug() << "// render info: " << width << "x" << height;
340 while (width >= maxWidth || height >= maxHeight) {
342 height = height * 0.8;
344 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
345 videoBox->setFixedSize(width, height);
348 //m_ui.video_frame->setMinimumSize(0, 0);
349 emit adjustMonitorSize();
352 void Monitor::resetSize()
354 videoBox->setMinimumSize(0, 0);
357 QString Monitor::getTimecodeFromFrames(int pos)
359 return m_monitorManager->timecode().getTimecodeFromFrames(pos);
362 double Monitor::fps() const
364 return m_monitorManager->timecode().fps();
367 DocClipBase *Monitor::activeClip()
369 return m_currentClip;
372 void Monitor::updateMarkers(DocClipBase *source)
374 if (source == m_currentClip && source != NULL) {
375 m_markerMenu->clear();
376 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
377 if (!markers.isEmpty()) {
379 for (int i = 0; i < markers.count(); ++i) {
380 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
382 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
383 QAction *go = m_markerMenu->addAction(position);
387 m_ruler->setMarkers(markers);
388 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
392 void Monitor::setMarkers(const QList<CommentedTime> &markers)
394 m_ruler->setMarkers(markers);
397 void Monitor::slotSeekToPreviousSnap()
399 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
402 void Monitor::slotSeekToNextSnap()
404 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
407 GenTime Monitor::position()
409 return render->seekPosition();
412 GenTime Monitor::getSnapForPos(bool previous)
414 QList <GenTime> snaps;
415 QList < GenTime > markers = m_currentClip->snapMarkers();
416 for (int i = 0; i < markers.size(); ++i) {
417 GenTime t = markers.at(i);
420 QPoint zone = m_ruler->zone();
421 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
422 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
423 snaps.append(GenTime());
424 snaps.append(m_currentClip->duration());
427 const GenTime pos = render->seekPosition();
428 for (int i = 0; i < snaps.size(); ++i) {
429 if (previous && snaps.at(i) >= pos) {
431 return snaps.at(i - 1);
432 } else if (!previous && snaps.at(i) > pos) {
439 void Monitor::slotZoneMoved(int start, int end)
441 m_ruler->setZone(start, end);
442 setClipZone(m_ruler->zone());
446 void Monitor::slotSetZoneStart()
448 m_ruler->setZoneStart();
449 emit zoneUpdated(m_ruler->zone());
450 setClipZone(m_ruler->zone());
454 void Monitor::slotSetZoneEnd()
456 m_ruler->setZoneEnd();
457 emit zoneUpdated(m_ruler->zone());
458 setClipZone(m_ruler->zone());
463 void Monitor::mousePressEvent(QMouseEvent * event)
465 if (render) render->setActiveMonitor();
466 if (event->button() != Qt::RightButton) {
467 if (videoBox->geometry().contains(event->pos()) && (!m_overlay || !m_overlay->underMouse())) {
468 m_dragStarted = true;
469 m_DragStartPosition = event->pos();
471 } else if (m_contextMenu && (!m_effectWidget || !m_effectWidget->isVisible())) {
472 m_contextMenu->popup(event->globalPos());
476 void Monitor::resizeEvent(QResizeEvent *event)
479 if (render && isVisible() && isActive()) render->doRefresh();
482 void Monitor::slotSwitchFullScreen()
484 videoBox->switchFullScreen();
488 void Monitor::mouseReleaseEvent(QMouseEvent * event)
490 if (m_dragStarted && event->button() != Qt::RightButton) {
491 if (videoBox->geometry().contains(event->pos()) && (!m_effectWidget || !m_effectWidget->isVisible())) {
492 if (isActive()) slotPlay();
493 else slotActivateMonitor();
494 } //else event->ignore(); //QWidget::mouseReleaseEvent(event);
496 m_dragStarted = false;
501 void Monitor::mouseMoveEvent(QMouseEvent *event)
503 if (!m_dragStarted || m_currentClip == NULL) return;
505 if ((event->pos() - m_DragStartPosition).manhattanLength()
506 < QApplication::startDragDistance())
510 QDrag *drag = new QDrag(this);
511 QMimeData *mimeData = new QMimeData;
514 list.append(m_currentClip->getId());
515 QPoint p = m_ruler->zone();
516 list.append(QString::number(p.x()));
517 list.append(QString::number(p.y()));
519 data.append(list.join(";").toUtf8());
520 mimeData->setData("kdenlive/clip", data);
521 drag->setMimeData(mimeData);
522 /*QPixmap pix = m_currentClip->thumbnail();
523 drag->setPixmap(pix);
524 drag->setHotSpot(QPoint(0, 50));*/
525 drag->start(Qt::MoveAction);
526 /*Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
527 Qt::DropAction dropAction;
528 dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);*/
530 //Qt::DropAction dropAction = drag->exec();
537 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
538 event->setDropAction(Qt::IgnoreAction);
539 event->setDropAction(Qt::MoveAction);
540 if (event->mimeData()->hasText()) {
541 event->acceptProposedAction();
545 Qt::DropActions Monitor::supportedDropActions() const {
546 // returns what actions are supported when dropping
547 return Qt::MoveAction;
550 QStringList Monitor::mimeTypes() const
552 QStringList qstrList;
553 // list of accepted mime types for drop
554 qstrList.append("kdenlive/clip");
559 void Monitor::wheelEvent(QWheelEvent * event)
561 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
565 void Monitor::mouseDoubleClickEvent(QMouseEvent * event)
567 if (!KdenliveSettings::openglmonitors()) {
568 videoBox->switchFullScreen();
573 void Monitor::slotMouseSeek(int eventDelta, bool fast)
576 int delta = m_monitorManager->timecode().fps();
577 if (eventDelta > 0) delta = 0 - delta;
578 if (render->requestedSeekPosition != SEEK_INACTIVE)
579 slotSeek(render->requestedSeekPosition - delta);
580 else slotSeek(render->seekFramePosition() - delta);
582 if (eventDelta >= 0) slotForwardOneFrame();
583 else slotRewindOneFrame();
587 void Monitor::slotSetThumbFrame()
589 if (m_currentClip == NULL) {
592 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
593 emit refreshClipThumbnail(m_currentClip->getId(), true);
596 void Monitor::slotExtractCurrentZone()
598 if (m_currentClip == NULL) return;
599 emit extractZone(m_currentClip->getId(), m_ruler->zone());
602 void Monitor::slotExtractCurrentFrame()
605 // check if we are using a proxy
606 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
607 // using proxy, use original clip url to get frame
608 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
610 else frame = render->extractFrame(render->seekFramePosition());
611 QPointer<KFileDialog> fs = new KFileDialog(KUrl(), "image/png", this);
612 fs->setOperationMode(KFileDialog::Saving);
613 fs->setMode(KFile::File);
614 fs->setConfirmOverwrite(true);
615 fs->setKeepLocation(true);
617 QString path = fs->selectedFile();
618 if (!path.isEmpty()) {
625 void Monitor::setTimePos(const QString &pos)
627 m_timePos->setValue(pos);
631 void Monitor::slotSeek()
633 slotSeek(m_timePos->getValue());
636 void Monitor::slotSeek(int pos)
638 if (render == NULL) return;
639 slotActivateMonitor();
640 render->seekToFrame(pos);
644 void Monitor::checkOverlay()
646 if (m_overlay == NULL) return;
648 int pos = m_timePos->getValue();//render->seekFramePosition();
649 QPoint zone = m_ruler->zone();
651 overlayText = i18n("In Point");
652 else if (pos == zone.y())
653 overlayText = i18n("Out Point");
656 overlayText = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
657 if (!overlayText.isEmpty()) {
658 m_overlay->setOverlayText(overlayText, false);
663 if (m_overlay->isVisible() && overlayText.isEmpty()) m_overlay->setOverlayText(QString(), false);
664 else m_overlay->setOverlayText(overlayText);
667 void Monitor::slotStart()
669 slotActivateMonitor();
671 render->seekToFrame(0);
674 void Monitor::slotEnd()
676 slotActivateMonitor();
678 render->seekToFrame(render->getLength());
681 void Monitor::slotZoneStart()
683 slotActivateMonitor();
685 render->seekToFrame(m_ruler->zone().x());
688 void Monitor::slotZoneEnd()
690 slotActivateMonitor();
692 render->seekToFrame(m_ruler->zone().y());
695 void Monitor::slotRewind(double speed)
697 slotActivateMonitor();
699 double currentspeed = render->playSpeed();
700 if (currentspeed >= 0) render->play(-1);
701 else switch((int) currentspeed) {
714 } else render->play(speed);
715 //m_playAction->setChecked(true);
716 m_playAction->setIcon(m_pauseIcon);
719 void Monitor::slotForward(double speed)
721 slotActivateMonitor();
723 double currentspeed = render->playSpeed();
724 if (currentspeed <= 0) render->play(1);
725 else switch((int) currentspeed) {
738 } else render->play(speed);
739 //m_playAction->setChecked(true);
740 m_playAction->setIcon(m_pauseIcon);
743 void Monitor::slotRewindOneFrame(int diff)
745 slotActivateMonitor();
747 render->seekToFrameDiff(-diff);
751 void Monitor::slotForwardOneFrame(int diff)
753 slotActivateMonitor();
755 render->seekToFrameDiff(diff);
759 void Monitor::seekCursor(int pos)
761 if (m_ruler->slotNewValue(pos)) {
762 m_timePos->setValue(pos);
767 void Monitor::rendererStopped(int pos)
769 if (m_ruler->slotNewValue(pos)) {
770 m_timePos->setValue(pos);
773 m_playAction->setIcon(m_playIcon);
776 void Monitor::adjustRulerSize(int length)
778 if (length > 0) m_length = length;
779 m_ruler->adjustScale(m_length);
780 if (m_currentClip != NULL) {
781 QPoint zone = m_currentClip->zone();
782 m_ruler->setZone(zone.x(), zone.y());
788 if (render) render->stop();
791 void Monitor::start()
793 if (!isVisible() || !isActive()) return;
795 if (m_glWidget) m_glWidget->activateMonitor();
797 if (render) render->startConsumer();
800 void Monitor::refreshMonitor(bool visible)
802 if (visible && render) {
803 if (!slotActivateMonitor()) {
804 // the monitor was already active, simply refreshClipThumbnail
810 void Monitor::refreshMonitor()
817 void Monitor::pause()
819 if (render == NULL) return;
820 slotActivateMonitor();
822 //m_playAction->setChecked(true);
823 m_playAction->setIcon(m_playIcon);
826 void Monitor::unpause()
830 void Monitor::slotPlay()
832 if (render == NULL) return;
833 slotActivateMonitor();
834 if (render->isPlaying()) {
835 m_playAction->setIcon(m_playIcon);
836 render->switchPlay(false);
839 m_playAction->setIcon(m_pauseIcon);
840 render->switchPlay(true);
842 m_ruler->refreshRuler();
845 void Monitor::slotPlayZone()
847 if (render == NULL) return;
848 slotActivateMonitor();
849 QPoint p = m_ruler->zone();
850 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
851 //m_playAction->setChecked(true);
852 m_playAction->setIcon(m_pauseIcon);
855 void Monitor::slotLoopZone()
857 if (render == NULL) return;
858 slotActivateMonitor();
859 QPoint p = m_ruler->zone();
860 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
861 //m_playAction->setChecked(true);
862 m_playAction->setIcon(m_pauseIcon);
865 void Monitor::slotLoopClip()
867 if (render == NULL || m_selectedClip == NULL)
869 slotActivateMonitor();
870 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
871 //m_playAction->setChecked(true);
872 m_playAction->setIcon(m_pauseIcon);
875 void Monitor::updateClipProducer(Mlt::Producer *prod)
877 if (render == NULL) return;
878 render->setProducer(prod, render->seekFramePosition());
881 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
883 if (render == NULL) return;
884 if (clip == NULL && m_currentClip != NULL) {
885 m_currentClip->lastSeekPosition = render->seekFramePosition();
886 m_currentClip = NULL;
888 render->setProducer(NULL, -1);
892 if (clip != m_currentClip || forceUpdate) {
893 if (m_currentClip) m_currentClip->lastSeekPosition = render->seekFramePosition();
894 m_currentClip = clip;
895 if (position == -1) position = clip->lastSeekPosition;
897 Mlt::Producer *prod = NULL;
898 if (clip) prod = clip->getCloneProducer();
899 if (render->setProducer(prod, position) == -1) {
900 // MLT CONSUMER is broken
901 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
905 slotActivateMonitor();
906 if (position == -1) position = render->seekFramePosition();
907 render->seek(position);
909 zone = m_currentClip->zone();
910 m_ruler->setZone(zone.x(), zone.y());
915 if (!zone.isNull()) {
916 m_ruler->setZone(zone.x(), zone.y());
917 render->seek(zone.x());
921 void Monitor::slotOpenFile(const QString &file)
923 if (render == NULL) return;
924 slotActivateMonitor();
925 render->loadUrl(file);
928 void Monitor::slotSaveZone()
930 if (render == NULL) return;
931 emit saveZone(render, m_ruler->zone(), m_currentClip);
933 //render->setSceneList(doc, 0);
936 void Monitor::setCustomProfile(const QString &profile, const Timecode &tc)
938 m_timePos->updateTimeCode(tc);
939 if (render == NULL) return;
940 if (!render->hasProfile(profile)) {
941 slotActivateMonitor();
942 render->resetProfile(profile);
944 if (m_glWidget) m_glWidget->setImageAspectRatio(render->dar());
949 void Monitor::resetProfile(const QString &profile)
951 m_timePos->updateTimeCode(m_monitorManager->timecode());
952 if (render == NULL) return;
953 if (!render->hasProfile(profile)) {
954 slotActivateMonitor();
955 render->resetProfile(profile);
957 if (m_glWidget) m_glWidget->setImageAspectRatio(render->dar());
961 m_effectWidget->resetProfile(render);
964 void Monitor::saveSceneList(const QString &path, const QDomElement &info)
966 if (render == NULL) return;
967 render->saveSceneList(path, info);
970 const QString Monitor::sceneList()
972 if (render == NULL) return QString();
973 return render->sceneList();
976 void Monitor::setClipZone(const QPoint &pos)
978 if (m_currentClip == NULL) return;
979 m_currentClip->setZone(pos);
982 void Monitor::slotSwitchDropFrames(bool show)
984 render->setDropFrames(show);
987 void Monitor::slotSwitchMonitorInfo(bool show)
989 KdenliveSettings::setDisplayMonitorInfo(show);
991 if (m_overlay) return;
992 if (videoSurface == NULL) {
993 // Using OpenGL display
995 if (m_glWidget->layout()) delete m_glWidget->layout();
996 m_overlay = new Overlay();
997 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
998 QVBoxLayout *layout = new QVBoxLayout;
999 layout->addStretch(10);
1000 layout->addWidget(m_overlay);
1001 m_glWidget->setLayout(layout);
1004 if (videoSurface->layout()) delete videoSurface->layout();
1005 m_overlay = new Overlay();
1006 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
1007 QVBoxLayout *layout = new QVBoxLayout;
1008 layout->addStretch(10);
1009 layout->addWidget(m_overlay);
1010 videoSurface->setLayout(layout);
1012 m_overlay->setHidden(true);
1021 void Monitor::slotEditMarker()
1023 if (m_editMarker) m_editMarker->trigger();
1026 void Monitor::updateTimecodeFormat()
1028 m_timePos->slotUpdateTimeCodeFormat();
1031 QStringList Monitor::getZoneInfo() const
1034 if (m_currentClip == NULL) return result;
1035 result << m_currentClip->getId();
1036 QPoint zone = m_ruler->zone();
1037 result << QString::number(zone.x()) << QString::number(zone.y());
1041 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
1044 if (m_loopClipAction) m_loopClipAction->setEnabled(true);
1045 m_selectedClip = item;
1047 if (m_loopClipAction) m_loopClipAction->setEnabled(false);
1051 void Monitor::slotSetSelectedClip(ClipItem* item)
1053 if (item || (!item && !m_loopClipTransition)) {
1054 m_loopClipTransition = false;
1055 slotSetSelectedClip((AbstractClipItem*)item);
1059 void Monitor::slotSetSelectedClip(Transition* item)
1061 if (item || (!item && m_loopClipTransition)) {
1062 m_loopClipTransition = true;
1063 slotSetSelectedClip((AbstractClipItem*)item);
1068 void Monitor::slotShowEffectScene(bool show, bool manuallyTriggered)
1070 if (m_id == Kdenlive::ProjectMonitor) {
1071 if (!m_effectWidget->getVisibilityAction()->isChecked())
1073 if (m_effectWidget->isVisible() == show)
1075 setUpdatesEnabled(false);
1078 videoSurface->setVisible(false);
1079 // Preview is handeled internally through the Render::showFrame method
1080 render->disablePreview(true);
1083 m_glWidget->setVisible(false);
1086 m_effectWidget->setVisible(true);
1087 m_effectWidget->getScene()->slotZoomFit();
1088 emit requestFrameForAnalysis(true);
1090 m_effectWidget->setVisible(false);
1091 emit requestFrameForAnalysis(false);
1093 videoSurface->setVisible(true);
1094 // Preview is handeled internally through the Render::showFrame method
1095 render->disablePreview(false);
1099 m_glWidget->setVisible(true);
1103 if (!manuallyTriggered)
1104 m_effectWidget->showVisibilityButton(show);
1105 setUpdatesEnabled(true);
1106 videoBox->setEnabled(show);
1107 //render->doRefresh();
1111 MonitorEditWidget* Monitor::getEffectEdit()
1113 return m_effectWidget;
1116 bool Monitor::effectSceneDisplayed()
1118 return m_effectWidget->isVisible();
1121 void Monitor::slotSetVolume(int volume)
1123 KdenliveSettings::setVolume(volume);
1125 if (volume == 0) icon = KIcon("audio-volume-muted");
1126 else icon = KIcon("audio-volume-medium");
1127 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1128 render->slotSetVolume(volume);
1131 void Monitor::slotShowVolume()
1133 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1134 int vol = render->volume();
1135 // Disable widget if we cannot get the volume
1136 m_volumePopup->setEnabled(vol != -1);
1137 m_audioSlider->blockSignals(true);
1138 m_audioSlider->setValue(vol);
1139 m_audioSlider->blockSignals(false);
1140 m_volumePopup->show();
1143 AbstractRender *Monitor::abstractRender()
1148 void Monitor::reloadProducer(const QString &id)
1150 if (!m_currentClip) return;
1151 if (m_currentClip->getId() == id)
1152 slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
1155 QString Monitor::getMarkerThumb(GenTime pos)
1157 if (!m_currentClip) return QString();
1158 if (!m_currentClip->getClipHash().isEmpty()) {
1159 QString url = m_monitorManager->getProjectFolder() + "thumbs/" + m_currentClip->getClipHash() + '#' + QString::number((int) pos.frames(m_monitorManager->timecode().fps())) + ".png";
1160 if (QFile::exists(url)) return url;
1165 void Monitor::setPalette ( const QPalette & p)
1167 QWidget::setPalette(p);
1168 if (m_ruler) m_ruler->updatePalette();
1172 Overlay::Overlay(QWidget* parent) :
1175 //setAttribute(Qt::WA_TransparentForMouseEvents);
1176 setAutoFillBackground(true);
1177 setBackgroundRole(QPalette::Base);
1178 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1179 setCursor(Qt::PointingHandCursor);
1184 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1190 void Overlay::mousePressEvent( QMouseEvent * event )
1196 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1202 void Overlay::setOverlayText(const QString &text, bool isZone)
1204 if (text.isEmpty()) {
1206 p.setColor(QPalette::Base, KdenliveSettings::window_background());
1215 p.setColor(QPalette::Text, Qt::white);
1216 if (isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1217 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1219 setText(' ' + text + ' ');
1224 #include "monitor.moc"