1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
22 #include "smallruler.h"
23 #include "docclipbase.h"
24 #include "abstractclipitem.h"
25 #include "monitorscene.h"
26 #include "monitoreditwidget.h"
27 #include "kdenlivesettings.h"
31 #include <KFileDialog>
32 #include <KApplication>
33 #include <KMessageBox>
35 #include <QMouseEvent>
36 #include <QStylePainter>
38 #include <QToolButton>
40 #include <QDesktopWidget>
42 #include <QIntValidator>
43 #include <QVBoxLayout>
46 Monitor::Monitor(QString name, MonitorManager *manager, QString profile, QWidget *parent) :
47 AbstractMonitor(parent),
50 m_monitorManager(manager),
52 m_ruler(new SmallRuler(m_monitorManager)),
57 m_monitorRefresh(NULL),
60 m_loopClipTransition(true),
63 QVBoxLayout *layout = new QVBoxLayout;
64 layout->setContentsMargins(0, 0, 0, 0);
65 layout->setSpacing(0);
67 // Video widget holder
68 m_videoBox = new VideoContainer(this);
69 m_videoBox->setContentsMargins(0, 0, 0, 0);
70 m_videoBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
71 layout->addWidget(m_videoBox, 10);
74 // Get base size for icons
75 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
78 layout->addWidget(m_ruler);
80 m_toolbar = new QToolBar(name, this);
81 m_toolbar->setIconSize(QSize(s, s));
83 m_playIcon = KIcon("media-playback-start");
84 m_pauseIcon = KIcon("media-playback-pause");
86 if (name != "chapter") {
87 m_toolbar->addAction(KIcon("kdenlive-zone-start"), i18n("Set zone start"), this, SLOT(slotSetZoneStart()));
88 m_toolbar->addAction(KIcon("kdenlive-zone-end"), i18n("Set zone end"), this, SLOT(slotSetZoneEnd()));
90 m_ruler->setZone(-3, -2);
93 m_toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"), this, SLOT(slotRewind()));
94 //m_toolbar->addAction(KIcon("media-skip-backward"), i18n("Rewind 1 frame"), this, SLOT(slotRewindOneFrame()));
96 QToolButton *playButton = new QToolButton(m_toolbar);
97 m_playMenu = new QMenu(i18n("Play..."), this);
98 m_playAction = m_playMenu->addAction(m_playIcon, i18n("Play"));
99 //m_playAction->setCheckable(true);
100 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
102 playButton->setMenu(m_playMenu);
103 playButton->setPopupMode(QToolButton::MenuButtonPopup);
104 m_toolbar->addWidget(playButton);
106 //m_toolbar->addAction(KIcon("media-skip-forward"), i18n("Forward 1 frame"), this, SLOT(slotForwardOneFrame()));
107 m_toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"), this, SLOT(slotForward()));
109 playButton->setDefaultAction(m_playAction);
111 if (name != "chapter") {
112 QToolButton *configButton = new QToolButton(m_toolbar);
113 m_configMenu = new QMenu(i18n("Misc..."), this);
114 configButton->setIcon(KIcon("system-run"));
115 configButton->setMenu(m_configMenu);
116 configButton->setPopupMode(QToolButton::QToolButton::InstantPopup);
117 m_toolbar->addWidget(configButton);
119 if (name == "clip") {
120 m_markerMenu = new QMenu(i18n("Go to marker..."), this);
121 m_markerMenu->setEnabled(false);
122 m_configMenu->addMenu(m_markerMenu);
123 connect(m_markerMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToMarker(QAction *)));
125 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (100%)"), this, SLOT(slotSetSizeOneToOne()));
126 m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (50%)"), this, SLOT(slotSetSizeOneToTwo()));
129 // Create Volume slider popup
130 m_volumePopup = new QFrame(this, Qt::Popup);
131 QVBoxLayout *poplayout = new QVBoxLayout;
132 poplayout->setContentsMargins(0, 0, 0, 0);
133 m_audioSlider = new QSlider(Qt::Vertical);
134 m_audioSlider->setRange(0, 100);
135 poplayout->addWidget(m_audioSlider);
136 m_volumePopup->setLayout(poplayout);
138 if (KdenliveSettings::volume() == 0) icon = KIcon("audio-volume-muted");
139 else icon = KIcon("audio-volume-medium");
141 m_volumeWidget = m_toolbar->widgetForAction(m_toolbar->addAction(icon, i18n("Audio volume"), this, SLOT(slotShowVolume())));
143 // we need to show / hide the popup once so that it's geometry can be calculated in slotShowVolume
144 m_volumePopup->show();
145 m_volumePopup->hide();
147 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
149 setMinimumHeight(200);
151 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
153 bool monitorCreated = false;
155 createOpenGlWidget(m_videoBox, profile);
156 monitorCreated = true;
157 //m_glWidget->setFixedSize(width, height);
158 #elif defined (USE_OPEN_GL)
159 if (KdenliveSettings::openglmonitors()) {
160 monitorCreated = createOpenGlWidget(m_videoBox, profile);
163 QVBoxLayout *lay = new QVBoxLayout;
164 lay->setContentsMargins(0, 0, 0, 0);
165 if (!monitorCreated) {
166 m_monitorRefresh = new MonitorRefresh;
167 lay->addWidget(m_monitorRefresh);
168 m_videoBox->setLayout(lay);
169 render = new Render(m_name, (int) m_monitorRefresh->winId(), profile, this);
170 m_monitorRefresh->setRenderer(render);
172 #if defined (USE_OPEN_GL)
173 else if (m_glWidget) {
174 lay->addWidget(m_glWidget);
175 m_videoBox->setLayout(lay);
179 connect(m_audioSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetVolume(int)));
180 connect(m_ruler, SIGNAL(seekRenderer(int)), this, SLOT(slotSeek(int)));
181 connect(render, SIGNAL(durationChanged(int)), this, SLOT(adjustRulerSize(int)));
182 connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int)));
184 if (name != "clip") {
185 connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int)));
186 connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int)));
187 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SIGNAL(zoneUpdated(QPoint)));
189 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SLOT(setClipZone(QPoint)));
192 if (m_monitorRefresh) m_monitorRefresh->show();
194 if (name == "project") {
195 m_effectWidget = new MonitorEditWidget(render, m_videoBox);
196 m_toolbar->addAction(m_effectWidget->getVisibilityAction());
197 lay->addWidget(m_effectWidget);
198 m_effectWidget->hide();
201 QWidget *spacer = new QWidget(this);
202 spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
203 m_toolbar->addWidget(spacer);
204 m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this);
205 m_toolbar->addWidget(m_timePos);
206 connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotSeek()));
207 m_toolbar->setMaximumHeight(s * 1.5);
208 layout->addWidget(m_toolbar);
217 delete m_effectWidget;
218 delete m_monitorRefresh;
222 QWidget *Monitor::container()
227 const QString Monitor::name() const
232 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
233 bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile)
235 render = new Render(m_name, 0, profile, this);
236 m_glWidget = new VideoGLWidget(parent);
237 if (m_glWidget == NULL) {
238 // Creation failed, we are in trouble...
241 m_glWidget->setImageAspectRatio(render->dar());
242 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
243 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
248 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
250 m_contextMenu = new QMenu(this);
251 m_contextMenu->addMenu(m_playMenu);
253 m_contextMenu->addMenu(goMenu);
255 m_contextMenu->addMenu(markerMenu);
256 QList <QAction *>list = markerMenu->actions();
257 for (int i = 0; i < list.count(); i++) {
258 if (list.at(i)->data().toString() == "edit_marker") {
259 m_editMarker = list.at(i);
265 m_playMenu->addAction(playZone);
266 m_playMenu->addAction(loopZone);
268 m_loopClipAction = loopClip;
269 m_playMenu->addAction(loopClip);
272 //TODO: add save zone to timeline monitor when fixed
273 if (m_name == "clip") {
274 m_contextMenu->addMenu(m_markerMenu);
275 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
277 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
278 m_contextMenu->addAction(extractFrame);
280 if (m_name != "clip") {
281 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
282 splitView->setCheckable(true);
283 m_configMenu->addAction(splitView);
285 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
286 m_configMenu->addAction(setThumbFrame);
289 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
290 showTips->setCheckable(true);
291 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
292 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
294 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
295 dropFrames->setCheckable(true);
296 dropFrames->setChecked(true);
297 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
299 m_configMenu->addAction(showTips);
300 m_configMenu->addAction(dropFrames);
304 void Monitor::slotGoToMarker(QAction *action)
306 int pos = action->data().toInt();
310 void Monitor::slotSetSizeOneToOne()
312 QRect r = QApplication::desktop()->screenGeometry();
313 const int maxWidth = r.width() - 20;
314 const int maxHeight = r.height() - 20;
315 int width = render->renderWidth();
316 int height = render->renderHeight();
317 kDebug() << "// render info: " << width << "x" << height;
318 while (width >= maxWidth || height >= maxHeight) {
320 height = height * 0.8;
322 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
323 m_videoBox->setFixedSize(width, height);
326 //m_ui.video_frame->setMinimumSize(0, 0);
327 emit adjustMonitorSize();
330 void Monitor::slotSetSizeOneToTwo()
332 QRect r = QApplication::desktop()->screenGeometry();
333 const int maxWidth = r.width() - 20;
334 const int maxHeight = r.height() - 20;
335 int width = render->renderWidth() / 2;
336 int height = render->renderHeight() / 2;
337 kDebug() << "// render info: " << width << "x" << height;
338 while (width >= maxWidth || height >= maxHeight) {
340 height = height * 0.8;
342 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
343 m_videoBox->setFixedSize(width, height);
346 //m_ui.video_frame->setMinimumSize(0, 0);
347 emit adjustMonitorSize();
350 void Monitor::resetSize()
352 m_videoBox->setMinimumSize(0, 0);
355 DocClipBase *Monitor::activeClip()
357 return m_currentClip;
360 void Monitor::updateMarkers(DocClipBase *source)
362 if (source == m_currentClip && source != NULL) {
363 m_markerMenu->clear();
364 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
365 if (!markers.isEmpty()) {
367 for (int i = 0; i < markers.count(); i++) {
368 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
370 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
371 QAction *go = m_markerMenu->addAction(position);
374 m_ruler->setMarkers(marks);
375 } else m_ruler->setMarkers(QList <int>());
376 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
380 void Monitor::slotSeekToPreviousSnap()
382 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
385 void Monitor::slotSeekToNextSnap()
387 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
390 GenTime Monitor::position()
392 return render->seekPosition();
395 GenTime Monitor::getSnapForPos(bool previous)
397 QList <GenTime> snaps;
398 QList < GenTime > markers = m_currentClip->snapMarkers();
399 for (int i = 0; i < markers.size(); ++i) {
400 GenTime t = markers.at(i);
403 QPoint zone = m_ruler->zone();
404 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
405 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
406 snaps.append(GenTime());
407 snaps.append(m_currentClip->duration());
410 const GenTime pos = render->seekPosition();
411 for (int i = 0; i < snaps.size(); ++i) {
412 if (previous && snaps.at(i) >= pos) {
414 return snaps.at(i - 1);
415 } else if (!previous && snaps.at(i) > pos) {
422 void Monitor::slotZoneMoved(int start, int end)
424 m_ruler->setZone(start, end);
426 setClipZone(m_ruler->zone());
429 void Monitor::slotSetZoneStart()
431 m_ruler->setZone(render->seekFramePosition(), -1);
432 emit zoneUpdated(m_ruler->zone());
434 setClipZone(m_ruler->zone());
437 void Monitor::slotSetZoneEnd()
439 m_ruler->setZone(-1, render->seekFramePosition());
440 emit zoneUpdated(m_ruler->zone());
442 setClipZone(m_ruler->zone());
446 void Monitor::mousePressEvent(QMouseEvent * event)
448 if (event->button() != Qt::RightButton) {
449 if (m_videoBox->underMouse() && (!m_overlay || !m_overlay->underMouse())) {
450 m_dragStarted = true;
451 m_DragStartPosition = event->pos();
453 } else if (!m_effectWidget || !m_effectWidget->isVisible()) {
454 m_contextMenu->popup(event->globalPos());
458 void Monitor::slotSwitchFullScreen()
460 m_videoBox->switchFullScreen();
464 void Monitor::mouseReleaseEvent(QMouseEvent * event)
467 if (m_videoBox->underMouse() && (!m_effectWidget || !m_effectWidget->isVisible())) {
468 if (isActive()) slotPlay();
469 else activateMonitor();
470 } else QWidget::mouseReleaseEvent(event);
471 m_dragStarted = false;
476 void Monitor::mouseMoveEvent(QMouseEvent *event)
478 // kDebug() << "// DRAG STARTED, MOUSE MOVED: ";
479 if (!m_dragStarted || m_currentClip == NULL) return;
481 if ((event->pos() - m_DragStartPosition).manhattanLength()
482 < QApplication::startDragDistance())
486 QDrag *drag = new QDrag(this);
487 QMimeData *mimeData = new QMimeData;
490 list.append(m_currentClip->getId());
491 QPoint p = m_ruler->zone();
492 list.append(QString::number(p.x()));
493 list.append(QString::number(p.y()));
495 data.append(list.join(";").toUtf8());
496 mimeData->setData("kdenlive/clip", data);
497 drag->setMimeData(mimeData);
498 QPixmap pix = m_currentClip->thumbnail();
499 drag->setPixmap(pix);
500 drag->setHotSpot(QPoint(0, 50));
501 drag->start(Qt::MoveAction);
503 //Qt::DropAction dropAction;
504 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
506 //Qt::DropAction dropAction = drag->exec();
512 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
513 event->setDropAction(Qt::IgnoreAction);
514 event->setDropAction(Qt::MoveAction);
515 if (event->mimeData()->hasText()) {
516 event->acceptProposedAction();
520 Qt::DropActions Monitor::supportedDropActions() const {
521 // returns what actions are supported when dropping
522 return Qt::MoveAction;
525 QStringList Monitor::mimeTypes() const
527 QStringList qstrList;
528 // list of accepted mime types for drop
529 qstrList.append("kdenlive/clip");
534 void Monitor::wheelEvent(QWheelEvent * event)
536 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
540 void Monitor::slotMouseSeek(int eventDelta, bool fast)
543 int delta = m_monitorManager->timecode().fps();
544 if (eventDelta > 0) delta = 0 - delta;
545 slotSeek(render->seekFramePosition() - delta);
547 if (eventDelta >= 0) slotForwardOneFrame();
548 else slotRewindOneFrame();
552 void Monitor::slotSetThumbFrame()
554 if (m_currentClip == NULL) {
557 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
558 emit refreshClipThumbnail(m_currentClip->getId(), true);
561 void Monitor::slotExtractCurrentFrame()
564 // check if we are using a proxy
565 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
566 // using proxy, use original clip url to get frame
567 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
569 else frame = render->extractFrame(render->seekFramePosition());
570 KFileDialog *fs = new KFileDialog(KUrl(), "image/png", this);
571 fs->setOperationMode(KFileDialog::Saving);
572 fs->setMode(KFile::File);
573 #if KDE_IS_VERSION(4,2,0)
574 fs->setConfirmOverwrite(true);
576 fs->setKeepLocation(true);
578 QString path = fs->selectedFile();
580 if (!path.isEmpty()) {
585 bool Monitor::isActive() const
587 return m_monitorManager->isActive(m_name);
590 void Monitor::activateMonitor()
592 m_monitorManager->activateMonitor(m_name);
595 void Monitor::setTimePos(const QString &pos)
597 m_timePos->setValue(pos);
601 void Monitor::slotSeek()
603 slotSeek(m_timePos->getValue());
606 void Monitor::slotSeek(int pos)
609 if (render == NULL) return;
610 render->seekToFrame(pos);
613 void Monitor::checkOverlay()
615 if (m_overlay == NULL) return;
616 int pos = render->seekFramePosition();
617 QPoint zone = m_ruler->zone();
619 m_overlay->setOverlayText(i18n("In Point"));
620 else if (pos == zone.y())
621 m_overlay->setOverlayText(i18n("Out Point"));
624 QString markerComment = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
625 if (markerComment.isEmpty())
626 m_overlay->setHidden(true);
628 m_overlay->setOverlayText(markerComment, false);
629 } else m_overlay->setHidden(true);
633 void Monitor::slotStart()
637 render->seekToFrame(0);
640 void Monitor::slotEnd()
644 render->seekToFrame(render->getLength());
647 void Monitor::slotZoneStart()
651 render->seekToFrame(m_ruler->zone().x());
654 void Monitor::slotZoneEnd()
658 render->seekToFrame(m_ruler->zone().y());
661 void Monitor::slotRewind(double speed)
665 double currentspeed = render->playSpeed();
666 if (currentspeed >= 0) render->play(-2);
667 else render->play(currentspeed * 2);
668 } else render->play(speed);
669 //m_playAction->setChecked(true);
670 m_playAction->setIcon(m_pauseIcon);
673 void Monitor::slotForward(double speed)
677 double currentspeed = render->playSpeed();
678 if (currentspeed <= 1) render->play(2);
679 else render->play(currentspeed * 2);
680 } else render->play(speed);
681 //m_playAction->setChecked(true);
682 m_playAction->setIcon(m_pauseIcon);
685 void Monitor::slotRewindOneFrame(int diff)
689 render->seekToFrameDiff(-diff);
692 void Monitor::slotForwardOneFrame(int diff)
696 render->seekToFrameDiff(diff);
699 void Monitor::seekCursor(int pos)
702 if (m_ruler->slotNewValue(pos)) {
704 m_timePos->setValue(pos);
708 void Monitor::rendererStopped(int pos)
710 if (m_ruler->slotNewValue(pos)) {
712 m_timePos->setValue(pos);
714 m_playAction->setIcon(m_playIcon);
717 void Monitor::adjustRulerSize(int length)
719 if (length > 0) m_length = length;
720 m_ruler->adjustScale(m_length);
721 if (m_currentClip != NULL) {
722 QPoint zone = m_currentClip->zone();
723 m_ruler->setZone(zone.x(), zone.y());
729 disconnect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
730 if (render) render->stop();
733 void Monitor::start()
735 if (render) render->start();
736 connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
739 void Monitor::refreshMonitor(bool visible)
741 if (visible && render) {
743 render->doRefresh(); //askForRefresh();
747 void Monitor::refreshMonitor()
754 void Monitor::pause()
756 if (render == NULL) return;
759 //m_playAction->setChecked(true);
760 m_playAction->setIcon(m_playIcon);
763 void Monitor::slotPlay()
765 if (render == NULL) return;
767 if (render->playSpeed() == 0) {
768 m_playAction->setIcon(m_pauseIcon);
769 render->switchPlay(true);
771 m_playAction->setIcon(m_playIcon);
772 render->switchPlay(false);
776 void Monitor::slotPlayZone()
778 if (render == NULL) return;
780 QPoint p = m_ruler->zone();
781 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
782 //m_playAction->setChecked(true);
783 m_playAction->setIcon(m_pauseIcon);
786 void Monitor::slotLoopZone()
788 if (render == NULL) return;
790 QPoint p = m_ruler->zone();
791 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
792 //m_playAction->setChecked(true);
793 m_playAction->setIcon(m_pauseIcon);
796 void Monitor::slotLoopClip()
798 if (render == NULL || m_selectedClip == NULL)
801 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
802 //m_playAction->setChecked(true);
803 m_playAction->setIcon(m_pauseIcon);
806 void Monitor::updateClipProducer(Mlt::Producer *prod)
808 if (render == NULL) return;
809 render->setProducer(prod, render->seekFramePosition());
812 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, int position)
814 if (render == NULL) return;
815 if (clip == NULL && m_currentClip != NULL) {
816 kDebug()<<"// SETTING NULL CLIP MONITOR";
817 m_currentClip = NULL;
819 render->setProducer(NULL, -1);
823 if (clip != m_currentClip) {
824 m_currentClip = clip;
825 if (m_currentClip) activateMonitor();
827 Mlt::Producer *prod = NULL;
828 if (clip) prod = clip->getCloneProducer();
829 if (render->setProducer(prod, position) == -1) {
830 // MLT CONSUMER is broken
831 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
836 if (position == -1) position = render->seekFramePosition();
837 render->seek(position);
840 if (!zone.isNull()) {
841 m_ruler->setZone(zone.x(), zone.y());
842 render->seek(zone.x());
846 void Monitor::slotOpenFile(const QString &file)
848 if (render == NULL) return;
851 QDomElement mlt = doc.createElement("mlt");
852 doc.appendChild(mlt);
853 QDomElement prod = doc.createElement("producer");
854 mlt.appendChild(prod);
855 prod.setAttribute("mlt_service", "avformat");
856 prod.setAttribute("resource", file);
857 render->setSceneList(doc, 0);
860 void Monitor::slotSaveZone()
862 if (render == NULL) return;
863 emit saveZone(render, m_ruler->zone(), m_currentClip);
865 //render->setSceneList(doc, 0);
868 void Monitor::resetProfile(const QString &profile)
870 m_timePos->updateTimeCode(m_monitorManager->timecode());
871 if (render == NULL) return;
872 render->resetProfile(profile);
874 m_effectWidget->resetProfile(render);
877 void Monitor::saveSceneList(QString path, QDomElement info)
879 if (render == NULL) return;
880 render->saveSceneList(path, info);
883 const QString Monitor::sceneList()
885 if (render == NULL) return QString();
886 return render->sceneList();
889 void Monitor::setClipZone(QPoint pos)
891 if (m_currentClip == NULL) return;
892 m_currentClip->setZone(pos);
895 void Monitor::slotSwitchDropFrames(bool show)
897 render->setDropFrames(show);
900 void Monitor::slotSwitchMonitorInfo(bool show)
902 KdenliveSettings::setDisplayMonitorInfo(show);
904 if (m_overlay) return;
905 if (m_monitorRefresh == NULL) {
906 // Using OpenGL display
907 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
908 if (m_glWidget->layout()) delete m_glWidget->layout();
909 m_overlay = new Overlay();
910 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
911 QVBoxLayout *layout = new QVBoxLayout;
912 layout->addStretch(10);
913 layout->addWidget(m_overlay);
914 m_glWidget->setLayout(layout);
917 if (m_monitorRefresh->layout()) delete m_monitorRefresh->layout();
918 m_overlay = new Overlay();
919 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
920 QVBoxLayout *layout = new QVBoxLayout;
921 layout->addStretch(10);
922 layout->addWidget(m_overlay);
923 m_monitorRefresh->setLayout(layout);
925 m_overlay->setHidden(true);
934 void Monitor::slotEditMarker()
936 if (m_editMarker) m_editMarker->trigger();
939 void Monitor::updateTimecodeFormat()
941 m_timePos->slotUpdateTimeCodeFormat();
944 QStringList Monitor::getZoneInfo() const
947 if (m_currentClip == NULL) return result;
948 result << m_currentClip->getId();
949 QPoint zone = m_ruler->zone();
950 result << QString::number(zone.x()) << QString::number(zone.y());
954 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
957 m_loopClipAction->setEnabled(true);
958 m_selectedClip = item;
960 m_loopClipAction->setEnabled(false);
964 void Monitor::slotSetSelectedClip(ClipItem* item)
966 if (item || (!item && !m_loopClipTransition)) {
967 m_loopClipTransition = false;
968 slotSetSelectedClip((AbstractClipItem*)item);
972 void Monitor::slotSetSelectedClip(Transition* item)
974 if (item || (!item && m_loopClipTransition)) {
975 m_loopClipTransition = true;
976 slotSetSelectedClip((AbstractClipItem*)item);
981 void Monitor::slotEffectScene(bool show)
983 if (m_name == "project") {
984 if (m_monitorRefresh) {
985 m_monitorRefresh->setVisible(!show);
987 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
988 m_glWidget->setVisible(!show);
991 m_effectWidget->setVisible(show);
992 m_effectWidget->getVisibilityAction()->setChecked(show);
993 emit requestFrameForAnalysis(show);
995 m_effectWidget->getScene()->slotZoomFit();
1001 MonitorEditWidget* Monitor::getEffectEdit()
1003 return m_effectWidget;
1006 bool Monitor::effectSceneDisplayed()
1008 return m_effectWidget->isVisible();
1011 void Monitor::slotSetVolume(int volume)
1013 KdenliveSettings::setVolume(volume);
1015 if (volume == 0) icon = KIcon("audio-volume-muted");
1016 else icon = KIcon("audio-volume-medium");
1017 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1018 render->slotSetVolume(volume);
1021 void Monitor::slotShowVolume()
1023 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1024 int vol = render->volume();
1025 // Disable widget if we cannot get the volume
1026 m_volumePopup->setEnabled(vol != -1);
1027 m_audioSlider->blockSignals(true);
1028 m_audioSlider->setValue(vol);
1029 m_audioSlider->blockSignals(false);
1030 m_volumePopup->show();
1033 AbstractRender *Monitor::abstractRender()
1038 MonitorRefresh::MonitorRefresh(QWidget* parent) :
1042 // MonitorRefresh is used as container for the SDL display (it's window id is passed to SDL)
1043 setAttribute(Qt::WA_PaintOnScreen);
1044 setAttribute(Qt::WA_OpaquePaintEvent);
1045 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
1046 //setAttribute(Qt::WA_NoSystemBackground);
1049 void MonitorRefresh::setRenderer(Render* render)
1051 m_renderer = render;
1055 void MonitorRefresh::resizeEvent(QResizeEvent *event)
1058 if (m_renderer && isVisible()) m_renderer->doRefresh();
1061 Overlay::Overlay(QWidget* parent) :
1064 //setAttribute(Qt::WA_TransparentForMouseEvents);
1065 setAutoFillBackground(true);
1066 setBackgroundRole(QPalette::Base);
1067 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1068 setCursor(Qt::PointingHandCursor);
1072 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1078 void Overlay::mousePressEvent( QMouseEvent * event )
1084 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1090 void Overlay::setOverlayText(const QString &text, bool isZone)
1095 p.setColor(QPalette::Text, Qt::white);
1096 if (m_isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1097 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1099 setText(' ' + text + ' ');
1104 VideoContainer::VideoContainer(Monitor* parent) :
1108 setFrameShape(QFrame::NoFrame);
1109 setFocusPolicy(Qt::ClickFocus);
1110 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
1114 void VideoContainer::mousePressEvent(QMouseEvent * event)
1116 if (m_monitor->underMouse()) event->setAccepted(false);
1120 void VideoContainer::mouseReleaseEvent(QMouseEvent * event)
1122 if (m_monitor->underMouse()) event->setAccepted(false);
1124 if (m_monitor->isActive()) {
1125 m_monitor->slotPlay();
1132 void VideoContainer::mouseMoveEvent(QMouseEvent *event)
1134 if (m_monitor->underMouse()) event->setAccepted(false);
1138 void VideoContainer::keyPressEvent(QKeyEvent *event)
1140 // Exit fullscreen with Esc key
1141 if (event->key() == Qt::Key_Escape && isFullScreen()) {
1143 event->setAccepted(true);
1144 } else event->setAccepted(false);
1148 void VideoContainer::wheelEvent(QWheelEvent * event)
1150 if (m_monitor->underMouse()) event->setAccepted(false);
1152 m_monitor->slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
1157 void VideoContainer::mouseDoubleClickEvent(QMouseEvent * event)
1161 if (!KdenliveSettings::openglmonitors())
1165 void VideoContainer::switchFullScreen()
1167 // TODO: disable screensaver?
1168 Qt::WindowFlags flags = windowFlags();
1169 if (!isFullScreen()) {
1170 // Check if we ahave a multiple monitor setup
1171 setUpdatesEnabled(false);
1172 #if QT_VERSION >= 0x040600
1173 int monitors = QApplication::desktop()->screenCount();
1175 int monitors = QApplication::desktop()->numScreens();
1179 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
1180 int currentScreen = QApplication::desktop()->screenNumber(this);
1181 if (currentScreen < monitors - 1)
1182 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
1184 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
1185 move(QPoint(screenres.x(), screenres.y()));
1186 resize(screenres.width(), screenres.height());
1189 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
1190 flags |= Qt::Window;
1191 flags ^= Qt::SubWindow;
1192 setWindowFlags(flags);
1194 // This works around a bug with Compiz
1195 // as the window must be visible before we can set the state
1198 setWindowState(windowState() | Qt::WindowFullScreen); // set
1200 setWindowState(windowState() | Qt::WindowFullScreen); // set
1201 setUpdatesEnabled(true);
1205 setUpdatesEnabled(false);
1206 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
1207 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
1208 setWindowFlags(flags);
1209 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset
1210 setUpdatesEnabled(true);
1217 #include "monitor.moc"