]> git.sesse.net Git - kdenlive/blob - src/stopmotion/stopmotion.cpp
Fix build on OSX by not using new V4LCaptureHandler.
[kdenlive] / src / stopmotion / stopmotion.cpp
1 /***************************************************************************
2                           stopmotion.cpp  -  description
3                              -------------------
4     begin                : Feb 28 2008
5     copyright            : (C) 2010 by Jean-Baptiste Mardelle
6     email                : jb@kdenlive.org
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
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.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include "stopmotion.h"
19 #include "../blackmagic/devices.h"
20 #include "../v4l/v4lcapture.h"
21 #include "../slideshowclip.h"
22 #include "kdenlivesettings.h"
23
24
25 #include <KDebug>
26 #include <KGlobalSettings>
27 #include <KFileDialog>
28 #include <KStandardDirs>
29 #include <KMessageBox>
30 #include <kdeversion.h>
31 #include <KNotification>
32
33 #ifdef QIMAGEBLITZ
34 #include <qimageblitz/qimageblitz.h>
35 #endif
36
37 #include <QtConcurrentRun>
38 #include <QInputDialog>
39 #include <QComboBox>
40 #include <QVBoxLayout>
41 #include <QTimer>
42 #include <QPainter>
43 #include <QAction>
44 #include <QWheelEvent>
45 #include <QMenu>
46
47 MyLabel::MyLabel(QWidget *parent) :
48     QLabel(parent)
49 {
50 }
51
52 void MyLabel::setImage(QImage img)
53 {
54     m_img = img;
55 }
56
57 //virtual
58 void MyLabel::wheelEvent(QWheelEvent * event)
59 {
60     if (event->delta() > 0) emit seek(true);
61     else emit seek(false);
62 }
63
64 //virtual
65 void MyLabel::mousePressEvent(QMouseEvent *)
66 {
67     emit switchToLive();
68 }
69
70 //virtual
71 void MyLabel::paintEvent(QPaintEvent * event)
72 {
73     Q_UNUSED(event);
74
75     QRect r(0, 0, width(), height());
76     QPainter p(this);
77     p.fillRect(r, QColor(KdenliveSettings::window_background()));
78     double aspect_ratio = (double) m_img.width() / m_img.height();
79     int pictureHeight = height();
80     int pictureWidth = width();
81     int calculatedWidth = aspect_ratio * height();
82     if (calculatedWidth > width()) pictureHeight = width() / aspect_ratio;
83     else {
84         int calculatedHeight = width() / aspect_ratio;
85         if (calculatedHeight > height()) pictureWidth = height() * aspect_ratio;
86     }
87     p.drawImage(QRect((width() - pictureWidth) / 2, (height() - pictureHeight) / 2, pictureWidth, pictureHeight), m_img, QRect(0, 0, m_img.width(), m_img.height()));
88     p.end();
89 }
90
91
92 StopmotionWidget::StopmotionWidget(KUrl projectFolder, const QList< QAction * > actions, QWidget *parent) :
93     QDialog(parent)
94     , Ui::Stopmotion_UI()
95     , m_projectFolder(projectFolder)
96     , m_bmCapture(NULL)
97     , m_sequenceFrame(0)
98     , m_animatedIndex(-1)
99 {
100     addActions(actions);
101     setupUi(this);
102     setWindowTitle(i18n("Stop Motion Capture"));
103     setFont(KGlobalSettings::toolBarFont());
104
105     live_button->setIcon(KIcon("camera-photo"));
106
107     m_captureAction = actions.at(0);
108     connect(m_captureAction, SIGNAL(triggered()), this, SLOT(slotCaptureFrame()));
109     capture_button->setDefaultAction(m_captureAction);
110
111     connect(actions.at(1), SIGNAL(triggered()), this, SLOT(slotSwitchLive()));
112
113     preview_button->setIcon(KIcon("media-playback-start"));
114     capture_button->setEnabled(false);
115
116     // Build config menu
117     QMenu *confMenu = new QMenu;
118     m_showOverlay = actions.at(2);
119     connect(m_showOverlay, SIGNAL(triggered(bool)), this, SLOT(slotShowOverlay(bool)));
120     confMenu->addAction(m_showOverlay);
121
122 #ifdef QIMAGEBLITZ
123     m_effectIndex = KdenliveSettings::blitzeffect();
124     QMenu *effectsMenu = new QMenu(i18n("Overlay effect"));
125     QActionGroup *effectGroup = new QActionGroup(this);
126     QAction *noEffect = new QAction(i18n("No Effect"), effectGroup);
127     noEffect->setData(1);
128     QAction *contrastEffect = new QAction(i18n("Contrast"), effectGroup);
129     contrastEffect->setData(2);
130     QAction *edgeEffect = new QAction(i18n("Edge detect"), effectGroup);
131     edgeEffect->setData(3);
132     QAction *brightEffect = new QAction(i18n("Brighten"), effectGroup);
133     brightEffect->setData(4);
134     QAction *invertEffect = new QAction(i18n("Invert"), effectGroup);
135     invertEffect->setData(5);
136     QAction *thresEffect = new QAction(i18n("Threshold"), effectGroup);
137     thresEffect->setData(6);
138
139     effectsMenu->addAction(noEffect);
140     effectsMenu->addAction(contrastEffect);
141     effectsMenu->addAction(edgeEffect);
142     effectsMenu->addAction(brightEffect);
143     effectsMenu->addAction(invertEffect);
144     effectsMenu->addAction(thresEffect);
145     QList <QAction *> list = effectsMenu->actions();
146     for (int i = 0; i < list.count(); i++) {
147         list.at(i)->setCheckable(true);
148         if (list.at(i)->data().toInt() == m_effectIndex) {
149             list.at(i)->setChecked(true);
150         }
151     }
152     connect(effectsMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotUpdateOverlayEffect(QAction*)));
153     confMenu->addMenu(effectsMenu);
154 #endif
155
156     QAction *showThumbs = new QAction(KIcon("image-x-generic"), i18n("Show sequence thumbnails"), this);
157     showThumbs->setCheckable(true);
158     showThumbs->setChecked(KdenliveSettings::showstopmotionthumbs());
159     connect(showThumbs, SIGNAL(triggered(bool)), this, SLOT(slotShowThumbs(bool)));
160
161     QAction *removeCurrent = new QAction(KIcon("edit-delete"), i18n("Delete current frame"), this);
162     removeCurrent->setShortcut(Qt::Key_Delete);
163     connect(removeCurrent, SIGNAL(triggered()), this, SLOT(slotRemoveFrame()));
164
165     QAction *capInterval = new QAction(KIcon(), i18n("Set capture interval"), this);
166     connect(capInterval, SIGNAL(triggered()), this, SLOT(slotSetCaptureInterval()));
167
168     confMenu->addAction(showThumbs);
169     confMenu->addAction(capInterval);
170     confMenu->addAction(removeCurrent);
171     config_button->setIcon(KIcon("configure"));
172     config_button->setMenu(confMenu);
173
174     // Build capture menu
175     QMenu *capMenu = new QMenu;
176     m_intervalCapture = new QAction(KIcon("edit-redo"), i18n("Interval capture"), this);
177     m_intervalCapture->setCheckable(true);
178     m_intervalCapture->setChecked(false);
179     connect(m_intervalCapture, SIGNAL(triggered(bool)), this, SLOT(slotIntervalCapture(bool)));
180     capMenu->addAction(m_intervalCapture);
181     capture_button->setMenu(capMenu);
182
183     connect(sequence_name, SIGNAL(textChanged(const QString &)), this, SLOT(sequenceNameChanged(const QString &)));
184     connect(sequence_name, SIGNAL(currentIndexChanged(int)), live_button, SLOT(setFocus()));
185
186     m_layout = new QVBoxLayout;
187     if (BMInterface::getBlackMagicDeviceList(capture_device, NULL)) {
188         // Found a BlackMagic device
189         m_bmCapture = new BmdCaptureHandler(m_layout);
190         connect(m_bmCapture, SIGNAL(gotMessage(const QString &)), this, SLOT(slotGotHDMIMessage(const QString &)));
191     }
192     if (QFile::exists(KdenliveSettings::video4vdevice())) {
193 #ifndef Q_WS_MAC
194         if (m_bmCapture == NULL) m_bmCapture = new V4lCaptureHandler(m_layout);
195         capture_device->addItem(m_bmCapture->getDeviceName(KdenliveSettings::video4vdevice()).at(0), "v4l");
196 #endif
197     }
198
199     connect(m_bmCapture, SIGNAL(frameSaved(const QString)), this, SLOT(slotNewThumb(const QString)));
200     connect(capture_device, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateHandler()));
201     m_frame_preview = new MyLabel(this);
202     connect(m_frame_preview, SIGNAL(seek(bool)), this, SLOT(slotSeekFrame(bool)));
203     connect(m_frame_preview, SIGNAL(switchToLive()), this, SLOT(slotSwitchLive()));
204     m_layout->addWidget(m_frame_preview);
205     m_frame_preview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
206     video_preview->setLayout(m_layout);
207     live_button->setChecked(false);
208     button_addsequence->setEnabled(false);
209     connect(live_button, SIGNAL(clicked(bool)), this, SLOT(slotLive(bool)));
210     connect(button_addsequence, SIGNAL(clicked(bool)), this, SLOT(slotAddSequence()));
211     connect(preview_button, SIGNAL(clicked(bool)), this, SLOT(slotPlayPreview(bool)));
212     connect(frame_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotShowSelectedFrame()));
213     connect(frame_list, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(slotShowSelectedFrame()));
214     connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
215
216     frame_list->addAction(removeCurrent);
217     frame_list->setContextMenuPolicy(Qt::ActionsContextMenu);
218     frame_list->setHidden(!KdenliveSettings::showstopmotionthumbs());
219     parseExistingSequences();
220 }
221
222 StopmotionWidget::~StopmotionWidget()
223 {
224     if (m_bmCapture)
225         m_bmCapture->stopPreview();
226 }
227
228 void StopmotionWidget::slotUpdateOverlayEffect(QAction *act)
229 {
230 #ifdef QIMAGEBLITZ
231     if (act) m_effectIndex = act->data().toInt();
232     KdenliveSettings::setBlitzeffect(m_effectIndex);
233     if (m_showOverlay->isChecked()) slotUpdateOverlay();
234 #endif
235 }
236
237 void StopmotionWidget::closeEvent(QCloseEvent *e)
238 {
239     slotLive(false);
240     QDialog::closeEvent(e);
241 }
242
243 void StopmotionWidget::slotSetCaptureInterval()
244 {
245     int interval = QInputDialog::getInteger(this, i18n("Set Capture Interval"), i18n("Interval (in seconds)"), KdenliveSettings::captureinterval(), 1);
246     if (interval > 0 && interval != KdenliveSettings::captureinterval())
247         KdenliveSettings::setCaptureinterval(interval);
248 }
249
250 void StopmotionWidget::slotShowThumbs(bool show)
251 {
252     KdenliveSettings::setShowstopmotionthumbs(show);
253     if (show) {
254         frame_list->clear();
255         sequenceNameChanged(sequence_name->currentText());
256     } else {
257         m_filesList.clear();
258         frame_list->clear();
259     }
260     frame_list->setHidden(!show);
261 }
262
263 void StopmotionWidget::slotIntervalCapture(bool capture)
264 {
265     if (capture) slotCaptureFrame();
266 }
267
268
269 void StopmotionWidget::slotUpdateHandler()
270 {
271     QString data = capture_device->itemData(capture_device->currentIndex()).toString();
272     m_bmCapture->stopPreview();
273     delete m_bmCapture;
274     m_layout->removeWidget(m_frame_preview);
275     if (data == "v4l") {
276 #ifndef Q_WS_MAC
277         m_bmCapture = new V4lCaptureHandler(m_layout);
278 #endif
279     } else {
280         m_bmCapture = new BmdCaptureHandler(m_layout);
281         connect(m_bmCapture, SIGNAL(gotMessage(const QString &)), this, SLOT(slotGotHDMIMessage(const QString &)));
282     }
283     m_layout->addWidget(m_frame_preview);
284 }
285
286 void StopmotionWidget::slotGotHDMIMessage(const QString &message)
287 {
288     log_box->insertItem(0, message);
289 }
290
291 void StopmotionWidget::parseExistingSequences()
292 {
293     sequence_name->clear();
294     sequence_name->addItem(QString());
295     QDir dir(m_projectFolder.path());
296     QStringList filters;
297     filters << "*_0000.png";
298     //dir.setNameFilters(filters);
299     QStringList sequences = dir.entryList(filters, QDir::Files, QDir::Name);
300     //kDebug()<<"PF: "<<<<", sm: "<<sequences;
301     foreach(QString sequencename, sequences) {
302         sequence_name->addItem(sequencename.section("_", 0, -2));
303     }
304 }
305
306 void StopmotionWidget::slotSwitchLive()
307 {
308     setUpdatesEnabled(false);
309     if (m_frame_preview->isHidden()) {
310         m_bmCapture->hidePreview(true);
311         m_frame_preview->setHidden(false);
312     } else {
313         m_frame_preview->setHidden(true);
314         m_bmCapture->hidePreview(false);
315     }
316     setUpdatesEnabled(true);
317 }
318
319 void StopmotionWidget::slotLive(bool isOn)
320 {
321     if (isOn) {
322         //m_frame_preview->setImage(QImage());
323         m_frame_preview->setHidden(true);
324         m_bmCapture->startPreview(KdenliveSettings::hdmi_capturedevice(), KdenliveSettings::hdmi_capturemode(), false);
325         capture_button->setEnabled(true);
326     } else {
327         m_bmCapture->stopPreview();
328         m_frame_preview->setHidden(false);
329         capture_button->setEnabled(false);
330         live_button->setChecked(false);
331     }
332 }
333
334 void StopmotionWidget::slotShowOverlay(bool isOn)
335 {
336     if (isOn) {
337         if (live_button->isChecked() && m_sequenceFrame > 0) {
338             slotUpdateOverlay();
339         }
340     } else {
341         m_bmCapture->hideOverlay();
342     }
343 }
344
345 void StopmotionWidget::slotUpdateOverlay()
346 {
347     QString path = getPathForFrame(m_sequenceFrame - 1);
348     if (!QFile::exists(path)) return;
349     QImage img(path);
350     if (img.isNull()) {
351         QTimer::singleShot(1000, this, SLOT(slotUpdateOverlay()));
352         return;
353     }
354
355 #ifdef QIMAGEBLITZ
356     //img = Blitz::convolveEdge(img, 0, Blitz::Low);
357     switch (m_effectIndex) {
358     case 2:
359         img = Blitz::contrast(img, true, 6);
360         break;
361     case 3:
362         img = Blitz::edge(img);
363         break;
364     case 4:
365         img = Blitz::intensity(img, 0.5);
366         break;
367     case 5:
368         Blitz::invert(img);
369         break;
370     case 6:
371         img = Blitz::threshold(img, 120, Blitz::Grayscale, qRgba(0, 0, 0, 0), qRgba(255, 0, 0, 255));
372         //img = Blitz::flatten(img, QColor(255, 0, 0, 255), QColor(0, 0, 0, 0));
373         break;
374     default:
375         break;
376
377     }
378 #endif
379     m_bmCapture->showOverlay(img);
380 }
381
382 void StopmotionWidget::sequenceNameChanged(const QString &name)
383 {
384     // Get rid of frames from previous sequence
385     disconnect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
386     m_filesList.clear();
387     m_future.waitForFinished();
388     frame_list->clear();
389     if (name.isEmpty()) {
390         button_addsequence->setEnabled(false);
391     } else {
392         // Check if we are editing an existing sequence
393         QString pattern = SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_filesList);
394         m_sequenceFrame = m_filesList.isEmpty() ? 0 : SlideshowClip::getFrameNumberFromPath(m_filesList.last()) + 1;
395         if (!m_filesList.isEmpty()) {
396             m_sequenceName = sequence_name->currentText();
397             connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
398             m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
399             button_addsequence->setEnabled(true);
400         } else {
401             // new sequence
402             connect(this, SIGNAL(doCreateThumbs(QImage, int)), this, SLOT(slotCreateThumbs(QImage, int)));
403             button_addsequence->setEnabled(false);
404         }
405         capture_button->setEnabled(live_button->isChecked());
406     }
407 }
408
409 void StopmotionWidget::slotCaptureFrame()
410 {
411     if (sequence_name->currentText().isEmpty()) {
412         QString seqName = QInputDialog::getText(this, i18n("Create New Sequence"), i18n("Enter sequence name"));
413         if (seqName.isEmpty()) return;
414         sequence_name->blockSignals(true);
415         sequence_name->setItemText(sequence_name->currentIndex(), seqName);
416         sequence_name->blockSignals(false);
417     }
418     if (m_sequenceName != sequence_name->currentText()) {
419         m_sequenceName = sequence_name->currentText();
420         m_sequenceFrame = 0;
421     }
422     //capture_button->setEnabled(false);
423     QString currentPath = getPathForFrame(m_sequenceFrame);
424     m_bmCapture->captureFrame(currentPath);
425     KNotification::event("FrameCaptured");
426     m_sequenceFrame++;
427     button_addsequence->setEnabled(true);
428     if (m_intervalCapture->isChecked()) QTimer::singleShot(KdenliveSettings::captureinterval() * 1000, this, SLOT(slotCaptureFrame()));
429 }
430
431
432 void StopmotionWidget::slotNewThumb(const QString path)
433 {
434     if (!KdenliveSettings::showstopmotionthumbs()) return;
435     m_filesList.append(path);
436     if (m_showOverlay->isChecked()) slotUpdateOverlay();
437     if (!m_future.isRunning()) m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
438 }
439
440 void StopmotionWidget::slotPrepareThumbs()
441 {
442     if (m_filesList.isEmpty()) return;
443     QString path = m_filesList.takeFirst();
444     emit doCreateThumbs(QImage(path), SlideshowClip::getFrameNumberFromPath(path));
445
446 }
447
448 void StopmotionWidget::slotCreateThumbs(QImage img, int ix)
449 {
450     if (img.isNull()) {
451         m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
452         return;
453     }
454     int height = 90;
455     int width = height * img.width() / img.height();
456     frame_list->setIconSize(QSize(width, height));
457     QPixmap pix = QPixmap::fromImage(img).scaled(width, height);
458     QString nb = QString::number(ix);
459     QPainter p(&pix);
460     QFontInfo finfo(font());
461     p.fillRect(0, 0, finfo.pixelSize() * nb.count() + 6, finfo.pixelSize() + 6, QColor(80, 80, 80, 150));
462     p.setPen(Qt::white);
463     p.drawText(QPoint(3, finfo.pixelSize() + 3), nb);
464     p.end();
465     QIcon icon(pix);
466     QListWidgetItem *item = new QListWidgetItem(icon, QString(), frame_list);
467     item->setToolTip(getPathForFrame(ix, sequence_name->currentText()));
468     item->setData(Qt::UserRole, ix);
469     frame_list->blockSignals(true);
470     frame_list->setCurrentItem(item);
471     frame_list->blockSignals(false);
472     m_future = QtConcurrent::run(this, &StopmotionWidget::slotPrepareThumbs);
473 }
474
475 QString StopmotionWidget::getPathForFrame(int ix, QString seqName)
476 {
477     if (seqName.isEmpty()) seqName = m_sequenceName;
478     return m_projectFolder.path(KUrl::AddTrailingSlash) + seqName + "_" + QString::number(ix).rightJustified(4, '0', false) + ".png";
479 }
480
481 void StopmotionWidget::slotShowFrame(const QString &path)
482 {
483     //slotLive(false);
484     QImage img(path);
485     capture_button->setEnabled(false);
486     if (!img.isNull()) {
487         m_bmCapture->hidePreview(true);
488         m_frame_preview->setImage(img);
489         m_frame_preview->setHidden(false);
490         m_frame_preview->update();
491     }
492 }
493
494 void StopmotionWidget::slotShowSelectedFrame()
495 {
496     QListWidgetItem *item = frame_list->currentItem();
497     if (item) {
498         //int ix = item->data(Qt::UserRole).toInt();;
499         slotShowFrame(item->toolTip());
500     }
501 }
502
503 void StopmotionWidget::slotAddSequence()
504 {
505     emit addOrUpdateSequence(getPathForFrame(0));
506 }
507
508 void StopmotionWidget::slotPlayPreview(bool animate)
509 {
510     if (!animate) {
511         // stop animation
512         m_animationList.clear();
513         return;
514     }
515     if (KdenliveSettings::showstopmotionthumbs()) {
516         frame_list->setCurrentRow(0);
517         QTimer::singleShot(200, this, SLOT(slotAnimate()));
518     } else {
519         SlideshowClip::selectedPath(getPathForFrame(0, sequence_name->currentText()), false, QString(), &m_animationList);
520         slotAnimate();
521     }
522 }
523
524 void StopmotionWidget::slotAnimate()
525 {
526     //slotShowFrame(m_animatedIndex);
527     if (KdenliveSettings::showstopmotionthumbs()) {
528         //TODO: loop
529         if (frame_list->currentRow() < (frame_list->count() - 1)) {
530             frame_list->setCurrentRow(frame_list->currentRow() + 1);
531             QTimer::singleShot(100, this, SLOT(slotAnimate()));
532         } else preview_button->setChecked(false);
533     } else if (!m_animationList.isEmpty()) {
534         slotShowFrame(m_animationList.takeFirst());
535         QTimer::singleShot(100, this, SLOT(slotAnimate()));
536     } else preview_button->setChecked(false);
537
538 }
539
540 QListWidgetItem *StopmotionWidget::getFrameFromIndex(int ix)
541 {
542     QListWidgetItem *item = NULL;
543     int pos = ix;
544     if (ix >= frame_list->count()) {
545         pos = frame_list->count() - 1;
546     }
547     if (ix < 0) pos = 0;
548     item = frame_list->item(pos);
549
550     int value = item->data(Qt::UserRole).toInt();
551     if (value == ix) return item;
552     else if (value < ix) {
553         pos++;
554         while (pos < frame_list->count()) {
555             item = frame_list->item(pos);
556             value = item->data(Qt::UserRole).toInt();
557             if (value == ix) return item;
558             pos++;
559         }
560     } else {
561         pos --;
562         while (pos >= 0) {
563             item = frame_list->item(pos);
564             value = item->data(Qt::UserRole).toInt();
565             if (value == ix) return item;
566             pos --;
567         }
568     }
569     return NULL;
570 }
571
572
573 void StopmotionWidget::selectFrame(int ix)
574 {
575     frame_list->blockSignals(true);
576     QListWidgetItem *item = getFrameFromIndex(ix);
577     if (!item) return;
578     frame_list->setCurrentItem(item);
579     frame_list->blockSignals(false);
580 }
581
582 void StopmotionWidget::slotSeekFrame(bool forward)
583 {
584     int ix = frame_list->currentRow();
585     if (forward) {
586         if (ix < frame_list->count() - 1) frame_list->setCurrentRow(ix + 1);
587     } else if (ix > 0) frame_list->setCurrentRow(ix - 1);
588 }
589
590 void StopmotionWidget::slotRemoveFrame()
591 {
592     if (frame_list->currentItem() == NULL) return;
593     QString path = frame_list->currentItem()->toolTip();
594     if (KMessageBox::questionYesNo(this, i18n("Delete frame %1 from disk?", path), i18n("Delete Frame")) != KMessageBox::Yes) return;
595     QFile f(path);
596     if (f.remove()) {
597         QListWidgetItem *item = frame_list->takeItem(frame_list->currentRow());
598         delete item;
599     }
600 }