1 /***************************************************************************
2 stopmotion.cpp - description
5 copyright : (C) 2010 by Jean-Baptiste Mardelle
6 email : jb@kdenlive.org
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include "stopmotion.h"
20 #include "v4l/v4lcapture.h"
22 #include "slideshowclip.h"
23 #include "profilesdialog.h"
24 #include "mltdevicecapture.h"
25 #include "recmonitor.h"
26 #include "monitormanager.h"
27 #include "ui_smconfig_ui.h"
28 #include "kdenlivesettings.h"
31 #include <KGlobalSettings>
32 #include <KFileDialog>
33 #include <KStandardDirs>
34 #include <KMessageBox>
35 #include <kdeversion.h>
36 #include <KNotification>
38 #include <QtConcurrentRun>
39 #include <QInputDialog>
41 #include <QVBoxLayout>
45 #include <QWheelEvent>
48 MyLabel::MyLabel(QWidget* parent) :
53 void MyLabel::setImage(const QImage& img)
59 void MyLabel::wheelEvent(QWheelEvent* event)
61 if (event->delta() > 0) emit seek(true);
62 else emit seek(false);
66 void MyLabel::mousePressEvent(QMouseEvent*)
72 void MyLabel::paintEvent(QPaintEvent* event)
76 QRect r(0, 0, width(), height());
78 p.fillRect(r, QColor(KdenliveSettings::window_background()));
79 double aspect_ratio = (double) m_img.width() / m_img.height();
80 int pictureHeight = height();
81 int pictureWidth = width();
82 int calculatedWidth = aspect_ratio * height();
83 if (calculatedWidth > width()) pictureHeight = width() / aspect_ratio;
85 int calculatedHeight = width() / aspect_ratio;
86 if (calculatedHeight > height()) pictureWidth = height() * aspect_ratio;
88 p.drawImage(QRect((width() - pictureWidth) / 2, (height() - pictureHeight) / 2, pictureWidth, pictureHeight), m_img, QRect(0, 0, m_img.width(), m_img.height()));
93 StopmotionMonitor::StopmotionMonitor(MonitorManager *manager, QWidget *parent) :
94 AbstractMonitor(Kdenlive::stopmotionMonitor, manager, parent),
100 StopmotionMonitor::~StopmotionMonitor()
104 void StopmotionMonitor::slotSwitchFullScreen()
108 void StopmotionMonitor::setRender(MltDeviceCapture *render)
110 m_captureDevice = render;
113 AbstractRender *StopmotionMonitor::abstractRender()
115 return m_captureDevice;
118 Kdenlive::MONITORID StopmotionMonitor::id() const
120 return Kdenlive::stopmotionMonitor;
124 void StopmotionMonitor::stop()
126 if (m_captureDevice) m_captureDevice->stop();
130 void StopmotionMonitor::start()
134 void StopmotionMonitor::slotPlay()
138 void StopmotionMonitor::slotMouseSeek(int /*eventDelta*/, bool /*fast*/)
142 StopmotionWidget::StopmotionWidget(MonitorManager *manager, const KUrl &projectFolder, const QList<QAction *> &actions, QWidget* parent) :
144 , Ui::Stopmotion_UI()
145 , m_projectFolder(projectFolder)
146 , m_captureDevice(NULL)
148 , m_animatedIndex(-1)
151 , m_monitor(new StopmotionMonitor(manager, this))
153 //setAttribute(Qt::WA_DeleteOnClose);
154 //HACK: the monitor widget is hidden, it is just used to control the capturedevice from monitormanager
155 m_monitor->setHidden(true);
156 connect(m_monitor, SIGNAL(stopCapture()), this, SLOT(slotStopCapture()));
157 m_manager->appendMonitor(m_monitor);
158 QAction* analyse = new QAction(i18n("Send frames to color scopes"), this);
159 analyse->setCheckable(true);
160 analyse->setChecked(KdenliveSettings::analyse_stopmotion());
161 connect(analyse, SIGNAL(triggered(bool)), this, SLOT(slotSwitchAnalyse(bool)));
163 QAction* mirror = new QAction(i18n("Mirror display"), this);
164 mirror->setCheckable(true);
165 //mirror->setChecked(KdenliveSettings::analyse_stopmotion());
166 connect(mirror, SIGNAL(triggered(bool)), this, SLOT(slotSwitchMirror(bool)));
170 setWindowTitle(i18n("Stop Motion Capture"));
171 setFont(KGlobalSettings::toolBarFont());
173 live_button->setIcon(KIcon("camera-photo"));
175 m_captureAction = actions.at(0);
176 connect(m_captureAction, SIGNAL(triggered()), this, SLOT(slotCaptureFrame()));
177 m_captureAction->setCheckable(true);
178 m_captureAction->setChecked(false);
179 capture_button->setDefaultAction(m_captureAction);
181 connect(actions.at(1), SIGNAL(triggered()), this, SLOT(slotSwitchLive()));
183 QAction *intervalCapture = new QAction(i18n("Interval capture"), this);
184 intervalCapture->setIcon(KIcon("chronometer"));
185 intervalCapture->setCheckable(true);
186 intervalCapture->setChecked(false);
187 capture_interval->setDefaultAction(intervalCapture);
189 preview_button->setIcon(KIcon("media-playback-start"));
190 capture_button->setEnabled(false);
194 QMenu* confMenu = new QMenu;
195 m_showOverlay = actions.at(2);
196 connect(m_showOverlay, SIGNAL(triggered(bool)), this, SLOT(slotShowOverlay(bool)));
197 overlay_button->setDefaultAction(m_showOverlay);
198 //confMenu->addAction(m_showOverlay);
200 m_effectIndex = KdenliveSettings::stopmotioneffect();
201 QMenu* effectsMenu = new QMenu(i18n("Overlay effect"));
202 QActionGroup* effectGroup = new QActionGroup(this);
203 QAction* noEffect = new QAction(i18n("No Effect"), effectGroup);
204 noEffect->setData(0);
205 QAction* contrastEffect = new QAction(i18n("Contrast"), effectGroup);
206 contrastEffect->setData(1);
207 QAction* edgeEffect = new QAction(i18n("Edge detect"), effectGroup);
208 edgeEffect->setData(2);
209 QAction* brightEffect = new QAction(i18n("Brighten"), effectGroup);
210 brightEffect->setData(3);
211 QAction* invertEffect = new QAction(i18n("Invert"), effectGroup);
212 invertEffect->setData(4);
213 QAction* thresEffect = new QAction(i18n("Threshold"), effectGroup);
214 thresEffect->setData(5);
216 effectsMenu->addAction(noEffect);
217 effectsMenu->addAction(contrastEffect);
218 effectsMenu->addAction(edgeEffect);
219 effectsMenu->addAction(brightEffect);
220 effectsMenu->addAction(invertEffect);
221 effectsMenu->addAction(thresEffect);
222 QList <QAction*> list = effectsMenu->actions();
223 for (int i = 0; i < list.count(); i++) {
224 list.at(i)->setCheckable(true);
225 if (list.at(i)->data().toInt() == m_effectIndex) {
226 list.at(i)->setChecked(true);
229 connect(effectsMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotUpdateOverlayEffect(QAction*)));
230 confMenu->addMenu(effectsMenu);
232 QAction* showThumbs = new QAction(KIcon("image-x-generic"), i18n("Show sequence thumbnails"), this);
233 showThumbs->setCheckable(true);
234 showThumbs->setChecked(KdenliveSettings::showstopmotionthumbs());
235 connect(showThumbs, SIGNAL(triggered(bool)), this, SLOT(slotShowThumbs(bool)));
237 QAction* removeCurrent = new QAction(KIcon("edit-delete"), i18n("Delete current frame"), this);
238 removeCurrent->setShortcut(Qt::Key_Delete);
239 connect(removeCurrent, SIGNAL(triggered()), this, SLOT(slotRemoveFrame()));
241 QAction* conf = new QAction(KIcon("configure"), i18n("Configure"), this);
242 connect(conf, SIGNAL(triggered()), this, SLOT(slotConfigure()));
244 confMenu->addAction(showThumbs);
245 confMenu->addAction(removeCurrent);
246 confMenu->addAction(analyse);
247 confMenu->addAction(mirror);
248 confMenu->addAction(conf);
249 config_button->setIcon(KIcon("configure"));
250 config_button->setMenu(confMenu);
252 connect(sequence_name, SIGNAL(textChanged(QString)), this, SLOT(sequenceNameChanged(QString)));
253 connect(sequence_name, SIGNAL(currentIndexChanged(int)), live_button, SLOT(setFocus()));
255 // Video widget holder
256 QVBoxLayout *layout = new QVBoxLayout;
257 layout->setContentsMargins(0, 0, 0, 0);
258 layout->setSpacing(0);
259 m_monitor->videoBox->setLineWidth(4);
260 layout->addWidget(m_monitor->videoBox);
262 if (KdenliveSettings::decklink_device_found()) {
263 // Found a BlackMagic device
266 if (QFile::exists(KdenliveSettings::video4vdevice())) {
268 // Video 4 Linux device detection
269 for (int i = 0; i < 10; i++) {
270 QString path = "/dev/video" + QString::number(i);
271 if (QFile::exists(path)) {
272 QStringList deviceInfo = V4lCaptureHandler::getDeviceName(path);
273 if (!deviceInfo.isEmpty()) {
274 capture_device->addItem(deviceInfo.at(0), "v4l");
275 capture_device->setItemData(capture_device->count() - 1, path, Qt::UserRole + 1);
276 capture_device->setItemData(capture_device->count() - 1, deviceInfo.at(1), Qt::UserRole + 2);
277 if (path == KdenliveSettings::video4vdevice()) capture_device->setCurrentIndex(capture_device->count() - 1);
284 connect(capture_device, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDeviceHandler()));
286 connect(m_bmCapture, SIGNAL(frameSaved(QString)), this, SLOT(slotNewThumb(QString)));
287 connect(m_bmCapture, SIGNAL(gotFrame(QImage)), this, SIGNAL(gotFrame(QImage)));
288 } else live_button->setEnabled(false);*/
290 m_frame_preview = new MyLabel(this);
291 connect(m_frame_preview, SIGNAL(seek(bool)), this, SLOT(slotSeekFrame(bool)));
292 connect(m_frame_preview, SIGNAL(switchToLive()), this, SLOT(slotSwitchLive()));
293 layout->addWidget(m_frame_preview);
294 m_frame_preview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
295 video_preview->setLayout(layout);
297 //kDebug()<<video_preview->winId();
300 // Create MLT producer data
301 if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
302 // Capture using a video4linux device
303 profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
307 profilePath = KdenliveSettings::current_profile();
310 m_captureDevice = new MltDeviceCapture(profilePath, m_monitor->videoSurface, this);
311 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
312 m_monitor->setRender(m_captureDevice);
313 connect(m_captureDevice, SIGNAL(frameSaved(QString)), this, SLOT(slotNewThumb(QString)));
315 live_button->setChecked(false);
316 button_addsequence->setEnabled(false);
317 connect(live_button, SIGNAL(toggled(bool)), this, SLOT(slotLive(bool)));
318 connect(button_addsequence, SIGNAL(clicked(bool)), this, SLOT(slotAddSequence()));
319 connect(preview_button, SIGNAL(clicked(bool)), this, SLOT(slotPlayPreview(bool)));
320 connect(frame_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotShowSelectedFrame()));
321 connect(frame_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(slotShowSelectedFrame()));
322 connect(this, SIGNAL(doCreateThumbs(QImage,int)), this, SLOT(slotCreateThumbs(QImage,int)));
324 frame_list->addAction(removeCurrent);
325 frame_list->setContextMenuPolicy(Qt::ActionsContextMenu);
326 frame_list->setHidden(!KdenliveSettings::showstopmotionthumbs());
327 parseExistingSequences();
328 QTimer::singleShot(500, this, SLOT(slotLive()));
329 connect(&m_intervalTimer, SIGNAL(timeout()), this, SLOT(slotCaptureFrame()));
330 m_intervalTimer.setSingleShot(true);
331 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
334 StopmotionWidget::~StopmotionWidget()
336 m_manager->removeMonitor(m_monitor);
337 if (m_captureDevice) {
338 m_captureDevice->stop();
339 delete m_captureDevice;
340 m_captureDevice = NULL;
346 void StopmotionWidget::slotUpdateOverlayEffect(QAction* act)
348 if (act) m_effectIndex = act->data().toInt();
349 KdenliveSettings::setStopmotioneffect(m_effectIndex);
353 void StopmotionWidget::closeEvent(QCloseEvent* e)
356 QDialog::closeEvent(e);
359 void StopmotionWidget::slotConfigure()
364 d.setWindowTitle(i18n("Configure Stop Motion"));
365 ui.sm_interval->setValue(KdenliveSettings::captureinterval());
366 ui.sm_interval->setSuffix(ki18np(" second", " seconds"));
367 ui.sm_notifytime->setSuffix(ki18np(" second", " seconds"));
368 ui.sm_notifytime->setValue(KdenliveSettings::sm_notifytime());
369 connect(ui.sm_prenotify, SIGNAL(toggled(bool)), ui.sm_notifytime, SLOT(setEnabled(bool)));
370 ui.sm_prenotify->setChecked(KdenliveSettings::sm_prenotify());
371 ui.sm_loop->setChecked(KdenliveSettings::sm_loop());
372 ui.sm_framesplayback->setValue(KdenliveSettings::sm_framesplayback());
374 if (d.exec() == QDialog::Accepted) {
375 KdenliveSettings::setSm_loop(ui.sm_loop->isChecked());
376 KdenliveSettings::setCaptureinterval(ui.sm_interval->value());
377 KdenliveSettings::setSm_framesplayback(ui.sm_framesplayback->value());
378 KdenliveSettings::setSm_notifytime(ui.sm_notifytime->value());
379 KdenliveSettings::setSm_prenotify(ui.sm_prenotify->isChecked());
380 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
384 void StopmotionWidget::slotShowThumbs(bool show)
386 KdenliveSettings::setShowstopmotionthumbs(show);
389 sequenceNameChanged(sequence_name->currentText());
394 frame_list->setHidden(!show);
398 void StopmotionWidget::slotUpdateDeviceHandler()
401 delete m_captureDevice;
402 m_captureDevice = NULL;
403 /*QString data = capture_device->itemData(capture_device->currentIndex()).toString();
408 m_layout->removeWidget(m_frame_preview);
411 m_bmCapture = new V4lCaptureHandler(m_layout);
412 m_bmCapture->setDevice(capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString(), capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 2).toString());
415 m_bmCapture = new BmdCaptureHandler(m_layout);
416 if (m_bmCapture) connect(m_bmCapture, SIGNAL(gotMessage(QString)), this, SLOT(slotGotHDMIMessage(QString)));
418 live_button->setEnabled(m_bmCapture != NULL);
419 m_layout->addWidget(m_frame_preview);*/
422 void StopmotionWidget::slotGotHDMIMessage(const QString& message)
424 log_box->insertItem(0, message);
427 void StopmotionWidget::parseExistingSequences()
429 sequence_name->clear();
430 sequence_name->addItem(QString());
431 QDir dir(m_projectFolder.path());
433 filters << "*_0000.png";
434 //dir.setNameFilters(filters);
435 QStringList sequences = dir.entryList(filters, QDir::Files, QDir::Name);
436 //kDebug()<<"PF: "<<<<", sm: "<<sequences;
437 foreach(const QString &sequencename, sequences) {
438 sequence_name->addItem(sequencename.section('_', 0, -2));
442 void StopmotionWidget::slotSwitchLive()
444 setUpdatesEnabled(false);
445 slotLive(!live_button->isChecked());
446 setUpdatesEnabled(true);
449 void StopmotionWidget::slotStopCapture()
454 void StopmotionWidget::slotLive(bool isOn)
456 live_button->blockSignals(true);
457 capture_button->setEnabled(false);
459 m_frame_preview->setHidden(true);
460 m_monitor->videoBox->setHidden(false);
463 MltVideoProfile profile;
467 // Create MLT producer data
468 if (capture_device->itemData(capture_device->currentIndex()) == "v4l") {
469 // Capture using a video4linux device
470 profilePath = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
471 profile = ProfilesDialog::getVideoProfile(profilePath);
472 service = "avformat-novalidate";
473 QString devicePath = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
474 resource = QString("video4linux2:%1?width:%2&height:%3&frame_rate:%4").arg(devicePath).arg(profile.width).arg(profile.height).arg((double) profile.frame_rate_num / profile.frame_rate_den);
478 profilePath = KdenliveSettings::current_profile();
479 profile = ProfilesDialog::getVideoProfile(profilePath);
480 service = "decklink";
481 resource = capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString();
484 if (m_captureDevice == NULL) {
485 m_captureDevice = new MltDeviceCapture(profilePath, m_monitor->videoSurface, this);
486 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
487 m_monitor->setRender(m_captureDevice);
488 connect(m_captureDevice, SIGNAL(frameSaved(QString)), this, SLOT(slotNewThumb(QString)));
491 m_manager->activateMonitor(Kdenlive::stopmotionMonitor);
492 QString producer = createProducer(profile, service, resource);
493 if (m_captureDevice->slotStartPreview(producer, true)) {
494 if (m_showOverlay->isChecked()) {
498 capture_button->setEnabled(true);
499 live_button->setChecked(true);
500 log_box->insertItem(-1, i18n("Playing %1x%2 (%3 fps)", profile.width, profile.height, locale.toString((double)profile.frame_rate_num/profile.frame_rate_den).rightJustified(2, '0')));
501 log_box->setCurrentIndex(0);
504 kDebug()<<"// problem starting stopmo";
505 log_box->insertItem(-1, i18n("Failed to start device"));
506 log_box->setCurrentIndex(0);
510 m_frame_preview->setHidden(false);
511 live_button->setChecked(false);
512 if (m_captureDevice) {
513 m_captureDevice->stop();
514 m_monitor->videoBox->setHidden(true);
515 log_box->insertItem(-1, i18n("Stopped"));
516 log_box->setCurrentIndex(0);
517 //delete m_captureDevice;
518 //m_captureDevice = NULL;
523 if (isOn && m_bmCapture) {
524 //m_frame_preview->setImage(QImage());
525 m_frame_preview->setHidden(true);
526 m_bmCapture->startPreview(KdenliveSettings::hdmi_capturedevice(), KdenliveSettings::hdmi_capturemode(), false);
527 capture_button->setEnabled(true);
528 live_button->setChecked(true);
530 if (m_bmCapture) m_bmCapture->stopPreview();
531 m_frame_preview->setHidden(false);
532 capture_button->setEnabled(false);
533 live_button->setChecked(false);
535 live_button->blockSignals(false);
538 void StopmotionWidget::slotShowOverlay(bool isOn)
541 // Overlay last frame of the sequence
547 m_captureDevice->setOverlay(QString());
551 void StopmotionWidget::reloadOverlay()
553 QString path = getPathForFrame(m_sequenceFrame - 1);
554 if (!QFile::exists(path)) {
555 log_box->insertItem(-1, i18n("No previous frame found"));
556 log_box->setCurrentIndex(0);
559 m_captureDevice->setOverlay(path);
562 void StopmotionWidget::slotUpdateOverlay()
564 if (m_captureDevice == NULL) return;
569 switch (m_effectIndex) {
571 tag = "frei0r.contrast0r";
572 params << "Contrast=1.2";
576 params << "x_scatter=4" << "y_scatter=4" << "scale=1" << "mix=0";
579 tag = "frei0r.brightness";
580 params << "Brightness=0.7";
587 params << "midpoint=125";
593 m_captureDevice->setOverlayEffect(tag, params);
596 void StopmotionWidget::sequenceNameChanged(const QString& name)
598 // Get rid of frames from previous sequence
599 disconnect(this, SIGNAL(doCreateThumbs(QImage,int)), this, SLOT(slotCreateThumbs(QImage,int)));
601 m_future.waitForFinished();
603 if (name.isEmpty()) {
604 button_addsequence->setEnabled(false);
606 // Check if we are editing an existing sequence
607 QString pattern = SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_filesList);
608 m_sequenceFrame = m_filesList.isEmpty() ? 0 : SlideshowClip::getFrameNumberFromPath(m_filesList.last()) + 1;
609 if (!m_filesList.isEmpty()) {
610 m_sequenceName = sequence_name->currentText();
611 connect(this, SIGNAL(doCreateThumbs(QImage,int)), this, SLOT(slotCreateThumbs(QImage,int)));
612 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
613 button_addsequence->setEnabled(true);
616 connect(this, SIGNAL(doCreateThumbs(QImage,int)), this, SLOT(slotCreateThumbs(QImage,int)));
617 button_addsequence->setEnabled(false);
619 capture_button->setEnabled(live_button->isChecked());
623 void StopmotionWidget::slotCaptureFrame()
625 if (m_captureDevice == NULL) return;
626 if (sequence_name->currentText().isEmpty()) {
627 QString seqName = QInputDialog::getText(this, i18n("Create New Sequence"), i18n("Enter sequence name"));
628 if (seqName.isEmpty()) {
629 m_captureAction->setChecked(false);
632 sequence_name->blockSignals(true);
633 sequence_name->setItemText(sequence_name->currentIndex(), seqName);
634 sequence_name->blockSignals(false);
636 if (m_sequenceName != sequence_name->currentText()) {
637 m_sequenceName = sequence_name->currentText();
640 //capture_button->setEnabled(false);
641 if (m_intervalTimer.isActive()) {
642 // stop interval capture
643 m_intervalTimer.stop();
646 QString currentPath = getPathForFrame(m_sequenceFrame);
647 m_captureDevice->captureFrame(currentPath);
648 KNotification::event("FrameCaptured", i18n("Frame Captured"), QPixmap(), this);
650 button_addsequence->setEnabled(true);
651 if (capture_interval->isChecked()) {
652 if (KdenliveSettings::sm_prenotify()) QTimer::singleShot((KdenliveSettings::captureinterval() - KdenliveSettings::sm_notifytime()) * 1000, this, SLOT(slotPreNotify()));
653 m_intervalTimer.start();
655 else m_captureAction->setChecked(false);
658 void StopmotionWidget::slotPreNotify()
660 if (m_captureAction->isChecked()) KNotification::event("ReadyToCapture", i18n("Going to Capture Frame"), QPixmap(), this);
664 void StopmotionWidget::slotNewThumb(const QString &path)
666 if (!KdenliveSettings::showstopmotionthumbs()) return;
667 m_filesList.append(path);
668 if (m_showOverlay->isChecked()) reloadOverlay();
669 if (!m_future.isRunning()) m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
673 void StopmotionWidget::slotPrepareThumbs()
675 if (m_filesList.isEmpty()) return;
676 QString path = m_filesList.takeFirst();
677 emit doCreateThumbs(QImage(path), SlideshowClip::getFrameNumberFromPath(path));
681 void StopmotionWidget::slotCreateThumbs(const QImage &img, int ix)
684 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
688 int width = height * img.width() / img.height();
689 frame_list->setIconSize(QSize(width, height));
690 QPixmap pix = QPixmap::fromImage(img).scaled(width, height);
691 QString nb = QString::number(ix);
693 QFontInfo finfo(font());
694 p.fillRect(0, 0, finfo.pixelSize() * nb.count() + 6, finfo.pixelSize() + 6, QColor(80, 80, 80, 150));
696 p.drawText(QPoint(3, finfo.pixelSize() + 3), nb);
699 QListWidgetItem* item = new QListWidgetItem(icon, QString(), frame_list);
700 item->setToolTip(getPathForFrame(ix, sequence_name->currentText()));
701 item->setData(Qt::UserRole, ix);
702 frame_list->blockSignals(true);
703 frame_list->setCurrentItem(item);
704 frame_list->blockSignals(false);
705 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
708 QString StopmotionWidget::getPathForFrame(int ix, QString seqName)
710 if (seqName.isEmpty()) seqName = m_sequenceName;
711 return m_projectFolder.path(KUrl::AddTrailingSlash) + seqName + '_' + QString::number(ix).rightJustified(4, '0', false) + ".png";
714 void StopmotionWidget::slotShowFrame(const QString& path)
718 capture_button->setEnabled(false);
721 m_frame_preview->setImage(img);
722 m_frame_preview->setHidden(false);
723 m_frame_preview->update();
727 void StopmotionWidget::slotShowSelectedFrame()
729 QListWidgetItem* item = frame_list->currentItem();
731 //int ix = item->data(Qt::UserRole).toInt();;
732 slotShowFrame(item->toolTip());
736 void StopmotionWidget::slotAddSequence()
738 emit addOrUpdateSequence(getPathForFrame(0));
741 void StopmotionWidget::slotPlayPreview(bool animate)
746 m_animationList.clear();
749 if (KdenliveSettings::showstopmotionthumbs()) {
750 if (KdenliveSettings::sm_framesplayback() == 0) frame_list->setCurrentRow(0);
751 else frame_list->setCurrentRow(frame_list->count() - KdenliveSettings::sm_framesplayback());
752 QTimer::singleShot(200, this, SLOT(slotAnimate()));
754 SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_animationList);
755 if (KdenliveSettings::sm_framesplayback() > 0) {
756 // only play the last x frames
757 while (m_animationList.count() > KdenliveSettings::sm_framesplayback() + 1) {
758 m_animationList.removeFirst();
766 void StopmotionWidget::slotAnimate()
769 if (KdenliveSettings::showstopmotionthumbs()) {
770 int newRow = frame_list->currentRow() + 1;
771 if (KdenliveSettings::sm_loop() || newRow < frame_list->count()) {
772 if (newRow >= frame_list->count()) {
773 if (KdenliveSettings::sm_framesplayback() == 0) newRow = 0;
775 // seek to correct frame
776 newRow = frame_list->count() - KdenliveSettings::sm_framesplayback();
779 frame_list->setCurrentRow(newRow);
780 QTimer::singleShot(100, this, SLOT(slotAnimate()));
784 if (m_animatedIndex >= m_animationList.count()) {
785 if (KdenliveSettings::sm_loop()) m_animatedIndex = 0;
786 else m_animatedIndex = -1;
788 if (m_animatedIndex > -1) {
789 slotShowFrame(m_animationList.at(m_animatedIndex));
791 QTimer::singleShot(100, this, SLOT(slotAnimate()));
797 preview_button->setChecked(false);
801 QListWidgetItem* StopmotionWidget::getFrameFromIndex(int ix)
803 QListWidgetItem* item = NULL;
805 if (ix >= frame_list->count()) {
806 pos = frame_list->count() - 1;
809 item = frame_list->item(pos);
811 int value = item->data(Qt::UserRole).toInt();
812 if (value == ix) return item;
813 else if (value < ix) {
815 while (pos < frame_list->count()) {
816 item = frame_list->item(pos);
817 value = item->data(Qt::UserRole).toInt();
818 if (value == ix) return item;
824 item = frame_list->item(pos);
825 value = item->data(Qt::UserRole).toInt();
826 if (value == ix) return item;
834 void StopmotionWidget::selectFrame(int ix)
836 frame_list->blockSignals(true);
837 QListWidgetItem* item = getFrameFromIndex(ix);
839 frame_list->setCurrentItem(item);
840 frame_list->blockSignals(false);
843 void StopmotionWidget::slotSeekFrame(bool forward)
845 int ix = frame_list->currentRow();
847 if (ix < frame_list->count() - 1) frame_list->setCurrentRow(ix + 1);
848 } else if (ix > 0) frame_list->setCurrentRow(ix - 1);
851 void StopmotionWidget::slotRemoveFrame()
853 if (frame_list->currentItem() == NULL) return;
854 QString path = frame_list->currentItem()->toolTip();
855 if (KMessageBox::questionYesNo(this, i18n("Delete frame %1 from disk?", path), i18n("Delete Frame")) != KMessageBox::Yes) return;
858 QListWidgetItem* item = frame_list->takeItem(frame_list->currentRow());
859 int ix = item->data(Qt::UserRole).toInt();
860 if (ix == m_sequenceFrame - 1) {
861 // We are removing the last frame, update counter
862 QListWidgetItem* item2 = frame_list->item(frame_list->count() - 1);
863 if (item2) m_sequenceFrame = item2->data(Qt::UserRole).toInt() + 1;
869 void StopmotionWidget::slotSwitchAnalyse(bool isOn)
871 KdenliveSettings::setAnalyse_stopmotion(isOn);
872 if (m_captureDevice) m_captureDevice->sendFrameForAnalysis = isOn;
875 void StopmotionWidget::slotSwitchMirror(bool isOn)
877 //KdenliveSettings::setAnalyse_stopmotion(isOn);
878 if (m_captureDevice) m_captureDevice->mirror(isOn);
882 const QString StopmotionWidget::createProducer(MltVideoProfile profile, const QString &service, const QString &resource)
886 QString playlist = "<mlt title=\"capture\"><producer id=\"producer0\" in=\"0\" out=\"99999\"><property name=\"mlt_type\">producer</property><property name=\"length\">100000</property><property name=\"eof\">pause</property><property name=\"resource\">" + resource + "</property><property name=\"mlt_service\">" + service + "</property></producer>";
889 playlist.append("<playlist id=\"playlist0\"></playlist>");
892 playlist.append("<playlist id=\"playlist1\"><entry producer=\"producer0\" in=\"0\" out=\"99999\"/></playlist>");
894 playlist.append("<tractor id=\"tractor0\" title=\"video0\" global_feed=\"1\" in=\"0\" out=\"99999\">");
895 playlist.append("<track producer=\"playlist0\"/>");
896 playlist.append("<track producer=\"playlist1\"/>");
897 playlist.append("</tractor></mlt>");