+#include <QMouseEvent>
+#include <QStylePainter>
+#include <QMenu>
+#include <QToolButton>
+#include <QToolBar>
+#include <QDesktopWidget>
+#include <QLabel>
+
+
+Monitor::Monitor(QString name, MonitorManager *manager, QWidget *parent) :
+ QWidget(parent),
+ render(NULL),
+ m_name(name),
+ m_monitorManager(manager),
+ m_currentClip(NULL),
+ m_ruler(new SmallRuler()),
+ m_overlay(NULL),
+ m_isActive(false),
+ m_scale(1),
+ m_length(0),
+ m_dragStarted(false)
+{
+ m_ui.setupUi(this);
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->addWidget(m_ruler);
+ m_ui.ruler_frame->setLayout(layout);
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ setMinimumHeight(200);
+ QToolBar *toolbar = new QToolBar(name, this);
+ QVBoxLayout *layout2 = new QVBoxLayout;
+ layout2->setContentsMargins(0, 0, 0, 0);
+
+ m_playIcon = KIcon("media-playback-start");
+ m_pauseIcon = KIcon("media-playback-pause");
+
+ if (name != "chapter") {
+ toolbar->addAction(KIcon("kdenlive-zone-start"), i18n("Set zone start"), this, SLOT(slotSetZoneStart()));
+ toolbar->addAction(KIcon("kdenlive-zone-end"), i18n("Set zone end"), this, SLOT(slotSetZoneEnd()));
+ } else m_ruler->setZone(-3, -2);
+
+ toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"), this, SLOT(slotRewind()));
+ toolbar->addAction(KIcon("media-skip-backward"), i18n("Rewind 1 frame"), this, SLOT(slotRewindOneFrame()));
+
+ QToolButton *playButton = new QToolButton(toolbar);
+ m_playMenu = new QMenu(i18n("Play..."), this);
+ m_playAction = m_playMenu->addAction(m_playIcon, i18n("Play"));
+ m_playAction->setCheckable(true);
+ connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay()));
+
+ playButton->setMenu(m_playMenu);
+ playButton->setPopupMode(QToolButton::MenuButtonPopup);
+ toolbar->addWidget(playButton);
+
+ toolbar->addAction(KIcon("media-skip-forward"), i18n("Forward 1 frame"), this, SLOT(slotForwardOneFrame()));
+ toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"), this, SLOT(slotForward()));
+
+ playButton->setDefaultAction(m_playAction);
+
+ if (name != "chapter") {
+ QToolButton *configButton = new QToolButton(toolbar);
+ m_configMenu = new QMenu(i18n("Misc..."), this);
+ configButton->setIcon(KIcon("system-run"));
+ configButton->setMenu(m_configMenu);
+ configButton->setPopupMode(QToolButton::QToolButton::InstantPopup);
+ toolbar->addWidget(configButton);
+ m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (100%)"), this, SLOT(slotSetSizeOneToOne()));
+ m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (50%)"), this, SLOT(slotSetSizeOneToTwo()));
+ }
+
+ QWidget *spacer = new QWidget(this);
+ spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+ toolbar->addWidget(spacer);
+ m_timePos = new KRestrictedLine(this);
+ m_timePos->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
+ m_frametimecode = KdenliveSettings::frametimecode();
+ if (m_frametimecode) m_timePos->setInputMask("999999999");
+ else m_timePos->setInputMask("99:99:99:99");
+ toolbar->addWidget(m_timePos);
+
+ connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotSeek()));
+
+ layout2->addWidget(toolbar);
+ m_ui.button_frame->setLayout(layout2);
+ const int toolHeight = toolbar->height();
+ m_ui.button_frame->setMinimumHeight(toolHeight);
+
+ //m_ruler->setPixelPerMark(3);
+
+ QVBoxLayout *rendererBox = new QVBoxLayout(m_ui.video_frame);
+ rendererBox->setContentsMargins(0, 0, 0, 0);
+ m_monitorRefresh = new MonitorRefresh(m_ui.video_frame);
+ rendererBox->addWidget(m_monitorRefresh);
+ render = new Render(m_name, (int) m_monitorRefresh->winId(), -1, this);
+ m_monitorRefresh->setRenderer(render);
+
+ connect(m_ruler, SIGNAL(seekRenderer(int)), this, SLOT(slotSeek(int)));
+ connect(render, SIGNAL(durationChanged(int)), this, SLOT(adjustRulerSize(int)));
+ connect(render, SIGNAL(rendererPosition(int)), this, SLOT(seekCursor(int)));
+ connect(render, SIGNAL(rendererStopped(int)), this, SLOT(rendererStopped(int)));
+ connect(render, SIGNAL(blockMonitors()), this, SIGNAL(blockMonitors()));
+
+ //render->createVideoXWindow(m_ui.video_frame->winId(), -1);
+
+ if (name != "clip") {
+ connect(render, SIGNAL(rendererPosition(int)), this, SIGNAL(renderPosition(int)));
+ connect(render, SIGNAL(durationChanged(int)), this, SIGNAL(durationChanged(int)));
+ connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SIGNAL(zoneUpdated(QPoint)));
+ } else {
+ connect(m_ruler, SIGNAL(zoneChanged(QPoint)), this, SLOT(setClipZone(QPoint)));
+ }
+ m_monitorRefresh->show();
+ kDebug() << "/////// BUILDING MONITOR, ID: " << m_ui.video_frame->winId();
+}
+
+Monitor::~Monitor()
+{
+ delete m_ruler;
+ delete m_timePos;
+ delete m_overlay;
+ delete m_monitorRefresh;
+ delete render;
+}
+
+QString Monitor::name() const
+{
+ return m_name;
+}
+
+void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu)
+{
+ m_contextMenu = new QMenu(this);
+ m_contextMenu->addMenu(m_playMenu);
+ if (goMenu) m_contextMenu->addMenu(goMenu);
+ if (markerMenu) m_contextMenu->addMenu(markerMenu);
+
+ m_playMenu->addAction(playZone);
+ m_playMenu->addAction(loopZone);
+
+ //TODO: add save zone to timeline monitor when fixed
+ if (m_name == "clip") m_contextMenu->addAction(KIcon("document-save"), i18n("Save zone"), this, SLOT(slotSaveZone()));
+
+ QAction *extractFrame = m_configMenu->addAction(KIcon("document-new"), i18n("Extract frame"), this, SLOT(slotExtractCurrentFrame()));
+ m_contextMenu->addAction(extractFrame);
+
+ if (m_name != "clip") {
+ QAction *splitView = m_contextMenu->addAction(KIcon("view-split-left-right"), i18n("Split view"), render, SLOT(slotSplitView(bool)));
+ splitView->setCheckable(true);
+ m_configMenu->addAction(splitView);
+ } else {
+ QAction *setThumbFrame = m_contextMenu->addAction(KIcon("document-new"), i18n("Set current image as thumbnail"), this, SLOT(slotSetThumbFrame()));
+ m_configMenu->addAction(setThumbFrame);
+ }
+
+ QAction *showTips = m_contextMenu->addAction(KIcon("help-hint"), i18n("Monitor overlay infos"));
+ showTips->setCheckable(true);
+ connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool)));
+ showTips->setChecked(KdenliveSettings::displayMonitorInfo());
+
+ QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)"));
+ dropFrames->setCheckable(true);
+ dropFrames->setChecked(true);
+ connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
+
+ m_configMenu->addAction(showTips);
+ m_configMenu->addAction(dropFrames);
+
+}
+
+void Monitor::slotSetSizeOneToOne()
+{
+ QRect r = QApplication::desktop()->screenGeometry();
+ const int maxWidth = r.width() - 20;
+ const int maxHeight = r.height() - 20;
+ int width = render->renderWidth();
+ int height = render->renderHeight();
+ kDebug() << "// render info: " << width << "x" << height;
+ while (width >= maxWidth || height >= maxHeight) {
+ width = width * 0.8;
+ height = height * 0.8;
+ }
+ kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
+ m_ui.video_frame->setFixedSize(width, height);
+ updateGeometry();
+ adjustSize();
+ //m_ui.video_frame->setMinimumSize(0, 0);
+ emit adjustMonitorSize();
+}
+
+void Monitor::slotSetSizeOneToTwo()
+{
+ QRect r = QApplication::desktop()->screenGeometry();
+ const int maxWidth = r.width() - 20;
+ const int maxHeight = r.height() - 20;
+ int width = render->renderWidth() / 2;
+ int height = render->renderHeight() / 2;
+ kDebug() << "// render info: " << width << "x" << height;
+ while (width >= maxWidth || height >= maxHeight) {
+ width = width * 0.8;
+ height = height * 0.8;
+ }
+ kDebug() << "// MONITOR; set SIZE: " << width << ", " << height;
+ m_ui.video_frame->setFixedSize(width, height);
+ updateGeometry();
+ adjustSize();
+ //m_ui.video_frame->setMinimumSize(0, 0);
+ emit adjustMonitorSize();
+}
+
+void Monitor::resetSize()
+{
+ m_ui.video_frame->setMinimumSize(0, 0);
+}
+
+DocClipBase *Monitor::activeClip()
+{
+ return m_currentClip;
+}
+
+void Monitor::slotSeekToPreviousSnap()
+{
+ if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
+}
+
+void Monitor::slotSeekToNextSnap()
+{
+ if (m_currentClip) slotSeek(getSnapForPos(false).frames(m_monitorManager->timecode().fps()));
+}
+
+GenTime Monitor::position()
+{
+ return render->seekPosition();
+}
+
+GenTime Monitor::getSnapForPos(bool previous)
+{
+ QList <GenTime> snaps;
+ QList < GenTime > markers = m_currentClip->snapMarkers();
+ for (int i = 0; i < markers.size(); ++i) {
+ GenTime t = markers.at(i);
+ snaps.append(t);
+ }
+ QPoint zone = m_ruler->zone();
+ snaps.append(GenTime(zone.x(), m_monitorManager->timecode().fps()));
+ snaps.append(GenTime(zone.y(), m_monitorManager->timecode().fps()));
+ snaps.append(GenTime());
+ snaps.append(m_currentClip->duration());
+ qSort(snaps);
+
+ const GenTime pos = render->seekPosition();
+ for (int i = 0; i < snaps.size(); ++i) {
+ if (previous && snaps.at(i) >= pos) {
+ if (i == 0) i = 1;
+ return snaps.at(i - 1);
+ } else if (!previous && snaps.at(i) > pos) {
+ return snaps.at(i);
+ }
+ }
+ return GenTime();
+}
+
+
+
+void Monitor::slotZoneMoved(int start, int end)
+{
+ m_ruler->setZone(start, end);
+ checkOverlay();
+ setClipZone(m_ruler->zone());
+}
+
+void Monitor::slotSetZoneStart()
+{
+ m_ruler->setZone(render->seekFramePosition(), -1);
+ emit zoneUpdated(m_ruler->zone());
+ checkOverlay();
+ setClipZone(m_ruler->zone());
+}
+
+void Monitor::slotSetZoneEnd()
+{
+ m_ruler->setZone(-1, render->seekFramePosition());
+ emit zoneUpdated(m_ruler->zone());
+ checkOverlay();
+ setClipZone(m_ruler->zone());
+}
+
+// virtual
+void Monitor::mousePressEvent(QMouseEvent * event)
+{
+ if (event->button() != Qt::RightButton) {
+ if (m_ui.video_frame->underMouse()) {
+ m_dragStarted = true;
+ m_DragStartPosition = event->pos();
+ }
+ } else m_contextMenu->popup(event->globalPos());
+}