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 ***************************************************************************/
23 #include "monitormanager.h"
24 #include "smallruler.h"
25 #include "docclipbase.h"
26 #include "abstractclipitem.h"
27 #include "monitorscene.h"
28 #include "monitoreditwidget.h"
29 #include "kdenlivesettings.h"
33 #include <KFileDialog>
34 #include <KApplication>
35 #include <KMessageBox>
37 #include <QMouseEvent>
38 #include <QStylePainter>
40 #include <QToolButton>
42 #include <QDesktopWidget>
44 #include <QIntValidator>
45 #include <QVBoxLayout>
48 Monitor::Monitor(QString name, MonitorManager *manager, QString profile, QWidget *parent) :
52 m_monitorManager(manager),
54 m_ruler(new SmallRuler(m_monitorManager)),
60 m_monitorRefresh(NULL),
63 m_loopClipTransition(true)
66 QVBoxLayout *layout = new QVBoxLayout;
67 layout->setContentsMargins(0, 0, 0, 0);
68 layout->setSpacing(0);
70 // Video widget holder
71 m_videoBox = new VideoContainer(this);
72 m_videoBox->setContentsMargins(0, 0, 0, 0);
73 m_videoBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
74 layout->addWidget(m_videoBox, 10);
77 // Get base size for icons
78 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
81 layout->addWidget(m_ruler);
83 m_toolbar = new QToolBar(name, this);
84 m_toolbar->setIconSize(QSize(s, s));
86 m_playIcon = KIcon("media-playback-start");
87 m_pauseIcon = KIcon("media-playback-pause");
89 if (name != "chapter") {
90 m_toolbar->addAction(KIcon("kdenlive-zone-start"), i18n("Set zone start"), this, SLOT(slotSetZoneStart()));
91 m_toolbar->addAction(KIcon("kdenlive-zone-end"), i18n("Set zone end"), this, SLOT(slotSetZoneEnd()));
93 m_ruler->setZone(-3, -2);
96 m_toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"), this, SLOT(slotRewind()));
97 //m_toolbar->addAction(KIcon("media-skip-backward"), i18n("Rewind 1 frame"), this, SLOT(slotRewindOneFrame()));
99 QToolButton *playButton = new QToolButton(m_toolbar);
100 m_playMenu = new QMenu(i18n("Play..."), this);
101 m_playAction = m_playMenu->addAction(m_playIcon, i18n("Play"));
102 //m_playAction->setCheckable(true);
103 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
105 playButton->setMenu(m_playMenu);
106 playButton->setPopupMode(QToolButton::MenuButtonPopup);
107 m_toolbar->addWidget(playButton);
109 //m_toolbar->addAction(KIcon("media-skip-forward"), i18n("Forward 1 frame"), this, SLOT(slotForwardOneFrame()));
110 m_toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"), this, SLOT(slotForward()));
112 playButton->setDefaultAction(m_playAction);
114 if (name != "chapter") {
115 QToolButton *configButton = new QToolButton(m_toolbar);
116 m_configMenu = new QMenu(i18n("Misc..."), this);
117 configButton->setIcon(KIcon("system-run"));
118 configButton->setMenu(m_configMenu);
119 configButton->setPopupMode(QToolButton::QToolButton::InstantPopup);
120 m_toolbar->addWidget(configButton);
122 if (name == "clip") {
123 m_markerMenu = new QMenu(i18n("Go to marker..."), this);
124 m_markerMenu->setEnabled(false);
125 m_configMenu->addMenu(m_markerMenu);
126 connect(m_markerMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToMarker(QAction *)));
128 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (100%)"), this, SLOT(slotSetSizeOneToOne()));
129 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (50%)"), this, SLOT(slotSetSizeOneToTwo()));
132 // Create Volume slider popup
133 m_volumePopup = new QFrame(this, Qt::Popup);
134 QVBoxLayout *poplayout = new QVBoxLayout;
135 poplayout->setContentsMargins(0, 0, 0, 0);
136 m_audioSlider = new QSlider(Qt::Vertical);
137 m_audioSlider->setRange(0, 100);
138 poplayout->addWidget(m_audioSlider);
139 m_volumePopup->setLayout(poplayout);
141 if (KdenliveSettings::volume() == 0) icon = KIcon("audio-volume-muted");
142 else icon = KIcon("audio-volume-medium");
144 m_volumeWidget = m_toolbar->widgetForAction(m_toolbar->addAction(icon, i18n("Audio volume"), this, SLOT(slotShowVolume())));
146 // we need to show / hide the popup once so that it's geometry can be calculated in slotShowVolume
147 m_volumePopup->show();
148 m_volumePopup->hide();
150 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
152 setMinimumHeight(200);
154 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
156 bool monitorCreated = false;
158 createOpenGlWidget(m_videoBox, profile);
159 monitorCreated = true;
160 //m_glWidget->setFixedSize(width, height);
161 #elif defined (USE_OPEN_GL)
162 if (KdenliveSettings::openglmonitors()) {
163 monitorCreated = createOpenGlWidget(m_videoBox, profile);
166 QVBoxLayout *lay = new QVBoxLayout;
167 lay->setContentsMargins(0, 0, 0, 0);
168 if (!monitorCreated) {
169 m_monitorRefresh = new MonitorRefresh;
170 lay->addWidget(m_monitorRefresh);
171 m_videoBox->setLayout(lay);
172 render = new Render(m_name, (int) m_monitorRefresh->winId(), profile, this);
173 m_monitorRefresh->setRenderer(render);
175 #if defined (USE_OPEN_GL)
176 else if (m_glWidget) {
177 lay->addWidget(m_glWidget);
178 m_videoBox->setLayout(lay);
182 connect(m_audioSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetVolume(int)));
183 connect(m_ruler, SIGNAL(seekRenderer(int)), this, SLOT(slotSeek(int)));
184 connect(render, SIGNAL(durationChanged(int)), this, SLOT(adjustRulerSize(int)));
185 connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int)));
187 //render->createVideoXWindow(m_ui.video_frame->winId(), -1);
189 if (name != "clip") {
190 connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int)));
191 connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int)));
192 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SIGNAL(zoneUpdated(QPoint)));
194 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SLOT(setClipZone(QPoint)));
197 if (m_monitorRefresh) m_monitorRefresh->show();
199 if (name == "project") {
200 m_effectWidget = new MonitorEditWidget(render, m_videoBox);
201 m_toolbar->addAction(m_effectWidget->getVisibilityAction());
202 lay->addWidget(m_effectWidget);
203 m_effectWidget->hide();
206 QWidget *spacer = new QWidget(this);
207 spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
208 m_toolbar->addWidget(spacer);
209 m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this);
210 m_toolbar->addWidget(m_timePos);
211 connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotSeek()));
212 m_toolbar->setMaximumHeight(s * 1.5);
213 layout->addWidget(m_toolbar);
222 delete m_effectWidget;
223 delete m_monitorRefresh;
227 QWidget *Monitor::container()
232 QString Monitor::name() const
237 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
238 bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile)
240 render = new Render(m_name, 0, profile, this);
241 m_glWidget = new VideoGLWidget(parent);
242 if (m_glWidget == NULL) {
243 // Creation failed, we are in trouble...
246 m_glWidget->setImageAspectRatio(render->dar());
247 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
248 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
253 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
255 m_contextMenu = new QMenu(this);
256 m_contextMenu->addMenu(m_playMenu);
258 m_contextMenu->addMenu(goMenu);
260 m_contextMenu->addMenu(markerMenu);
262 m_playMenu->addAction(playZone);
263 m_playMenu->addAction(loopZone);
265 m_loopClipAction = loopClip;
266 m_playMenu->addAction(loopClip);
269 //TODO: add save zone to timeline monitor when fixed
270 if (m_name == "clip") {
271 m_contextMenu->addMenu(m_markerMenu);
272 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
274 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
275 m_contextMenu->addAction(extractFrame);
277 if (m_name != "clip") {
278 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
279 splitView->setCheckable(true);
280 m_configMenu->addAction(splitView);
282 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
283 m_configMenu->addAction(setThumbFrame);
286 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
287 showTips->setCheckable(true);
288 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
289 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
291 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
292 dropFrames->setCheckable(true);
293 dropFrames->setChecked(true);
294 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
296 m_configMenu->addAction(showTips);
297 m_configMenu->addAction(dropFrames);
301 void Monitor::slotGoToMarker(QAction *action)
303 int pos = action->data().toInt();
307 void Monitor::slotSetSizeOneToOne()
309 QRect r = QApplication::desktop()->screenGeometry();
310 const int maxWidth = r.width() - 20;
311 const int maxHeight = r.height() - 20;
312 int width = render->renderWidth();
313 int height = render->renderHeight();
314 kDebug() << "// render info: " << width << "x" << height;
315 while (width >= maxWidth || height >= maxHeight) {
317 height = height * 0.8;
319 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
320 m_videoBox->setFixedSize(width, height);
323 //m_ui.video_frame->setMinimumSize(0, 0);
324 emit adjustMonitorSize();
327 void Monitor::slotSetSizeOneToTwo()
329 QRect r = QApplication::desktop()->screenGeometry();
330 const int maxWidth = r.width() - 20;
331 const int maxHeight = r.height() - 20;
332 int width = render->renderWidth() / 2;
333 int height = render->renderHeight() / 2;
334 kDebug() << "// render info: " << width << "x" << height;
335 while (width >= maxWidth || height >= maxHeight) {
337 height = height * 0.8;
339 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
340 m_videoBox->setFixedSize(width, height);
343 //m_ui.video_frame->setMinimumSize(0, 0);
344 emit adjustMonitorSize();
347 void Monitor::resetSize()
349 m_videoBox->setMinimumSize(0, 0);
352 DocClipBase *Monitor::activeClip()
354 return m_currentClip;
357 void Monitor::updateMarkers(DocClipBase *source)
359 if (source == m_currentClip && source != NULL) {
360 m_markerMenu->clear();
361 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
362 if (!markers.isEmpty()) {
364 for (int i = 0; i < markers.count(); i++) {
365 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
367 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
368 QAction *go = m_markerMenu->addAction(position);
371 m_ruler->setMarkers(marks);
372 } else m_ruler->setMarkers(QList <int>());
373 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
377 void Monitor::slotSeekToPreviousSnap()
379 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
382 void Monitor::slotSeekToNextSnap()
384 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
387 GenTime Monitor::position()
389 return render->seekPosition();
392 GenTime Monitor::getSnapForPos(bool previous)
394 QList <GenTime> snaps;
395 QList < GenTime > markers = m_currentClip->snapMarkers();
396 for (int i = 0; i < markers.size(); ++i) {
397 GenTime t = markers.at(i);
400 QPoint zone = m_ruler->zone();
401 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
402 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
403 snaps.append(GenTime());
404 snaps.append(m_currentClip->duration());
407 const GenTime pos = render->seekPosition();
408 for (int i = 0; i < snaps.size(); ++i) {
409 if (previous && snaps.at(i) >= pos) {
411 return snaps.at(i - 1);
412 } else if (!previous && snaps.at(i) > pos) {
419 void Monitor::slotZoneMoved(int start, int end)
421 m_ruler->setZone(start, end);
423 setClipZone(m_ruler->zone());
426 void Monitor::slotSetZoneStart()
428 m_ruler->setZone(render->seekFramePosition(), -1);
429 emit zoneUpdated(m_ruler->zone());
431 setClipZone(m_ruler->zone());
434 void Monitor::slotSetZoneEnd()
436 m_ruler->setZone(-1, render->seekFramePosition());
437 emit zoneUpdated(m_ruler->zone());
439 setClipZone(m_ruler->zone());
443 void Monitor::mousePressEvent(QMouseEvent * event)
445 if (event->button() != Qt::RightButton) {
446 if (m_videoBox->underMouse()) {
447 m_dragStarted = true;
448 m_DragStartPosition = event->pos();
450 } else m_contextMenu->popup(event->globalPos());
453 void Monitor::slotSwitchFullScreen()
455 m_videoBox->switchFullScreen();
459 void Monitor::mouseReleaseEvent(QMouseEvent * event)
462 if (m_videoBox->underMouse() && (!m_effectWidget || !m_effectWidget->isVisible())) {
463 if (isActive()) slotPlay();
464 else activateMonitor();
465 } else QWidget::mouseReleaseEvent(event);
466 m_dragStarted = false;
471 void Monitor::mouseMoveEvent(QMouseEvent *event)
473 // kDebug() << "// DRAG STARTED, MOUSE MOVED: ";
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::slotMouseSeek(int eventDelta, bool fast)
538 int delta = m_monitorManager->timecode().fps();
539 if (eventDelta > 0) delta = 0 - delta;
540 slotSeek(render->seekFramePosition() - delta);
542 if (eventDelta >= 0) slotForwardOneFrame();
543 else slotRewindOneFrame();
547 void Monitor::slotSetThumbFrame()
549 if (m_currentClip == NULL) {
552 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
553 emit refreshClipThumbnail(m_currentClip->getId());
556 void Monitor::slotExtractCurrentFrame()
558 QImage frame = render->extractFrame(render->seekFramePosition());
559 KFileDialog *fs = new KFileDialog(KUrl(), "image/png", this);
560 fs->setOperationMode(KFileDialog::Saving);
561 fs->setMode(KFile::File);
562 #if KDE_IS_VERSION(4,2,0)
563 fs->setConfirmOverwrite(true);
565 fs->setKeepLocation(true);
567 QString path = fs->selectedFile();
569 if (!path.isEmpty()) {
574 bool Monitor::isActive() const
579 void Monitor::activateMonitor()
582 m_monitorManager->slotSwitchMonitors(m_name == "clip");
586 void Monitor::setTimePos(const QString &pos)
588 m_timePos->setValue(pos);
592 void Monitor::slotSeek()
594 slotSeek(m_timePos->getValue());
597 void Monitor::slotSeek(int pos)
600 if (render == NULL) return;
601 render->seekToFrame(pos);
604 void Monitor::checkOverlay()
606 if (m_overlay == NULL) return;
607 int pos = render->seekFramePosition();
608 QPoint zone = m_ruler->zone();
610 m_overlay->setOverlayText(i18n("In Point"));
611 else if (pos == zone.y())
612 m_overlay->setOverlayText(i18n("Out Point"));
615 QString markerComment = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
616 if (markerComment.isEmpty())
617 m_overlay->setHidden(true);
619 m_overlay->setOverlayText(markerComment, false);
620 } else m_overlay->setHidden(true);
624 void Monitor::slotStart()
628 render->seekToFrame(0);
631 void Monitor::slotEnd()
635 render->seekToFrame(render->getLength());
638 void Monitor::slotZoneStart()
642 render->seekToFrame(m_ruler->zone().x());
645 void Monitor::slotZoneEnd()
649 render->seekToFrame(m_ruler->zone().y());
652 void Monitor::slotRewind(double speed)
656 double currentspeed = render->playSpeed();
657 if (currentspeed >= 0) render->play(-2);
658 else render->play(currentspeed * 2);
659 } else render->play(speed);
660 //m_playAction->setChecked(true);
661 m_playAction->setIcon(m_pauseIcon);
664 void Monitor::slotForward(double speed)
668 double currentspeed = render->playSpeed();
669 if (currentspeed <= 1) render->play(2);
670 else render->play(currentspeed * 2);
671 } else render->play(speed);
672 //m_playAction->setChecked(true);
673 m_playAction->setIcon(m_pauseIcon);
676 void Monitor::slotRewindOneFrame(int diff)
680 render->seekToFrameDiff(-diff);
683 void Monitor::slotForwardOneFrame(int diff)
687 render->seekToFrameDiff(diff);
690 void Monitor::seekCursor(int pos)
693 if (m_ruler->slotNewValue(pos)) {
695 m_timePos->setValue(pos);
699 void Monitor::rendererStopped(int pos)
701 if (m_ruler->slotNewValue(pos)) {
703 m_timePos->setValue(pos);
705 disconnect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
706 //m_playAction->setChecked(false);
707 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
708 m_playAction->setIcon(m_playIcon);
711 void Monitor::adjustRulerSize(int length)
713 if (length > 0) m_length = length;
714 m_ruler->adjustScale(m_length);
715 if (m_currentClip != NULL) {
716 QPoint zone = m_currentClip->zone();
717 m_ruler->setZone(zone.x(), zone.y());
724 disconnect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
725 if (render) render->stop();
728 void Monitor::start()
731 if (render) render->start();
732 connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
735 void Monitor::refreshMonitor(bool visible)
737 if (visible && render && !m_isActive) {
739 render->doRefresh(); //askForRefresh();
743 void Monitor::refreshMonitor()
750 void Monitor::pause()
752 if (render == NULL) return;
755 //m_playAction->setChecked(true);
756 m_playAction->setIcon(m_playIcon);
759 void Monitor::slotPlay()
761 if (render == NULL) return;
763 if (render->playSpeed() == 0) {
764 //m_playAction->setChecked(true);
765 m_playAction->setIcon(m_pauseIcon);
767 //m_playAction->setChecked(false);
768 m_playAction->setIcon(m_playIcon);
770 render->switchPlay();
773 void Monitor::slotPlayZone()
775 if (render == NULL) return;
777 QPoint p = m_ruler->zone();
778 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
779 //m_playAction->setChecked(true);
780 m_playAction->setIcon(m_pauseIcon);
783 void Monitor::slotLoopZone()
785 if (render == NULL) return;
787 QPoint p = m_ruler->zone();
788 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
789 //m_playAction->setChecked(true);
790 m_playAction->setIcon(m_pauseIcon);
793 void Monitor::slotLoopClip()
795 if (render == NULL || m_selectedClip == NULL)
798 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
799 //m_playAction->setChecked(true);
800 m_playAction->setIcon(m_pauseIcon);
803 void Monitor::slotSetXml(DocClipBase *clip, QPoint zone, const int position)
805 if (render == NULL) return;
806 if (clip == NULL && m_currentClip != NULL) {
807 m_currentClip = NULL;
809 render->setProducer(NULL, -1);
812 if (m_currentClip != NULL || clip != NULL) activateMonitor();
813 if (clip != m_currentClip) {
814 m_currentClip = clip;
816 if (render->setProducer(clip->producer(), position) == -1) {
817 // MLT CONSUMER is broken
818 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
820 } else if (position != -1) render->seek(GenTime(position, m_monitorManager->timecode().fps()));
821 if (!zone.isNull()) {
822 m_ruler->setZone(zone.x(), zone.y());
823 render->seek(GenTime(zone.x(), m_monitorManager->timecode().fps()));
827 void Monitor::slotOpenFile(const QString &file)
829 if (render == NULL) return;
832 QDomElement mlt = doc.createElement("mlt");
833 doc.appendChild(mlt);
834 QDomElement prod = doc.createElement("producer");
835 mlt.appendChild(prod);
836 prod.setAttribute("mlt_service", "avformat");
837 prod.setAttribute("resource", file);
838 render->setSceneList(doc, 0);
841 void Monitor::slotSaveZone()
843 if (render == NULL) return;
844 emit saveZone(render, m_ruler->zone());
846 //render->setSceneList(doc, 0);
849 void Monitor::resetProfile(const QString profile)
851 m_timePos->updateTimeCode(m_monitorManager->timecode());
852 if (render == NULL) return;
853 render->resetProfile(profile);
855 m_effectWidget->resetProfile(render);
858 void Monitor::saveSceneList(QString path, QDomElement info)
860 if (render == NULL) return;
861 render->saveSceneList(path, info);
864 const QString Monitor::sceneList()
866 if (render == NULL) return QString();
867 return render->sceneList();
870 void Monitor::setClipZone(QPoint pos)
872 if (m_currentClip == NULL) return;
873 m_currentClip->setZone(pos);
876 void Monitor::slotSwitchDropFrames(bool show)
878 render->setDropFrames(show);
881 void Monitor::slotSwitchMonitorInfo(bool show)
883 KdenliveSettings::setDisplayMonitorInfo(show);
885 if (m_overlay) return;
886 if (m_monitorRefresh == NULL) {
887 // Using OpenGL display
888 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
889 m_overlay = new Overlay(m_glWidget);
892 m_overlay = new Overlay(m_monitorRefresh);
894 m_overlay->setHidden(true);
902 void Monitor::updateTimecodeFormat()
904 m_timePos->slotUpdateTimeCodeFormat();
907 QStringList Monitor::getZoneInfo() const
910 if (m_currentClip == NULL) return result;
911 result << m_currentClip->getId();
912 QPoint zone = m_ruler->zone();
913 result << QString::number(zone.x()) << QString::number(zone.y());
917 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
920 m_loopClipAction->setEnabled(true);
921 m_selectedClip = item;
923 m_loopClipAction->setEnabled(false);
927 void Monitor::slotSetSelectedClip(ClipItem* item)
929 if (item || (!item && !m_loopClipTransition)) {
930 m_loopClipTransition = false;
931 slotSetSelectedClip((AbstractClipItem*)item);
935 void Monitor::slotSetSelectedClip(Transition* item)
937 if (item || (!item && m_loopClipTransition)) {
938 m_loopClipTransition = true;
939 slotSetSelectedClip((AbstractClipItem*)item);
944 void Monitor::slotEffectScene(bool show)
946 if (m_name == "project") {
947 if (m_monitorRefresh) {
948 m_monitorRefresh->setVisible(!show);
950 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
951 m_glWidget->setVisible(!show);
954 m_effectWidget->setVisible(show);
955 m_effectWidget->getVisibilityAction()->setChecked(show);
956 emit requestFrameForAnalysis(show);
958 m_effectWidget->getScene()->slotZoomFit();
964 MonitorEditWidget* Monitor::getEffectEdit()
966 return m_effectWidget;
969 bool Monitor::effectSceneDisplayed()
971 return m_effectWidget->isVisible();
974 void Monitor::slotSetVolume(int volume)
976 KdenliveSettings::setVolume(volume);
978 if (volume == 0) icon = KIcon("audio-volume-muted");
979 else icon = KIcon("audio-volume-medium");
980 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
981 render->slotSetVolume(volume);
984 void Monitor::slotShowVolume()
986 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
987 int vol = render->volume();
988 // Disable widget if we cannot get the volume
989 m_volumePopup->setEnabled(vol != -1);
990 m_audioSlider->blockSignals(true);
991 m_audioSlider->setValue(vol);
992 m_audioSlider->blockSignals(false);
993 m_volumePopup->show();
996 MonitorRefresh::MonitorRefresh(QWidget* parent) :
1000 // MonitorRefresh is used as container for the SDL display (it's window id is passed to SDL)
1001 setAttribute(Qt::WA_PaintOnScreen);
1002 setAttribute(Qt::WA_OpaquePaintEvent);
1003 //setAttribute(Qt::WA_NoSystemBackground);
1006 void MonitorRefresh::setRenderer(Render* render)
1008 m_renderer = render;
1011 void MonitorRefresh::paintEvent(QPaintEvent *event)
1014 if (m_renderer) m_renderer->doRefresh();
1017 Overlay::Overlay(QWidget* parent) :
1020 setAttribute(Qt::WA_TransparentForMouseEvents);
1021 //setAttribute(Qt::WA_OpaquePaintEvent);
1022 //setAttribute(Qt::WA_NoSystemBackground);
1023 setAutoFillBackground(true);
1024 setBackgroundRole(QPalette::Base);
1027 void Overlay::setOverlayText(const QString &text, bool isZone)
1032 p.setColor(QPalette::Text, Qt::white);
1033 if (m_isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1034 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1036 setText(' ' + text + ' ');
1041 VideoContainer::VideoContainer(Monitor* parent) :
1045 setFrameShape(QFrame::NoFrame);
1046 setFocusPolicy(Qt::ClickFocus);
1047 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
1051 void VideoContainer::mousePressEvent(QMouseEvent * event)
1053 if (m_monitor->underMouse()) event->setAccepted(false);
1057 void VideoContainer::mouseReleaseEvent(QMouseEvent * event)
1059 if (m_monitor->underMouse()) event->setAccepted(false);
1061 if (m_monitor->isActive()) {
1062 m_monitor->slotPlay();
1069 void VideoContainer::mouseMoveEvent(QMouseEvent *event)
1071 if (m_monitor->underMouse()) event->setAccepted(false);
1075 void VideoContainer::keyPressEvent(QKeyEvent *event)
1077 // Exit fullscreen with Esc key
1078 if (event->key() == Qt::Key_Escape && isFullScreen()) {
1080 event->setAccepted(true);
1081 } else event->setAccepted(false);
1085 void VideoContainer::wheelEvent(QWheelEvent * event)
1087 if (m_monitor->underMouse()) event->setAccepted(false);
1089 m_monitor->slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
1094 void VideoContainer::mouseDoubleClickEvent(QMouseEvent * event)
1098 if (!KdenliveSettings::openglmonitors())
1102 void VideoContainer::switchFullScreen()
1104 // TODO: disable screensaver?
1105 Qt::WindowFlags flags = windowFlags();
1106 if (!isFullScreen()) {
1107 // Check if we ahave a multiple monitor setup
1108 setUpdatesEnabled(false);
1109 #if QT_VERSION >= 0x040600
1110 int monitors = QApplication::desktop()->screenCount();
1112 int monitors = QApplication::desktop()->numScreens();
1116 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
1117 int currentScreen = QApplication::desktop()->screenNumber(this);
1118 if (currentScreen < monitors - 1)
1119 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
1121 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
1122 move(QPoint(screenres.x(), screenres.y()));
1123 resize(screenres.width(), screenres.height());
1126 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
1127 flags |= Qt::Window;
1128 flags ^= Qt::SubWindow;
1129 setWindowFlags(flags);
1131 // This works around a bug with Compiz
1132 // as the window must be visible before we can set the state
1135 setWindowState(windowState() | Qt::WindowFullScreen); // set
1137 setWindowState(windowState() | Qt::WindowFullScreen); // set
1138 setUpdatesEnabled(true);
1142 setUpdatesEnabled(false);
1143 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
1144 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
1145 setWindowFlags(flags);
1146 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset
1147 setUpdatesEnabled(true);
1154 #include "monitor.moc"