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(editingFinished()), 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 m_glWidget = new VideoGLWidget(parent);
230 if (m_glWidget == NULL) {
231 // Creation failed, we are in trouble...
234 m_glWidget->setImageAspectRatio(render->dar());
235 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
236 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
241 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
243 m_contextMenu = new QMenu(this);
244 m_contextMenu->addMenu(m_playMenu);
246 m_contextMenu->addMenu(goMenu);
248 m_contextMenu->addMenu(markerMenu);
249 QList <QAction *>list = markerMenu->actions();
250 for (int i = 0; i < list.count(); i++) {
251 if (list.at(i)->data().toString() == "edit_marker") {
252 m_editMarker = list.at(i);
258 m_playMenu->addAction(playZone);
259 m_playMenu->addAction(loopZone);
261 m_loopClipAction = loopClip;
262 m_playMenu->addAction(loopClip);
265 //TODO: add save zone to timeline monitor when fixed
266 if (m_id == Kdenlive::clipMonitor) {
267 m_contextMenu->addMenu(m_markerMenu);
268 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
269 QAction *extractZone = m_configMenu->addAction(KIcon("document-new"), i18n("Extract Zone"), this, SLOT(slotExtractCurrentZone()));
270 m_contextMenu->addAction(extractZone);
272 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
273 m_contextMenu->addAction(extractFrame);
275 if (m_id != Kdenlive::clipMonitor) {
276 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
277 splitView->setCheckable(true);
278 m_configMenu->addAction(splitView);
280 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
281 m_configMenu->addAction(setThumbFrame);
284 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
285 showTips->setCheckable(true);
286 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
287 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
289 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
290 dropFrames->setCheckable(true);
291 dropFrames->setChecked(true);
292 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
294 m_configMenu->addAction(showTips);
295 m_configMenu->addAction(dropFrames);
299 void Monitor::slotGoToMarker(QAction *action)
301 int pos = action->data().toInt();
305 void Monitor::slotSetSizeOneToOne()
307 QRect r = QApplication::desktop()->screenGeometry();
308 const int maxWidth = r.width() - 20;
309 const int maxHeight = r.height() - 20;
310 int width = render->renderWidth();
311 int height = render->renderHeight();
312 kDebug() << "// render info: " << width << "x" << height;
313 while (width >= maxWidth || height >= maxHeight) {
315 height = height * 0.8;
317 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
318 videoBox->setFixedSize(width, height);
321 //m_ui.video_frame->setMinimumSize(0, 0);
322 emit adjustMonitorSize();
325 void Monitor::slotSetSizeOneToTwo()
327 QRect r = QApplication::desktop()->screenGeometry();
328 const int maxWidth = r.width() - 20;
329 const int maxHeight = r.height() - 20;
330 int width = render->renderWidth() / 2;
331 int height = render->renderHeight() / 2;
332 kDebug() << "// render info: " << width << "x" << height;
333 while (width >= maxWidth || height >= maxHeight) {
335 height = height * 0.8;
337 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
338 videoBox->setFixedSize(width, height);
341 //m_ui.video_frame->setMinimumSize(0, 0);
342 emit adjustMonitorSize();
345 void Monitor::resetSize()
347 videoBox->setMinimumSize(0, 0);
350 DocClipBase *Monitor::activeClip()
352 return m_currentClip;
355 void Monitor::updateMarkers(DocClipBase *source)
357 if (source == m_currentClip && source != NULL) {
358 m_markerMenu->clear();
359 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
360 if (!markers.isEmpty()) {
362 for (int i = 0; i < markers.count(); i++) {
363 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
365 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
366 QAction *go = m_markerMenu->addAction(position);
369 m_ruler->setMarkers(marks);
370 } else m_ruler->setMarkers(QList <int>());
371 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
375 void Monitor::slotSeekToPreviousSnap()
377 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
380 void Monitor::slotSeekToNextSnap()
382 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
385 GenTime Monitor::position()
387 return render->seekPosition();
390 GenTime Monitor::getSnapForPos(bool previous)
392 QList <GenTime> snaps;
393 QList < GenTime > markers = m_currentClip->snapMarkers();
394 for (int i = 0; i < markers.size(); ++i) {
395 GenTime t = markers.at(i);
398 QPoint zone = m_ruler->zone();
399 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
400 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
401 snaps.append(GenTime());
402 snaps.append(m_currentClip->duration());
405 const GenTime pos = render->seekPosition();
406 for (int i = 0; i < snaps.size(); ++i) {
407 if (previous && snaps.at(i) >= pos) {
409 return snaps.at(i - 1);
410 } else if (!previous && snaps.at(i) > pos) {
417 void Monitor::slotZoneMoved(int start, int end)
419 m_ruler->setZone(start, end);
421 setClipZone(m_ruler->zone());
424 void Monitor::slotSetZoneStart()
426 m_ruler->setZoneStart();
427 emit zoneUpdated(m_ruler->zone());
429 setClipZone(m_ruler->zone());
432 void Monitor::slotSetZoneEnd()
434 m_ruler->setZoneEnd();
435 emit zoneUpdated(m_ruler->zone());
437 setClipZone(m_ruler->zone());
441 void Monitor::mousePressEvent(QMouseEvent * event)
443 if (event->button() != Qt::RightButton) {
444 if (videoBox->geometry().contains(event->pos()) && (!m_overlay || !m_overlay->underMouse())) {
445 m_dragStarted = true;
446 m_DragStartPosition = event->pos();
448 } else if (m_contextMenu && (!m_effectWidget || !m_effectWidget->isVisible())) {
449 m_contextMenu->popup(event->globalPos());
453 void Monitor::resizeEvent(QResizeEvent *event)
456 if (render && isVisible() && isActive()) render->doRefresh();
459 void Monitor::slotSwitchFullScreen()
461 videoBox->switchFullScreen();
465 void Monitor::mouseReleaseEvent(QMouseEvent * event)
467 if (m_dragStarted && event->button() != Qt::RightButton) {
468 if (videoBox->geometry().contains(event->pos()) && (!m_effectWidget || !m_effectWidget->isVisible())) {
469 if (isActive()) slotPlay();
470 else slotActivateMonitor();
471 } //else event->ignore(); //QWidget::mouseReleaseEvent(event);
472 m_dragStarted = false;
477 void Monitor::mouseMoveEvent(QMouseEvent *event)
479 if (!m_dragStarted || m_currentClip == NULL) return;
481 if ((event->pos() - m_DragStartPosition).manhattanLength()
482 < QApplication::startDragDistance())
486 QDrag *drag = new QDrag(this);
487 QMimeData *mimeData = new QMimeData;
490 list.append(m_currentClip->getId());
491 QPoint p = m_ruler->zone();
492 list.append(QString::number(p.x()));
493 list.append(QString::number(p.y()));
495 data.append(list.join(";").toUtf8());
496 mimeData->setData("kdenlive/clip", data);
497 drag->setMimeData(mimeData);
498 /*QPixmap pix = m_currentClip->thumbnail();
499 drag->setPixmap(pix);
500 drag->setHotSpot(QPoint(0, 50));*/
501 drag->start(Qt::MoveAction);
503 //Qt::DropAction dropAction;
504 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
506 //Qt::DropAction dropAction = drag->exec();
512 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
513 event->setDropAction(Qt::IgnoreAction);
514 event->setDropAction(Qt::MoveAction);
515 if (event->mimeData()->hasText()) {
516 event->acceptProposedAction();
520 Qt::DropActions Monitor::supportedDropActions() const {
521 // returns what actions are supported when dropping
522 return Qt::MoveAction;
525 QStringList Monitor::mimeTypes() const
527 QStringList qstrList;
528 // list of accepted mime types for drop
529 qstrList.append("kdenlive/clip");
534 void Monitor::wheelEvent(QWheelEvent * event)
536 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
540 void Monitor::mouseDoubleClickEvent(QMouseEvent * event)
542 if (!KdenliveSettings::openglmonitors()) {
543 videoBox->switchFullScreen();
548 void Monitor::slotMouseSeek(int eventDelta, bool fast)
551 int delta = m_monitorManager->timecode().fps();
552 if (eventDelta > 0) delta = 0 - delta;
553 if (render->requestedSeekPosition != SEEK_INACTIVE)
554 slotSeek(render->requestedSeekPosition - delta);
555 else slotSeek(render->seekFramePosition() - delta);
557 if (eventDelta >= 0) slotForwardOneFrame();
558 else slotRewindOneFrame();
562 void Monitor::slotSetThumbFrame()
564 if (m_currentClip == NULL) {
567 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
568 emit refreshClipThumbnail(m_currentClip->getId(), true);
571 void Monitor::slotExtractCurrentZone()
573 if (m_currentClip == NULL) return;
574 emit extractZone(m_currentClip->getId(), m_ruler->zone());
577 void Monitor::slotExtractCurrentFrame()
580 // check if we are using a proxy
581 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
582 // using proxy, use original clip url to get frame
583 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
585 else frame = render->extractFrame(render->seekFramePosition());
586 QPointer<KFileDialog> fs = new KFileDialog(KUrl(), "image/png", this);
587 fs->setOperationMode(KFileDialog::Saving);
588 fs->setMode(KFile::File);
589 fs->setConfirmOverwrite(true);
590 fs->setKeepLocation(true);
593 if (fs) path = fs->selectedFile();
595 if (!path.isEmpty()) {
600 void Monitor::setTimePos(const QString &pos)
602 m_timePos->setValue(pos);
606 void Monitor::slotSeek()
608 slotSeek(m_timePos->getValue());
611 void Monitor::slotSeek(int pos)
613 if (render == NULL) return;
614 slotActivateMonitor();
615 render->seekToFrame(pos);
619 void Monitor::checkOverlay()
621 if (m_overlay == NULL) return;
623 int pos = render->seekFramePosition();
624 QPoint zone = m_ruler->zone();
626 overlayText = i18n("In Point");
627 else if (pos == zone.y())
628 overlayText = i18n("Out Point");
631 overlayText = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
632 if (!overlayText.isEmpty()) {
633 m_overlay->setOverlayText(overlayText, false);
638 if (m_overlay->isVisible() && overlayText.isEmpty()) m_overlay->setOverlayText(QString(), false);
639 else m_overlay->setOverlayText(overlayText);
642 void Monitor::slotStart()
644 slotActivateMonitor();
646 render->seekToFrame(0);
649 void Monitor::slotEnd()
651 slotActivateMonitor();
653 render->seekToFrame(render->getLength());
656 void Monitor::slotZoneStart()
658 slotActivateMonitor();
660 render->seekToFrame(m_ruler->zone().x());
663 void Monitor::slotZoneEnd()
665 slotActivateMonitor();
667 render->seekToFrame(m_ruler->zone().y());
670 void Monitor::slotRewind(double speed)
672 slotActivateMonitor();
674 double currentspeed = render->playSpeed();
675 if (currentspeed >= 0) render->play(-2);
676 else render->play(currentspeed * 2);
677 } else render->play(speed);
678 //m_playAction->setChecked(true);
679 m_playAction->setIcon(m_pauseIcon);
682 void Monitor::slotForward(double speed)
684 slotActivateMonitor();
686 double currentspeed = render->playSpeed();
687 if (currentspeed <= 1) render->play(2);
688 else render->play(currentspeed * 2);
689 } else render->play(speed);
690 //m_playAction->setChecked(true);
691 m_playAction->setIcon(m_pauseIcon);
694 void Monitor::slotRewindOneFrame(int diff)
696 slotActivateMonitor();
698 render->seekToFrameDiff(-diff);
702 void Monitor::slotForwardOneFrame(int diff)
704 slotActivateMonitor();
706 render->seekToFrameDiff(diff);
710 void Monitor::seekCursor(int pos)
712 if (m_ruler->slotNewValue(pos)) {
714 m_timePos->setValue(pos);
718 void Monitor::rendererStopped(int pos)
720 if (m_ruler->slotNewValue(pos)) {
722 m_timePos->setValue(pos);
724 m_playAction->setIcon(m_playIcon);
727 void Monitor::adjustRulerSize(int length)
729 if (length > 0) m_length = length;
730 m_ruler->adjustScale(m_length);
731 if (m_currentClip != NULL) {
732 QPoint zone = m_currentClip->zone();
733 m_ruler->setZone(zone.x(), zone.y());
739 if (render) render->stop();
742 void Monitor::start()
744 if (!isVisible() || !isActive()) return;
745 if (render) render->doRefresh();// start();
748 void Monitor::refreshMonitor(bool visible)
750 if (visible && render) {
751 if (!slotActivateMonitor()) {
752 // the monitor was already active, simply refreshClipThumbnail
758 void Monitor::refreshMonitor()
765 void Monitor::pause()
767 if (render == NULL) return;
768 slotActivateMonitor();
770 //m_playAction->setChecked(true);
771 m_playAction->setIcon(m_playIcon);
774 void Monitor::unpause()
778 void Monitor::slotPlay()
780 if (render == NULL) return;
781 slotActivateMonitor();
782 if (render->playSpeed() == 0.0) {
783 m_playAction->setIcon(m_pauseIcon);
784 render->switchPlay(true);
786 m_playAction->setIcon(m_playIcon);
787 render->switchPlay(false);
789 m_ruler->refreshRuler();
792 void Monitor::slotPlayZone()
794 if (render == NULL) return;
795 slotActivateMonitor();
796 QPoint p = m_ruler->zone();
797 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
798 //m_playAction->setChecked(true);
799 m_playAction->setIcon(m_pauseIcon);
802 void Monitor::slotLoopZone()
804 if (render == NULL) return;
805 slotActivateMonitor();
806 QPoint p = m_ruler->zone();
807 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
808 //m_playAction->setChecked(true);
809 m_playAction->setIcon(m_pauseIcon);
812 void Monitor::slotLoopClip()
814 if (render == NULL || m_selectedClip == NULL)
816 slotActivateMonitor();
817 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
818 //m_playAction->setChecked(true);
819 m_playAction->setIcon(m_pauseIcon);
822 void Monitor::updateClipProducer(Mlt::Producer *prod)
824 if (render == NULL) return;
825 render->setProducer(prod, render->seekFramePosition());
828 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
830 if (render == NULL) return;
831 if (clip == NULL && m_currentClip != NULL) {
832 kDebug()<<"// SETTING NULL CLIP MONITOR";
833 m_currentClip = NULL;
835 render->setProducer(NULL, -1);
839 if (clip != m_currentClip || forceUpdate) {
840 m_currentClip = clip;
841 if (m_currentClip) slotActivateMonitor();
843 Mlt::Producer *prod = NULL;
844 if (clip) prod = clip->getCloneProducer();
845 if (render->setProducer(prod, position) == -1) {
846 // MLT CONSUMER is broken
847 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
851 slotActivateMonitor();
852 if (position == -1) position = render->seekFramePosition();
853 render->seek(position);
856 if (!zone.isNull()) {
857 m_ruler->setZone(zone.x(), zone.y());
858 render->seek(zone.x());
862 void Monitor::slotOpenFile(const QString &file)
864 if (render == NULL) return;
865 slotActivateMonitor();
867 QDomElement mlt = doc.createElement("mlt");
868 doc.appendChild(mlt);
869 QDomElement prod = doc.createElement("producer");
870 mlt.appendChild(prod);
871 prod.setAttribute("mlt_service", "avformat");
872 prod.setAttribute("resource", file);
873 render->setSceneList(doc, 0);
876 void Monitor::slotSaveZone()
878 if (render == NULL) return;
879 emit saveZone(render, m_ruler->zone(), m_currentClip);
881 //render->setSceneList(doc, 0);
884 void Monitor::resetProfile(const QString &profile)
886 m_timePos->updateTimeCode(m_monitorManager->timecode());
887 if (render == NULL) return;
888 if (!render->hasProfile(profile)) {
889 slotActivateMonitor();
890 render->resetProfile(profile);
893 m_effectWidget->resetProfile(render);
896 void Monitor::saveSceneList(QString path, QDomElement info)
898 if (render == NULL) return;
899 render->saveSceneList(path, info);
902 const QString Monitor::sceneList()
904 if (render == NULL) return QString();
905 return render->sceneList();
908 void Monitor::setClipZone(QPoint pos)
910 if (m_currentClip == NULL) return;
911 m_currentClip->setZone(pos);
914 void Monitor::slotSwitchDropFrames(bool show)
916 render->setDropFrames(show);
919 void Monitor::slotSwitchMonitorInfo(bool show)
921 KdenliveSettings::setDisplayMonitorInfo(show);
923 if (m_overlay) return;
924 if (videoSurface == NULL) {
925 // Using OpenGL display
927 if (m_glWidget->layout()) delete m_glWidget->layout();
928 m_overlay = new Overlay();
929 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
930 QVBoxLayout *layout = new QVBoxLayout;
931 layout->addStretch(10);
932 layout->addWidget(m_overlay);
933 m_glWidget->setLayout(layout);
936 if (videoSurface->layout()) delete videoSurface->layout();
937 m_overlay = new Overlay();
938 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
939 QVBoxLayout *layout = new QVBoxLayout;
940 layout->addStretch(10);
941 layout->addWidget(m_overlay);
942 videoSurface->setLayout(layout);
944 m_overlay->setHidden(true);
953 void Monitor::slotEditMarker()
955 if (m_editMarker) m_editMarker->trigger();
958 void Monitor::updateTimecodeFormat()
960 m_timePos->slotUpdateTimeCodeFormat();
963 QStringList Monitor::getZoneInfo() const
966 if (m_currentClip == NULL) return result;
967 result << m_currentClip->getId();
968 QPoint zone = m_ruler->zone();
969 result << QString::number(zone.x()) << QString::number(zone.y());
973 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
976 m_loopClipAction->setEnabled(true);
977 m_selectedClip = item;
979 m_loopClipAction->setEnabled(false);
983 void Monitor::slotSetSelectedClip(ClipItem* item)
985 if (item || (!item && !m_loopClipTransition)) {
986 m_loopClipTransition = false;
987 slotSetSelectedClip((AbstractClipItem*)item);
991 void Monitor::slotSetSelectedClip(Transition* item)
993 if (item || (!item && m_loopClipTransition)) {
994 m_loopClipTransition = true;
995 slotSetSelectedClip((AbstractClipItem*)item);
1000 void Monitor::slotShowEffectScene(bool show, bool manuallyTriggered)
1002 if (m_id == Kdenlive::projectMonitor) {
1003 if (!m_effectWidget->getVisibilityAction()->isChecked())
1005 if (m_effectWidget->isVisible() == show)
1007 setUpdatesEnabled(false);
1010 videoSurface->setVisible(false);
1011 // Preview is handeled internally through the Render::showFrame method
1012 render->disablePreview(true);
1015 m_glWidget->setVisible(false);
1018 m_effectWidget->setVisible(true);
1019 m_effectWidget->getScene()->slotZoomFit();
1020 emit requestFrameForAnalysis(true);
1022 m_effectWidget->setVisible(false);
1023 emit requestFrameForAnalysis(false);
1025 videoSurface->setVisible(true);
1026 // Preview is handeled internally through the Render::showFrame method
1027 render->disablePreview(false);
1031 m_glWidget->setVisible(true);
1035 if (!manuallyTriggered)
1036 m_effectWidget->showVisibilityButton(show);
1037 setUpdatesEnabled(true);
1038 videoBox->setEnabled(show);
1039 //render->doRefresh();
1043 MonitorEditWidget* Monitor::getEffectEdit()
1045 return m_effectWidget;
1048 bool Monitor::effectSceneDisplayed()
1050 return m_effectWidget->isVisible();
1053 void Monitor::slotSetVolume(int volume)
1055 KdenliveSettings::setVolume(volume);
1057 if (volume == 0) icon = KIcon("audio-volume-muted");
1058 else icon = KIcon("audio-volume-medium");
1059 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1060 render->slotSetVolume(volume);
1063 void Monitor::slotShowVolume()
1065 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1066 int vol = render->volume();
1067 // Disable widget if we cannot get the volume
1068 m_volumePopup->setEnabled(vol != -1);
1069 m_audioSlider->blockSignals(true);
1070 m_audioSlider->setValue(vol);
1071 m_audioSlider->blockSignals(false);
1072 m_volumePopup->show();
1075 AbstractRender *Monitor::abstractRender()
1080 void Monitor::reloadProducer(const QString &id)
1082 if (!m_currentClip) return;
1083 if (m_currentClip->getId() == id)
1084 slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
1087 void Monitor::setPalette ( const QPalette & p)
1089 QWidget::setPalette(p);
1090 if (m_ruler) m_ruler->updatePalette();
1094 Overlay::Overlay(QWidget* parent) :
1097 //setAttribute(Qt::WA_TransparentForMouseEvents);
1098 setAutoFillBackground(true);
1099 setBackgroundRole(QPalette::Base);
1100 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1101 setCursor(Qt::PointingHandCursor);
1105 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1111 void Overlay::mousePressEvent( QMouseEvent * event )
1117 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1123 void Overlay::setOverlayText(const QString &text, bool isZone)
1125 if (text.isEmpty()) {
1127 p.setColor(QPalette::Base, KdenliveSettings::window_background());
1136 p.setColor(QPalette::Text, Qt::white);
1137 if (isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1138 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1140 setText(' ' + text + ' ');
1145 #include "monitor.moc"