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(Kdenlive::MONITORID id, MonitorManager *manager, QString profile, QWidget *parent) :
47 AbstractMonitor(id, parent),
49 m_monitorManager(manager),
51 m_ruler(new SmallRuler(m_monitorManager)),
56 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(this);
81 m_toolbar->setIconSize(QSize(s, s));
83 m_playIcon = KIcon("media-playback-start");
84 m_pauseIcon = KIcon("media-playback-pause");
86 if (id != Kdenlive::dvdMonitor) {
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 (id != Kdenlive::dvdMonitor) {
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 (id == Kdenlive::clipMonitor) {
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_id, (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 (id != Kdenlive::clipMonitor) {
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 (id == Kdenlive::projectMonitor) {
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()
229 bool Monitor::createOpenGlWidget(QWidget *parent, const QString profile)
231 render = new Render(id(), 0, profile, this);
232 m_glWidget = new VideoGLWidget(parent);
233 if (m_glWidget == NULL) {
234 // Creation failed, we are in trouble...
237 m_glWidget->setImageAspectRatio(render->dar());
238 m_glWidget->setBackgroundColor(KdenliveSettings::window_background());
239 connect(render, SIGNAL(showImageSignal(QImage)), m_glWidget, SLOT(showImage(QImage)));
244 void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu, QAction *loopClip)
246 m_contextMenu = new QMenu(this);
247 m_contextMenu->addMenu(m_playMenu);
249 m_contextMenu->addMenu(goMenu);
251 m_contextMenu->addMenu(markerMenu);
252 QList <QAction *>list = markerMenu->actions();
253 for (int i = 0; i < list.count(); i++) {
254 if (list.at(i)->data().toString() == "edit_marker") {
255 m_editMarker = list.at(i);
261 m_playMenu->addAction(playZone);
262 m_playMenu->addAction(loopZone);
264 m_loopClipAction = loopClip;
265 m_playMenu->addAction(loopClip);
268 //TODO: add save zone to timeline monitor when fixed
269 if (m_id == Kdenlive::clipMonitor) {
270 m_contextMenu->addMenu(m_markerMenu);
271 m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
272 QAction *extractZone = m_configMenu->addAction(KIcon("document-new"), i18n("Extract Zone"), this, SLOT(slotExtractCurrentZone()));
273 m_contextMenu->addAction(extractZone);
275 QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
276 m_contextMenu->addAction(extractFrame);
278 if (m_id != Kdenlive::clipMonitor) {
279 QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
280 splitView->setCheckable(true);
281 m_configMenu->addAction(splitView);
283 QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
284 m_configMenu->addAction(setThumbFrame);
287 QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
288 showTips->setCheckable(true);
289 connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
290 showTips->setChecked(KdenliveSettings::displayMonitorInfo());
292 QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
293 dropFrames->setCheckable(true);
294 dropFrames->setChecked(true);
295 connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
297 m_configMenu->addAction(showTips);
298 m_configMenu->addAction(dropFrames);
302 void Monitor::slotGoToMarker(QAction *action)
304 int pos = action->data().toInt();
308 void Monitor::slotSetSizeOneToOne()
310 QRect r = QApplication::desktop()->screenGeometry();
311 const int maxWidth = r.width() - 20;
312 const int maxHeight = r.height() - 20;
313 int width = render->renderWidth();
314 int height = render->renderHeight();
315 kDebug() << "// render info: " << width << "x" << height;
316 while (width >= maxWidth || height >= maxHeight) {
318 height = height * 0.8;
320 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
321 m_videoBox->setFixedSize(width, height);
324 //m_ui.video_frame->setMinimumSize(0, 0);
325 emit adjustMonitorSize();
328 void Monitor::slotSetSizeOneToTwo()
330 QRect r = QApplication::desktop()->screenGeometry();
331 const int maxWidth = r.width() - 20;
332 const int maxHeight = r.height() - 20;
333 int width = render->renderWidth() / 2;
334 int height = render->renderHeight() / 2;
335 kDebug() << "// render info: " << width << "x" << height;
336 while (width >= maxWidth || height >= maxHeight) {
338 height = height * 0.8;
340 kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
341 m_videoBox->setFixedSize(width, height);
344 //m_ui.video_frame->setMinimumSize(0, 0);
345 emit adjustMonitorSize();
348 void Monitor::resetSize()
350 m_videoBox->setMinimumSize(0, 0);
353 DocClipBase *Monitor::activeClip()
355 return m_currentClip;
358 void Monitor::updateMarkers(DocClipBase *source)
360 if (source == m_currentClip && source != NULL) {
361 m_markerMenu->clear();
362 QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
363 if (!markers.isEmpty()) {
365 for (int i = 0; i < markers.count(); i++) {
366 int pos = (int) markers.at(i).time().frames(m_monitorManager->timecode().fps());
368 QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
369 QAction *go = m_markerMenu->addAction(position);
372 m_ruler->setMarkers(marks);
373 } else m_ruler->setMarkers(QList <int>());
374 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
378 void Monitor::slotSeekToPreviousSnap()
380 if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
383 void Monitor::slotSeekToNextSnap()
385 if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
388 GenTime Monitor::position()
390 return render->seekPosition();
393 GenTime Monitor::getSnapForPos(bool previous)
395 QList <GenTime> snaps;
396 QList < GenTime > markers = m_currentClip->snapMarkers();
397 for (int i = 0; i < markers.size(); ++i) {
398 GenTime t = markers.at(i);
401 QPoint zone = m_ruler->zone();
402 snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
403 snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
404 snaps.append(GenTime());
405 snaps.append(m_currentClip->duration());
408 const GenTime pos = render->seekPosition();
409 for (int i = 0; i < snaps.size(); ++i) {
410 if (previous && snaps.at(i) >= pos) {
412 return snaps.at(i - 1);
413 } else if (!previous && snaps.at(i) > pos) {
420 void Monitor::slotZoneMoved(int start, int end)
422 m_ruler->setZone(start, end);
424 setClipZone(m_ruler->zone());
427 void Monitor::slotSetZoneStart()
429 m_ruler->setZone(m_ruler->position(), -1);
430 emit zoneUpdated(m_ruler->zone());
432 setClipZone(m_ruler->zone());
435 void Monitor::slotSetZoneEnd()
437 m_ruler->setZone(-1, m_ruler->position());
438 emit zoneUpdated(m_ruler->zone());
440 setClipZone(m_ruler->zone());
444 void Monitor::mousePressEvent(QMouseEvent * event)
446 if (event->button() != Qt::RightButton) {
447 if (m_videoBox->geometry().contains(event->pos()) && (!m_overlay || !m_overlay->underMouse())) {
448 m_dragStarted = true;
449 m_DragStartPosition = event->pos();
451 } else if (m_contextMenu && (!m_effectWidget || !m_effectWidget->isVisible())) {
452 m_contextMenu->popup(event->globalPos());
456 void Monitor::resizeEvent(QResizeEvent *event)
459 if (render && isVisible() && isActive()) render->doRefresh();
463 void Monitor::slotSwitchFullScreen()
465 m_videoBox->switchFullScreen();
469 void Monitor::mouseReleaseEvent(QMouseEvent * event)
471 if (m_dragStarted && event->button() != Qt::RightButton) {
472 if (m_videoBox->geometry().contains(event->pos()) && (!m_effectWidget || !m_effectWidget->isVisible())) {
473 if (isActive()) slotPlay();
474 else activateMonitor();
475 } //else event->ignore(); //QWidget::mouseReleaseEvent(event);
476 m_dragStarted = false;
481 void Monitor::mouseMoveEvent(QMouseEvent *event)
483 if (!m_dragStarted || m_currentClip == NULL) return;
485 if ((event->pos() - m_DragStartPosition).manhattanLength()
486 < QApplication::startDragDistance())
490 QDrag *drag = new QDrag(this);
491 QMimeData *mimeData = new QMimeData;
494 list.append(m_currentClip->getId());
495 QPoint p = m_ruler->zone();
496 list.append(QString::number(p.x()));
497 list.append(QString::number(p.y()));
499 data.append(list.join(";").toUtf8());
500 mimeData->setData("kdenlive/clip", data);
501 drag->setMimeData(mimeData);
502 /*QPixmap pix = m_currentClip->thumbnail();
503 drag->setPixmap(pix);
504 drag->setHotSpot(QPoint(0, 50));*/
505 drag->start(Qt::MoveAction);
507 //Qt::DropAction dropAction;
508 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
510 //Qt::DropAction dropAction = drag->exec();
516 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
517 event->setDropAction(Qt::IgnoreAction);
518 event->setDropAction(Qt::MoveAction);
519 if (event->mimeData()->hasText()) {
520 event->acceptProposedAction();
524 Qt::DropActions Monitor::supportedDropActions() const {
525 // returns what actions are supported when dropping
526 return Qt::MoveAction;
529 QStringList Monitor::mimeTypes() const
531 QStringList qstrList;
532 // list of accepted mime types for drop
533 qstrList.append("kdenlive/clip");
538 void Monitor::wheelEvent(QWheelEvent * event)
540 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
544 void Monitor::mouseDoubleClickEvent(QMouseEvent * event)
546 if (!KdenliveSettings::openglmonitors()) {
547 m_videoBox->switchFullScreen();
552 void Monitor::slotMouseSeek(int eventDelta, bool fast)
555 int delta = m_monitorManager->timecode().fps();
556 if (eventDelta > 0) delta = 0 - delta;
557 slotSeek(m_ruler->position() - delta);
559 if (eventDelta >= 0) slotForwardOneFrame();
560 else slotRewindOneFrame();
564 void Monitor::slotSetThumbFrame()
566 if (m_currentClip == NULL) {
569 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
570 emit refreshClipThumbnail(m_currentClip->getId(), true);
573 void Monitor::slotExtractCurrentZone()
575 if (m_currentClip == NULL) return;
576 emit extractZone(m_currentClip->getId(), m_ruler->zone());
579 void Monitor::slotExtractCurrentFrame()
582 // check if we are using a proxy
583 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
584 // using proxy, use original clip url to get frame
585 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
587 else frame = render->extractFrame(render->seekFramePosition());
588 KFileDialog *fs = new KFileDialog(KUrl(), "image/png", this);
589 fs->setOperationMode(KFileDialog::Saving);
590 fs->setMode(KFile::File);
591 fs->setConfirmOverwrite(true);
592 fs->setKeepLocation(true);
594 QString path = fs->selectedFile();
596 if (!path.isEmpty()) {
601 bool Monitor::isActive() const
603 return m_monitorManager->isActive(m_id);
606 bool Monitor::activateMonitor()
608 return m_monitorManager->activateMonitor(m_id);
611 void Monitor::setTimePos(const QString &pos)
613 m_timePos->setValue(pos);
617 void Monitor::slotSeek()
619 slotSeek(m_timePos->getValue());
622 void Monitor::slotSeek(int pos)
624 if (render == NULL) return;
626 render->seekToFrame(pos);
629 void Monitor::checkOverlay()
631 if (m_overlay == NULL) return;
632 int pos = m_ruler->position();
633 QPoint zone = m_ruler->zone();
635 m_overlay->setOverlayText(i18n("In Point"));
636 else if (pos == zone.y())
637 m_overlay->setOverlayText(i18n("Out Point"));
640 QString markerComment = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
641 if (markerComment.isEmpty())
642 m_overlay->setHidden(true);
644 m_overlay->setOverlayText(markerComment, false);
645 } else m_overlay->setHidden(true);
649 void Monitor::slotStart()
653 render->seekToFrame(0);
656 void Monitor::slotEnd()
660 render->seekToFrame(render->getLength());
663 void Monitor::slotZoneStart()
667 render->seekToFrame(m_ruler->zone().x());
670 void Monitor::slotZoneEnd()
674 render->seekToFrame(m_ruler->zone().y());
677 void Monitor::slotRewind(double speed)
681 double currentspeed = render->playSpeed();
682 if (currentspeed >= 0) render->play(-2);
683 else render->play(currentspeed * 2);
684 } else render->play(speed);
685 //m_playAction->setChecked(true);
686 m_playAction->setIcon(m_pauseIcon);
689 void Monitor::slotForward(double speed)
693 double currentspeed = render->playSpeed();
694 if (currentspeed <= 1) render->play(2);
695 else render->play(currentspeed * 2);
696 } else render->play(speed);
697 //m_playAction->setChecked(true);
698 m_playAction->setIcon(m_pauseIcon);
701 void Monitor::slotRewindOneFrame(int diff)
705 render->seekToFrameDiff(-diff);
708 void Monitor::slotForwardOneFrame(int diff)
712 render->seekToFrameDiff(diff);
715 void Monitor::seekCursor(int pos)
718 if (m_ruler->slotNewValue(pos)) {
720 m_timePos->setValue(pos);
724 void Monitor::rendererStopped(int pos)
726 if (m_ruler->slotNewValue(pos)) {
728 m_timePos->setValue(pos);
730 m_playAction->setIcon(m_playIcon);
733 void Monitor::adjustRulerSize(int length)
735 if (length > 0) m_length = length;
736 m_ruler->adjustScale(m_length);
737 if (m_currentClip != NULL) {
738 QPoint zone = m_currentClip->zone();
739 m_ruler->setZone(zone.x(), zone.y());
745 if (render) render->stop();
748 void Monitor::start()
750 if (!isVisible()) return;
751 if (render) render->start();
754 void Monitor::refreshMonitor(bool visible)
756 if (visible && render) {
757 if (!activateMonitor()) {
758 // the monitor was already active, simply refreshClipThumbnail
764 void Monitor::refreshMonitor()
771 void Monitor::pause()
773 if (render == NULL) return;
776 //m_playAction->setChecked(true);
777 m_playAction->setIcon(m_playIcon);
780 void Monitor::slotPlay()
782 if (render == NULL) return;
784 if (render->playSpeed() == 0.0) {
785 m_playAction->setIcon(m_pauseIcon);
786 render->switchPlay(true);
788 m_playAction->setIcon(m_playIcon);
789 render->switchPlay(false);
793 void Monitor::slotPlayZone()
795 if (render == NULL) return;
797 QPoint p = m_ruler->zone();
798 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
799 //m_playAction->setChecked(true);
800 m_playAction->setIcon(m_pauseIcon);
803 void Monitor::slotLoopZone()
805 if (render == NULL) return;
807 QPoint p = m_ruler->zone();
808 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
809 //m_playAction->setChecked(true);
810 m_playAction->setIcon(m_pauseIcon);
813 void Monitor::slotLoopClip()
815 if (render == NULL || m_selectedClip == NULL)
818 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
819 //m_playAction->setChecked(true);
820 m_playAction->setIcon(m_pauseIcon);
823 void Monitor::updateClipProducer(Mlt::Producer *prod)
825 if (render == NULL) return;
826 render->setProducer(prod, render->seekFramePosition());
829 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
831 if (render == NULL) return;
832 if (clip == NULL && m_currentClip != NULL) {
833 kDebug()<<"// SETTING NULL CLIP MONITOR";
834 m_currentClip = NULL;
836 render->setProducer(NULL, -1);
840 if (clip != m_currentClip || forceUpdate) {
841 m_currentClip = clip;
842 if (m_currentClip) activateMonitor();
844 Mlt::Producer *prod = NULL;
845 if (clip) prod = clip->getCloneProducer();
846 if (render->setProducer(prod, position) == -1) {
847 // MLT CONSUMER is broken
848 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
853 if (position == -1) position = render->seekFramePosition();
854 render->seek(position);
857 if (!zone.isNull()) {
858 m_ruler->setZone(zone.x(), zone.y());
859 render->seek(zone.x());
863 void Monitor::slotOpenFile(const QString &file)
865 if (render == NULL) return;
868 QDomElement mlt = doc.createElement("mlt");
869 doc.appendChild(mlt);
870 QDomElement prod = doc.createElement("producer");
871 mlt.appendChild(prod);
872 prod.setAttribute("mlt_service", "avformat");
873 prod.setAttribute("resource", file);
874 render->setSceneList(doc, 0);
877 void Monitor::slotSaveZone()
879 if (render == NULL) return;
880 emit saveZone(render, m_ruler->zone(), m_currentClip);
882 //render->setSceneList(doc, 0);
885 void Monitor::resetProfile(const QString &profile)
887 m_timePos->updateTimeCode(m_monitorManager->timecode());
888 if (render == NULL) return;
889 if (!render->hasProfile(profile)) {
891 render->resetProfile(profile);
894 m_effectWidget->resetProfile(render);
897 void Monitor::saveSceneList(QString path, QDomElement info)
899 if (render == NULL) return;
900 render->saveSceneList(path, info);
903 const QString Monitor::sceneList()
905 if (render == NULL) return QString();
906 return render->sceneList();
909 void Monitor::setClipZone(QPoint pos)
911 if (m_currentClip == NULL) return;
912 m_currentClip->setZone(pos);
915 void Monitor::slotSwitchDropFrames(bool show)
917 render->setDropFrames(show);
920 void Monitor::slotSwitchMonitorInfo(bool show)
922 KdenliveSettings::setDisplayMonitorInfo(show);
924 if (m_overlay) return;
925 if (m_monitorRefresh == NULL) {
926 // Using OpenGL display
928 if (m_glWidget->layout()) delete m_glWidget->layout();
929 m_overlay = new Overlay();
930 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
931 QVBoxLayout *layout = new QVBoxLayout;
932 layout->addStretch(10);
933 layout->addWidget(m_overlay);
934 m_glWidget->setLayout(layout);
937 if (m_monitorRefresh->layout()) delete m_monitorRefresh->layout();
938 m_overlay = new Overlay();
939 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
940 QVBoxLayout *layout = new QVBoxLayout;
941 layout->addStretch(10);
942 layout->addWidget(m_overlay);
943 m_monitorRefresh->setLayout(layout);
945 m_overlay->setHidden(true);
954 void Monitor::slotEditMarker()
956 if (m_editMarker) m_editMarker->trigger();
959 void Monitor::updateTimecodeFormat()
961 m_timePos->slotUpdateTimeCodeFormat();
964 QStringList Monitor::getZoneInfo() const
967 if (m_currentClip == NULL) return result;
968 result << m_currentClip->getId();
969 QPoint zone = m_ruler->zone();
970 result << QString::number(zone.x()) << QString::number(zone.y());
974 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
977 m_loopClipAction->setEnabled(true);
978 m_selectedClip = item;
980 m_loopClipAction->setEnabled(false);
984 void Monitor::slotSetSelectedClip(ClipItem* item)
986 if (item || (!item && !m_loopClipTransition)) {
987 m_loopClipTransition = false;
988 slotSetSelectedClip((AbstractClipItem*)item);
992 void Monitor::slotSetSelectedClip(Transition* item)
994 if (item || (!item && m_loopClipTransition)) {
995 m_loopClipTransition = true;
996 slotSetSelectedClip((AbstractClipItem*)item);
1001 void Monitor::slotEffectScene(bool show)
1003 if (m_id == Kdenlive::projectMonitor) {
1004 if (m_monitorRefresh) {
1005 m_monitorRefresh->setVisible(!show);
1008 m_glWidget->setVisible(!show);
1011 m_effectWidget->setVisible(show);
1012 m_effectWidget->getVisibilityAction()->setChecked(show);
1013 emit requestFrameForAnalysis(show);
1015 m_effectWidget->getScene()->slotZoomFit();
1017 m_videoBox->setEnabled(show);
1018 render->doRefresh();
1022 MonitorEditWidget* Monitor::getEffectEdit()
1024 return m_effectWidget;
1027 bool Monitor::effectSceneDisplayed()
1029 return m_effectWidget->isVisible();
1032 void Monitor::slotSetVolume(int volume)
1034 KdenliveSettings::setVolume(volume);
1036 if (volume == 0) icon = KIcon("audio-volume-muted");
1037 else icon = KIcon("audio-volume-medium");
1038 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1039 render->slotSetVolume(volume);
1042 void Monitor::slotShowVolume()
1044 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1045 int vol = render->volume();
1046 // Disable widget if we cannot get the volume
1047 m_volumePopup->setEnabled(vol != -1);
1048 m_audioSlider->blockSignals(true);
1049 m_audioSlider->setValue(vol);
1050 m_audioSlider->blockSignals(false);
1051 m_volumePopup->show();
1054 AbstractRender *Monitor::abstractRender()
1059 void Monitor::reloadProducer(const QString &id)
1061 if (!m_currentClip) return;
1062 if (m_currentClip->getId() == id)
1063 slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
1066 MonitorRefresh::MonitorRefresh(QWidget* parent) :
1070 // MonitorRefresh is used as container for the SDL display (it's window id is passed to SDL)
1071 setAttribute(Qt::WA_PaintOnScreen);
1072 setAttribute(Qt::WA_OpaquePaintEvent);
1073 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
1074 //setAttribute(Qt::WA_NoSystemBackground);
1077 void MonitorRefresh::setRenderer(Render* render)
1079 m_renderer = render;
1083 Overlay::Overlay(QWidget* parent) :
1086 //setAttribute(Qt::WA_TransparentForMouseEvents);
1087 setAutoFillBackground(true);
1088 setBackgroundRole(QPalette::Base);
1089 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1090 setCursor(Qt::PointingHandCursor);
1094 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1100 void Overlay::mousePressEvent( QMouseEvent * event )
1106 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1112 void Overlay::setOverlayText(const QString &text, bool isZone)
1117 p.setColor(QPalette::Text, Qt::white);
1118 if (m_isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1119 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1121 setText(' ' + text + ' ');
1126 VideoContainer::VideoContainer(Monitor* parent) :
1130 setFrameShape(QFrame::NoFrame);
1131 setFocusPolicy(Qt::ClickFocus);
1133 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
1137 void VideoContainer::mouseReleaseEvent(QMouseEvent * event)
1139 if (event->button() != Qt::RightButton) {
1140 if (m_monitor->isActive()) {
1141 m_monitor->slotPlay();
1148 void VideoContainer::keyPressEvent(QKeyEvent *event)
1150 // Exit fullscreen with Esc key
1151 if (event->key() == Qt::Key_Escape && isFullScreen()) {
1153 event->setAccepted(true);
1154 } else event->setAccepted(false);
1158 void VideoContainer::wheelEvent(QWheelEvent * event)
1160 m_monitor->slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
1164 void VideoContainer::mouseDoubleClickEvent(QMouseEvent * event)
1166 if (!KdenliveSettings::openglmonitors())
1171 void VideoContainer::switchFullScreen()
1173 // TODO: disable screensaver?
1174 Qt::WindowFlags flags = windowFlags();
1175 if (!isFullScreen()) {
1176 // Check if we ahave a multiple monitor setup
1177 setUpdatesEnabled(false);
1178 #if QT_VERSION >= 0x040600
1179 int monitors = QApplication::desktop()->screenCount();
1181 int monitors = QApplication::desktop()->numScreens();
1185 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
1186 int currentScreen = QApplication::desktop()->screenNumber(this);
1187 if (currentScreen < monitors - 1)
1188 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
1190 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
1191 move(QPoint(screenres.x(), screenres.y()));
1192 resize(screenres.width(), screenres.height());
1195 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
1196 flags |= Qt::Window;
1197 flags ^= Qt::SubWindow;
1198 setWindowFlags(flags);
1200 // This works around a bug with Compiz
1201 // as the window must be visible before we can set the state
1204 setWindowState(windowState() | Qt::WindowFullScreen); // set
1206 setWindowState(windowState() | Qt::WindowFullScreen); // set
1207 setUpdatesEnabled(true);
1212 setUpdatesEnabled(false);
1213 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
1214 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
1215 setWindowFlags(flags);
1216 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset
1217 setUpdatesEnabled(true);
1225 #include "monitor.moc"