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->geometry().contains(event->pos()) && (!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)
476 if (m_dragStarted && event->button() != Qt::RightButton) {
477 if (m_videoBox->geometry().contains(event->pos()) && (!m_effectWidget || !m_effectWidget->isVisible())) {
478 if (isActive()) slotPlay();
479 else activateMonitor();
480 } //else event->ignore(); //QWidget::mouseReleaseEvent(event);
481 m_dragStarted = false;
486 void Monitor::mouseMoveEvent(QMouseEvent *event)
488 if (!m_dragStarted || m_currentClip == NULL) return;
490 if ((event->pos() - m_DragStartPosition).manhattanLength()
491 < QApplication::startDragDistance())
495 QDrag *drag = new QDrag(this);
496 QMimeData *mimeData = new QMimeData;
499 list.append(m_currentClip->getId());
500 QPoint p = m_ruler->zone();
501 list.append(QString::number(p.x()));
502 list.append(QString::number(p.y()));
504 data.append(list.join(";").toUtf8());
505 mimeData->setData("kdenlive/clip", data);
506 drag->setMimeData(mimeData);
507 /*QPixmap pix = m_currentClip->thumbnail();
508 drag->setPixmap(pix);
509 drag->setHotSpot(QPoint(0, 50));*/
510 drag->start(Qt::MoveAction);
512 //Qt::DropAction dropAction;
513 //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
515 //Qt::DropAction dropAction = drag->exec();
521 /*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
522 event->setDropAction(Qt::IgnoreAction);
523 event->setDropAction(Qt::MoveAction);
524 if (event->mimeData()->hasText()) {
525 event->acceptProposedAction();
529 Qt::DropActions Monitor::supportedDropActions() const {
530 // returns what actions are supported when dropping
531 return Qt::MoveAction;
534 QStringList Monitor::mimeTypes() const
536 QStringList qstrList;
537 // list of accepted mime types for drop
538 qstrList.append("kdenlive/clip");
543 void Monitor::wheelEvent(QWheelEvent * event)
545 slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
549 void Monitor::mouseDoubleClickEvent(QMouseEvent * event)
551 if (!KdenliveSettings::openglmonitors()) {
552 m_videoBox->switchFullScreen();
557 void Monitor::slotMouseSeek(int eventDelta, bool fast)
560 int delta = m_monitorManager->timecode().fps();
561 if (eventDelta > 0) delta = 0 - delta;
562 slotSeek(m_ruler->position() - delta);
564 if (eventDelta >= 0) slotForwardOneFrame();
565 else slotRewindOneFrame();
569 void Monitor::slotSetThumbFrame()
571 if (m_currentClip == NULL) {
574 m_currentClip->setClipThumbFrame((uint) render->seekFramePosition());
575 emit refreshClipThumbnail(m_currentClip->getId(), true);
578 void Monitor::slotExtractCurrentZone()
580 if (m_currentClip == NULL) return;
581 emit extractZone(m_currentClip->getId(), m_ruler->zone());
584 void Monitor::slotExtractCurrentFrame()
587 // check if we are using a proxy
588 if (m_currentClip && !m_currentClip->getProperty("proxy").isEmpty() && m_currentClip->getProperty("proxy") != "-") {
589 // using proxy, use original clip url to get frame
590 frame = render->extractFrame(render->seekFramePosition(), m_currentClip->fileURL().path());
592 else frame = render->extractFrame(render->seekFramePosition());
593 KFileDialog *fs = new KFileDialog(KUrl(), "image/png", this);
594 fs->setOperationMode(KFileDialog::Saving);
595 fs->setMode(KFile::File);
596 fs->setConfirmOverwrite(true);
597 fs->setKeepLocation(true);
599 QString path = fs->selectedFile();
601 if (!path.isEmpty()) {
606 bool Monitor::isActive() const
608 return m_monitorManager->isActive(m_name);
611 bool Monitor::activateMonitor()
613 return m_monitorManager->activateMonitor(m_name);
616 void Monitor::setTimePos(const QString &pos)
618 m_timePos->setValue(pos);
622 void Monitor::slotSeek()
624 slotSeek(m_timePos->getValue());
627 void Monitor::slotSeek(int pos)
629 if (render == NULL) return;
631 render->seekToFrame(pos);
634 void Monitor::checkOverlay()
636 if (m_overlay == NULL) return;
637 int pos = m_ruler->position();
638 QPoint zone = m_ruler->zone();
640 m_overlay->setOverlayText(i18n("In Point"));
641 else if (pos == zone.y())
642 m_overlay->setOverlayText(i18n("Out Point"));
645 QString markerComment = m_currentClip->markerComment(GenTime(pos, m_monitorManager->timecode().fps()));
646 if (markerComment.isEmpty())
647 m_overlay->setHidden(true);
649 m_overlay->setOverlayText(markerComment, false);
650 } else m_overlay->setHidden(true);
654 void Monitor::slotStart()
658 render->seekToFrame(0);
661 void Monitor::slotEnd()
665 render->seekToFrame(render->getLength());
668 void Monitor::slotZoneStart()
672 render->seekToFrame(m_ruler->zone().x());
675 void Monitor::slotZoneEnd()
679 render->seekToFrame(m_ruler->zone().y());
682 void Monitor::slotRewind(double speed)
686 double currentspeed = render->playSpeed();
687 if (currentspeed >= 0) render->play(-2);
688 else render->play(currentspeed * 2);
689 } else render->play(speed);
690 //m_playAction->setChecked(true);
691 m_playAction->setIcon(m_pauseIcon);
694 void Monitor::slotForward(double speed)
698 double currentspeed = render->playSpeed();
699 if (currentspeed <= 1) render->play(2);
700 else render->play(currentspeed * 2);
701 } else render->play(speed);
702 //m_playAction->setChecked(true);
703 m_playAction->setIcon(m_pauseIcon);
706 void Monitor::slotRewindOneFrame(int diff)
710 render->seekToFrameDiff(-diff);
713 void Monitor::slotForwardOneFrame(int diff)
717 render->seekToFrameDiff(diff);
720 void Monitor::seekCursor(int pos)
723 if (m_ruler->slotNewValue(pos)) {
725 m_timePos->setValue(pos);
729 void Monitor::rendererStopped(int pos)
731 if (m_ruler->slotNewValue(pos)) {
733 m_timePos->setValue(pos);
735 m_playAction->setIcon(m_playIcon);
738 void Monitor::adjustRulerSize(int length)
740 if (length > 0) m_length = length;
741 m_ruler->adjustScale(m_length);
742 if (m_currentClip != NULL) {
743 QPoint zone = m_currentClip->zone();
744 m_ruler->setZone(zone.x(), zone.y());
750 if (render) render->stop();
753 void Monitor::start()
755 if (!isVisible()) return;
756 if (render) render->start();
759 void Monitor::refreshMonitor(bool visible)
761 if (visible && render) {
762 if (!activateMonitor()) {
763 // the monitor was already active, simply refreshClipThumbnail
769 void Monitor::refreshMonitor()
776 void Monitor::pause()
778 if (render == NULL) return;
781 //m_playAction->setChecked(true);
782 m_playAction->setIcon(m_playIcon);
785 void Monitor::slotPlay()
787 if (render == NULL) return;
789 if (render->playSpeed() == 0.0) {
790 m_playAction->setIcon(m_pauseIcon);
791 render->switchPlay(true);
793 m_playAction->setIcon(m_playIcon);
794 render->switchPlay(false);
798 void Monitor::slotPlayZone()
800 if (render == NULL) return;
802 QPoint p = m_ruler->zone();
803 render->playZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
804 //m_playAction->setChecked(true);
805 m_playAction->setIcon(m_pauseIcon);
808 void Monitor::slotLoopZone()
810 if (render == NULL) return;
812 QPoint p = m_ruler->zone();
813 render->loopZone(GenTime(p.x(), m_monitorManager->timecode().fps()), GenTime(p.y(), m_monitorManager->timecode().fps()));
814 //m_playAction->setChecked(true);
815 m_playAction->setIcon(m_pauseIcon);
818 void Monitor::slotLoopClip()
820 if (render == NULL || m_selectedClip == NULL)
823 render->loopZone(m_selectedClip->startPos(), m_selectedClip->endPos());
824 //m_playAction->setChecked(true);
825 m_playAction->setIcon(m_pauseIcon);
828 void Monitor::updateClipProducer(Mlt::Producer *prod)
830 if (render == NULL) return;
831 render->setProducer(prod, render->seekFramePosition());
834 void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpdate, int position)
836 if (render == NULL) return;
837 if (clip == NULL && m_currentClip != NULL) {
838 kDebug()<<"// SETTING NULL CLIP MONITOR";
839 m_currentClip = NULL;
841 render->setProducer(NULL, -1);
845 if (clip != m_currentClip || forceUpdate) {
846 m_currentClip = clip;
847 if (m_currentClip) activateMonitor();
849 Mlt::Producer *prod = NULL;
850 if (clip) prod = clip->getCloneProducer();
851 if (render->setProducer(prod, position) == -1) {
852 // MLT CONSUMER is broken
853 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
858 if (position == -1) position = render->seekFramePosition();
859 render->seek(position);
862 if (!zone.isNull()) {
863 m_ruler->setZone(zone.x(), zone.y());
864 render->seek(zone.x());
868 void Monitor::slotOpenFile(const QString &file)
870 if (render == NULL) return;
873 QDomElement mlt = doc.createElement("mlt");
874 doc.appendChild(mlt);
875 QDomElement prod = doc.createElement("producer");
876 mlt.appendChild(prod);
877 prod.setAttribute("mlt_service", "avformat");
878 prod.setAttribute("resource", file);
879 render->setSceneList(doc, 0);
882 void Monitor::slotSaveZone()
884 if (render == NULL) return;
885 emit saveZone(render, m_ruler->zone(), m_currentClip);
887 //render->setSceneList(doc, 0);
890 void Monitor::resetProfile(const QString &profile)
892 m_timePos->updateTimeCode(m_monitorManager->timecode());
893 if (render == NULL) return;
894 if (!render->hasProfile(profile)) {
896 render->resetProfile(profile);
899 m_effectWidget->resetProfile(render);
902 void Monitor::saveSceneList(QString path, QDomElement info)
904 if (render == NULL) return;
905 render->saveSceneList(path, info);
908 const QString Monitor::sceneList()
910 if (render == NULL) return QString();
911 return render->sceneList();
914 void Monitor::setClipZone(QPoint pos)
916 if (m_currentClip == NULL) return;
917 m_currentClip->setZone(pos);
920 void Monitor::slotSwitchDropFrames(bool show)
922 render->setDropFrames(show);
925 void Monitor::slotSwitchMonitorInfo(bool show)
927 KdenliveSettings::setDisplayMonitorInfo(show);
929 if (m_overlay) return;
930 if (m_monitorRefresh == NULL) {
931 // Using OpenGL display
933 if (m_glWidget->layout()) delete m_glWidget->layout();
934 m_overlay = new Overlay();
935 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
936 QVBoxLayout *layout = new QVBoxLayout;
937 layout->addStretch(10);
938 layout->addWidget(m_overlay);
939 m_glWidget->setLayout(layout);
942 if (m_monitorRefresh->layout()) delete m_monitorRefresh->layout();
943 m_overlay = new Overlay();
944 connect(m_overlay, SIGNAL(editMarker()), this, SLOT(slotEditMarker()));
945 QVBoxLayout *layout = new QVBoxLayout;
946 layout->addStretch(10);
947 layout->addWidget(m_overlay);
948 m_monitorRefresh->setLayout(layout);
950 m_overlay->setHidden(true);
959 void Monitor::slotEditMarker()
961 if (m_editMarker) m_editMarker->trigger();
964 void Monitor::updateTimecodeFormat()
966 m_timePos->slotUpdateTimeCodeFormat();
969 QStringList Monitor::getZoneInfo() const
972 if (m_currentClip == NULL) return result;
973 result << m_currentClip->getId();
974 QPoint zone = m_ruler->zone();
975 result << QString::number(zone.x()) << QString::number(zone.y());
979 void Monitor::slotSetSelectedClip(AbstractClipItem* item)
982 m_loopClipAction->setEnabled(true);
983 m_selectedClip = item;
985 m_loopClipAction->setEnabled(false);
989 void Monitor::slotSetSelectedClip(ClipItem* item)
991 if (item || (!item && !m_loopClipTransition)) {
992 m_loopClipTransition = false;
993 slotSetSelectedClip((AbstractClipItem*)item);
997 void Monitor::slotSetSelectedClip(Transition* item)
999 if (item || (!item && m_loopClipTransition)) {
1000 m_loopClipTransition = true;
1001 slotSetSelectedClip((AbstractClipItem*)item);
1006 void Monitor::slotEffectScene(bool show)
1008 if (m_name == "project") {
1009 if (m_monitorRefresh) {
1010 m_monitorRefresh->setVisible(!show);
1013 m_glWidget->setVisible(!show);
1016 m_effectWidget->setVisible(show);
1017 m_effectWidget->getVisibilityAction()->setChecked(show);
1018 emit requestFrameForAnalysis(show);
1020 m_effectWidget->getScene()->slotZoomFit();
1022 m_videoBox->setEnabled(show);
1023 render->doRefresh();
1027 MonitorEditWidget* Monitor::getEffectEdit()
1029 return m_effectWidget;
1032 bool Monitor::effectSceneDisplayed()
1034 return m_effectWidget->isVisible();
1037 void Monitor::slotSetVolume(int volume)
1039 KdenliveSettings::setVolume(volume);
1041 if (volume == 0) icon = KIcon("audio-volume-muted");
1042 else icon = KIcon("audio-volume-medium");
1043 static_cast <QToolButton *>(m_volumeWidget)->setIcon(icon);
1044 render->slotSetVolume(volume);
1047 void Monitor::slotShowVolume()
1049 m_volumePopup->move(mapToGlobal(m_toolbar->geometry().topLeft()) + QPoint(mapToParent(m_volumeWidget->geometry().bottomLeft()).x(), -m_volumePopup->height()));
1050 int vol = render->volume();
1051 // Disable widget if we cannot get the volume
1052 m_volumePopup->setEnabled(vol != -1);
1053 m_audioSlider->blockSignals(true);
1054 m_audioSlider->setValue(vol);
1055 m_audioSlider->blockSignals(false);
1056 m_volumePopup->show();
1059 AbstractRender *Monitor::abstractRender()
1064 void Monitor::reloadProducer(const QString &id)
1066 if (!m_currentClip) return;
1067 if (m_currentClip->getId() == id)
1068 slotSetClipProducer(m_currentClip, m_currentClip->zone(), true);
1071 MonitorRefresh::MonitorRefresh(QWidget* parent) :
1075 // MonitorRefresh is used as container for the SDL display (it's window id is passed to SDL)
1076 setAttribute(Qt::WA_PaintOnScreen);
1077 setAttribute(Qt::WA_OpaquePaintEvent);
1078 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
1079 //setAttribute(Qt::WA_NoSystemBackground);
1082 void MonitorRefresh::setRenderer(Render* render)
1084 m_renderer = render;
1088 Overlay::Overlay(QWidget* parent) :
1091 //setAttribute(Qt::WA_TransparentForMouseEvents);
1092 setAutoFillBackground(true);
1093 setBackgroundRole(QPalette::Base);
1094 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1095 setCursor(Qt::PointingHandCursor);
1099 void Overlay::mouseReleaseEvent ( QMouseEvent * event )
1105 void Overlay::mousePressEvent( QMouseEvent * event )
1111 void Overlay::mouseDoubleClickEvent ( QMouseEvent * event )
1117 void Overlay::setOverlayText(const QString &text, bool isZone)
1122 p.setColor(QPalette::Text, Qt::white);
1123 if (m_isZone) p.setColor(QPalette::Base, QColor(200, 0, 0));
1124 else p.setColor(QPalette::Base, QColor(0, 0, 200));
1126 setText(' ' + text + ' ');
1131 VideoContainer::VideoContainer(Monitor* parent) :
1135 setFrameShape(QFrame::NoFrame);
1136 setFocusPolicy(Qt::ClickFocus);
1138 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
1142 void VideoContainer::mouseReleaseEvent(QMouseEvent * event)
1144 if (event->button() != Qt::RightButton) {
1145 if (m_monitor->isActive()) {
1146 m_monitor->slotPlay();
1153 void VideoContainer::keyPressEvent(QKeyEvent *event)
1155 // Exit fullscreen with Esc key
1156 if (event->key() == Qt::Key_Escape && isFullScreen()) {
1158 event->setAccepted(true);
1159 } else event->setAccepted(false);
1163 void VideoContainer::wheelEvent(QWheelEvent * event)
1165 m_monitor->slotMouseSeek(event->delta(), event->modifiers() == Qt::ControlModifier);
1169 void VideoContainer::mouseDoubleClickEvent(QMouseEvent * event)
1171 if (!KdenliveSettings::openglmonitors())
1176 void VideoContainer::switchFullScreen()
1178 // TODO: disable screensaver?
1179 Qt::WindowFlags flags = windowFlags();
1180 if (!isFullScreen()) {
1181 // Check if we ahave a multiple monitor setup
1182 setUpdatesEnabled(false);
1183 #if QT_VERSION >= 0x040600
1184 int monitors = QApplication::desktop()->screenCount();
1186 int monitors = QApplication::desktop()->numScreens();
1190 // Move monitor widget to the second screen (one screen for Kdenlive, the other one for the Monitor widget
1191 int currentScreen = QApplication::desktop()->screenNumber(this);
1192 if (currentScreen < monitors - 1)
1193 screenres = QApplication::desktop()->screenGeometry(currentScreen + 1);
1195 screenres = QApplication::desktop()->screenGeometry(currentScreen - 1);
1196 move(QPoint(screenres.x(), screenres.y()));
1197 resize(screenres.width(), screenres.height());
1200 m_baseFlags = flags & (Qt::Window | Qt::SubWindow);
1201 flags |= Qt::Window;
1202 flags ^= Qt::SubWindow;
1203 setWindowFlags(flags);
1205 // This works around a bug with Compiz
1206 // as the window must be visible before we can set the state
1209 setWindowState(windowState() | Qt::WindowFullScreen); // set
1211 setWindowState(windowState() | Qt::WindowFullScreen); // set
1212 setUpdatesEnabled(true);
1217 setUpdatesEnabled(false);
1218 flags ^= (Qt::Window | Qt::SubWindow); //clear the flags...
1219 flags |= m_baseFlags; //then we reset the flags (window and subwindow)
1220 setWindowFlags(flags);
1221 setWindowState(windowState() ^ Qt::WindowFullScreen); // reset
1222 setUpdatesEnabled(true);
1230 #include "monitor.moc"