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 ***************************************************************************/
22 #include <KStandardDirs>
26 #include "kdenlivesettings.h"
27 #include "slideshowclip.h"
29 static const int TYPE_JPEG = 0;
30 static const int TYPE_PNG = 1;
31 static const int TYPE_BMP = 2;
32 static const int TYPE_GIF = 3;
34 SlideshowClip::SlideshowClip(QWidget * parent): QDialog(parent), m_count(0) {
35 setFont(KGlobalSettings::toolBarFont());
36 setWindowTitle(i18n("Add Slideshow Clip"));
38 m_view.clip_name->setText(i18n("Slideshow Clip"));
39 m_view.folder_url->setMode(KFile::Directory);
40 m_view.icon_list->setIconSize(QSize(50, 50));
41 connect(m_view.folder_url, SIGNAL(textChanged(const QString &)), this, SLOT(parseFolder()));
42 connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
44 connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
45 connect(m_view.luma_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
47 m_view.image_type->addItem("JPG");
48 m_view.image_type->addItem("PNG");
49 m_view.image_type->addItem("BMP");
50 m_view.image_type->addItem("GIF");
51 m_view.clip_duration->setText(KdenliveSettings::image_duration());
52 m_view.luma_duration->setText("00:00:00:24");
53 m_view.folder_url->setUrl(QDir::homePath());
56 QString profilePath = KdenliveSettings::mltpath();
57 profilePath = profilePath.section('/', 0, -3);
58 profilePath += "/lumas/PAL/";
60 QDir dir(profilePath);
63 const QStringList result = dir.entryList(filter, QDir::Files);
64 QStringList imagefiles;
65 QStringList imagenamelist;
66 foreach(const QString file, result) {
67 m_view.luma_file->addItem(KIcon(profilePath + file), file, profilePath + file);
73 void SlideshowClip::slotEnableLuma(int state) {
75 if (state == Qt::Checked) enable = true;
76 m_view.luma_duration->setEnabled(enable);
77 m_view.luma_fade->setEnabled(enable);
78 if (enable) m_view.luma_file->setEnabled(m_view.luma_fade->isChecked());
79 else m_view.luma_file->setEnabled(false);
82 void SlideshowClip::slotEnableLumaFile(int state) {
84 if (state == Qt::Checked) enable = true;
85 m_view.luma_file->setEnabled(enable);
86 m_view.luma_softness->setEnabled(enable);
87 m_view.label_softness->setEnabled(enable);
90 void SlideshowClip::parseFolder() {
91 m_view.icon_list->clear();
92 QDir dir(m_view.folder_url->url().path());
95 switch (m_view.image_type->currentIndex()) {
107 // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
112 dir.setNameFilters(filters);
113 const QStringList result = dir.entryList(QDir::Files);
114 m_count = result.count();
115 if (m_count == 0) m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
116 else m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
117 m_view.label_info->setText(i18n("%1 images found", m_count));
118 foreach(const QString &path, result) {
119 QIcon icon(dir.filePath(path));
120 QListWidgetItem *item = new QListWidgetItem(icon, KUrl(path).fileName());
121 m_view.icon_list->addItem(item);
125 QString SlideshowClip::selectedPath() const {
127 switch (m_view.image_type->currentIndex()) {
129 extension = "/.all.png";
132 extension = "/.all.bmp";
135 extension = "/.all.gif";
138 extension = "/.all.jpg";
141 return m_view.folder_url->url().path() + extension;
145 QString SlideshowClip::clipName() const {
146 return m_view.clip_name->text();
149 QString SlideshowClip::clipDuration() const {
150 return m_view.clip_duration->text();
153 int SlideshowClip::imageCount() const {
157 int SlideshowClip::softness() const {
158 return m_view.luma_softness->value();
161 bool SlideshowClip::loop() const {
162 return m_view.slide_loop->isChecked();
165 bool SlideshowClip::fade() const {
166 return m_view.slide_fade->isChecked();
169 QString SlideshowClip::lumaDuration() const {
170 return m_view.luma_duration->text();
173 QString SlideshowClip::lumaFile() const {
174 if (!m_view.luma_fade->isChecked() || !m_view.luma_file->isEnabled()) return QString();
175 return m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
178 #include "slideshowclip.moc"