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"
19 #include "../blackmagic/devices.h"
20 #include "../v4l/v4lcapture.h"
21 #include "../slideshowclip.h"
22 #include "../profilesdialog.h"
23 #include "../mltdevicecapture.h"
24 #include "../recmonitor.h"
25 #include "../monitormanager.h"
26 #include "ui_smconfig_ui.h"
27 #include "kdenlivesettings.h"
31 #include <KGlobalSettings>
32 #include <KFileDialog>
33 #include <KStandardDirs>
34 #include <KMessageBox>
35 #include <kdeversion.h>
36 #include <KNotification>
39 #include <qimageblitz/qimageblitz.h>
42 #include <QtConcurrentRun>
43 #include <QInputDialog>
45 #include <QVBoxLayout>
49 #include <QWheelEvent>
52 MyLabel::MyLabel(QWidget* parent) :
57 void MyLabel::setImage(QImage img)
63 void MyLabel::wheelEvent(QWheelEvent* event)
65 if (event->delta() > 0) emit seek(true);
66 else emit seek(false);
70 void MyLabel::mousePressEvent(QMouseEvent*)
76 void MyLabel::paintEvent(QPaintEvent* event)
80 QRect r(0, 0, width(), height());
82 p.fillRect(r, QColor(KdenliveSettings::window_background()));
83 double aspect_ratio = (double) m_img.width() / m_img.height();
84 int pictureHeight = height();
85 int pictureWidth = width();
86 int calculatedWidth = aspect_ratio * height();
87 if (calculatedWidth > width()) pictureHeight = width() / aspect_ratio;
89 int calculatedHeight = width() / aspect_ratio;
90 if (calculatedHeight > height()) pictureWidth = height() * aspect_ratio;
92 p.drawImage(QRect((width() - pictureWidth) / 2, (height() - pictureHeight) / 2, pictureWidth, pictureHeight), m_img, QRect(0, 0, m_img.width(), m_img.height()));
97 StopmotionMonitor::StopmotionMonitor(QWidget *parent) :
98 AbstractMonitor(parent),
103 StopmotionMonitor::~StopmotionMonitor()
107 void StopmotionMonitor::setRender(MltDeviceCapture *render)
109 m_captureDevice = render;
112 AbstractRender *StopmotionMonitor::abstractRender()
114 return m_captureDevice;
117 const QString StopmotionMonitor::name() const
119 return QString("stopmotion");
123 void StopmotionMonitor::stop()
125 if (m_captureDevice) m_captureDevice->stop();
129 void StopmotionMonitor::start()
133 StopmotionWidget::StopmotionWidget(MonitorManager *manager, KUrl projectFolder, QList< QAction* > actions, QWidget* parent) :
135 , Ui::Stopmotion_UI()
136 , m_projectFolder(projectFolder)
137 , m_captureDevice(NULL)
139 , m_animatedIndex(-1)
142 , m_monitor(new StopmotionMonitor(this))
144 //setAttribute(Qt::WA_DeleteOnClose);
145 //HACK: the monitor widget is hidden, it is just used to control the capturedevice from monitormanager
146 m_monitor->setHidden(true);
147 connect(m_monitor, SIGNAL(stopCapture()), this, SLOT(slotStopCapture()));
148 m_manager->appendMonitor(m_monitor);
149 QAction* analyse = new QAction(i18n("Send frames to color scopes"), this);
150 analyse->setCheckable(true);
151 analyse->setChecked(KdenliveSettings::analyse_stopmotion());
152 connect(analyse, SIGNAL(triggered(bool)), this, SLOT(slotSwitchAnalyse(bool)));
155 setWindowTitle(i18n("Stop Motion Capture"));
156 setFont(KGlobalSettings::toolBarFont());
158 live_button->setIcon(KIcon("camera-photo"));
160 m_captureAction = actions.at(0);
161 connect(m_captureAction, SIGNAL(triggered()), this, SLOT(slotCaptureFrame()));
162 m_captureAction->setCheckable(true);
163 m_captureAction->setChecked(false);
164 capture_button->setDefaultAction(m_captureAction);
166 connect(actions.at(1), SIGNAL(triggered()), this, SLOT(slotSwitchLive()));
168 QAction *intervalCapture = new QAction(i18n("Interval capture"), this);
169 intervalCapture->setIcon(KIcon("chronometer"));
170 intervalCapture->setCheckable(true);
171 intervalCapture->setChecked(false);
172 capture_interval->setDefaultAction(intervalCapture);
174 preview_button->setIcon(KIcon("media-playback-start"));
175 capture_button->setEnabled(false);
179 QMenu* confMenu = new QMenu;
180 m_showOverlay = actions.at(2);
181 connect(m_showOverlay, SIGNAL(triggered(bool)), this, SLOT(slotShowOverlay(bool)));
182 overlay_button->setDefaultAction(m_showOverlay);
183 //confMenu->addAction(m_showOverlay);
186 m_effectIndex = KdenliveSettings::blitzeffect();
187 QMenu* effectsMenu = new QMenu(i18n("Overlay effect"));
188 QActionGroup* effectGroup = new QActionGroup(this);
189 QAction* noEffect = new QAction(i18n("No Effect"), effectGroup);
190 noEffect->setData(1);
191 QAction* contrastEffect = new QAction(i18n("Contrast"), effectGroup);
192 contrastEffect->setData(2);
193 QAction* edgeEffect = new QAction(i18n("Edge detect"), effectGroup);
194 edgeEffect->setData(3);
195 QAction* brightEffect = new QAction(i18n("Brighten"), effectGroup);
196 brightEffect->setData(4);
197 QAction* invertEffect = new QAction(i18n("Invert"), effectGroup);
198 invertEffect->setData(5);
199 QAction* thresEffect = new QAction(i18n("Threshold"), effectGroup);
200 thresEffect->setData(6);
202 effectsMenu->addAction(noEffect);
203 effectsMenu->addAction(contrastEffect);
204 effectsMenu->addAction(edgeEffect);
205 effectsMenu->addAction(brightEffect);
206 effectsMenu->addAction(invertEffect);
207 effectsMenu->addAction(thresEffect);
208 QList <QAction*> list = effectsMenu->actions();
209 for (int i = 0; i < list.count(); i++) {
210 list.at(i)->setCheckable(true);
211 if (list.at(i)->data().toInt() == m_effectIndex) {
212 list.at(i)->setChecked(true);
215 connect(effectsMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotUpdateOverlayEffect(QAction*)));
216 confMenu->addMenu(effectsMenu);
219 QAction* showThumbs = new QAction(KIcon("image-x-generic"), i18n("Show sequence thumbnails"), this);
220 showThumbs->setCheckable(true);
221 showThumbs->setChecked(KdenliveSettings::showstopmotionthumbs());
222 connect(showThumbs, SIGNAL(triggered(bool)), this, SLOT(slotShowThumbs(bool)));
224 QAction* removeCurrent = new QAction(KIcon("edit-delete"), i18n("Delete current frame"), this);
225 removeCurrent->setShortcut(Qt::Key_Delete);
226 connect(removeCurrent, SIGNAL(triggered()), this, SLOT(slotRemoveFrame()));
228 QAction* conf = new QAction(KIcon("configure"), i18n("Configure"), this);
229 connect(conf, SIGNAL(triggered()), this, SLOT(slotConfigure()));
231 confMenu->addAction(showThumbs);
232 confMenu->addAction(removeCurrent);
233 confMenu->addAction(analyse);
234 confMenu->addAction(conf);
235 config_button->setIcon(KIcon("configure"));
236 config_button->setMenu(confMenu);
238 connect(sequence_name, SIGNAL(textChanged(const QString&)), this, SLOT(sequenceNameChanged(const QString&)));
239 connect(sequence_name, SIGNAL(currentIndexChanged(int)), live_button, SLOT(setFocus()));
241 // Video widget holder
242 QVBoxLayout *layout = new QVBoxLayout;
243 layout->setContentsMargins(0, 0, 0, 0);
244 layout->setSpacing(0);
245 m_videoBox = new VideoPreviewContainer();
246 m_videoBox->setContentsMargins(0, 0, 0, 0);
247 m_videoBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
248 //m_videoBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
249 m_videoBox->setLineWidth(4);
250 layout->addWidget(m_videoBox);
253 if (BMInterface::getBlackMagicDeviceList(capture_device, NULL)) {
254 // Found a BlackMagic device
255 //m_bmCapture = new BmdCaptureHandler(m_layout);
256 //connect(m_bmCapture, SIGNAL(gotMessage(const QString&)), this, SLOT(slotGotHDMIMessage(const QString&)));
258 if (QFile::exists(KdenliveSettings::video4vdevice())) {
259 #if !defined(Q_WS_MAC) && !defined(Q_OS_FREEBSD)
260 // Video 4 Linux device detection
261 for (int i = 0; i < 10; i++) {
262 QString path = "/dev/video" + QString::number(i);
263 if (QFile::exists(path)) {
264 QStringList deviceInfo = V4lCaptureHandler::getDeviceName(path);
265 if (!deviceInfo.isEmpty()) {
266 capture_device->addItem(deviceInfo.at(0), "v4l");
267 capture_device->setItemData(capture_device->count() - 1, path, Qt::UserRole + 1);
268 capture_device->setItemData(capture_device->count() - 1, deviceInfo.at(1), Qt::UserRole + 2);
269 if (path == KdenliveSettings::video4vdevice()) capture_device->setCurrentIndex(capture_device->count() - 1);
274 //if (m_bmCapture == NULL) {
276 //m_captureDevice->sendFrameForAnalysis = m_analyse;
277 /*m_bmCapture = new V4lCaptureHandler(m_layout);
278 m_bmCapture->setDevice(capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString(), capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 2).toString());*/
283 connect(capture_device, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateHandler()));
285 connect(m_bmCapture, SIGNAL(frameSaved(const QString)), this, SLOT(slotNewThumb(const QString)));
286 connect(m_bmCapture, SIGNAL(gotFrame(QImage)), this, SIGNAL(gotFrame(QImage)));
287 } else live_button->setEnabled(false);*/
289 m_frame_preview = new MyLabel(this);
290 connect(m_frame_preview, SIGNAL(seek(bool)), this, SLOT(slotSeekFrame(bool)));
291 connect(m_frame_preview, SIGNAL(switchToLive()), this, SLOT(slotSwitchLive()));
292 layout->addWidget(m_frame_preview);
293 m_frame_preview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
294 video_preview->setLayout(layout);
296 //kDebug()<<video_preview->winId();
298 QString path = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
299 m_captureDevice = new MltDeviceCapture(path, m_videoBox, this);
300 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
301 m_monitor->setRender(m_captureDevice);
302 connect(m_captureDevice, SIGNAL(frameSaved(const QString)), this, SLOT(slotNewThumb(const QString)));
304 live_button->setChecked(false);
305 button_addsequence->setEnabled(false);
306 connect(live_button, SIGNAL(toggled(bool)), this, SLOT(slotLive(bool)));
307 connect(button_addsequence, SIGNAL(clicked(bool)), this, SLOT(slotAddSequence()));
308 connect(preview_button, SIGNAL(clicked(bool)), this, SLOT(slotPlayPreview(bool)));
309 connect(frame_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotShowSelectedFrame()));
310 connect(frame_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(slotShowSelectedFrame()));
311 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
313 frame_list->addAction(removeCurrent);
314 frame_list->setContextMenuPolicy(Qt::ActionsContextMenu);
315 frame_list->setHidden(!KdenliveSettings::showstopmotionthumbs());
316 parseExistingSequences();
317 QTimer::singleShot(500, this, SLOT(slotLive()));
318 connect(&m_intervalTimer, SIGNAL(timeout()), this, SLOT(slotCaptureFrame()));
319 m_intervalTimer.setSingleShot(true);
320 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
323 StopmotionWidget::~StopmotionWidget()
326 m_bmCapture->stopPreview();*/
327 if (m_captureDevice) {
328 m_captureDevice->stop();
329 delete m_captureDevice;
330 m_captureDevice = NULL;
336 void StopmotionWidget::slotUpdateOverlayEffect(QAction* act)
339 if (act) m_effectIndex = act->data().toInt();
340 KdenliveSettings::setBlitzeffect(m_effectIndex);
341 if (m_showOverlay->isChecked()) slotUpdateOverlay();
345 void StopmotionWidget::closeEvent(QCloseEvent* e)
348 QDialog::closeEvent(e);
351 void StopmotionWidget::slotConfigure()
356 d.setWindowTitle(i18n("Configure Stop Motion"));
357 ui.sm_interval->setValue(KdenliveSettings::captureinterval());
358 ui.sm_interval->setSuffix(ki18np(" second", " seconds"));
359 ui.sm_notifytime->setSuffix(ki18np(" second", " seconds"));
360 ui.sm_notifytime->setValue(KdenliveSettings::sm_notifytime());
361 connect(ui.sm_prenotify, SIGNAL(toggled(bool)), ui.sm_notifytime, SLOT(setEnabled(bool)));
362 ui.sm_prenotify->setChecked(KdenliveSettings::sm_prenotify());
363 ui.sm_loop->setChecked(KdenliveSettings::sm_loop());
364 ui.sm_framesplayback->setValue(KdenliveSettings::sm_framesplayback());
366 if (d.exec() == QDialog::Accepted) {
367 KdenliveSettings::setSm_loop(ui.sm_loop->isChecked());
368 KdenliveSettings::setCaptureinterval(ui.sm_interval->value());
369 KdenliveSettings::setSm_framesplayback(ui.sm_framesplayback->value());
370 KdenliveSettings::setSm_notifytime(ui.sm_notifytime->value());
371 KdenliveSettings::setSm_prenotify(ui.sm_prenotify->isChecked());
372 m_intervalTimer.setInterval(KdenliveSettings::captureinterval() * 1000);
376 void StopmotionWidget::slotShowThumbs(bool show)
378 KdenliveSettings::setShowstopmotionthumbs(show);
381 sequenceNameChanged(sequence_name->currentText());
386 frame_list->setHidden(!show);
390 void StopmotionWidget::slotUpdateHandler()
392 /*QString data = capture_device->itemData(capture_device->currentIndex()).toString();
397 m_layout->removeWidget(m_frame_preview);
399 #if !defined(Q_WS_MAC) && !defined(Q_OS_FREEBSD)
400 m_bmCapture = new V4lCaptureHandler(m_layout);
401 m_bmCapture->setDevice(capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 1).toString(), capture_device->itemData(capture_device->currentIndex(), Qt::UserRole + 2).toString());
404 m_bmCapture = new BmdCaptureHandler(m_layout);
405 if (m_bmCapture) connect(m_bmCapture, SIGNAL(gotMessage(const QString&)), this, SLOT(slotGotHDMIMessage(const QString&)));
407 live_button->setEnabled(m_bmCapture != NULL);
408 m_layout->addWidget(m_frame_preview);*/
411 void StopmotionWidget::slotGotHDMIMessage(const QString& message)
413 log_box->insertItem(0, message);
416 void StopmotionWidget::parseExistingSequences()
418 sequence_name->clear();
419 sequence_name->addItem(QString());
420 QDir dir(m_projectFolder.path());
422 filters << "*_0000.png";
423 //dir.setNameFilters(filters);
424 QStringList sequences = dir.entryList(filters, QDir::Files, QDir::Name);
425 //kDebug()<<"PF: "<<<<", sm: "<<sequences;
426 foreach(QString sequencename, sequences) {
427 sequence_name->addItem(sequencename.section("_", 0, -2));
431 void StopmotionWidget::slotSwitchLive()
433 setUpdatesEnabled(false);
434 slotLive(!live_button->isChecked());
435 /*if (m_frame_preview->isHidden()) {
436 //if (m_bmCapture) m_bmCapture->hidePreview(true);
437 m_videoBox->setHidden(true);
438 m_frame_preview->setHidden(false);
440 m_frame_preview->setHidden(true);
441 //if (m_bmCapture) m_bmCapture->hidePreview(false);
442 m_videoBox->setHidden(false);
443 capture_button->setEnabled(true);
445 setUpdatesEnabled(true);
448 void StopmotionWidget::slotStopCapture()
453 void StopmotionWidget::slotLive(bool isOn)
455 live_button->blockSignals(true);
456 capture_button->setEnabled(false);
458 m_frame_preview->setHidden(true);
459 m_videoBox->setHidden(false);
460 QString path = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
462 kDebug()<<"SURFACE; "<<m_videoBox->width()<<"x"<<m_videoBox->height();
463 if (m_captureDevice == NULL) {
464 m_captureDevice = new MltDeviceCapture(path, m_videoBox, this);
465 m_captureDevice->sendFrameForAnalysis = KdenliveSettings::analyse_stopmotion();
466 m_monitor->setRender(m_captureDevice);
467 connect(m_captureDevice, SIGNAL(frameSaved(const QString)), this, SLOT(slotNewThumb(const QString)));
470 MltVideoProfile profile = ProfilesDialog::getVideoProfile(path);
471 m_manager->activateMonitor("stopmotion");
472 QString producer = QString("avformat-novalidate:video4linux2:%1?width:%2&height:%3&frame_rate:%4").arg(KdenliveSettings::video4vdevice()).arg(profile.width).arg(profile.height).arg((double) profile.frame_rate_num / profile.frame_rate_den);
473 if (m_captureDevice->slotStartPreview(producer)) {
474 kDebug()<<"// STARt CAPTURE GO";
475 capture_button->setEnabled(true);
476 live_button->setChecked(true);
477 log_box->insertItem(-1, i18n("Playing %1x%2 (%3 fps)", profile.width, profile.height, QString::number((double)profile.frame_rate_num/profile.frame_rate_den).rightJustified(2, '0')));
478 log_box->setCurrentIndex(0);
481 kDebug()<<"// problem starting stopmo";
482 log_box->insertItem(-1, i18n("Failed to start device"));
483 log_box->setCurrentIndex(0);
487 m_frame_preview->setHidden(false);
488 live_button->setChecked(false);
489 if (m_captureDevice) {
490 m_captureDevice->stop();
491 m_videoBox->setHidden(true);
492 log_box->insertItem(-1, i18n("Stopped"));
493 log_box->setCurrentIndex(0);
494 //delete m_captureDevice;
495 //m_captureDevice = NULL;
500 if (isOn && m_bmCapture) {
501 //m_frame_preview->setImage(QImage());
502 m_frame_preview->setHidden(true);
503 m_bmCapture->startPreview(KdenliveSettings::hdmi_capturedevice(), KdenliveSettings::hdmi_capturemode(), false);
504 capture_button->setEnabled(true);
505 live_button->setChecked(true);
507 if (m_bmCapture) m_bmCapture->stopPreview();
508 m_frame_preview->setHidden(false);
509 capture_button->setEnabled(false);
510 live_button->setChecked(false);
512 live_button->blockSignals(false);
515 void StopmotionWidget::slotShowOverlay(bool /*isOn*/)
518 if (live_button->isChecked() && m_sequenceFrame > 0) {
521 } else if (m_bmCapture) {
522 m_bmCapture->hideOverlay();
526 void StopmotionWidget::slotUpdateOverlay()
528 if (m_captureDevice == NULL) return;
529 QString path = getPathForFrame(m_sequenceFrame - 1);
530 if (!QFile::exists(path)) return;
533 QTimer::singleShot(1000, this, SLOT(slotUpdateOverlay()));
538 //img = Blitz::convolveEdge(img, 0, Blitz::Low);
539 switch (m_effectIndex) {
541 img = Blitz::contrast(img, true, 6);
544 img = Blitz::edge(img);
547 img = Blitz::intensity(img, 0.5);
553 img = Blitz::threshold(img, 120, Blitz::Grayscale, qRgba(0, 0, 0, 0), qRgba(255, 0, 0, 255));
554 //img = Blitz::flatten(img, QColor(255, 0, 0, 255), QColor(0, 0, 0, 0));
561 //m_bmCapture->showOverlay(img);
564 void StopmotionWidget::sequenceNameChanged(const QString& name)
566 // Get rid of frames from previous sequence
567 disconnect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
569 m_future.waitForFinished();
571 if (name.isEmpty()) {
572 button_addsequence->setEnabled(false);
574 // Check if we are editing an existing sequence
575 QString pattern = SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_filesList);
576 m_sequenceFrame = m_filesList.isEmpty() ? 0 : SlideshowClip::getFrameNumberFromPath(m_filesList.last()) + 1;
577 if (!m_filesList.isEmpty()) {
578 m_sequenceName = sequence_name->currentText();
579 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
580 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
581 button_addsequence->setEnabled(true);
584 connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
585 button_addsequence->setEnabled(false);
587 capture_button->setEnabled(live_button->isChecked());
591 void StopmotionWidget::slotCaptureFrame()
593 if (m_captureDevice == NULL) return;
594 if (sequence_name->currentText().isEmpty()) {
595 QString seqName = QInputDialog::getText(this, i18n("Create New Sequence"), i18n("Enter sequence name"));
596 if (seqName.isEmpty()) {
597 m_captureAction->setChecked(false);
600 sequence_name->blockSignals(true);
601 sequence_name->setItemText(sequence_name->currentIndex(), seqName);
602 sequence_name->blockSignals(false);
604 if (m_sequenceName != sequence_name->currentText()) {
605 m_sequenceName = sequence_name->currentText();
608 //capture_button->setEnabled(false);
609 if (m_intervalTimer.isActive()) {
610 // stop interval capture
611 m_intervalTimer.stop();
614 QString currentPath = getPathForFrame(m_sequenceFrame);
615 m_captureDevice->captureFrame(currentPath);
616 KNotification::event("FrameCaptured", i18n("Frame Captured"), QPixmap(), this);
618 button_addsequence->setEnabled(true);
619 if (capture_interval->isChecked()) {
620 if (KdenliveSettings::sm_prenotify()) QTimer::singleShot((KdenliveSettings::captureinterval() - KdenliveSettings::sm_notifytime()) * 1000, this, SLOT(slotPreNotify()));
621 m_intervalTimer.start();
623 else m_captureAction->setChecked(false);
626 void StopmotionWidget::slotPreNotify()
628 if (m_captureAction->isChecked()) KNotification::event("ReadyToCapture", i18n("Going to Capture Frame"), QPixmap(), this);
632 void StopmotionWidget::slotNewThumb(const QString path)
634 if (!KdenliveSettings::showstopmotionthumbs()) return;
635 m_filesList.append(path);
636 if (m_showOverlay->isChecked()) slotUpdateOverlay();
637 if (!m_future.isRunning()) m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
640 void StopmotionWidget::slotPrepareThumbs()
642 if (m_filesList.isEmpty()) return;
643 QString path = m_filesList.takeFirst();
644 emit doCreateThumbs(QImage(path), SlideshowClip::getFrameNumberFromPath(path));
648 void StopmotionWidget::slotCreateThumbs(QImage img, int ix)
651 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
655 int width = height * img.width() / img.height();
656 frame_list->setIconSize(QSize(width, height));
657 QPixmap pix = QPixmap::fromImage(img).scaled(width, height);
658 QString nb = QString::number(ix);
660 QFontInfo finfo(font());
661 p.fillRect(0, 0, finfo.pixelSize() * nb.count() + 6, finfo.pixelSize() + 6, QColor(80, 80, 80, 150));
663 p.drawText(QPoint(3, finfo.pixelSize() + 3), nb);
666 QListWidgetItem* item = new QListWidgetItem(icon, QString(), frame_list);
667 item->setToolTip(getPathForFrame(ix, sequence_name->currentText()));
668 item->setData(Qt::UserRole, ix);
669 frame_list->blockSignals(true);
670 frame_list->setCurrentItem(item);
671 frame_list->blockSignals(false);
672 m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
675 QString StopmotionWidget::getPathForFrame(int ix, QString seqName)
677 if (seqName.isEmpty()) seqName = m_sequenceName;
678 return m_projectFolder.path(KUrl::AddTrailingSlash) + seqName + "_" + QString::number(ix).rightJustified(4, '0', false) + ".png";
681 void StopmotionWidget::slotShowFrame(const QString& path)
685 capture_button->setEnabled(false);
688 //m_videoBox->setHidden(true);
690 m_frame_preview->setImage(img);
691 m_frame_preview->setHidden(false);
692 m_frame_preview->update();
696 void StopmotionWidget::slotShowSelectedFrame()
698 QListWidgetItem* item = frame_list->currentItem();
700 //int ix = item->data(Qt::UserRole).toInt();;
701 slotShowFrame(item->toolTip());
705 void StopmotionWidget::slotAddSequence()
707 emit addOrUpdateSequence(getPathForFrame(0));
710 void StopmotionWidget::slotPlayPreview(bool animate)
715 m_animationList.clear();
718 if (KdenliveSettings::showstopmotionthumbs()) {
719 if (KdenliveSettings::sm_framesplayback() == 0) frame_list->setCurrentRow(0);
720 else frame_list->setCurrentRow(frame_list->count() - KdenliveSettings::sm_framesplayback());
721 QTimer::singleShot(200, this, SLOT(slotAnimate()));
723 SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_animationList);
724 if (KdenliveSettings::sm_framesplayback() > 0) {
725 // only play the last x frames
726 while (m_animationList.count() > KdenliveSettings::sm_framesplayback() + 1) {
727 m_animationList.removeFirst();
735 void StopmotionWidget::slotAnimate()
738 if (KdenliveSettings::showstopmotionthumbs()) {
739 int newRow = frame_list->currentRow() + 1;
740 if (KdenliveSettings::sm_loop() || newRow < frame_list->count()) {
741 if (newRow >= frame_list->count()) {
742 if (KdenliveSettings::sm_framesplayback() == 0) newRow = 0;
744 // seek to correct frame
745 newRow = frame_list->count() - KdenliveSettings::sm_framesplayback();
748 frame_list->setCurrentRow(newRow);
749 QTimer::singleShot(100, this, SLOT(slotAnimate()));
753 if (m_animatedIndex >= m_animationList.count()) {
754 if (KdenliveSettings::sm_loop()) m_animatedIndex = 0;
755 else m_animatedIndex = -1;
757 if (m_animatedIndex > -1) {
758 slotShowFrame(m_animationList.at(m_animatedIndex));
760 QTimer::singleShot(100, this, SLOT(slotAnimate()));
766 preview_button->setChecked(false);
770 QListWidgetItem* StopmotionWidget::getFrameFromIndex(int ix)
772 QListWidgetItem* item = NULL;
774 if (ix >= frame_list->count()) {
775 pos = frame_list->count() - 1;
778 item = frame_list->item(pos);
780 int value = item->data(Qt::UserRole).toInt();
781 if (value == ix) return item;
782 else if (value < ix) {
784 while (pos < frame_list->count()) {
785 item = frame_list->item(pos);
786 value = item->data(Qt::UserRole).toInt();
787 if (value == ix) return item;
793 item = frame_list->item(pos);
794 value = item->data(Qt::UserRole).toInt();
795 if (value == ix) return item;
803 void StopmotionWidget::selectFrame(int ix)
805 frame_list->blockSignals(true);
806 QListWidgetItem* item = getFrameFromIndex(ix);
808 frame_list->setCurrentItem(item);
809 frame_list->blockSignals(false);
812 void StopmotionWidget::slotSeekFrame(bool forward)
814 int ix = frame_list->currentRow();
816 if (ix < frame_list->count() - 1) frame_list->setCurrentRow(ix + 1);
817 } else if (ix > 0) frame_list->setCurrentRow(ix - 1);
820 void StopmotionWidget::slotRemoveFrame()
822 if (frame_list->currentItem() == NULL) return;
823 QString path = frame_list->currentItem()->toolTip();
824 if (KMessageBox::questionYesNo(this, i18n("Delete frame %1 from disk?", path), i18n("Delete Frame")) != KMessageBox::Yes) return;
827 QListWidgetItem* item = frame_list->takeItem(frame_list->currentRow());
828 int ix = item->data(Qt::UserRole).toInt();
829 if (ix == m_sequenceFrame - 1) {
830 // We are removing the last frame, update counter
831 QListWidgetItem* item2 = frame_list->item(frame_list->count() - 1);
832 if (item2) m_sequenceFrame = item2->data(Qt::UserRole).toInt() + 1;
838 void StopmotionWidget::slotSwitchAnalyse(bool isOn)
840 KdenliveSettings::setAnalyse_stopmotion(isOn);
841 if (m_captureDevice) m_captureDevice->sendFrameForAnalysis = isOn;
842 //m_bmCapture->setAnalyse(isOn);