1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "slideshowclip.h"
21 #include "kdenlivesettings.h"
23 #include <KStandardDirs>
30 SlideshowClip::SlideshowClip(Timecode tc, QWidget * parent) :
36 setFont(KGlobalSettings::toolBarFont());
37 setWindowTitle(i18n("Add Slideshow Clip"));
39 m_view.clip_name->setText(i18n("Slideshow Clip"));
40 m_view.folder_url->setMode(KFile::Directory);
41 m_view.icon_list->setIconSize(QSize(50, 50));
42 m_view.show_thumbs->setChecked(KdenliveSettings::showslideshowthumbs());
44 connect(m_view.folder_url, SIGNAL(textChanged(const QString &)), this, SLOT(parseFolder()));
45 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
46 connect(m_view.pattern_url, SIGNAL(textChanged(const QString &)), this, SLOT(parseFolder()));
48 connect(m_view.show_thumbs, SIGNAL(stateChanged(int)), this, SLOT(slotEnableThumbs(int)));
49 connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
50 connect(m_view.luma_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
52 //WARNING: keep in sync with clipproperties.cpp
53 m_view.image_type->addItem("JPG (*.jpg)", "jpg");
54 m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
55 m_view.image_type->addItem("PNG (*.png)", "png");
56 m_view.image_type->addItem("BMP (*.bmp)", "bmp");
57 m_view.image_type->addItem("GIF (*.gif)", "gif");
58 m_view.image_type->addItem("TGA (*.tga)", "tga");
59 m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
60 m_view.image_type->addItem("Open EXR (*.exr)", "exr");
62 m_view.clip_duration->setInputMask("");
63 m_view.clip_duration->setValidator(m_timecode.validator());
64 m_view.clip_duration->setText(m_timecode.reformatSeparators(KdenliveSettings::image_duration()));
65 m_view.luma_duration->setInputMask("");
66 m_view.luma_duration->setValidator(m_timecode.validator());
67 m_view.luma_duration->setText(m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))));
68 m_view.folder_url->setUrl(QDir::homePath());
70 m_view.clip_duration_format->addItem(i18n("hh:mm:ss::ff"));
71 m_view.clip_duration_format->addItem(i18n("Frames"));
72 connect(m_view.clip_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
73 m_view.clip_duration_frames->setHidden(true);
74 m_view.luma_duration_frames->setHidden(true);
75 m_view.method_mime->setChecked(KdenliveSettings::slideshowbymime());
76 connect(m_view.method_mime, SIGNAL(toggled(bool)), this, SLOT(slotMethodChanged(bool)));
77 slotMethodChanged(m_view.method_mime->isChecked());
79 // Check for Kdenlive installed luma files
81 filters << "*.pgm" << "*.png";
83 QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
84 foreach(const QString &folder, customLumas) {
85 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
86 foreach(const QString &fname, filesnames) {
87 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
88 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
92 // Check for MLT lumas
93 QString profilePath = KdenliveSettings::mltpath();
94 QString folder = profilePath.section('/', 0, -3);
95 folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
96 QDir lumafolder(folder);
97 QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
98 foreach(const QString &fname, filesnames) {
99 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
100 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
106 SlideshowClip::~SlideshowClip()
113 void SlideshowClip::slotEnableLuma(int state)
116 if (state == Qt::Checked) enable = true;
117 m_view.luma_duration->setEnabled(enable);
118 m_view.luma_duration_frames->setEnabled(enable);
119 m_view.luma_fade->setEnabled(enable);
121 m_view.luma_file->setEnabled(m_view.luma_fade->isChecked());
122 } else m_view.luma_file->setEnabled(false);
123 m_view.label_softness->setEnabled(m_view.luma_fade->isChecked() && enable);
124 m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
127 void SlideshowClip::slotEnableThumbs(int state)
129 if (state == Qt::Checked) {
130 KdenliveSettings::setShowslideshowthumbs(true);
131 slotGenerateThumbs();
133 KdenliveSettings::setShowslideshowthumbs(false);
135 disconnect(m_thumbJob, SIGNAL(gotPreview(const KFileItem &, const QPixmap &)), this, SLOT(slotSetPixmap(const KFileItem &, const QPixmap &)));
143 void SlideshowClip::slotEnableLumaFile(int state)
146 if (state == Qt::Checked) enable = true;
147 m_view.luma_file->setEnabled(enable);
148 m_view.luma_softness->setEnabled(enable);
149 m_view.label_softness->setEnabled(enable);
152 void SlideshowClip::parseFolder()
154 m_view.icon_list->clear();
155 bool isMime = m_view.method_mime->isChecked();
156 QString path = isMime ? m_view.folder_url->url().path() : m_view.pattern_url->url().directory();
158 if (path.isEmpty() || !dir.exists()) return;
163 // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
164 filter = m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
165 filters << "*." + filter;
166 dir.setNameFilters(filters);
169 QStringList result = dir.entryList(QDir::Files);
173 filter = m_view.pattern_url->url().fileName();
174 QString ext = filter.section('.', -1);
175 filter = filter.section('.', 0, -2);
177 while (filter.at(filter.size() - 1).isDigit()) {
178 filter.remove(filter.size() - 1, 1);
180 QString regexp = "^" + filter + "\\d+\\." + ext + "$";
183 foreach(const QString &path, result) {
184 if (rx.exactMatch(path)) entries << path;
189 m_count = result.count();
190 if (m_count == 0) m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
191 else m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
192 m_view.label_info->setText(i18np("1 image found", "%1 images found", m_count));
193 QListWidgetItem *item;
195 KIcon unknownicon("unknown");
196 foreach(const QString &path, result) {
198 item = new QListWidgetItem(unknownicon, KUrl(path).fileName());
199 item->setData(Qt::UserRole, dir.filePath(path));
200 m_view.icon_list->addItem(item);
202 if (m_view.show_thumbs->isChecked()) slotGenerateThumbs();
203 m_view.icon_list->setCurrentRow(0);
206 void SlideshowClip::slotGenerateThumbs()
211 KFileItemList fileList;
212 for (int i = 0; i < m_view.icon_list->count(); i++) {
213 QListWidgetItem* item = m_view.icon_list->item(i);
215 QString path = item->data(Qt::UserRole).toString();
216 if (!path.isEmpty()) {
217 fileList.append(KFileItem(KFileItem::Unknown, KFileItem::Unknown, KUrl(path)));
221 m_thumbJob = new KIO::PreviewJob(fileList, 50, 0, 0, 0, true, true, 0);
222 m_thumbJob->setAutoDelete(false);
223 connect(m_thumbJob, SIGNAL(gotPreview(const KFileItem &, const QPixmap &)), this, SLOT(slotSetPixmap(const KFileItem &, const QPixmap &)));
227 void SlideshowClip::slotSetPixmap(const KFileItem &fileItem, const QPixmap &pix)
229 for (int i = 0; i < m_view.icon_list->count(); i++) {
230 QListWidgetItem* item = m_view.icon_list->item(i);
232 QString path = item->data(Qt::UserRole).toString();
233 if (path == fileItem.url().path()) {
234 item->setIcon(KIcon(pix));
235 item->setData(Qt::UserRole, QString());
243 QString SlideshowClip::selectedPath() const
248 bool isMime = m_view.method_mime->isChecked();
251 folder = m_view.folder_url->url().path(KUrl::AddTrailingSlash);
252 extension = ".all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
254 folder = m_view.pattern_url->url().directory(KUrl::AppendTrailingSlash);
255 QString filter = m_view.pattern_url->url().fileName();
256 QString ext = filter.section('.', -1);
257 filter = filter.section('.', 0, -2);
259 while (filter.at(filter.size() - 1).isDigit()) {
260 filter.remove(filter.size() - 1, 1);
262 extension = filter + "%d." + ext;
264 return folder + extension;
268 QString SlideshowClip::clipName() const
270 return m_view.clip_name->text();
273 QString SlideshowClip::clipDuration() const
275 if (m_view.clip_duration_format->currentIndex() == 1) {
276 // we are in frames mode
277 return m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value());
279 return m_view.clip_duration->text();
282 int SlideshowClip::imageCount() const
287 int SlideshowClip::softness() const
289 return m_view.luma_softness->value();
292 bool SlideshowClip::loop() const
294 return m_view.slide_loop->isChecked();
297 bool SlideshowClip::fade() const
299 return m_view.slide_fade->isChecked();
302 QString SlideshowClip::lumaDuration() const
304 if (m_view.clip_duration_format->currentIndex() == 1) {
305 // we are in frames mode
306 return m_timecode.getTimecodeFromFrames(m_view.luma_duration_frames->value());
308 return m_view.luma_duration->text();
311 QString SlideshowClip::lumaFile() const
313 if (!m_view.luma_fade->isChecked() || !m_view.luma_file->isEnabled()) return QString();
314 return m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
317 void SlideshowClip::slotUpdateDurationFormat(int ix)
319 bool framesFormat = ix == 1;
321 // switching to frames count, update widget
322 m_view.clip_duration_frames->setValue(m_timecode.getFrameCount(m_view.clip_duration->text()));
323 m_view.luma_duration_frames->setValue(m_timecode.getFrameCount(m_view.luma_duration->text()));
325 // switching to timecode format
326 m_view.clip_duration->setInputMask("");
327 m_view.clip_duration->setValidator(m_timecode.validator());
328 m_view.clip_duration->setText(m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value()));
329 m_view.luma_duration->setInputMask("");
330 m_view.luma_duration->setValidator(m_timecode.validator());
331 m_view.luma_duration->setText(m_timecode.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
333 m_view.clip_duration_frames->setHidden(!framesFormat);
334 m_view.clip_duration->setHidden(framesFormat);
335 m_view.luma_duration_frames->setHidden(!framesFormat);
336 m_view.luma_duration->setHidden(framesFormat);
339 void SlideshowClip::slotMethodChanged(bool active)
342 // User wants mimetype image sequence
343 m_view.stackedWidget->setCurrentIndex(0);
344 KdenliveSettings::setSlideshowbymime(true);
346 // User wants pattern image sequence
347 m_view.stackedWidget->setCurrentIndex(1);
348 KdenliveSettings::setSlideshowbymime(false);
355 #include "slideshowclip.moc"