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_OPENGL)
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);
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)));
183 connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
185 if (name != "clip") {
186 connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int)));
187 connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int)));
188 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SIGNAL(zoneUpdated(QPoint)));
190 connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SLOT(setClipZone(QPoint)));
193 if (m_monitorRefresh) m_monitorRefresh->show();
195 if (name == "project") {
196 m_effectWidget = new MonitorEditWidget(render, m_videoBox);
197 m_toolbar->addAction(m_effectWidget->getVisibilityAction());
198 lay->addWidget(m_effectWidget);
199 m_effectWidget->hide();
202 QWidget *spacer = new QWidget(this);
203 spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
204 m_toolbar->addWidget(spacer);
205 m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this);
206 m_toolbar->addWidget(m_timePos);
207 connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotSeek()));
208 m_toolbar->setMaximumHeight(s * 1.5);
209 layout->addWidget(m_toolbar);
218 delete m_effectWidget;
219 delete m_monitorRefresh;
223 QWidget *Monitor::container()
228 const QString Monitor::name() const
234 bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile)
236 render = new Render(m_name, 0, profile, this);
237 m_glWidget = new VideoGLWidget(parent);
238 if (m_glWidget == NULL) {
239 // Creation failed, we are in trouble...
242 m_glWidget->setImageAspectRatio(render->dar());
243 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
244 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
249 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
251 m_contextMenu = new QMenu(this);
252 m_contextMenu->addMenu(m_playMenu);
254 m_contextMenu->addMenu(goMenu);
256 m_contextMenu->addMenu(markerMenu);
257 QList <QAction *>list = markerMenu->actions();
258 for (int i = 0; i < list.count(); i++) {
259 if (list.at(i)->data().toString() == "edit_marker") {
260 m_editMarker = list.at(i);
266 m_playMenu->addAction(playZone);
267 m_playMenu->addAction(loopZone);
269 m_loopClipAction = loopClip;
270 m_playMenu->addAction(loopClip);
273 //TODO: add save zone to timeline monitor when fixed
274 if (m_name == "clip") {
275 m_contextMenu->addMenu(m_markerMenu);
276 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
277 QAction *extractZone = m_configMenu->addAction(KIcon("document-new"), i18n("Extract Zone"), this, SLOT(slotExtractCurrentZone()));
278 m_contextMenu->addAction(extractZone);
280 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
281 m_contextMenu->addAction(extractFrame);
283 if (m_name != "clip") {
284 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
285 splitView->setCheckable(true);
286 m_configMenu->addAction(splitView);
288 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
289 m_configMenu->addAction(setThumbFrame);
292 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
293 showTips->setCheckable(true);
294 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
295 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
297 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
298 dropFrames->setCheckable(true);
299 dropFrames->setChecked(true);
300 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
302 m_configMenu->addAction(showTips);
303 m_configMenu->addAction(dropFrames);
307 void Monitor::slotGoToMarker(QAction *action)
309 int pos = action->data().toInt();
313 void Monitor::slotSetSizeOneToOne()
315 QRect r = QApplication::desktop()->screenGeometry();
316 const int maxWidth = r.width() - 20;
317 const int maxHeight = r.height() - 20;
318 int width = render->renderWidth();
319 int height = render->renderHeight();
320 kDebug() << "// render info: " << width << "x" << height;
321 while (width >= maxWidth || height >= maxHeight) {
323 height = height * 0.8;
325 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
326 m_videoBox->setFixedSize(width, height);
329 //m_ui.video_frame->setMinimumSize(0, 0);
330 emit adjustMonitorSize();
333 void Monitor::slotSetSizeOneToTwo()
335 QRect r = QApplication::desktop()->screenGeometry();
336 const int maxWidth = r.width() - 20;
337 const int maxHeight = r.height() - 20;
338 int width = render->renderWidth() / 2;
339 int height = render->renderHeight() / 2;
340 kDebug() << "// render info: " << width << "x" << height;
341 while (width >= maxWidth || height >= maxHeight) {
343 height = height * 0.8;
345 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
346 m_videoBox->setFixedSize(width, height);
349 //m_ui.video_frame->setMinimumSize(0, 0);
350 emit adjustMonitorSize();
353 void Monitor::resetSize()
355 m_videoBox->setMinimumSize(0, 0);
358 DocClipBase *Monitor::activeClip()
360 return m_currentClip;
363 void Monitor::updateMarkers(DocClipBase *source)
365 if (source == m_currentClip && source != NULL) {
366 m_markerMenu->clear();
367 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
368 if (!markers.isEmpty()) {
370 for (int i = 0; i < markers.count(); i++) {
371 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
373 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
374 QAction *go = m_markerMenu->addAction(position);
377 m_ruler->setMarkers(marks);
378 } else m_ruler->setMarkers(QList <int>());
379 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
383 void Monitor::slotSeekToPreviousSnap()
385 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
388 void Monitor::slotSeekToNextSnap()
390 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
393 GenTime Monitor::position()
395 return render->seekPosition();
398 GenTime Monitor::getSnapForPos(bool previous)
400 QList <GenTime> snaps;
401 QList < GenTime > markers = m_currentClip->snapMarkers();
402 for (int i = 0; i < markers.size(); ++i) {
403 GenTime t = markers.at(i);
406 QPoint zone = m_ruler->zone();
407 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
408 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
409 snaps.append(GenTime());
410 snaps.append(m_currentClip->duration());
413 const GenTime pos = render->seekPosition();
414 for (int i = 0; i < snaps.size(); ++i) {
415 if (previous && snaps.at(i) >= pos) {
417 return snaps.at(i - 1);
418 } else if (!previous && snaps.at(i) > pos) {
425 void Monitor::slotZoneMoved(int start, int end)
427 m_ruler->setZone(start, end);
429 setClipZone(m_ruler->zone());
432 void Monitor::slotSetZoneStart()
434 m_ruler->setZone(m_ruler->position(), -1);
435 emit zoneUpdated(m_ruler->zone());
437 setClipZone(m_ruler->zone());
440 void Monitor::slotSetZoneEnd()
442 m_ruler->setZone(-1, m_ruler->position());
443 emit zoneUpdated(m_ruler->zone());
445 setClipZone(m_ruler->zone());
449 void Monitor::mousePressEvent(QMouseEvent * event)
451 if (event->button() != Qt::RightButton) {
452 if (m_videoBox->underMouse() && (!m_overlay || !m_overlay->underMouse())) {
453 m_dragStarted = true;
454 m_DragStartPosition = event->pos();
456 } else if (!m_effectWidget || !m_effectWidget->isVisible()) {
457 m_contextMenu->popup(event->globalPos());
461 void Monitor::resizeEvent(QResizeEvent *event)
464 if (render && isVisible() && isActive()) render->doRefresh();
468 void Monitor::slotSwitchFullScreen()
470 m_videoBox->switchFullScreen();
474 void Monitor::mouseReleaseEvent(QMouseEvent * event)
477 if (m_videoBox->underMouse() && (!m_effectWidget || !m_effectWidget->isVisible())) {
478 if (isActive()) slotPlay();
479 else activateMonitor();
480 } else QWidget::mouseReleaseEvent(event);
481 m_dragStarted = false;
486 void Monitor::mouseMoveEvent(QMouseEvent *event)
488 // kDebug() << "// DRAG STARTED, MOUSE MOVED: ";
489 if (!m_dragStarted || m_currentClip == NULL) return;
491 if ((event->pos() - m_DragStartPosition).manhattanLength()
492 < QApplication::startDragDistance())
496 QDrag *drag = new QDrag(this);
497 QMimeData *mimeData = new QMimeData;
500 list.append(m_currentClip->getId());
501 QPoint p = m_ruler->zone();
502 list.append(QString::number(p.x()));
503 list.append(QString::number(p.y()));
505 data.append(list.join(";").toUtf8());
506 mimeData->setData("kdenlive/clip", data);
507 drag->setMimeData(mimeData);
508 /*QPixmap pix = m_currentClip->thumbnail();
509 drag->setPixmap(pix);
510 drag->setHotSpot(QPoint(0, 50));*/
511 drag->start(Qt::MoveAction);
513 //Qt::DropAction dropAction;
514 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
516 //Qt::DropAction dropAction = drag->exec();
522 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
523 event->setDropAction(Qt::IgnoreAction);
524 event->setDropAction(Qt::MoveAction);
525 if (event->mimeData()->hasText()) {
526 event->acceptProposedAction();
530 Qt::DropActions Monitor::supportedDropActions() const {
531 // returns what actions are supported when dropping
532 return Qt::MoveAction;
535 QStringList Monitor::mimeTypes() const
537 QStringList qstrList;
538 // list of accepted mime types for drop
539 qstrList.append("kdenlive/clip");
544 void Monitor::wheelEvent(QWheelEvent * event)
546 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
550 void Monitor::slotMouseSeek(int eventDelta, bool fast)
553 int delta = m_monitorManager->timecode().fps();
554 if (eventDelta > 0) delta = 0 - delta;
555 slotSeek(m_ruler->position() - delta);
557 if (eventDelta >= 0) slotForwardOneFrame();
558 else slotRewindOneFrame();
562 void Monitor::slotSetThumbFrame()
564 if (m_currentClip == NULL) {
567 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
568 emit refreshClipThumbnail(m_currentClip->getId(), true);
571 void Monitor::slotExtractCurrentZone()
573 if (m_currentClip == NULL) return;
574 emit extractZone(m_currentClip->getId(), m_ruler->zone());
577 void Monitor::slotExtractCurrentFrame()
580 // check if we are using a proxy
581 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
582 // using proxy, use original clip url to get frame
583 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
585 else frame = render->extractFrame(render->seekFramePosition());
586 KFileDialog *fs = new KFileDialog(KUrl(), "image/png", this);
587 fs->setOperationMode(KFileDialog::Saving);
588 fs->setMode(KFile::File);
589 fs->setConfirmOverwrite(true);
590 fs->setKeepLocation(true);
592 QString path = fs->selectedFile();
594 if (!path.isEmpty()) {
599 bool Monitor::isActive() const
601 return m_monitorManager->isActive(m_name);
604 bool Monitor::activateMonitor()
606 return m_monitorManager->activateMonitor(m_name);
609 void Monitor::setTimePos(const QString &pos)
611 m_timePos->setValue(pos);
615 void Monitor::slotSeek()
617 slotSeek(m_timePos->getValue());
620 void Monitor::slotSeek(int pos)
622 if (render == NULL) return;
624 render->seekToFrame(pos);
627 void Monitor::checkOverlay()
629 if (m_overlay == NULL) return;
630 int pos = m_ruler->position();
631 QPoint zone = m_ruler->zone();
633 m_overlay->setOverlayText(i18n("In Point"));
634 else if (pos == zone.y())
635 m_overlay->setOverlayText(i18n("Out Point"));
638 QString markerComment = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
639 if (markerComment.isEmpty())
640 m_overlay->setHidden(true);
642 m_overlay->setOverlayText(markerComment, false);
643 } else m_overlay->setHidden(true);
647 void Monitor::slotStart()
651 render->seekToFrame(0);
654 void Monitor::slotEnd()
658 render->seekToFrame(render->getLength());
661 void Monitor::slotZoneStart()
665 render->seekToFrame(m_ruler->zone().x());
668 void Monitor::slotZoneEnd()
672 render->seekToFrame(m_ruler->zone().y());
675 void Monitor::slotRewind(double speed)
679 double currentspeed = render->playSpeed();
680 if (currentspeed >= 0) render->play(-2);
681 else render->play(currentspeed * 2);
682 } else render->play(speed);
683 //m_playAction->setChecked(true);
684 m_playAction->setIcon(m_pauseIcon);
687 void Monitor::slotForward(double speed)
691 double currentspeed = render->playSpeed();
692 if (currentspeed <= 1) render->play(2);
693 else render->play(currentspeed * 2);
694 } else render->play(speed);
695 //m_playAction->setChecked(true);
696 m_playAction->setIcon(m_pauseIcon);
699 void Monitor::slotRewindOneFrame(int diff)
703 render->seekToFrameDiff(-diff);
706 void Monitor::slotForwardOneFrame(int diff)
710 render->seekToFrameDiff(diff);
713 void Monitor::seekCursor(int pos)
716 if (m_ruler->slotNewValue(pos)) {
718 m_timePos->setValue(pos);
722 void Monitor::rendererStopped(int pos)
724 if (m_ruler->slotNewValue(pos)) {
726 m_timePos->setValue(pos);
728 m_playAction->setIcon(m_playIcon);
731 void Monitor::adjustRulerSize(int length)
733 if (length > 0) m_length = length;
734 m_ruler->adjustScale(m_length);
735 if (m_currentClip != NULL) {
736 QPoint zone = m_currentClip->zone();
737 m_ruler->setZone(zone.x(), zone.y());
743 if (render) render->stop();
746 void Monitor::start()
748 if (!isVisible()) return;
749 if (render) render->start();
752 void Monitor::refreshMonitor(bool visible)
754 if (visible && render) {
755 if (!activateMonitor()) {
756 // the monitor was already active, simply refreshClipThumbnail
762 void Monitor::refreshMonitor()
769 void Monitor::pause()
771 if (render == NULL) return;
774 //m_playAction->setChecked(true);
775 m_playAction->setIcon(m_playIcon);
778 void Monitor::slotPlay()
780 if (render == NULL) return;
782 if (render->playSpeed() == 0.0) {
783 m_playAction->setIcon(m_pauseIcon);
784 render->switchPlay(true);
786 m_playAction->setIcon(m_playIcon);
787 render->switchPlay(false);
791 void Monitor::slotPlayZone()
793 if (render == NULL) return;
795 QPoint p = m_ruler->zone();
796 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
797 //m_playAction->setChecked(true);
798 m_playAction->setIcon(m_pauseIcon);
801 void Monitor::slotLoopZone()
803 if (render == NULL) return;
805 QPoint p = m_ruler->zone();
806 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
807 //m_playAction->setChecked(true);
808 m_playAction->setIcon(m_pauseIcon);
811 void Monitor::slotLoopClip()
813 if (render == NULL || m_selectedClip == NULL)
816 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
817 //m_playAction->setChecked(true);
818 m_playAction->setIcon(m_pauseIcon);
821 void Monitor::updateClipProducer(Mlt::Producer *prod)
823 if (render == NULL) return;
824 render->setProducer(prod, render->seekFramePosition());
827 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
829 if (render == NULL) return;
830 if (clip == NULL && m_currentClip != NULL) {
831 kDebug()<<"// SETTING NULL CLIP MONITOR";
832 m_currentClip = NULL;
834 render->setProducer(NULL, -1);
838 if (clip != m_currentClip || forceUpdate) {
839 m_currentClip = clip;
840 if (m_currentClip) activateMonitor();
842 Mlt::Producer *prod = NULL;
843 if (clip) prod = clip->getCloneProducer();
844 if (render->setProducer(prod, position) == -1) {
845 // MLT CONSUMER is broken
846 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
851 if (position == -1) position = render->seekFramePosition();
852 render->seek(position);
855 if (!zone.isNull()) {
856 m_ruler->setZone(zone.x(), zone.y());
857 render->seek(zone.x());
861 void Monitor::slotOpenFile(const QString &file)
863 if (render == NULL) return;
866 QDomElement mlt = doc.createElement("mlt");
867 doc.appendChild(mlt);
868 QDomElement prod = doc.createElement("producer");
869 mlt.appendChild(prod);
870 prod.setAttribute("mlt_service", "avformat");
871 prod.setAttribute("resource", file);
872 render->setSceneList(doc, 0);
875 void Monitor::slotSaveZone()
877 if (render == NULL) return;
878 emit saveZone(render, m_ruler->zone(), m_currentClip);
880 //render->setSceneList(doc, 0);
883 void Monitor::resetProfile(const QString &profile)
885 m_timePos->updateTimeCode(m_monitorManager->timecode());
886 if (render == NULL) return;
887 if (!render->hasProfile(profile)) {
889 render->resetProfile(profile);
892 m_effectWidget->resetProfile(render);
895 void Monitor::saveSceneList(QString path, QDomElement info)
897 if (render == NULL) return;
898 render->saveSceneList(path, info);
901 const QString Monitor::sceneList()
903 if (render == NULL) return QString();
904 return render->sceneList();
907 void Monitor::setClipZone(QPoint pos)
909 if (m_currentClip == NULL) return;
910 m_currentClip->setZone(pos);
913 void Monitor::slotSwitchDropFrames(bool show)
915 render->setDropFrames(show);
918 void Monitor::slotSwitchMonitorInfo(bool show)
920 KdenliveSettings::setDisplayMonitorInfo(show);
922 if (m_overlay) return;
923 if (m_monitorRefresh == NULL) {
924 // Using OpenGL display
926 if (m_glWidget->layout()) delete m_glWidget->layout();
927 m_overlay = new Overlay();
928 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
929 QVBoxLayout *layout = new QVBoxLayout;
930 layout->addStretch(10);
931 layout->addWidget(m_overlay);
932 m_glWidget->setLayout(layout);
935 if (m_monitorRefresh->layout()) delete m_monitorRefresh->layout();
936 m_overlay = new Overlay();
937 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
938 QVBoxLayout *layout = new QVBoxLayout;
939 layout->addStretch(10);
940 layout->addWidget(m_overlay);
941 m_monitorRefresh->setLayout(layout);
943 m_overlay->setHidden(true);
952 void Monitor::slotEditMarker()
954 if (m_editMarker) m_editMarker->trigger();
957 void Monitor::updateTimecodeFormat()
959 m_timePos->slotUpdateTimeCodeFormat();
962 QStringList Monitor::getZoneInfo() const
965 if (m_currentClip == NULL) return result;
966 result << m_currentClip->getId();
967 QPoint zone = m_ruler->zone();
968 result << QString::number(zone.x()) << QString::number(zone.y());
972 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
975 m_loopClipAction->setEnabled(true);
976 m_selectedClip = item;
978 m_loopClipAction->setEnabled(false);
982 void Monitor::slotSetSelectedClip(ClipItem* item)
984 if (item || (!item && !m_loopClipTransition)) {
985 m_loopClipTransition = false;
986 slotSetSelectedClip((AbstractClipItem*)item);
990 void Monitor::slotSetSelectedClip(Transition* item)
992 if (item || (!item && m_loopClipTransition)) {
993 m_loopClipTransition = true;
994 slotSetSelectedClip((AbstractClipItem*)item);
999 void Monitor::slotEffectScene(bool show)
1001 if (m_name == "project") {
1002 if (m_monitorRefresh) {
1003 m_monitorRefresh->setVisible(!show);
1006 m_glWidget->setVisible(!show);
1009 m_effectWidget->setVisible(show);
1010 m_effectWidget->getVisibilityAction()->setChecked(show);
1011 emit requestFrameForAnalysis(show);
1013 m_effectWidget->getScene()->slotZoomFit();
1015 render->doRefresh();
1019 MonitorEditWidget* Monitor::getEffectEdit()
1021 return m_effectWidget;
1024 bool Monitor::effectSceneDisplayed()
1026 return m_effectWidget->isVisible();
1029 void Monitor::slotSetVolume(int volume)
1031 KdenliveSettings::setVolume(volume);
1033 if (volume == 0) icon = KIcon("audio-volume-muted");
1034 else icon = KIcon("audio-volume-medium");
1035 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1036 render->slotSetVolume(volume);
1039 void Monitor::slotShowVolume()
1041 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1042 int vol = render->volume();
1043 // Disable widget if we cannot get the volume
1044 m_volumePopup->setEnabled(vol != -1);
1045 m_audioSlider->blockSignals(true);
1046 m_audioSlider->setValue(vol);
1047 m_audioSlider->blockSignals(false);
1048 m_volumePopup->show();
1051 AbstractRender *Monitor::abstractRender()
1056 void Monitor::reloadProducer(const QString &id)
1058 if (!m_currentClip) return;
1059 if (m_currentClip->getId() == id)
1060 slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
1063 MonitorRefresh::MonitorRefresh(QWidget* parent) :
1067 // MonitorRefresh is used as container for the SDL display (it's window id is passed to SDL)
1068 setAttribute(Qt::WA_PaintOnScreen);
1069 setAttribute(Qt::WA_OpaquePaintEvent);
1070 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
1071 //setAttribute(Qt::WA_NoSystemBackground);
1074 void MonitorRefresh::setRenderer(Render* render)
1076 m_renderer = render;
1080 Overlay::Overlay(QWidget* parent) :
1083 //setAttribute(Qt::WA_TransparentForMouseEvents);
1084 setAutoFillBackground(true);
1085 setBackgroundRole(QPalette::Base);
1086 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1087 setCursor(Qt::PointingHandCursor);
1091 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1097 void Overlay::mousePressEvent( QMouseEvent * event )
1103 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1109 void Overlay::setOverlayText(const QString &text, bool isZone)
1114 p.setColor(QPalette::Text, Qt::white);
1115 if (m_isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1116 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1118 setText(' ' + text + ' ');
1123 VideoContainer::VideoContainer(Monitor* parent) :
1127 setFrameShape(QFrame::NoFrame);
1128 setFocusPolicy(Qt::ClickFocus);
1129 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
1133 void VideoContainer::mousePressEvent(QMouseEvent * event)
1135 if (m_monitor->underMouse()) event->setAccepted(false);
1139 void VideoContainer::mouseReleaseEvent(QMouseEvent * event)
1141 if (m_monitor->underMouse()) event->setAccepted(false);
1143 if (m_monitor->isActive()) {
1144 m_monitor->slotPlay();
1151 void VideoContainer::mouseMoveEvent(QMouseEvent *event)
1153 if (m_monitor->underMouse()) event->setAccepted(false);
1157 void VideoContainer::keyPressEvent(QKeyEvent *event)
1159 // Exit fullscreen with Esc key
1160 if (event->key() == Qt::Key_Escape && isFullScreen()) {
1162 event->setAccepted(true);
1163 } else event->setAccepted(false);
1167 void VideoContainer::wheelEvent(QWheelEvent * event)
1169 if (m_monitor->underMouse()) event->setAccepted(false);
1171 m_monitor->slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
1176 void VideoContainer::mouseDoubleClickEvent(QMouseEvent * event)
1180 if (!KdenliveSettings::openglmonitors())
1184 void VideoContainer::switchFullScreen()
1186 // TODO: disable screensaver?
1187 Qt::WindowFlags flags = windowFlags();
1188 if (!isFullScreen()) {
1189 // Check if we ahave a multiple monitor setup
1190 setUpdatesEnabled(false);
1191 #if QT_VERSION >= 0x040600
1192 int monitors = QApplication::desktop()->screenCount();
1194 int monitors = QApplication::desktop()->numScreens();
1198 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
1199 int currentScreen = QApplication::desktop()->screenNumber(this);
1200 if (currentScreen < monitors - 1)
1201 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
1203 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
1204 move(QPoint(screenres.x(), screenres.y()));
1205 resize(screenres.width(), screenres.height());
1208 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
1209 flags |= Qt::Window;
1210 flags ^= Qt::SubWindow;
1211 setWindowFlags(flags);
1213 // This works around a bug with Compiz
1214 // as the window must be visible before we can set the state
1217 setWindowState(windowState() | Qt::WindowFullScreen); // set
1219 setWindowState(windowState() | Qt::WindowFullScreen); // set
1220 setUpdatesEnabled(true);
1224 setUpdatesEnabled(false);
1225 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
1226 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
1227 setWindowFlags(flags);
1228 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset
1229 setUpdatesEnabled(true);
1236 #include "monitor.moc"