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 "monitorscene.h"
27 #include "abstractclipitem.h"
28 #include "kdenlivesettings.h"
32 #include <KFileDialog>
33 #include <KApplication>
34 #include <KMessageBox>
36 #include <QMouseEvent>
37 #include <QStylePainter>
39 #include <QToolButton>
41 #include <QDesktopWidget>
43 #include <QIntValidator>
44 #include <QVBoxLayout>
45 #include <QGraphicsView>
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),
64 m_loopClipTransition(true)
67 QVBoxLayout *layout = new QVBoxLayout;
68 layout->setContentsMargins(0, 0, 0, 0);
69 layout->setSpacing(0);
71 // Video widget holder
72 m_videoBox = new VideoContainer(this);
73 m_videoBox->setContentsMargins(0, 0, 0, 0);
74 m_videoBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
75 layout->addWidget(m_videoBox, 10);
78 // Get base size for icons
79 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
82 layout->addWidget(m_ruler);
84 m_toolbar = new QToolBar(name, this);
85 m_toolbar->setIconSize(QSize(s, s));
87 m_playIcon = KIcon("media-playback-start");
88 m_pauseIcon = KIcon("media-playback-pause");
90 if (name != "chapter") {
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()));
94 m_ruler->setZone(-3, -2);
97 m_toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"), this, SLOT(slotRewind()));
98 //m_toolbar->addAction(KIcon("media-skip-backward"), i18n("Rewind 1 frame"), this, SLOT(slotRewindOneFrame()));
100 QToolButton *playButton = new QToolButton(m_toolbar);
101 m_playMenu = new QMenu(i18n("Play..."), this);
102 m_playAction = m_playMenu->addAction(m_playIcon, i18n("Play"));
103 //m_playAction->setCheckable(true);
104 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
106 playButton->setMenu(m_playMenu);
107 playButton->setPopupMode(QToolButton::MenuButtonPopup);
108 m_toolbar->addWidget(playButton);
110 //m_toolbar->addAction(KIcon("media-skip-forward"), i18n("Forward 1 frame"), this, SLOT(slotForwardOneFrame()));
111 m_toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"), this, SLOT(slotForward()));
113 playButton->setDefaultAction(m_playAction);
115 if (name != "chapter") {
116 QToolButton *configButton = new QToolButton(m_toolbar);
117 m_configMenu = new QMenu(i18n("Misc..."), this);
118 configButton->setIcon(KIcon("system-run"));
119 configButton->setMenu(m_configMenu);
120 configButton->setPopupMode(QToolButton::QToolButton::InstantPopup);
121 m_toolbar->addWidget(configButton);
123 if (name == "clip") {
124 m_markerMenu = new QMenu(i18n("Go to marker..."), this);
125 m_markerMenu->setEnabled(false);
126 m_configMenu->addMenu(m_markerMenu);
127 connect(m_markerMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToMarker(QAction *)));
129 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (100%)"), this, SLOT(slotSetSizeOneToOne()));
130 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (50%)"), this, SLOT(slotSetSizeOneToTwo()));
133 // Create Volume slider popup
134 m_volumePopup = new QFrame(this, Qt::Popup);
135 QVBoxLayout *poplayout = new QVBoxLayout;
136 poplayout->setContentsMargins(0, 0, 0, 0);
137 m_audioSlider = new QSlider(Qt::Vertical);
138 m_audioSlider->setRange(0, 100);
139 poplayout->addWidget(m_audioSlider);
140 m_volumePopup->setLayout(poplayout);
142 if (KdenliveSettings::volume() == 0) icon = KIcon("audio-volume-muted");
143 else icon = KIcon("audio-volume-medium");
145 m_volumeWidget = m_toolbar->widgetForAction(m_toolbar->addAction(icon, i18n("Audio volume"), this, SLOT(slotShowVolume())));
147 // we need to show / hide the popup once so that it's geometry can be calculated in slotShowVolume
148 m_volumePopup->show();
149 m_volumePopup->hide();
151 QWidget *spacer = new QWidget(this);
152 spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
153 m_toolbar->addWidget(spacer);
154 m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this);
155 m_toolbar->addWidget(m_timePos);
156 connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotSeek()));
157 m_toolbar->setMaximumHeight(s * 1.5);
158 layout->addWidget(m_toolbar);
160 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
162 setMinimumHeight(200);
164 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
166 bool monitorCreated = false;
168 createOpenGlWidget(m_videoBox, profile);
169 monitorCreated = true;
170 //m_glWidget->setFixedSize(width, height);
171 #elif defined (USE_OPEN_GL)
172 if (KdenliveSettings::openglmonitors()) {
173 monitorCreated = createOpenGlWidget(m_videoBox, profile);
176 QVBoxLayout *lay = new QVBoxLayout;
177 lay->setContentsMargins(0, 0, 0, 0);
178 if (!monitorCreated) {
179 m_monitorRefresh = new MonitorRefresh;
180 lay->addWidget(m_monitorRefresh);
181 m_videoBox->setLayout(lay);
182 render = new Render(m_name, (int) m_monitorRefresh->winId(), profile, this);
183 m_monitorRefresh->setRenderer(render);
186 connect(m_audioSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetVolume(int)));
187 connect(m_ruler, SIGNAL(seekRenderer(int)), this, SLOT(slotSeek(int)));
188 connect(render, SIGNAL(durationChanged(int)), this, SLOT(adjustRulerSize(int)));
189 connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int)));
191 //render->createVideoXWindow(m_ui.video_frame->winId(), -1);
193 if (name != "clip") {
194 connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int)));
195 connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int)));
196 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SIGNAL(zoneUpdated(QPoint)));
198 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SLOT(setClipZone(QPoint)));
201 if (m_monitorRefresh) m_monitorRefresh->show();
203 if (name == "project") {
204 m_effectScene = new MonitorScene(render);
205 m_effectView = new QGraphicsView(m_effectScene, m_videoBox);
206 lay->addWidget(m_effectView);
207 m_effectView->setRenderHints(QFlags<QPainter::RenderHint>());
208 m_effectView->scale(((double) render->renderWidth()) / render->frameRenderWidth(), 1.0);
209 m_effectView->setMouseTracking(true);
210 m_effectScene->setUp();
211 m_effectView->hide();
220 if (m_name == "project") {
222 delete m_effectScene;
224 delete m_monitorRefresh;
228 QWidget *Monitor::container()
233 QString Monitor::name() const
238 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
239 bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile)
241 render = new Render(m_name, 0, profile, this);
242 m_glWidget = new VideoGLWidget(parent);
243 if (m_glWidget == NULL) {
244 // Creation failed, we are in trouble...
247 m_glWidget->setImageAspectRatio(render->dar());
248 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
249 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
254 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
256 m_contextMenu = new QMenu(this);
257 m_contextMenu->addMenu(m_playMenu);
259 m_contextMenu->addMenu(goMenu);
261 m_contextMenu->addMenu(markerMenu);
263 m_playMenu->addAction(playZone);
264 m_playMenu->addAction(loopZone);
266 m_loopClipAction = loopClip;
267 m_playMenu->addAction(loopClip);
270 //TODO: add save zone to timeline monitor when fixed
271 if (m_name == "clip") {
272 m_contextMenu->addMenu(m_markerMenu);
273 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
275 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
276 m_contextMenu->addAction(extractFrame);
278 if (m_name != "clip") {
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 m_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 m_videoBox->setFixedSize(width, height);
344 //m_ui.video_frame->setMinimumSize(0, 0);
345 emit adjustMonitorSize();
348 void Monitor::resetSize()
350 m_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);
372 m_ruler->setMarkers(marks);
373 } else m_ruler->setMarkers(QList <int>());
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);
424 setClipZone(m_ruler->zone());
427 void Monitor::slotSetZoneStart()
429 m_ruler->setZone(render->seekFramePosition(), -1);
430 emit zoneUpdated(m_ruler->zone());
432 setClipZone(m_ruler->zone());
435 void Monitor::slotSetZoneEnd()
437 m_ruler->setZone(-1, render->seekFramePosition());
438 emit zoneUpdated(m_ruler->zone());
440 setClipZone(m_ruler->zone());
444 void Monitor::mousePressEvent(QMouseEvent * event)
446 if (event->button() != Qt::RightButton) {
447 if (m_videoBox->underMouse()) {
448 m_dragStarted = true;
449 m_DragStartPosition = event->pos();
451 } else m_contextMenu->popup(event->globalPos());
454 void Monitor::slotSwitchFullScreen()
456 m_videoBox->switchFullScreen();
460 void Monitor::mouseReleaseEvent(QMouseEvent * event)
463 if (m_videoBox->underMouse() && (!m_effectView || !m_effectView->isVisible())) {
464 if (isActive()) slotPlay();
465 else activateMonitor();
466 } else QWidget::mouseReleaseEvent(event);
467 m_dragStarted = false;
472 void Monitor::mouseMoveEvent(QMouseEvent *event)
474 // kDebug() << "// DRAG STARTED, MOUSE MOVED: ";
475 if (!m_dragStarted || m_currentClip == NULL) return;
477 if ((event->pos() - m_DragStartPosition).manhattanLength()
478 < QApplication::startDragDistance())
482 QDrag *drag = new QDrag(this);
483 QMimeData *mimeData = new QMimeData;
486 list.append(m_currentClip->getId());
487 QPoint p = m_ruler->zone();
488 list.append(QString::number(p.x()));
489 list.append(QString::number(p.y()));
491 data.append(list.join(";").toUtf8());
492 mimeData->setData("kdenlive/clip", data);
493 drag->setMimeData(mimeData);
494 QPixmap pix = m_currentClip->thumbnail();
495 drag->setPixmap(pix);
496 drag->setHotSpot(QPoint(0, 50));
497 drag->start(Qt::MoveAction);
499 //Qt::DropAction dropAction;
500 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
502 //Qt::DropAction dropAction = drag->exec();
508 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
509 event->setDropAction(Qt::IgnoreAction);
510 event->setDropAction(Qt::MoveAction);
511 if (event->mimeData()->hasText()) {
512 event->acceptProposedAction();
516 Qt::DropActions Monitor::supportedDropActions() const {
517 // returns what actions are supported when dropping
518 return Qt::MoveAction;
521 QStringList Monitor::mimeTypes() const
523 QStringList qstrList;
524 // list of accepted mime types for drop
525 qstrList.append("kdenlive/clip");
530 void Monitor::wheelEvent(QWheelEvent * event)
532 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
536 void Monitor::slotMouseSeek(int eventDelta, bool fast)
539 int delta = m_monitorManager->timecode().fps();
540 if (eventDelta > 0) delta = 0 - delta;
541 slotSeek(render->seekFramePosition() - delta);
543 if (eventDelta >= 0) slotForwardOneFrame();
544 else slotRewindOneFrame();
548 void Monitor::slotSetThumbFrame()
550 if (m_currentClip == NULL) {
553 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
554 emit refreshClipThumbnail(m_currentClip->getId());
557 void Monitor::slotExtractCurrentFrame()
559 QImage frame = render->extractFrame(render->seekFramePosition());
560 KFileDialog *fs = new KFileDialog(KUrl(), "image/png", this);
561 fs->setOperationMode(KFileDialog::Saving);
562 fs->setMode(KFile::File);
563 #if KDE_IS_VERSION(4,2,0)
564 fs->setConfirmOverwrite(true);
566 fs->setKeepLocation(true);
568 QString path = fs->selectedFile();
570 if (!path.isEmpty()) {
575 bool Monitor::isActive() const
580 void Monitor::activateMonitor()
583 m_monitorManager->slotSwitchMonitors(m_name == "clip");
587 void Monitor::setTimePos(const QString &pos)
589 m_timePos->setValue(pos);
593 void Monitor::slotSeek()
595 slotSeek(m_timePos->getValue());
598 void Monitor::slotSeek(int pos)
601 if (render == NULL) return;
602 render->seekToFrame(pos);
605 void Monitor::checkOverlay()
607 if (m_overlay == NULL) return;
608 int pos = render->seekFramePosition();
609 QPoint zone = m_ruler->zone();
611 m_overlay->setOverlayText(i18n("In Point"));
612 else if (pos == zone.y())
613 m_overlay->setOverlayText(i18n("Out Point"));
616 QString markerComment = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
617 if (markerComment.isEmpty())
618 m_overlay->setHidden(true);
620 m_overlay->setOverlayText(markerComment, false);
621 } else m_overlay->setHidden(true);
625 void Monitor::slotStart()
629 render->seekToFrame(0);
632 void Monitor::slotEnd()
636 render->seekToFrame(render->getLength());
639 void Monitor::slotZoneStart()
643 render->seekToFrame(m_ruler->zone().x());
646 void Monitor::slotZoneEnd()
650 render->seekToFrame(m_ruler->zone().y());
653 void Monitor::slotRewind(double speed)
657 double currentspeed = render->playSpeed();
658 if (currentspeed >= 0) render->play(-2);
659 else render->play(currentspeed * 2);
660 } else render->play(speed);
661 //m_playAction->setChecked(true);
662 m_playAction->setIcon(m_pauseIcon);
665 void Monitor::slotForward(double speed)
669 double currentspeed = render->playSpeed();
670 if (currentspeed <= 1) render->play(2);
671 else render->play(currentspeed * 2);
672 } else render->play(speed);
673 //m_playAction->setChecked(true);
674 m_playAction->setIcon(m_pauseIcon);
677 void Monitor::slotRewindOneFrame(int diff)
681 render->seekToFrameDiff(-diff);
684 void Monitor::slotForwardOneFrame(int diff)
688 render->seekToFrameDiff(diff);
691 void Monitor::seekCursor(int pos)
694 if (m_ruler->slotNewValue(pos)) {
696 m_timePos->setValue(pos);
700 void Monitor::rendererStopped(int pos)
702 if (m_ruler->slotNewValue(pos)) {
704 m_timePos->setValue(pos);
706 disconnect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
707 //m_playAction->setChecked(false);
708 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
709 m_playAction->setIcon(m_playIcon);
712 void Monitor::adjustRulerSize(int length)
714 if (length > 0) m_length = length;
715 m_ruler->adjustScale(m_length);
716 if (m_currentClip != NULL) {
717 QPoint zone = m_currentClip->zone();
718 m_ruler->setZone(zone.x(), zone.y());
725 disconnect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
726 if (render) render->stop();
729 void Monitor::start()
732 if (render) render->start();
733 connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
736 void Monitor::refreshMonitor(bool visible)
738 if (visible && render && !m_isActive) {
740 render->doRefresh(); //askForRefresh();
744 void Monitor::refreshMonitor()
751 void Monitor::pause()
753 if (render == NULL) return;
756 //m_playAction->setChecked(true);
757 m_playAction->setIcon(m_playIcon);
760 void Monitor::slotPlay()
762 if (render == NULL) return;
764 if (render->playSpeed() == 0) {
765 //m_playAction->setChecked(true);
766 m_playAction->setIcon(m_pauseIcon);
768 //m_playAction->setChecked(false);
769 m_playAction->setIcon(m_playIcon);
771 render->switchPlay();
774 void Monitor::slotPlayZone()
776 if (render == NULL) return;
778 QPoint p = m_ruler->zone();
779 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
780 //m_playAction->setChecked(true);
781 m_playAction->setIcon(m_pauseIcon);
784 void Monitor::slotLoopZone()
786 if (render == NULL) return;
788 QPoint p = m_ruler->zone();
789 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
790 //m_playAction->setChecked(true);
791 m_playAction->setIcon(m_pauseIcon);
794 void Monitor::slotLoopClip()
796 if (render == NULL || m_selectedClip == NULL)
799 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
800 //m_playAction->setChecked(true);
801 m_playAction->setIcon(m_pauseIcon);
804 void Monitor::slotSetXml(DocClipBase *clip, QPoint zone, const int position)
806 if (render == NULL) return;
807 if (clip == NULL && m_currentClip != NULL) {
808 m_currentClip = NULL;
810 render->setProducer(NULL, -1);
813 if (m_currentClip != NULL || clip != NULL) activateMonitor();
814 if (clip != m_currentClip) {
815 m_currentClip = clip;
817 if (render->setProducer(clip->producer(), position) == -1) {
818 // MLT CONSUMER is broken
819 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
821 } else if (position != -1) render->seek(GenTime(position, m_monitorManager->timecode().fps()));
822 if (!zone.isNull()) {
823 m_ruler->setZone(zone.x(), zone.y());
824 render->seek(GenTime(zone.x(), m_monitorManager->timecode().fps()));
828 void Monitor::slotOpenFile(const QString &file)
830 if (render == NULL) return;
833 QDomElement mlt = doc.createElement("mlt");
834 doc.appendChild(mlt);
835 QDomElement prod = doc.createElement("producer");
836 mlt.appendChild(prod);
837 prod.setAttribute("mlt_service", "avformat");
838 prod.setAttribute("resource", file);
839 render->setSceneList(doc, 0);
842 void Monitor::slotSaveZone()
844 if (render == NULL) return;
845 emit saveZone(render, m_ruler->zone());
847 //render->setSceneList(doc, 0);
850 void Monitor::resetProfile(const QString profile)
852 m_timePos->updateTimeCode(m_monitorManager->timecode());
853 if (render == NULL) return;
854 render->resetProfile(profile);
856 m_effectView->scale(((double) render->renderWidth()) / render->frameRenderWidth(), 1.0);
857 m_effectScene->resetProfile();
861 void Monitor::saveSceneList(QString path, QDomElement info)
863 if (render == NULL) return;
864 render->saveSceneList(path, info);
867 const QString Monitor::sceneList()
869 if (render == NULL) return QString();
870 return render->sceneList();
873 void Monitor::setClipZone(QPoint pos)
875 if (m_currentClip == NULL) return;
876 m_currentClip->setZone(pos);
879 void Monitor::slotSwitchDropFrames(bool show)
881 render->setDropFrames(show);
884 void Monitor::slotSwitchMonitorInfo(bool show)
886 KdenliveSettings::setDisplayMonitorInfo(show);
888 if (m_overlay) return;
889 if (m_monitorRefresh == NULL) {
890 // Using OpenGL display
891 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
892 m_overlay = new Overlay(m_glWidget);
895 m_overlay = new Overlay(m_monitorRefresh);
897 m_overlay->setHidden(true);
905 void Monitor::updateTimecodeFormat()
907 m_timePos->slotUpdateTimeCodeFormat();
910 QStringList Monitor::getZoneInfo() const
913 if (m_currentClip == NULL) return result;
914 result << m_currentClip->getId();
915 QPoint zone = m_ruler->zone();
916 result << QString::number(zone.x()) << QString::number(zone.y());
920 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
923 m_loopClipAction->setEnabled(true);
924 m_selectedClip = item;
926 m_loopClipAction->setEnabled(false);
930 void Monitor::slotSetSelectedClip(ClipItem* item)
932 if (item || (!item && !m_loopClipTransition)) {
933 m_loopClipTransition = false;
934 slotSetSelectedClip((AbstractClipItem*)item);
938 void Monitor::slotSetSelectedClip(Transition* item)
940 if (item || (!item && m_loopClipTransition)) {
941 m_loopClipTransition = true;
942 slotSetSelectedClip((AbstractClipItem*)item);
947 void Monitor::slotEffectScene(bool show)
949 if (m_name == "project") {
950 if (m_monitorRefresh) {
951 m_monitorRefresh->setVisible(!show);
953 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
954 m_glWidget->setVisible(!show);
957 m_effectView->setVisible(show);
958 emit requestFrameForAnalysis(show);
961 m_effectScene->slotZoomFit();
966 MonitorScene * Monitor::getEffectScene()
968 return m_effectScene;
971 bool Monitor::effectSceneDisplayed()
973 return m_effectView->isVisible();
976 void Monitor::slotSetVolume(int volume)
978 KdenliveSettings::setVolume(volume);
980 if (volume == 0) icon = KIcon("audio-volume-muted");
981 else icon = KIcon("audio-volume-medium");
982 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
983 render->slotSetVolume(volume);
986 void Monitor::slotShowVolume()
988 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
989 int vol = render->volume();
990 // Disable widget if we cannot get the volume
991 m_volumePopup->setEnabled(vol != -1);
992 m_audioSlider->blockSignals(true);
993 m_audioSlider->setValue(vol);
994 m_audioSlider->blockSignals(false);
995 m_volumePopup->show();
998 MonitorRefresh::MonitorRefresh(QWidget* parent) :
1002 // MonitorRefresh is used as container for the SDL display (it's window id is passed to SDL)
1003 setAttribute(Qt::WA_PaintOnScreen);
1004 setAttribute(Qt::WA_OpaquePaintEvent);
1005 //setAttribute(Qt::WA_NoSystemBackground);
1008 void MonitorRefresh::setRenderer(Render* render)
1010 m_renderer = render;
1013 void MonitorRefresh::paintEvent(QPaintEvent *event)
1016 if (m_renderer) m_renderer->doRefresh();
1019 Overlay::Overlay(QWidget* parent) :
1022 setAttribute(Qt::WA_TransparentForMouseEvents);
1023 //setAttribute(Qt::WA_OpaquePaintEvent);
1024 //setAttribute(Qt::WA_NoSystemBackground);
1025 setAutoFillBackground(true);
1026 setBackgroundRole(QPalette::Base);
1029 void Overlay::setOverlayText(const QString &text, bool isZone)
1034 p.setColor(QPalette::Text, Qt::white);
1035 if (m_isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1036 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1038 setText(' ' + text + ' ');
1043 VideoContainer::VideoContainer(Monitor* parent) :
1047 setFrameShape(QFrame::NoFrame);
1048 setFocusPolicy(Qt::ClickFocus);
1049 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
1053 void VideoContainer::mousePressEvent(QMouseEvent * event)
1055 if (m_monitor->underMouse()) event->setAccepted(false);
1059 void VideoContainer::mouseReleaseEvent(QMouseEvent * event)
1061 if (m_monitor->underMouse()) event->setAccepted(false);
1063 if (m_monitor->isActive()) {
1064 m_monitor->slotPlay();
1071 void VideoContainer::mouseMoveEvent(QMouseEvent *event)
1073 if (m_monitor->underMouse()) event->setAccepted(false);
1077 void VideoContainer::keyPressEvent(QKeyEvent *event)
1079 // Exit fullscreen with Esc key
1080 if (event->key() == Qt::Key_Escape && isFullScreen()) {
1082 event->setAccepted(true);
1083 } else event->setAccepted(false);
1087 void VideoContainer::wheelEvent(QWheelEvent * event)
1089 if (m_monitor->underMouse()) event->setAccepted(false);
1091 m_monitor->slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
1096 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"