slideshowclip.cpp 21.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/***************************************************************************
 *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

20
#include "slideshowclip.h"
21
#include "bin/projectclip.h"
Nicolas Carion's avatar
Nicolas Carion committed
22
#include "kdenlivesettings.h"
23

24
#include <KFileItem>
25
#include <KRecentDirs>
Nicolas Carion's avatar
Nicolas Carion committed
26
#include <klocalizedstring.h>
27

Laurent Montel's avatar
Laurent Montel committed
28
#include "kdenlive_debug.h"
29
#include <QDir>
Nicolas Carion's avatar
Nicolas Carion committed
30
#include <QFontDatabase>
31
#include <QStandardPaths>
32

Nicolas Carion's avatar
Nicolas Carion committed
33
SlideshowClip::SlideshowClip(const Timecode &tc, QString clipFolder, ProjectClip *clip, QWidget *parent)
34 35 36 37
    : QDialog(parent)
    , m_count(0)
    , m_timecode(tc)
    , m_thumbJob(nullptr)
38
{
39
    setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
40
    m_view.setupUi(this);
41
    setWindowTitle(i18n("Add Image Sequence"));
42 43 44
    if (clip) {
        m_view.clip_name->setText(clip->name());
        m_view.groupBox->setHidden(true);
Laurent Montel's avatar
Laurent Montel committed
45
    } else {
46
        m_view.clip_name->setText(i18n("Image Sequence"));
47
    }
48
    m_view.folder_url->setMode(KFile::Directory);
49
    m_view.folder_url->setUrl(QUrl::fromLocalFile(KRecentDirs::dir(QStringLiteral(":KdenliveSlideShowFolder"))));
50
    m_view.icon_list->setIconSize(QSize(50, 50));
51 52
    m_view.show_thumbs->setChecked(KdenliveSettings::showslideshowthumbs());

Laurent Montel's avatar
Laurent Montel committed
53 54 55
    connect(m_view.show_thumbs, &QCheckBox::stateChanged, this, &SlideshowClip::slotEnableThumbs);
    connect(m_view.slide_fade, &QCheckBox::stateChanged, this, &SlideshowClip::slotEnableLuma);
    connect(m_view.luma_fade, &QCheckBox::stateChanged, this, &SlideshowClip::slotEnableLumaFile);
56

Nicolas Carion's avatar
Nicolas Carion committed
57
    // WARNING: keep in sync with project/clipproperties.cpp
Laurent Montel's avatar
Laurent Montel committed
58 59 60 61 62 63 64 65 66 67
    m_view.image_type->addItem(QStringLiteral("JPG (*.jpg)"), QStringLiteral("jpg"));
    m_view.image_type->addItem(QStringLiteral("JPEG (*.jpeg)"), QStringLiteral("jpeg"));
    m_view.image_type->addItem(QStringLiteral("PNG (*.png)"), QStringLiteral("png"));
    m_view.image_type->addItem(QStringLiteral("SVG (*.svg)"), QStringLiteral("svg"));
    m_view.image_type->addItem(QStringLiteral("BMP (*.bmp)"), QStringLiteral("bmp"));
    m_view.image_type->addItem(QStringLiteral("GIF (*.gif)"), QStringLiteral("gif"));
    m_view.image_type->addItem(QStringLiteral("TGA (*.tga)"), QStringLiteral("tga"));
    m_view.image_type->addItem(QStringLiteral("TIF (*.tif)"), QStringLiteral("tif"));
    m_view.image_type->addItem(QStringLiteral("TIFF (*.tiff)"), QStringLiteral("tiff"));
    m_view.image_type->addItem(QStringLiteral("Open EXR (*.exr)"), QStringLiteral("exr"));
68
    m_view.animation->addItem(i18n("None"), QString());
Laurent Montel's avatar
Laurent Montel committed
69 70 71 72 73 74
    m_view.animation->addItem(i18n("Pan"), QStringLiteral("Pan"));
    m_view.animation->addItem(i18n("Pan, low-pass"), QStringLiteral("Pan, low-pass"));
    m_view.animation->addItem(i18n("Pan and zoom"), QStringLiteral("Pan and zoom"));
    m_view.animation->addItem(i18n("Pan and zoom, low-pass"), QStringLiteral("Pan and zoom, low-pass"));
    m_view.animation->addItem(i18n("Zoom"), QStringLiteral("Zoom"));
    m_view.animation->addItem(i18n("Zoom, low-pass"), QStringLiteral("Zoom, low-pass"));
75

76 77
    m_view.clip_duration->setInputMask(m_timecode.mask());
    m_view.luma_duration->setInputMask(m_timecode.mask());
78
    m_view.luma_duration->setText(m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))));
79 80 81 82 83

    if (clipFolder.isEmpty()) {
        clipFolder = QDir::homePath();
    }
    m_view.folder_url->setUrl(QUrl::fromLocalFile(clipFolder));
84

85
    m_view.clip_duration_format->addItem(i18n("hh:mm:ss:ff"));
86 87 88 89
    m_view.clip_duration_format->addItem(i18n("Frames"));
    connect(m_view.clip_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
    m_view.clip_duration_frames->setHidden(true);
    m_view.luma_duration_frames->setHidden(true);
90
    if (clip) {
91 92
        QString url = clip->url();
        if (QFileInfo(url).fileName().startsWith(QLatin1String(".all."))) {
93
            // the image sequence is defined by MIME type
94
            m_view.method_mime->setChecked(true);
95 96
            m_view.folder_url->setText(QFileInfo(url).absolutePath());
            QString filter = QFileInfo(url).fileName();
97
            QString ext = filter.section(QLatin1Char('.'), -1);
98 99 100 101 102 103 104 105 106
            for (int i = 0; i < m_view.image_type->count(); ++i) {
                if (m_view.image_type->itemData(i).toString() == ext) {
                    m_view.image_type->setCurrentIndex(i);
                    break;
                }
            }
        } else {
            // the image sequence is defined by pattern
            m_view.method_pattern->setChecked(true);
107
            m_view.pattern_url->setText(url);
108 109 110 111 112
        }
    } else {
        m_view.method_mime->setChecked(KdenliveSettings::slideshowbymime());
        slotMethodChanged(m_view.method_mime->isChecked());
    }
Laurent Montel's avatar
Laurent Montel committed
113
    connect(m_view.method_mime, &QAbstractButton::toggled, this, &SlideshowClip::slotMethodChanged);
114
    connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
Laurent Montel's avatar
Laurent Montel committed
115 116
    connect(m_view.folder_url, &KUrlRequester::textChanged, this, &SlideshowClip::parseFolder);
    connect(m_view.pattern_url, &KUrlRequester::textChanged, this, &SlideshowClip::parseFolder);
117

118 119
    // Check for Kdenlive installed luma files
    QStringList filters;
120
    filters << QStringLiteral("*.pgm") << QStringLiteral("*.png");
121

122
    const QStringList customLumas = QStandardPaths::locateAll(QStandardPaths::AppDataLocation, QStringLiteral("lumas"), QStandardPaths::LocateDirectory);
123
    for (const QString &folder : customLumas) {
124
        QDir directory(folder);
Laurent Montel's avatar
Laurent Montel committed
125 126
        const QStringList filesnames = directory.entryList(filters, QDir::Files);
        for (const QString &fname : filesnames) {
127
            QString filePath = directory.absoluteFilePath(fname);
128
            m_view.luma_file->addItem(QIcon::fromTheme(filePath), fname, filePath);
129 130 131 132
        }
    }

    // Check for MLT lumas
133
    QString profilePath = KdenliveSettings::mltpath();
134
    QString folder = profilePath.section(QLatin1Char('/'), 0, -3);
Laurent Montel's avatar
Laurent Montel committed
135
    folder.append(QStringLiteral("/lumas/PAL")); // TODO: cleanup the PAL / NTSC mess in luma files
136 137
    QDir lumafolder(folder);
    QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
Nicolas Carion's avatar
Nicolas Carion committed
138
    for (const QString &fname : filesnames) {
139
        QString filePath = lumafolder.absoluteFilePath(fname);
140
        m_view.luma_file->addItem(QIcon::fromTheme(filePath), fname, filePath);
141
    }
142

143
    if (clip) {
Nicolas Carion's avatar
Nicolas Carion committed
144 145 146
        m_view.slide_loop->setChecked(clip->getProducerIntProperty(QStringLiteral("loop")) != 0);
        m_view.slide_crop->setChecked(clip->getProducerIntProperty(QStringLiteral("crop")) != 0);
        m_view.slide_fade->setChecked(clip->getProducerIntProperty(QStringLiteral("fade")) != 0);
147 148
        m_view.luma_softness->setValue(clip->getProducerIntProperty(QStringLiteral("softness")));
        QString anim = clip->getProducerProperty(QStringLiteral("animation"));
Laurent Montel's avatar
Laurent Montel committed
149
        if (!anim.isEmpty()) {
150 151
            int ix = m_view.animation->findData(anim);
            m_view.animation->setCurrentIndex(qMax(0, ix));
Laurent Montel's avatar
Laurent Montel committed
152
        } else {
153
            m_view.animation->setCurrentIndex(0);
Laurent Montel's avatar
Laurent Montel committed
154
        }
155
        int ttl = clip->getProducerIntProperty(QStringLiteral("ttl"));
156 157
        m_view.clip_duration->setText(tc.getTimecodeFromFrames(ttl));
        m_view.clip_duration_frames->setValue(ttl);
158 159
        m_view.luma_duration->setText(tc.getTimecodeFromFrames(clip->getProducerIntProperty(QStringLiteral("luma_duration"))));
        QString lumaFile = clip->getProducerProperty(QStringLiteral("luma_file"));
160 161 162
        if (!lumaFile.isEmpty()) {
            m_view.luma_fade->setChecked(true);
            m_view.luma_file->setCurrentIndex(m_view.luma_file->findData(lumaFile));
Laurent Montel's avatar
Laurent Montel committed
163 164 165
        } else {
            m_view.luma_file->setEnabled(false);
        }
166 167
        slotEnableLuma(m_view.slide_fade->checkState());
        slotEnableLumaFile(m_view.luma_fade->checkState());
168
        parseFolder();
169
    }
Nicolas Carion's avatar
Nicolas Carion committed
170
    // adjustSize();
171 172
}

173 174
SlideshowClip::~SlideshowClip()
{
Laurent Montel's avatar
Laurent Montel committed
175
    delete m_thumbJob;
176 177
}

178 179
void SlideshowClip::slotEnableLuma(int state)
{
180
    bool enable = false;
Laurent Montel's avatar
Laurent Montel committed
181 182 183
    if (state == Qt::Checked) {
        enable = true;
    }
184
    m_view.luma_duration->setEnabled(enable);
185
    m_view.luma_duration_frames->setEnabled(enable);
186
    m_view.luma_fade->setEnabled(enable);
187 188
    if (enable) {
        m_view.luma_file->setEnabled(m_view.luma_fade->isChecked());
Laurent Montel's avatar
Laurent Montel committed
189 190 191
    } else {
        m_view.luma_file->setEnabled(false);
    }
192 193
    m_view.label_softness->setEnabled(m_view.luma_fade->isChecked() && enable);
    m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
194 195
}

196 197 198 199 200 201 202
void SlideshowClip::slotEnableThumbs(int state)
{
    if (state == Qt::Checked) {
        KdenliveSettings::setShowslideshowthumbs(true);
        slotGenerateThumbs();
    } else {
        KdenliveSettings::setShowslideshowthumbs(false);
203
        if (m_thumbJob) {
Laurent Montel's avatar
Laurent Montel committed
204
            disconnect(m_thumbJob, &KIO::PreviewJob::gotPreview, this, &SlideshowClip::slotSetPixmap);
205
            m_thumbJob->kill();
David Faure's avatar
David Faure committed
206
            m_thumbJob->deleteLater();
Laurent Montel's avatar
Laurent Montel committed
207
            m_thumbJob = nullptr;
208
        }
209 210 211
    }
}

212 213
void SlideshowClip::slotEnableLumaFile(int state)
{
214
    bool enable = false;
Laurent Montel's avatar
Laurent Montel committed
215 216 217
    if (state == Qt::Checked) {
        enable = true;
    }
218
    m_view.luma_file->setEnabled(enable);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
219 220
    m_view.luma_softness->setEnabled(enable);
    m_view.label_softness->setEnabled(enable);
221 222
}

223 224
void SlideshowClip::parseFolder()
{
225
    m_view.icon_list->clear();
226
    bool isMime = m_view.method_mime->isChecked();
227
    QString path = isMime ? m_view.folder_url->url().toLocalFile() : m_view.pattern_url->url().adjusted(QUrl::RemoveFilename).toLocalFile();
228
    QDir dir(path);
229
    if (path.isEmpty() || !dir.exists()) {
Laurent Montel's avatar
Laurent Montel committed
230 231 232 233
        m_count = 0;
        m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
        m_view.label_info->setText(QString());
        return;
234
    }
235

236
    QIcon unknownicon(QStringLiteral("unknown"));
237
    QStringList result;
238
    QStringList filters;
239 240 241 242
    QString filter;
    if (isMime) {
        // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
        filter = m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
Laurent Montel's avatar
Laurent Montel committed
243
        filters << QStringLiteral("*.") + filter;
244
        dir.setNameFilters(filters);
245 246
        result = dir.entryList(QDir::Files);
    } else {
247
        int offset = 0;
248 249 250
        QString path_pattern = m_view.pattern_url->text();
        QDir abs_dir = QFileInfo(m_view.pattern_url->text()).absoluteDir();
        result = abs_dir.entryList(QDir::Files);
251
        // find pattern
252
        if (path_pattern.contains(QLatin1Char('?'))) {
253
            // New MLT syntax
Nicolas Carion's avatar
Nicolas Carion committed
254
            if (path_pattern.section(QLatin1Char('?'), 1).contains(QLatin1Char(':'))) {
255
                // Old deprecated format
256
                offset = path_pattern.section(QLatin1Char(':'), -1).toInt();
257
            } else {
258
                offset = path_pattern.section(QLatin1Char('='), -1).toInt();
259
            }
260
            path_pattern = path_pattern.section(QLatin1Char('?'), 0, 0);
261
        }
262
        filter = QFileInfo(path_pattern).fileName();
263
        QString ext = filter.section(QLatin1Char('.'), -1);
Laurent Montel's avatar
Laurent Montel committed
264
        if (filter.contains(QLatin1Char('%'))) {
Laurent Montel's avatar
Laurent Montel committed
265
            filter = filter.section(QLatin1Char('%'), 0, -2);
266
        } else {
267
            filter = filter.section(QLatin1Char('.'), 0, -2);
268 269 270 271
            while (!filter.isEmpty() && filter.at(filter.count() - 1).isDigit()) {
                filter.remove(filter.count() - 1, 1);
            }
        }
272
        // qCDebug(KDENLIVE_LOG) << " / /" << path_pattern << " / " << ext << " / " << filter;
Laurent Montel's avatar
Laurent Montel committed
273
        QString regexp = QLatin1Char('^') + filter + QStringLiteral("\\d+\\.") + ext + QLatin1Char('$');
274 275 276
        QRegExp rx(regexp);
        QStringList entries;
        int ix;
Nicolas Carion's avatar
Nicolas Carion committed
277
        for (const QString &p : result) {
278
            if (rx.exactMatch(p)) {
279 280
                if (offset > 0) {
                    // make sure our image is in the range we want (> begin)
281 282
                    ix = p.section(filter, 1).section(QLatin1Char('.'), 0, 0).toInt();
                    ix = p.section(filter, 1).section('.', 0, 0).toInt();
Laurent Montel's avatar
Laurent Montel committed
283 284 285
                    if (ix < offset) {
                        continue;
                    }
286
                }
287
                entries << p;
288
            }
289
        }
290
        result = entries;
291
    }
Nicolas Carion's avatar
Nicolas Carion committed
292
    for (const QString &p : result) {
Nicolas Carion's avatar
Nicolas Carion committed
293
        auto *item = new QListWidgetItem(unknownicon, p);
294
        item->setData(Qt::UserRole, dir.filePath(p));
295
        m_view.icon_list->addItem(item);
296
    }
297 298
    m_count = m_view.icon_list->count();
    m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_count > 0);
299 300 301 302 303
    if (m_count == 0) {
        m_view.label_info->setText(i18n("No image found"));
    } else {
        m_view.label_info->setText(i18np("1 image found", "%1 images found", m_count));
    }
Laurent Montel's avatar
Laurent Montel committed
304 305 306
    if (m_view.show_thumbs->isChecked()) {
        slotGenerateThumbs();
    }
307 308 309
    m_view.icon_list->setCurrentRow(0);
}

310 311
void SlideshowClip::slotGenerateThumbs()
{
312
    delete m_thumbJob;
313
    KFileItemList fileList;
314
    for (int i = 0; i < m_view.icon_list->count(); ++i) {
Laurent Montel's avatar
Laurent Montel committed
315
        QListWidgetItem *item = m_view.icon_list->item(i);
316 317 318
        if (item) {
            QString path = item->data(Qt::UserRole).toString();
            if (!path.isEmpty()) {
319
                KFileItem f(QUrl::fromLocalFile(path));
320 321
                f.setDelayedMimeTypes(true);
                fileList.append(f);
322 323
            }
        }
324
    }
325 326
    m_thumbJob = new KIO::PreviewJob(fileList, QSize(50, 50));
    m_thumbJob->setScaleType(KIO::PreviewJob::Scaled);
327
    m_thumbJob->setAutoDelete(false);
Laurent Montel's avatar
Laurent Montel committed
328
    connect(m_thumbJob, &KIO::PreviewJob::gotPreview, this, &SlideshowClip::slotSetPixmap);
329
    m_thumbJob->start();
330 331
}

332
void SlideshowClip::slotSetPixmap(const KFileItem &fileItem, const QPixmap &pix)
333
{
334
    for (int i = 0; i < m_view.icon_list->count(); ++i) {
Laurent Montel's avatar
Laurent Montel committed
335
        QListWidgetItem *item = m_view.icon_list->item(i);
336
        if (item) {
337
            QString path = item->data(Qt::UserRole).toString();
338
            if (path == fileItem.url().toLocalFile()) {
339
                item->setIcon(QIcon(pix));
340 341 342
                item->setData(Qt::UserRole, QString());
                break;
            }
343 344
        }
    }
345 346
}

347
QString SlideshowClip::selectedPath()
348
{
349
    QStringList list;
350
    QUrl url;
Laurent Montel's avatar
Laurent Montel committed
351 352 353 354 355
    if (m_view.method_mime->isChecked()) {
        url = m_view.folder_url->url();
    } else {
        url = m_view.pattern_url->url();
    }
Nicolas Carion's avatar
Nicolas Carion committed
356 357
    QString path = selectedPath(url, m_view.method_mime->isChecked(),
                                QStringLiteral(".all.") + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString(), &list);
358
    m_count = list.count();
Nicolas Carion's avatar
Nicolas Carion committed
359
    // qCDebug(KDENLIVE_LOG)<<"// SELECTED PATH: "<<path;
360
    return path;
361
}
362

363
// static
364
int SlideshowClip::getFrameNumberFromPath(const QUrl &path)
365
{
366
    QString filter = path.fileName();
367
    filter = filter.section(QLatin1Char('.'), 0, -2);
368
    int ix = filter.size() - 1;
369
    while (ix >= 0 && filter.at(ix).isDigit()) {
370 371 372 373
        ix--;
    }
    return filter.remove(0, ix + 1).toInt();
}
374

375
// static
376
QString SlideshowClip::selectedPath(const QUrl &url, bool isMime, QString extension, QStringList *list)
377 378
{
    QString folder;
379
    if (isMime) {
380
        folder = url.toLocalFile();
Vincent Pinon's avatar
Vincent Pinon committed
381 382
        if (!folder.endsWith(QLatin1Char('/'))) {
            folder.append(QLatin1Char('/'));
383
        }
Laurent Montel's avatar
Laurent Montel committed
384
        // Check how many files we have
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
385
        QDir dir(folder);
Laurent Montel's avatar
Laurent Montel committed
386
        QStringList filters;
Laurent Montel's avatar
Laurent Montel committed
387
        filters << QStringLiteral("*.") + extension.section(QLatin1Char('.'), -1);
Laurent Montel's avatar
Laurent Montel committed
388 389
        dir.setNameFilters(filters);
        *list = dir.entryList(QDir::Files);
390
    } else {
391
        folder = url.adjusted(QUrl::RemoveFilename).toLocalFile();
392
        QString filter = url.fileName();
Laurent Montel's avatar
Laurent Montel committed
393
        QString ext = QLatin1Char('.') + filter.section(QLatin1Char('.'), -1);
394
        filter = filter.section(QLatin1Char('.'), 0, -2);
395
        int fullSize = filter.size();
Laurent Montel's avatar
Laurent Montel committed
396
        QString firstFrameData = filter;
397

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
398
        while (filter.size() > 0 && filter.at(filter.size() - 1).isDigit()) {
399
            filter.chop(1);
400
        }
401

402 403
        // Find number of digits in sequence
        int precision = fullSize - filter.size();
Laurent Montel's avatar
Laurent Montel committed
404
        int firstFrame = firstFrameData.rightRef(precision).toInt();
405

406
        // Check how many files we have
407
        QDir dir(folder);
408 409
        QString path;
        int gap = 0;
410
        for (int i = firstFrame; gap < 100; ++i) {
Laurent Montel's avatar
Laurent Montel committed
411
            path = filter + QString::number(i).rightJustified(precision, QLatin1Char('0'), false) + ext;
412 413 414 415 416
            if (dir.exists(path)) {
                (*list).append(folder + path);
                gap = 0;
            } else {
                gap++;
417 418
            }
        }
Laurent Montel's avatar
Laurent Montel committed
419
        extension = filter + QStringLiteral("%0") + QString::number(precision) + QLatin1Char('d') + ext;
Laurent Montel's avatar
Laurent Montel committed
420
        if (firstFrame > 0) {
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
421
            extension.append(QStringLiteral("?begin=%1").arg(firstFrame));
Laurent Montel's avatar
Laurent Montel committed
422
        }
423
    }
Nicolas Carion's avatar
Nicolas Carion committed
424 425
    // qCDebug(KDENLIVE_LOG) << "// FOUND " << (*list).count() << " items for " << url.toLocalFile();
    return folder + extension;
426 427
}

428 429
QString SlideshowClip::clipName() const
{
430 431 432
    return m_view.clip_name->text();
}

433 434
QString SlideshowClip::clipDuration() const
{
435 436 437 438
    if (m_view.clip_duration_format->currentIndex() == 1) {
        // we are in frames mode
        return m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value());
    }
439 440 441
    return m_view.clip_duration->text();
}

442 443
int SlideshowClip::imageCount() const
{
444 445 446
    return m_count;
}

447 448
int SlideshowClip::softness() const
{
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
449 450 451
    return m_view.luma_softness->value();
}

452 453
bool SlideshowClip::loop() const
{
454 455
    return m_view.slide_loop->isChecked();
}
456

457 458 459 460 461
bool SlideshowClip::crop() const
{
    return m_view.slide_crop->isChecked();
}

462 463
bool SlideshowClip::fade() const
{
464 465 466
    return m_view.slide_fade->isChecked();
}

467 468
QString SlideshowClip::lumaDuration() const
{
469 470 471 472
    if (m_view.clip_duration_format->currentIndex() == 1) {
        // we are in frames mode
        return m_timecode.getTimecodeFromFrames(m_view.luma_duration_frames->value());
    }
473 474 475
    return m_view.luma_duration->text();
}

476 477
QString SlideshowClip::lumaFile() const
{
Laurent Montel's avatar
Laurent Montel committed
478 479 480
    if (!m_view.luma_fade->isChecked() || !m_view.luma_file->isEnabled()) {
        return QString();
    }
481 482 483
    return m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
}

484 485
QString SlideshowClip::animation() const
{
Laurent Montel's avatar
Laurent Montel committed
486 487 488
    if (m_view.animation->itemData(m_view.animation->currentIndex()).isNull()) {
        return QString();
    }
489 490 491
    return m_view.animation->itemData(m_view.animation->currentIndex()).toString();
}

492 493 494 495 496
void SlideshowClip::slotUpdateDurationFormat(int ix)
{
    bool framesFormat = ix == 1;
    if (framesFormat) {
        // switching to frames count, update widget
497 498
        m_view.clip_duration_frames->setValue(m_timecode.getFrameCount(m_view.clip_duration->text()));
        m_view.luma_duration_frames->setValue(m_timecode.getFrameCount(m_view.luma_duration->text()));
499 500 501 502 503 504 505 506 507 508 509
    } else {
        // switching to timecode format
        m_view.clip_duration->setText(m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value()));
        m_view.luma_duration->setText(m_timecode.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
    }
    m_view.clip_duration_frames->setHidden(!framesFormat);
    m_view.clip_duration->setHidden(framesFormat);
    m_view.luma_duration_frames->setHidden(!framesFormat);
    m_view.luma_duration->setHidden(framesFormat);
}

510 511 512
void SlideshowClip::slotMethodChanged(bool active)
{
    if (active) {
513
        // User wants MIME type image sequence
514
        m_view.clip_duration->setText(m_timecode.reformatSeparators(KdenliveSettings::image_duration()));
515 516 517 518
        m_view.stackedWidget->setCurrentIndex(0);
        KdenliveSettings::setSlideshowbymime(true);
    } else {
        // User wants pattern image sequence
519
        m_view.clip_duration->setText(m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()));
520 521 522 523 524 525
        m_view.stackedWidget->setCurrentIndex(1);
        KdenliveSettings::setSlideshowbymime(false);
    }
    parseFolder();
}

526 527 528 529
// static
QString SlideshowClip::animationToGeometry(const QString &animation, int &ttl)
{
    QString geometry;
530
    if (animation.startsWith(QLatin1String("Pan and zoom"))) {
531
        geometry = QString::asprintf(
Nicolas Carion's avatar
Nicolas Carion committed
532 533
            "0=0/0:100%%x100%%;%d=-14%%/-14%%:120%%x120%%;%d=-5%%/-5%%:110%%x110%%;%d=0/0:110%%x110%%;%d=0/-5%%:110%%x110%%;%d=-5%%/0:110%%x110%%", ttl - 1,
            ttl, ttl * 2 - 1, ttl * 2, ttl * 3 - 1);
534
        ttl *= 3;
535
    } else if (animation.startsWith(QLatin1String("Pan"))) {
536
        geometry = QString::asprintf("0=-5%%/-5%%:110%%x110%%;%d=0/0:110%%x110%%;%d=0/0:110%%x110%%;%d=0/-5%%:110%%x110%%;%d=0/-5%%:110%%x110%%;%d=-5%%/"
Nicolas Carion's avatar
Nicolas Carion committed
537
                                     "-5%%:110%%x110%%;%d=0/-5%%:110%%x110%%;%d=-5%%/0:110%%x110%%",
538
                                     ttl - 1, ttl, ttl * 2 - 1, ttl * 2, ttl * 3 - 1, ttl * 3, ttl * 4 - 1);
539
        ttl *= 4;
540
    } else if (animation.startsWith(QLatin1String("Zoom"))) {
541
        geometry = QString::asprintf("0=0/0:100%%x100%%;%d=-14%%/-14%%:120%%x120%%", ttl - 1);
542 543 544
    }
    return geometry;
}