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(QWidget * parent) :
33 setFont(KGlobalSettings::toolBarFont());
34 setWindowTitle(i18n("Add Slideshow Clip"));
36 m_view.clip_name->setText(i18n("Slideshow Clip"));
37 m_view.folder_url->setMode(KFile::Directory);
38 m_view.icon_list->setIconSize(QSize(50, 50));
39 connect(m_view.folder_url, SIGNAL(textChanged(const QString &)), this, SLOT(parseFolder()));
40 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
42 connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
43 connect(m_view.luma_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
45 m_view.image_type->addItem("JPG (*.jpg)", "jpg");
46 m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
47 m_view.image_type->addItem("PNG (*.png)", "png");
48 m_view.image_type->addItem("BMP (*.bmp)", "bmp");
49 m_view.image_type->addItem("GIF (*.gif)", "gif");
50 m_view.image_type->addItem("TGA (*.tga)", "tga");
51 m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
52 m_view.image_type->addItem("Open EXR (*.exr)", "exr");
53 m_view.clip_duration->setText(KdenliveSettings::image_duration());
54 m_view.luma_duration->setText("00:00:00:24");
55 m_view.folder_url->setUrl(QDir::homePath());
58 // Check for Kdenlive installed luma files
60 filters << "*.pgm" << "*.png";
62 QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
63 foreach(const QString &folder, customLumas) {
64 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
65 foreach(const QString &fname, filesnames) {
66 m_view.luma_file->addItem(KIcon(folder + '/' + fname), fname, folder + '/' + fname);
70 // Check for MLT lumas
71 QString profilePath = KdenliveSettings::mltpath();
72 QString folder = profilePath.section('/', 0, -3);
73 folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
74 QDir lumafolder(folder);
75 QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
76 foreach(const QString &fname, filesnames) {
77 m_view.luma_file->addItem(KIcon(folder + '/' + fname), fname, folder + '/' + fname);
83 void SlideshowClip::slotEnableLuma(int state)
86 if (state == Qt::Checked) enable = true;
87 m_view.luma_duration->setEnabled(enable);
88 m_view.luma_fade->setEnabled(enable);
90 m_view.luma_file->setEnabled(m_view.luma_fade->isChecked());
91 } else m_view.luma_file->setEnabled(false);
92 m_view.label_softness->setEnabled(m_view.luma_fade->isChecked() && enable);
93 m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
96 void SlideshowClip::slotEnableLumaFile(int state)
99 if (state == Qt::Checked) enable = true;
100 m_view.luma_file->setEnabled(enable);
101 m_view.luma_softness->setEnabled(enable);
102 m_view.label_softness->setEnabled(enable);
105 void SlideshowClip::parseFolder()
107 m_view.icon_list->clear();
108 QDir dir(m_view.folder_url->url().path());
111 QString filter = m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
112 filters << "*." + filter;
113 // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
116 dir.setNameFilters(filters);
117 const QStringList result = dir.entryList(QDir::Files);
118 m_count = result.count();
119 if (m_count == 0) m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
120 else m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
121 m_view.label_info->setText(i18n("%1 images found", m_count));
122 QListWidgetItem *item;
124 KIcon unknownicon("unknown");
125 foreach(const QString &path, result) {
128 QIcon icon(dir.filePath(path));
129 item = new QListWidgetItem(icon, KUrl(path).fileName());
131 item = new QListWidgetItem(unknownicon, KUrl(path).fileName());
132 item->setData(Qt::UserRole, dir.filePath(path));
134 m_view.icon_list->addItem(item);
136 if (m_count >= 80) connect(m_view.icon_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotSetItemIcon(int)));
137 m_view.icon_list->setCurrentRow(0);
140 void SlideshowClip::slotSetItemIcon(int row)
142 QListWidgetItem * item = m_view.icon_list->item(row);
144 QString path = item->data(Qt::UserRole).toString();
145 if (!path.isEmpty()) {
148 item->setData(Qt::UserRole, QString());
153 QString SlideshowClip::selectedPath() const
155 QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
156 return m_view.folder_url->url().path() + extension;
160 QString SlideshowClip::clipName() const
162 return m_view.clip_name->text();
165 QString SlideshowClip::clipDuration() const
167 return m_view.clip_duration->text();
170 int SlideshowClip::imageCount() const
175 int SlideshowClip::softness() const
177 return m_view.luma_softness->value();
180 bool SlideshowClip::loop() const
182 return m_view.slide_loop->isChecked();
185 bool SlideshowClip::fade() const
187 return m_view.slide_fade->isChecked();
190 QString SlideshowClip::lumaDuration() const
192 return m_view.luma_duration->text();
195 QString SlideshowClip::lumaFile() const
197 if (!m_view.luma_fade->isChecked() || !m_view.luma_file->isEnabled()) return QString();
198 return m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
201 #include "slideshowclip.moc"