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>
29 SlideshowClip::SlideshowClip(Timecode tc, QWidget * parent) :
34 setFont(KGlobalSettings::toolBarFont());
35 setWindowTitle(i18n("Add Slideshow Clip"));
37 m_view.clip_name->setText(i18n("Slideshow Clip"));
38 m_view.folder_url->setMode(KFile::Directory);
39 m_view.icon_list->setIconSize(QSize(50, 50));
40 connect(m_view.folder_url, SIGNAL(textChanged(const QString &)), this, SLOT(parseFolder()));
41 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
43 connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
44 connect(m_view.luma_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
46 //WARNING: keep in sync with clipproperties.cpp
47 m_view.image_type->addItem("JPG (*.jpg)", "jpg");
48 m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
49 m_view.image_type->addItem("PNG (*.png)", "png");
50 m_view.image_type->addItem("BMP (*.bmp)", "bmp");
51 m_view.image_type->addItem("GIF (*.gif)", "gif");
52 m_view.image_type->addItem("TGA (*.tga)", "tga");
53 m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
54 m_view.image_type->addItem("Open EXR (*.exr)", "exr");
55 m_view.clip_duration->setText(KdenliveSettings::image_duration());
56 m_view.luma_duration->setText("00:00:00:24");
57 m_view.folder_url->setUrl(QDir::homePath());
59 m_view.clip_duration_format->addItem(i18n("hh:mm:ss::ff"));
60 m_view.clip_duration_format->addItem(i18n("Frames"));
61 connect(m_view.clip_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
62 m_view.clip_duration_frames->setHidden(true);
63 m_view.luma_duration_frames->setHidden(true);
65 // Check for Kdenlive installed luma files
67 filters << "*.pgm" << "*.png";
69 QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
70 foreach(const QString &folder, customLumas) {
71 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
72 foreach(const QString &fname, filesnames) {
73 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
74 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
78 // Check for MLT lumas
79 QString profilePath = KdenliveSettings::mltpath();
80 QString folder = profilePath.section('/', 0, -3);
81 folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
82 QDir lumafolder(folder);
83 QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
84 foreach(const QString &fname, filesnames) {
85 QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
86 m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
92 void SlideshowClip::slotEnableLuma(int state)
95 if (state == Qt::Checked) enable = true;
96 m_view.luma_duration->setEnabled(enable);
97 m_view.luma_duration_frames->setEnabled(enable);
98 m_view.luma_fade->setEnabled(enable);
100 m_view.luma_file->setEnabled(m_view.luma_fade->isChecked());
101 } else m_view.luma_file->setEnabled(false);
102 m_view.label_softness->setEnabled(m_view.luma_fade->isChecked() && enable);
103 m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
106 void SlideshowClip::slotEnableLumaFile(int state)
109 if (state == Qt::Checked) enable = true;
110 m_view.luma_file->setEnabled(enable);
111 m_view.luma_softness->setEnabled(enable);
112 m_view.label_softness->setEnabled(enable);
115 void SlideshowClip::parseFolder()
117 m_view.icon_list->clear();
118 QDir dir(m_view.folder_url->url().path());
121 QString filter = m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
122 filters << "*." + filter;
123 // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
126 dir.setNameFilters(filters);
127 const QStringList result = dir.entryList(QDir::Files);
128 m_count = result.count();
129 if (m_count == 0) m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
130 else m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
131 m_view.label_info->setText(i18np("1 image found", "%1 images found", m_count));
132 QListWidgetItem *item;
134 KIcon unknownicon("unknown");
135 foreach(const QString &path, result) {
138 QIcon icon(dir.filePath(path));
139 item = new QListWidgetItem(icon, KUrl(path).fileName());
141 item = new QListWidgetItem(unknownicon, KUrl(path).fileName());
142 item->setData(Qt::UserRole, dir.filePath(path));
144 m_view.icon_list->addItem(item);
146 if (m_count >= 80) connect(m_view.icon_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotSetItemIcon(int)));
147 m_view.icon_list->setCurrentRow(0);
150 void SlideshowClip::slotSetItemIcon(int row)
152 QListWidgetItem * item = m_view.icon_list->item(row);
154 QString path = item->data(Qt::UserRole).toString();
155 if (!path.isEmpty()) {
158 item->setData(Qt::UserRole, QString());
163 QString SlideshowClip::selectedPath() const
165 QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
166 return m_view.folder_url->url().path() + extension;
170 QString SlideshowClip::clipName() const
172 return m_view.clip_name->text();
175 QString SlideshowClip::clipDuration() const
177 if (m_view.clip_duration_format->currentIndex() == 1) {
178 // we are in frames mode
179 return m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value());
181 return m_view.clip_duration->text();
184 int SlideshowClip::imageCount() const
189 int SlideshowClip::softness() const
191 return m_view.luma_softness->value();
194 bool SlideshowClip::loop() const
196 return m_view.slide_loop->isChecked();
199 bool SlideshowClip::fade() const
201 return m_view.slide_fade->isChecked();
204 QString SlideshowClip::lumaDuration() const
206 if (m_view.clip_duration_format->currentIndex() == 1) {
207 // we are in frames mode
208 return m_timecode.getTimecodeFromFrames(m_view.luma_duration_frames->value());
210 return m_view.luma_duration->text();
213 QString SlideshowClip::lumaFile() const
215 if (!m_view.luma_fade->isChecked() || !m_view.luma_file->isEnabled()) return QString();
216 return m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
219 void SlideshowClip::slotUpdateDurationFormat(int ix)
221 bool framesFormat = ix == 1;
223 // switching to frames count, update widget
224 m_view.clip_duration_frames->setValue(m_timecode.getFrameCount(m_view.clip_duration->text()));
225 m_view.luma_duration_frames->setValue(m_timecode.getFrameCount(m_view.luma_duration->text()));
227 // switching to timecode format
228 m_view.clip_duration->setText(m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value()));
229 m_view.luma_duration->setText(m_timecode.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
231 m_view.clip_duration_frames->setHidden(!framesFormat);
232 m_view.clip_duration->setHidden(framesFormat);
233 m_view.luma_duration_frames->setHidden(!framesFormat);
234 m_view.luma_duration->setHidden(framesFormat);
237 #include "slideshowclip.moc"