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);
185 #if defined (USE_OPEN_GL)
186 else if (m_glWidget) {
187 lay->addWidget(m_glWidget);
188 m_videoBox->setLayout(lay);
192 connect(m_audioSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetVolume(int)));
193 connect(m_ruler, SIGNAL(seekRenderer(int)), this, SLOT(slotSeek(int)));
194 connect(render, SIGNAL(durationChanged(int)), this, SLOT(adjustRulerSize(int)));
195 connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int)));
197 //render->createVideoXWindow(m_ui.video_frame->winId(), -1);
199 if (name != "clip") {
200 connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int)));
201 connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int)));
202 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SIGNAL(zoneUpdated(QPoint)));
204 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SLOT(setClipZone(QPoint)));
207 if (m_monitorRefresh) m_monitorRefresh->show();
209 if (name == "project") {
210 m_effectScene = new MonitorScene(render);
211 m_effectView = new QGraphicsView(m_effectScene, m_videoBox);
212 lay->addWidget(m_effectView);
213 m_effectView->setRenderHints(QFlags<QPainter::RenderHint>());
214 m_effectView->scale(((double) render->renderWidth()) / render->frameRenderWidth(), 1.0);
215 m_effectView->setMouseTracking(true);
216 m_effectScene->setUp();
217 m_effectView->hide();
226 if (m_name == "project") {
228 delete m_effectScene;
230 delete m_monitorRefresh;
234 QWidget *Monitor::container()
239 QString Monitor::name() const
244 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
245 bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile)
247 render = new Render(m_name, 0, profile, this);
248 m_glWidget = new VideoGLWidget(parent);
249 if (m_glWidget == NULL) {
250 // Creation failed, we are in trouble...
253 m_glWidget->setImageAspectRatio(render->dar());
254 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
255 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
260 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
262 m_contextMenu = new QMenu(this);
263 m_contextMenu->addMenu(m_playMenu);
265 m_contextMenu->addMenu(goMenu);
267 m_contextMenu->addMenu(markerMenu);
269 m_playMenu->addAction(playZone);
270 m_playMenu->addAction(loopZone);
272 m_loopClipAction = loopClip;
273 m_playMenu->addAction(loopClip);
276 //TODO: add save zone to timeline monitor when fixed
277 if (m_name == "clip") {
278 m_contextMenu->addMenu(m_markerMenu);
279 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
281 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
282 m_contextMenu->addAction(extractFrame);
284 if (m_name != "clip") {
285 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
286 splitView->setCheckable(true);
287 m_configMenu->addAction(splitView);
289 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
290 m_configMenu->addAction(setThumbFrame);
293 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
294 showTips->setCheckable(true);
295 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
296 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
298 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
299 dropFrames->setCheckable(true);
300 dropFrames->setChecked(true);
301 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
303 m_configMenu->addAction(showTips);
304 m_configMenu->addAction(dropFrames);
308 void Monitor::slotGoToMarker(QAction *action)
310 int pos = action->data().toInt();
314 void Monitor::slotSetSizeOneToOne()
316 QRect r = QApplication::desktop()->screenGeometry();
317 const int maxWidth = r.width() - 20;
318 const int maxHeight = r.height() - 20;
319 int width = render->renderWidth();
320 int height = render->renderHeight();
321 kDebug() << "// render info: " << width << "x" << height;
322 while (width >= maxWidth || height >= maxHeight) {
324 height = height * 0.8;
326 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
327 m_videoBox->setFixedSize(width, height);
330 //m_ui.video_frame->setMinimumSize(0, 0);
331 emit adjustMonitorSize();
334 void Monitor::slotSetSizeOneToTwo()
336 QRect r = QApplication::desktop()->screenGeometry();
337 const int maxWidth = r.width() - 20;
338 const int maxHeight = r.height() - 20;
339 int width = render->renderWidth() / 2;
340 int height = render->renderHeight() / 2;
341 kDebug() << "// render info: " << width << "x" << height;
342 while (width >= maxWidth || height >= maxHeight) {
344 height = height * 0.8;
346 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
347 m_videoBox->setFixedSize(width, height);
350 //m_ui.video_frame->setMinimumSize(0, 0);
351 emit adjustMonitorSize();
354 void Monitor::resetSize()
356 m_videoBox->setMinimumSize(0, 0);
359 DocClipBase *Monitor::activeClip()
361 return m_currentClip;
364 void Monitor::updateMarkers(DocClipBase *source)
366 if (source == m_currentClip && source != NULL) {
367 m_markerMenu->clear();
368 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
369 if (!markers.isEmpty()) {
371 for (int i = 0; i < markers.count(); i++) {
372 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
374 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
375 QAction *go = m_markerMenu->addAction(position);
378 m_ruler->setMarkers(marks);
379 } else m_ruler->setMarkers(QList <int>());
380 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
384 void Monitor::slotSeekToPreviousSnap()
386 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
389 void Monitor::slotSeekToNextSnap()
391 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
394 GenTime Monitor::position()
396 return render->seekPosition();
399 GenTime Monitor::getSnapForPos(bool previous)
401 QList <GenTime> snaps;
402 QList < GenTime > markers = m_currentClip->snapMarkers();
403 for (int i = 0; i < markers.size(); ++i) {
404 GenTime t = markers.at(i);
407 QPoint zone = m_ruler->zone();
408 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
409 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
410 snaps.append(GenTime());
411 snaps.append(m_currentClip->duration());
414 const GenTime pos = render->seekPosition();
415 for (int i = 0; i < snaps.size(); ++i) {
416 if (previous && snaps.at(i) >= pos) {
418 return snaps.at(i - 1);
419 } else if (!previous && snaps.at(i) > pos) {
426 void Monitor::slotZoneMoved(int start, int end)
428 m_ruler->setZone(start, end);
430 setClipZone(m_ruler->zone());
433 void Monitor::slotSetZoneStart()
435 m_ruler->setZone(render->seekFramePosition(), -1);
436 emit zoneUpdated(m_ruler->zone());
438 setClipZone(m_ruler->zone());
441 void Monitor::slotSetZoneEnd()
443 m_ruler->setZone(-1, render->seekFramePosition());
444 emit zoneUpdated(m_ruler->zone());
446 setClipZone(m_ruler->zone());
450 void Monitor::mousePressEvent(QMouseEvent * event)
452 if (event->button() != Qt::RightButton) {
453 if (m_videoBox->underMouse()) {
454 m_dragStarted = true;
455 m_DragStartPosition = event->pos();
457 } else m_contextMenu->popup(event->globalPos());
460 void Monitor::slotSwitchFullScreen()
462 m_videoBox->switchFullScreen();
466 void Monitor::mouseReleaseEvent(QMouseEvent * event)
469 if (m_videoBox->underMouse() && (!m_effectView || !m_effectView->isVisible())) {
470 if (isActive()) slotPlay();
471 else activateMonitor();
472 } else QWidget::mouseReleaseEvent(event);
473 m_dragStarted = false;
478 void Monitor::mouseMoveEvent(QMouseEvent *event)
480 // kDebug() << "// DRAG STARTED, MOUSE MOVED: ";
481 if (!m_dragStarted || m_currentClip == NULL) return;
483 if ((event->pos() - m_DragStartPosition).manhattanLength()
484 < QApplication::startDragDistance())
488 QDrag *drag = new QDrag(this);
489 QMimeData *mimeData = new QMimeData;
492 list.append(m_currentClip->getId());
493 QPoint p = m_ruler->zone();
494 list.append(QString::number(p.x()));
495 list.append(QString::number(p.y()));
497 data.append(list.join(";").toUtf8());
498 mimeData->setData("kdenlive/clip", data);
499 drag->setMimeData(mimeData);
500 QPixmap pix = m_currentClip->thumbnail();
501 drag->setPixmap(pix);
502 drag->setHotSpot(QPoint(0, 50));
503 drag->start(Qt::MoveAction);
505 //Qt::DropAction dropAction;
506 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
508 //Qt::DropAction dropAction = drag->exec();
514 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
515 event->setDropAction(Qt::IgnoreAction);
516 event->setDropAction(Qt::MoveAction);
517 if (event->mimeData()->hasText()) {
518 event->acceptProposedAction();
522 Qt::DropActions Monitor::supportedDropActions() const {
523 // returns what actions are supported when dropping
524 return Qt::MoveAction;
527 QStringList Monitor::mimeTypes() const
529 QStringList qstrList;
530 // list of accepted mime types for drop
531 qstrList.append("kdenlive/clip");
536 void Monitor::wheelEvent(QWheelEvent * event)
538 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
542 void Monitor::slotMouseSeek(int eventDelta, bool fast)
545 int delta = m_monitorManager->timecode().fps();
546 if (eventDelta > 0) delta = 0 - delta;
547 slotSeek(render->seekFramePosition() - delta);
549 if (eventDelta >= 0) slotForwardOneFrame();
550 else slotRewindOneFrame();
554 void Monitor::slotSetThumbFrame()
556 if (m_currentClip == NULL) {
559 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
560 emit refreshClipThumbnail(m_currentClip->getId());
563 void Monitor::slotExtractCurrentFrame()
565 QImage frame = render->extractFrame(render->seekFramePosition());
566 KFileDialog *fs = new KFileDialog(KUrl(), "image/png", this);
567 fs->setOperationMode(KFileDialog::Saving);
568 fs->setMode(KFile::File);
569 #if KDE_IS_VERSION(4,2,0)
570 fs->setConfirmOverwrite(true);
572 fs->setKeepLocation(true);
574 QString path = fs->selectedFile();
576 if (!path.isEmpty()) {
581 bool Monitor::isActive() const
586 void Monitor::activateMonitor()
589 m_monitorManager->slotSwitchMonitors(m_name == "clip");
593 void Monitor::setTimePos(const QString &pos)
595 m_timePos->setValue(pos);
599 void Monitor::slotSeek()
601 slotSeek(m_timePos->getValue());
604 void Monitor::slotSeek(int pos)
607 if (render == NULL) return;
608 render->seekToFrame(pos);
611 void Monitor::checkOverlay()
613 if (m_overlay == NULL) return;
614 int pos = render->seekFramePosition();
615 QPoint zone = m_ruler->zone();
617 m_overlay->setOverlayText(i18n("In Point"));
618 else if (pos == zone.y())
619 m_overlay->setOverlayText(i18n("Out Point"));
622 QString markerComment = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
623 if (markerComment.isEmpty())
624 m_overlay->setHidden(true);
626 m_overlay->setOverlayText(markerComment, false);
627 } else m_overlay->setHidden(true);
631 void Monitor::slotStart()
635 render->seekToFrame(0);
638 void Monitor::slotEnd()
642 render->seekToFrame(render->getLength());
645 void Monitor::slotZoneStart()
649 render->seekToFrame(m_ruler->zone().x());
652 void Monitor::slotZoneEnd()
656 render->seekToFrame(m_ruler->zone().y());
659 void Monitor::slotRewind(double speed)
663 double currentspeed = render->playSpeed();
664 if (currentspeed >= 0) render->play(-2);
665 else render->play(currentspeed * 2);
666 } else render->play(speed);
667 //m_playAction->setChecked(true);
668 m_playAction->setIcon(m_pauseIcon);
671 void Monitor::slotForward(double speed)
675 double currentspeed = render->playSpeed();
676 if (currentspeed <= 1) render->play(2);
677 else render->play(currentspeed * 2);
678 } else render->play(speed);
679 //m_playAction->setChecked(true);
680 m_playAction->setIcon(m_pauseIcon);
683 void Monitor::slotRewindOneFrame(int diff)
687 render->seekToFrameDiff(-diff);
690 void Monitor::slotForwardOneFrame(int diff)
694 render->seekToFrameDiff(diff);
697 void Monitor::seekCursor(int pos)
700 if (m_ruler->slotNewValue(pos)) {
702 m_timePos->setValue(pos);
706 void Monitor::rendererStopped(int pos)
708 if (m_ruler->slotNewValue(pos)) {
710 m_timePos->setValue(pos);
712 disconnect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
713 //m_playAction->setChecked(false);
714 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
715 m_playAction->setIcon(m_playIcon);
718 void Monitor::adjustRulerSize(int length)
720 if (length > 0) m_length = length;
721 m_ruler->adjustScale(m_length);
722 if (m_currentClip != NULL) {
723 QPoint zone = m_currentClip->zone();
724 m_ruler->setZone(zone.x(), zone.y());
731 disconnect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
732 if (render) render->stop();
735 void Monitor::start()
738 if (render) render->start();
739 connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
742 void Monitor::refreshMonitor(bool visible)
744 if (visible && render && !m_isActive) {
746 render->doRefresh(); //askForRefresh();
750 void Monitor::refreshMonitor()
757 void Monitor::pause()
759 if (render == NULL) return;
762 //m_playAction->setChecked(true);
763 m_playAction->setIcon(m_playIcon);
766 void Monitor::slotPlay()
768 if (render == NULL) return;
770 if (render->playSpeed() == 0) {
771 //m_playAction->setChecked(true);
772 m_playAction->setIcon(m_pauseIcon);
774 //m_playAction->setChecked(false);
775 m_playAction->setIcon(m_playIcon);
777 render->switchPlay();
780 void Monitor::slotPlayZone()
782 if (render == NULL) return;
784 QPoint p = m_ruler->zone();
785 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
786 //m_playAction->setChecked(true);
787 m_playAction->setIcon(m_pauseIcon);
790 void Monitor::slotLoopZone()
792 if (render == NULL) return;
794 QPoint p = m_ruler->zone();
795 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
796 //m_playAction->setChecked(true);
797 m_playAction->setIcon(m_pauseIcon);
800 void Monitor::slotLoopClip()
802 if (render == NULL || m_selectedClip == NULL)
805 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
806 //m_playAction->setChecked(true);
807 m_playAction->setIcon(m_pauseIcon);
810 void Monitor::slotSetXml(DocClipBase *clip, QPoint zone, const int position)
812 if (render == NULL) return;
813 if (clip == NULL && m_currentClip != NULL) {
814 m_currentClip = NULL;
816 render->setProducer(NULL, -1);
819 if (m_currentClip != NULL || clip != NULL) activateMonitor();
820 if (clip != m_currentClip) {
821 m_currentClip = clip;
823 if (render->setProducer(clip->producer(), position) == -1) {
824 // MLT CONSUMER is broken
825 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
827 } else if (position != -1) render->seek(GenTime(position, m_monitorManager->timecode().fps()));
828 if (!zone.isNull()) {
829 m_ruler->setZone(zone.x(), zone.y());
830 render->seek(GenTime(zone.x(), m_monitorManager->timecode().fps()));
834 void Monitor::slotOpenFile(const QString &file)
836 if (render == NULL) return;
839 QDomElement mlt = doc.createElement("mlt");
840 doc.appendChild(mlt);
841 QDomElement prod = doc.createElement("producer");
842 mlt.appendChild(prod);
843 prod.setAttribute("mlt_service", "avformat");
844 prod.setAttribute("resource", file);
845 render->setSceneList(doc, 0);
848 void Monitor::slotSaveZone()
850 if (render == NULL) return;
851 emit saveZone(render, m_ruler->zone());
853 //render->setSceneList(doc, 0);
856 void Monitor::resetProfile(const QString profile)
858 m_timePos->updateTimeCode(m_monitorManager->timecode());
859 if (render == NULL) return;
860 render->resetProfile(profile);
862 m_effectView->scale(((double) render->renderWidth()) / render->frameRenderWidth(), 1.0);
863 m_effectScene->resetProfile();
867 void Monitor::saveSceneList(QString path, QDomElement info)
869 if (render == NULL) return;
870 render->saveSceneList(path, info);
873 const QString Monitor::sceneList()
875 if (render == NULL) return QString();
876 return render->sceneList();
879 void Monitor::setClipZone(QPoint pos)
881 if (m_currentClip == NULL) return;
882 m_currentClip->setZone(pos);
885 void Monitor::slotSwitchDropFrames(bool show)
887 render->setDropFrames(show);
890 void Monitor::slotSwitchMonitorInfo(bool show)
892 KdenliveSettings::setDisplayMonitorInfo(show);
894 if (m_overlay) return;
895 if (m_monitorRefresh == NULL) {
896 // Using OpenGL display
897 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
898 m_overlay = new Overlay(m_glWidget);
901 m_overlay = new Overlay(m_monitorRefresh);
903 m_overlay->setHidden(true);
911 void Monitor::updateTimecodeFormat()
913 m_timePos->slotUpdateTimeCodeFormat();
916 QStringList Monitor::getZoneInfo() const
919 if (m_currentClip == NULL) return result;
920 result << m_currentClip->getId();
921 QPoint zone = m_ruler->zone();
922 result << QString::number(zone.x()) << QString::number(zone.y());
926 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
929 m_loopClipAction->setEnabled(true);
930 m_selectedClip = item;
932 m_loopClipAction->setEnabled(false);
936 void Monitor::slotSetSelectedClip(ClipItem* item)
938 if (item || (!item && !m_loopClipTransition)) {
939 m_loopClipTransition = false;
940 slotSetSelectedClip((AbstractClipItem*)item);
944 void Monitor::slotSetSelectedClip(Transition* item)
946 if (item || (!item && m_loopClipTransition)) {
947 m_loopClipTransition = true;
948 slotSetSelectedClip((AbstractClipItem*)item);
953 void Monitor::slotEffectScene(bool show)
955 if (m_name == "project") {
956 if (m_monitorRefresh) {
957 m_monitorRefresh->setVisible(!show);
959 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
960 m_glWidget->setVisible(!show);
963 m_effectView->setVisible(show);
964 emit requestFrameForAnalysis(show);
967 m_effectScene->slotZoomFit();
972 MonitorScene * Monitor::getEffectScene()
974 return m_effectScene;
977 bool Monitor::effectSceneDisplayed()
979 return m_effectView->isVisible();
982 void Monitor::slotSetVolume(int volume)
984 KdenliveSettings::setVolume(volume);
986 if (volume == 0) icon = KIcon("audio-volume-muted");
987 else icon = KIcon("audio-volume-medium");
988 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
989 render->slotSetVolume(volume);
992 void Monitor::slotShowVolume()
994 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
995 int vol = render->volume();
996 // Disable widget if we cannot get the volume
997 m_volumePopup->setEnabled(vol != -1);
998 m_audioSlider->blockSignals(true);
999 m_audioSlider->setValue(vol);
1000 m_audioSlider->blockSignals(false);
1001 m_volumePopup->show();
1004 MonitorRefresh::MonitorRefresh(QWidget* parent) :
1008 // MonitorRefresh is used as container for the SDL display (it's window id is passed to SDL)
1009 setAttribute(Qt::WA_PaintOnScreen);
1010 setAttribute(Qt::WA_OpaquePaintEvent);
1011 //setAttribute(Qt::WA_NoSystemBackground);
1014 void MonitorRefresh::setRenderer(Render* render)
1016 m_renderer = render;
1019 void MonitorRefresh::paintEvent(QPaintEvent *event)
1022 if (m_renderer) m_renderer->doRefresh();
1025 Overlay::Overlay(QWidget* parent) :
1028 setAttribute(Qt::WA_TransparentForMouseEvents);
1029 //setAttribute(Qt::WA_OpaquePaintEvent);
1030 //setAttribute(Qt::WA_NoSystemBackground);
1031 setAutoFillBackground(true);
1032 setBackgroundRole(QPalette::Base);
1035 void Overlay::setOverlayText(const QString &text, bool isZone)
1040 p.setColor(QPalette::Text, Qt::white);
1041 if (m_isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1042 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1044 setText(' ' + text + ' ');
1049 VideoContainer::VideoContainer(Monitor* parent) :
1053 setFrameShape(QFrame::NoFrame);
1054 setFocusPolicy(Qt::ClickFocus);
1055 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
1059 void VideoContainer::mousePressEvent(QMouseEvent * event)
1061 if (m_monitor->underMouse()) event->setAccepted(false);
1065 void VideoContainer::mouseReleaseEvent(QMouseEvent * event)
1067 if (m_monitor->underMouse()) event->setAccepted(false);
1069 if (m_monitor->isActive()) {
1070 m_monitor->slotPlay();
1077 void VideoContainer::mouseMoveEvent(QMouseEvent *event)
1079 if (m_monitor->underMouse()) event->setAccepted(false);
1083 void VideoContainer::keyPressEvent(QKeyEvent *event)
1085 // Exit fullscreen with Esc key
1086 if (event->key() == Qt::Key_Escape && isFullScreen()) {
1088 event->setAccepted(true);
1089 } else event->setAccepted(false);
1093 void VideoContainer::wheelEvent(QWheelEvent * event)
1095 if (m_monitor->underMouse()) event->setAccepted(false);
1097 m_monitor->slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
1102 void VideoContainer::mouseDoubleClickEvent(QMouseEvent * event)
1106 if (!KdenliveSettings::openglmonitors())
1110 void VideoContainer::switchFullScreen()
1112 // TODO: disable screensaver?
1113 Qt::WindowFlags flags = windowFlags();
1114 if (!isFullScreen()) {
1115 // Check if we ahave a multiple monitor setup
1116 setUpdatesEnabled(false);
1117 #if QT_VERSION >= 0x040600
1118 int monitors = QApplication::desktop()->screenCount();
1120 int monitors = QApplication::desktop()->numScreens();
1124 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
1125 int currentScreen = QApplication::desktop()->screenNumber(this);
1126 if (currentScreen < monitors - 1)
1127 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
1129 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
1130 move(QPoint(screenres.x(), screenres.y()));
1131 resize(screenres.width(), screenres.height());
1134 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
1135 flags |= Qt::Window;
1136 flags ^= Qt::SubWindow;
1137 setWindowFlags(flags);
1139 // This works around a bug with Compiz
1140 // as the window must be visible before we can set the state
1143 setWindowState(windowState() | Qt::WindowFullScreen); // set
1145 setWindowState(windowState() | Qt::WindowFullScreen); // set
1146 setUpdatesEnabled(true);
1150 setUpdatesEnabled(false);
1151 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
1152 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
1153 setWindowFlags(flags);
1154 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset
1155 setUpdatesEnabled(true);
1162 #include "monitor.moc"