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);
70 // Video widget holder
71 m_videoBox = new VideoContainer(this);
72 m_videoBox->setContentsMargins(0, 0, 0, 0);
73 m_videoBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
74 layout->addWidget(m_videoBox, 10);
78 layout->addWidget(m_ruler);
81 QToolBar *toolbar = new QToolBar(name, this);
82 QVBoxLayout *layout2 = new QVBoxLayout;
83 layout2->setContentsMargins(0, 0, 0, 0);
85 m_playIcon = KIcon("media-playback-start");
86 m_pauseIcon = KIcon("media-playback-pause");
88 if (name != "chapter") {
89 toolbar->addAction(KIcon("kdenlive-zone-start"), i18n("Set zone start"), this, SLOT(slotSetZoneStart()));
90 toolbar->addAction(KIcon("kdenlive-zone-end"), i18n("Set zone end"), this, SLOT(slotSetZoneEnd()));
92 m_ruler->setZone(-3, -2);
95 toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"), this, SLOT(slotRewind()));
96 //toolbar->addAction(KIcon("media-skip-backward"), i18n("Rewind 1 frame"), this, SLOT(slotRewindOneFrame()));
98 QToolButton *playButton = new QToolButton(toolbar);
99 m_playMenu = new QMenu(i18n("Play..."), this);
100 m_playAction = m_playMenu->addAction(m_playIcon, i18n("Play"));
101 //m_playAction->setCheckable(true);
102 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
104 playButton->setMenu(m_playMenu);
105 playButton->setPopupMode(QToolButton::MenuButtonPopup);
106 toolbar->addWidget(playButton);
108 //toolbar->addAction(KIcon("media-skip-forward"), i18n("Forward 1 frame"), this, SLOT(slotForwardOneFrame()));
109 toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"), this, SLOT(slotForward()));
111 playButton->setDefaultAction(m_playAction);
113 if (name != "chapter") {
114 QToolButton *configButton = new QToolButton(toolbar);
115 m_configMenu = new QMenu(i18n("Misc..."), this);
116 configButton->setIcon(KIcon("system-run"));
117 configButton->setMenu(m_configMenu);
118 configButton->setPopupMode(QToolButton::QToolButton::InstantPopup);
119 toolbar->addWidget(configButton);
121 if (name == "clip") {
122 m_markerMenu = new QMenu(i18n("Go to marker..."), this);
123 m_markerMenu->setEnabled(false);
124 m_configMenu->addMenu(m_markerMenu);
125 connect(m_markerMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToMarker(QAction *)));
127 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (100%)"), this, SLOT(slotSetSizeOneToOne()));
128 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (50%)"), this, SLOT(slotSetSizeOneToTwo()));
131 QWidget *spacer = new QWidget(this);
132 spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
133 toolbar->addWidget(spacer);
134 m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this);
135 toolbar->addWidget(m_timePos);
136 connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotSeek()));
137 layout->addWidget(toolbar);
139 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
141 setMinimumHeight(200);
143 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
145 bool monitorCreated = false;
147 createOpenGlWidget(videoBox, profile);
148 monitorCreated = true;
149 //m_glWidget->setFixedSize(width, height);
150 #elif defined (USE_OPEN_GL)
151 if (KdenliveSettings::openglmonitors()) {
152 monitorCreated = createOpenGlWidget(m_videoBox, profile);
155 QVBoxLayout *lay = new QVBoxLayout;
156 lay->setContentsMargins(0, 0, 0, 0);
157 if (!monitorCreated) {
158 m_monitorRefresh = new MonitorRefresh;
159 lay->addWidget(m_monitorRefresh);
160 m_videoBox->setLayout(lay);
161 render = new Render(m_name, (int) m_monitorRefresh->winId(), profile, this);
162 m_monitorRefresh->setRenderer(render);
165 connect(m_ruler, SIGNAL(seekRenderer(int)), this, SLOT(slotSeek(int)));
166 connect(render, SIGNAL(durationChanged(int)), this, SLOT(adjustRulerSize(int)));
167 connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int)));
169 //render->createVideoXWindow(m_ui.video_frame->winId(), -1);
171 if (name != "clip") {
172 connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int)));
173 connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int)));
174 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SIGNAL(zoneUpdated(QPoint)));
176 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SLOT(setClipZone(QPoint)));
179 if (m_monitorRefresh) m_monitorRefresh->show();
181 if (name == "project") {
182 m_effectScene = new MonitorScene(render);
183 m_effectView = new QGraphicsView(m_effectScene, m_videoBox);
184 lay->addWidget(m_effectView);
185 m_effectView->setRenderHints(QFlags<QPainter::RenderHint>());
186 m_effectView->scale(((double) render->renderWidth()) / render->frameRenderWidth(), 1.0);
187 m_effectView->setMouseTracking(true);
188 m_effectScene->setUp();
189 m_effectView->hide();
198 if (m_name == "project") {
200 delete m_effectScene;
202 delete m_monitorRefresh;
206 QWidget *Monitor::container()
211 QString Monitor::name() const
216 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
217 bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile)
219 render = new Render(m_name, 0, profile, this);
220 m_glWidget = new VideoGLWidget(parent);
221 if (m_glWidget == NULL) {
222 // Creation failed, we are in trouble...
225 m_glWidget->setImageAspectRatio(render->dar());
226 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
227 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
232 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
234 m_contextMenu = new QMenu(this);
235 m_contextMenu->addMenu(m_playMenu);
237 m_contextMenu->addMenu(goMenu);
239 m_contextMenu->addMenu(markerMenu);
241 m_playMenu->addAction(playZone);
242 m_playMenu->addAction(loopZone);
244 m_loopClipAction = loopClip;
245 m_playMenu->addAction(loopClip);
248 //TODO: add save zone to timeline monitor when fixed
249 if (m_name == "clip") {
250 m_contextMenu->addMenu(m_markerMenu);
251 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
253 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
254 m_contextMenu->addAction(extractFrame);
256 if (m_name != "clip") {
257 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
258 splitView->setCheckable(true);
259 m_configMenu->addAction(splitView);
261 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
262 m_configMenu->addAction(setThumbFrame);
265 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
266 showTips->setCheckable(true);
267 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
268 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
270 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
271 dropFrames->setCheckable(true);
272 dropFrames->setChecked(true);
273 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
275 m_configMenu->addAction(showTips);
276 m_configMenu->addAction(dropFrames);
280 void Monitor::slotGoToMarker(QAction *action)
282 int pos = action->data().toInt();
286 void Monitor::slotSetSizeOneToOne()
288 QRect r = QApplication::desktop()->screenGeometry();
289 const int maxWidth = r.width() - 20;
290 const int maxHeight = r.height() - 20;
291 int width = render->renderWidth();
292 int height = render->renderHeight();
293 kDebug() << "// render info: " << width << "x" << height;
294 while (width >= maxWidth || height >= maxHeight) {
296 height = height * 0.8;
298 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
299 m_videoBox->setFixedSize(width, height);
302 //m_ui.video_frame->setMinimumSize(0, 0);
303 emit adjustMonitorSize();
306 void Monitor::slotSetSizeOneToTwo()
308 QRect r = QApplication::desktop()->screenGeometry();
309 const int maxWidth = r.width() - 20;
310 const int maxHeight = r.height() - 20;
311 int width = render->renderWidth() / 2;
312 int height = render->renderHeight() / 2;
313 kDebug() << "// render info: " << width << "x" << height;
314 while (width >= maxWidth || height >= maxHeight) {
316 height = height * 0.8;
318 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
319 m_videoBox->setFixedSize(width, height);
322 //m_ui.video_frame->setMinimumSize(0, 0);
323 emit adjustMonitorSize();
326 void Monitor::resetSize()
328 m_videoBox->setMinimumSize(0, 0);
331 DocClipBase *Monitor::activeClip()
333 return m_currentClip;
336 void Monitor::updateMarkers(DocClipBase *source)
338 if (source == m_currentClip && source != NULL) {
339 m_markerMenu->clear();
340 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
341 if (!markers.isEmpty()) {
343 for (int i = 0; i < markers.count(); i++) {
344 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
346 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
347 QAction *go = m_markerMenu->addAction(position);
350 m_ruler->setMarkers(marks);
351 } else m_ruler->setMarkers(QList <int>());
352 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
356 void Monitor::slotSeekToPreviousSnap()
358 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
361 void Monitor::slotSeekToNextSnap()
363 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
366 GenTime Monitor::position()
368 return render->seekPosition();
371 GenTime Monitor::getSnapForPos(bool previous)
373 QList <GenTime> snaps;
374 QList < GenTime > markers = m_currentClip->snapMarkers();
375 for (int i = 0; i < markers.size(); ++i) {
376 GenTime t = markers.at(i);
379 QPoint zone = m_ruler->zone();
380 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
381 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
382 snaps.append(GenTime());
383 snaps.append(m_currentClip->duration());
386 const GenTime pos = render->seekPosition();
387 for (int i = 0; i < snaps.size(); ++i) {
388 if (previous && snaps.at(i) >= pos) {
390 return snaps.at(i - 1);
391 } else if (!previous && snaps.at(i) > pos) {
398 void Monitor::slotZoneMoved(int start, int end)
400 m_ruler->setZone(start, end);
402 setClipZone(m_ruler->zone());
405 void Monitor::slotSetZoneStart()
407 m_ruler->setZone(render->seekFramePosition(), -1);
408 emit zoneUpdated(m_ruler->zone());
410 setClipZone(m_ruler->zone());
413 void Monitor::slotSetZoneEnd()
415 m_ruler->setZone(-1, render->seekFramePosition());
416 emit zoneUpdated(m_ruler->zone());
418 setClipZone(m_ruler->zone());
422 void Monitor::mousePressEvent(QMouseEvent * event)
424 if (event->button() != Qt::RightButton) {
425 if (m_videoBox->underMouse()) {
426 m_dragStarted = true;
427 m_DragStartPosition = event->pos();
429 } else m_contextMenu->popup(event->globalPos());
432 void Monitor::slotSwitchFullScreen()
434 m_videoBox->switchFullScreen();
438 void Monitor::mouseReleaseEvent(QMouseEvent * event)
441 if (m_videoBox->underMouse() && (!m_effectView || !m_effectView->isVisible())) {
442 if (isActive()) slotPlay();
443 else activateMonitor();
444 } else QWidget::mouseReleaseEvent(event);
445 m_dragStarted = false;
450 void Monitor::mouseMoveEvent(QMouseEvent *event)
452 // kDebug() << "// DRAG STARTED, MOUSE MOVED: ";
453 if (!m_dragStarted || m_currentClip == NULL) return;
455 if ((event->pos() - m_DragStartPosition).manhattanLength()
456 < QApplication::startDragDistance())
460 QDrag *drag = new QDrag(this);
461 QMimeData *mimeData = new QMimeData;
464 list.append(m_currentClip->getId());
465 QPoint p = m_ruler->zone();
466 list.append(QString::number(p.x()));
467 list.append(QString::number(p.y()));
469 data.append(list.join(";").toUtf8());
470 mimeData->setData("kdenlive/clip", data);
471 drag->setMimeData(mimeData);
472 QPixmap pix = m_currentClip->thumbnail();
473 drag->setPixmap(pix);
474 drag->setHotSpot(QPoint(0, 50));
475 drag->start(Qt::MoveAction);
477 //Qt::DropAction dropAction;
478 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
480 //Qt::DropAction dropAction = drag->exec();
486 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
487 event->setDropAction(Qt::IgnoreAction);
488 event->setDropAction(Qt::MoveAction);
489 if (event->mimeData()->hasText()) {
490 event->acceptProposedAction();
494 Qt::DropActions Monitor::supportedDropActions() const {
495 // returns what actions are supported when dropping
496 return Qt::MoveAction;
499 QStringList Monitor::mimeTypes() const
501 QStringList qstrList;
502 // list of accepted mime types for drop
503 qstrList.append("kdenlive/clip");
508 void Monitor::wheelEvent(QWheelEvent * event)
510 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
514 void Monitor::slotMouseSeek(int eventDelta, bool fast)
517 int delta = m_monitorManager->timecode().fps();
518 if (eventDelta > 0) delta = 0 - delta;
519 slotSeek(render->seekFramePosition() - delta);
521 if (eventDelta >= 0) slotForwardOneFrame();
522 else slotRewindOneFrame();
526 void Monitor::slotSetThumbFrame()
528 if (m_currentClip == NULL) {
531 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
532 emit refreshClipThumbnail(m_currentClip->getId());
535 void Monitor::slotExtractCurrentFrame()
537 QImage frame = render->extractFrame(render->seekFramePosition());
538 KFileDialog *fs = new KFileDialog(KUrl(), "image/png", this);
539 fs->setOperationMode(KFileDialog::Saving);
540 fs->setMode(KFile::File);
541 #if KDE_IS_VERSION(4,2,0)
542 fs->setConfirmOverwrite(true);
544 fs->setKeepLocation(true);
546 QString path = fs->selectedFile();
548 if (!path.isEmpty()) {
553 bool Monitor::isActive() const
558 void Monitor::activateMonitor()
561 m_monitorManager->slotSwitchMonitors(m_name == "clip");
565 void Monitor::setTimePos(const QString &pos)
567 m_timePos->setValue(pos);
571 void Monitor::slotSeek()
573 slotSeek(m_timePos->getValue());
576 void Monitor::slotSeek(int pos)
579 if (render == NULL) return;
580 render->seekToFrame(pos);
583 void Monitor::checkOverlay()
585 if (m_overlay == NULL) return;
586 int pos = render->seekFramePosition();
587 QPoint zone = m_ruler->zone();
589 m_overlay->setOverlayText(i18n("In Point"));
590 else if (pos == zone.y())
591 m_overlay->setOverlayText(i18n("Out Point"));
594 QString markerComment = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
595 if (markerComment.isEmpty())
596 m_overlay->setHidden(true);
598 m_overlay->setOverlayText(markerComment, false);
599 } else m_overlay->setHidden(true);
603 void Monitor::slotStart()
607 render->seekToFrame(0);
610 void Monitor::slotEnd()
614 render->seekToFrame(render->getLength());
617 void Monitor::slotZoneStart()
621 render->seekToFrame(m_ruler->zone().x());
624 void Monitor::slotZoneEnd()
628 render->seekToFrame(m_ruler->zone().y());
631 void Monitor::slotRewind(double speed)
635 double currentspeed = render->playSpeed();
636 if (currentspeed >= 0) render->play(-2);
637 else render->play(currentspeed * 2);
638 } else render->play(speed);
639 //m_playAction->setChecked(true);
640 m_playAction->setIcon(m_pauseIcon);
643 void Monitor::slotForward(double speed)
647 double currentspeed = render->playSpeed();
648 if (currentspeed <= 1) render->play(2);
649 else render->play(currentspeed * 2);
650 } else render->play(speed);
651 //m_playAction->setChecked(true);
652 m_playAction->setIcon(m_pauseIcon);
655 void Monitor::slotRewindOneFrame(int diff)
659 render->seekToFrameDiff(-diff);
662 void Monitor::slotForwardOneFrame(int diff)
666 render->seekToFrameDiff(diff);
669 void Monitor::seekCursor(int pos)
672 if (m_ruler->slotNewValue(pos)) {
674 m_timePos->setValue(pos);
678 void Monitor::rendererStopped(int pos)
680 if (m_ruler->slotNewValue(pos)) {
682 m_timePos->setValue(pos);
684 disconnect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
685 //m_playAction->setChecked(false);
686 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
687 m_playAction->setIcon(m_playIcon);
690 void Monitor::adjustRulerSize(int length)
692 if (length > 0) m_length = length;
693 m_ruler->adjustScale(m_length);
694 if (m_currentClip != NULL) {
695 QPoint zone = m_currentClip->zone();
696 m_ruler->setZone(zone.x(), zone.y());
703 disconnect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
704 if (render) render->stop();
707 void Monitor::start()
710 if (render) render->start();
711 connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
714 void Monitor::refreshMonitor(bool visible)
716 if (visible && render && !m_isActive) {
718 render->doRefresh(); //askForRefresh();
722 void Monitor::refreshMonitor()
729 void Monitor::pause()
731 if (render == NULL) return;
734 //m_playAction->setChecked(true);
735 m_playAction->setIcon(m_playIcon);
738 void Monitor::slotPlay()
740 if (render == NULL) return;
742 if (render->playSpeed() == 0) {
743 //m_playAction->setChecked(true);
744 m_playAction->setIcon(m_pauseIcon);
746 //m_playAction->setChecked(false);
747 m_playAction->setIcon(m_playIcon);
749 render->switchPlay();
752 void Monitor::slotPlayZone()
754 if (render == NULL) return;
756 QPoint p = m_ruler->zone();
757 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
758 //m_playAction->setChecked(true);
759 m_playAction->setIcon(m_pauseIcon);
762 void Monitor::slotLoopZone()
764 if (render == NULL) return;
766 QPoint p = m_ruler->zone();
767 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
768 //m_playAction->setChecked(true);
769 m_playAction->setIcon(m_pauseIcon);
772 void Monitor::slotLoopClip()
774 if (render == NULL || m_selectedClip == NULL)
777 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
778 //m_playAction->setChecked(true);
779 m_playAction->setIcon(m_pauseIcon);
782 void Monitor::slotSetXml(DocClipBase *clip, QPoint zone, const int position)
784 if (render == NULL) return;
785 if (clip == NULL && m_currentClip != NULL) {
786 m_currentClip = NULL;
788 render->setProducer(NULL, -1);
791 if (m_currentClip != NULL || clip != NULL) activateMonitor();
792 if (clip != m_currentClip) {
793 m_currentClip = clip;
795 if (render->setProducer(clip->producer(), position) == -1) {
796 // MLT CONSUMER is broken
797 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
799 } else if (position != -1) render->seek(GenTime(position, m_monitorManager->timecode().fps()));
800 if (!zone.isNull()) {
801 m_ruler->setZone(zone.x(), zone.y());
802 render->seek(GenTime(zone.x(), m_monitorManager->timecode().fps()));
806 void Monitor::slotOpenFile(const QString &file)
808 if (render == NULL) return;
811 QDomElement mlt = doc.createElement("mlt");
812 doc.appendChild(mlt);
813 QDomElement prod = doc.createElement("producer");
814 mlt.appendChild(prod);
815 prod.setAttribute("mlt_service", "avformat");
816 prod.setAttribute("resource", file);
817 render->setSceneList(doc, 0);
820 void Monitor::slotSaveZone()
822 if (render == NULL) return;
823 emit saveZone(render, m_ruler->zone());
825 //render->setSceneList(doc, 0);
828 void Monitor::resetProfile(const QString profile)
830 m_timePos->updateTimeCode(m_monitorManager->timecode());
831 if (render == NULL) return;
832 render->resetProfile(profile);
834 m_effectView->scale(((double) render->renderWidth()) / render->frameRenderWidth(), 1.0);
835 m_effectScene->resetProfile();
839 void Monitor::saveSceneList(QString path, QDomElement info)
841 if (render == NULL) return;
842 render->saveSceneList(path, info);
845 const QString Monitor::sceneList()
847 if (render == NULL) return QString();
848 return render->sceneList();
851 void Monitor::setClipZone(QPoint pos)
853 if (m_currentClip == NULL) return;
854 m_currentClip->setZone(pos);
857 void Monitor::slotSwitchDropFrames(bool show)
859 render->setDropFrames(show);
862 void Monitor::slotSwitchMonitorInfo(bool show)
864 KdenliveSettings::setDisplayMonitorInfo(show);
866 if (m_overlay) return;
867 if (m_monitorRefresh == NULL) {
868 // Using OpenGL display
869 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
870 m_overlay = new Overlay(m_glWidget);
873 m_overlay = new Overlay(m_monitorRefresh);
875 m_overlay->setHidden(true);
883 void Monitor::updateTimecodeFormat()
885 m_timePos->slotUpdateTimeCodeFormat();
888 QStringList Monitor::getZoneInfo() const
891 if (m_currentClip == NULL) return result;
892 result << m_currentClip->getId();
893 QPoint zone = m_ruler->zone();
894 result << QString::number(zone.x()) << QString::number(zone.y());
898 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
901 m_loopClipAction->setEnabled(true);
902 m_selectedClip = item;
904 m_loopClipAction->setEnabled(false);
908 void Monitor::slotSetSelectedClip(ClipItem* item)
910 if (item || (!item && !m_loopClipTransition)) {
911 m_loopClipTransition = false;
912 slotSetSelectedClip((AbstractClipItem*)item);
916 void Monitor::slotSetSelectedClip(Transition* item)
918 if (item || (!item && m_loopClipTransition)) {
919 m_loopClipTransition = true;
920 slotSetSelectedClip((AbstractClipItem*)item);
925 void Monitor::slotEffectScene(bool show)
927 if (m_name == "project") {
928 if (m_monitorRefresh) {
929 m_monitorRefresh->setVisible(!show);
931 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
932 m_glWidget->setVisible(!show);
935 m_effectView->setVisible(show);
936 emit requestFrameForAnalysis(show);
939 m_effectScene->slotZoomFit();
944 MonitorScene * Monitor::getEffectScene()
946 return m_effectScene;
949 bool Monitor::effectSceneDisplayed()
951 return m_effectView->isVisible();
954 MonitorRefresh::MonitorRefresh(QWidget* parent) :
958 // MonitorRefresh is used as container for the SDL display (it's window id is passed to SDL)
959 setAttribute(Qt::WA_PaintOnScreen);
960 setAttribute(Qt::WA_OpaquePaintEvent);
961 //setAttribute(Qt::WA_NoSystemBackground);
964 void MonitorRefresh::setRenderer(Render* render)
969 void MonitorRefresh::paintEvent(QPaintEvent *event)
972 if (m_renderer) m_renderer->doRefresh();
975 Overlay::Overlay(QWidget* parent) :
978 setAttribute(Qt::WA_TransparentForMouseEvents);
979 //setAttribute(Qt::WA_OpaquePaintEvent);
980 //setAttribute(Qt::WA_NoSystemBackground);
981 setAutoFillBackground(true);
982 setBackgroundRole(QPalette::Base);
985 void Overlay::setOverlayText(const QString &text, bool isZone)
990 p.setColor(QPalette::Text, Qt::white);
991 if (m_isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
992 else p.setColor(QPalette::Base, QColor(0, 0, 200));
994 setText(' ' + text + ' ');
999 VideoContainer::VideoContainer(Monitor* parent) :
1003 setFrameShape(QFrame::NoFrame);
1004 setFocusPolicy(Qt::ClickFocus);
1005 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
1009 void VideoContainer::mousePressEvent(QMouseEvent * event)
1011 if (m_monitor->underMouse()) event->setAccepted(false);
1015 void VideoContainer::mouseReleaseEvent(QMouseEvent * event)
1017 if (m_monitor->underMouse()) event->setAccepted(false);
1019 if (m_monitor->isActive()) {
1020 m_monitor->slotPlay();
1027 void VideoContainer::mouseMoveEvent(QMouseEvent *event)
1029 if (m_monitor->underMouse()) event->setAccepted(false);
1033 void VideoContainer::wheelEvent(QWheelEvent * event)
1035 if (m_monitor->underMouse()) event->setAccepted(false);
1037 m_monitor->slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
1042 void VideoContainer::mouseDoubleClickEvent(QMouseEvent * event)
1044 if (!KdenliveSettings::openglmonitors())
1048 void VideoContainer::switchFullScreen()
1050 // TODO: disable screensaver?
1051 Qt::WindowFlags flags = windowFlags();
1052 if (!isFullScreen()) {
1053 // Check if we ahave a multiple monitor setup
1054 setUpdatesEnabled(false);
1055 #if QT_VERSION >= 0x040600
1056 int monitors = QApplication::desktop()->screenCount();
1058 int monitors = QApplication::desktop()->numScreens();
1062 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
1063 int currentScreen = QApplication::desktop()->screenNumber(this);
1064 if (currentScreen < monitors - 1)
1065 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
1067 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
1068 move(QPoint(screenres.x(), screenres.y()));
1069 resize(screenres.width(), screenres.height());
1072 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
1073 flags |= Qt::Window;
1074 flags ^= Qt::SubWindow;
1075 setWindowFlags(flags);
1077 // This works around a bug with Compiz
1078 // as the window must be visible before we can set the state
1081 setWindowState(windowState() | Qt::WindowFullScreen); // set
1083 setWindowState(windowState() | Qt::WindowFullScreen); // set
1084 setUpdatesEnabled(true);
1088 setUpdatesEnabled(false);
1089 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
1090 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
1091 setWindowFlags(flags);
1092 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset
1093 setUpdatesEnabled(true);
1100 #include "monitor.moc"