]> git.sesse.net Git - kdenlive/blob - src/slideshowclip.cpp
- Fix drop frame timecode format. [1]
[kdenlive] / src / slideshowclip.cpp
1 /***************************************************************************
2  *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20 #include "slideshowclip.h"
21 #include "kdenlivesettings.h"
22
23 #include <KStandardDirs>
24 #include <KDebug>
25 #include <KFileItem>
26
27 #include <QDir>
28
29
30 SlideshowClip::SlideshowClip(Timecode tc, QWidget * parent) :
31         QDialog(parent),
32         m_count(0),
33         m_timecode(tc),
34         m_thumbJob(NULL)
35 {
36     setFont(KGlobalSettings::toolBarFont());
37     setWindowTitle(i18n("Add Slideshow Clip"));
38     m_view.setupUi(this);
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());
43
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
47     connect(m_view.show_thumbs, SIGNAL(stateChanged(int)), this, SLOT(slotEnableThumbs(int)));
48     connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
49     connect(m_view.luma_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
50
51     //WARNING: keep in sync with clipproperties.cpp
52     m_view.image_type->addItem("JPG (*.jpg)", "jpg");
53     m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
54     m_view.image_type->addItem("PNG (*.png)", "png");
55     m_view.image_type->addItem("BMP (*.bmp)", "bmp");
56     m_view.image_type->addItem("GIF (*.gif)", "gif");
57     m_view.image_type->addItem("TGA (*.tga)", "tga");
58     m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
59     m_view.image_type->addItem("Open EXR (*.exr)", "exr");
60
61     m_view.clip_duration->setInputMask("");
62     m_view.clip_duration->setValidator(m_timecode.validator());
63     m_view.clip_duration->setText(m_timecode.reformatSeparators(KdenliveSettings::image_duration()));
64     m_view.luma_duration->setInputMask("");
65     m_view.luma_duration->setValidator(m_timecode.validator());
66     m_view.luma_duration->setText(m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))));
67     m_view.folder_url->setUrl(QDir::homePath());
68
69     m_view.clip_duration_format->addItem(i18n("hh:mm:ss::ff"));
70     m_view.clip_duration_format->addItem(i18n("Frames"));
71     connect(m_view.clip_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
72     m_view.clip_duration_frames->setHidden(true);
73     m_view.luma_duration_frames->setHidden(true);
74
75     // Check for Kdenlive installed luma files
76     QStringList filters;
77     filters << "*.pgm" << "*.png";
78
79     QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
80     foreach(const QString &folder, customLumas) {
81         QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
82         foreach(const QString &fname, filesnames) {
83             QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
84             m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
85         }
86     }
87
88     // Check for MLT lumas
89     QString profilePath = KdenliveSettings::mltpath();
90     QString folder = profilePath.section('/', 0, -3);
91     folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
92     QDir lumafolder(folder);
93     QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
94     foreach(const QString &fname, filesnames) {
95         QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
96         m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
97     }
98
99     //adjustSize();
100 }
101
102 SlideshowClip::~SlideshowClip()
103 {
104     if (m_thumbJob) {
105         delete m_thumbJob;
106     }
107 }
108
109 void SlideshowClip::slotEnableLuma(int state)
110 {
111     bool enable = false;
112     if (state == Qt::Checked) enable = true;
113     m_view.luma_duration->setEnabled(enable);
114     m_view.luma_duration_frames->setEnabled(enable);
115     m_view.luma_fade->setEnabled(enable);
116     if (enable) {
117         m_view.luma_file->setEnabled(m_view.luma_fade->isChecked());
118     } else m_view.luma_file->setEnabled(false);
119     m_view.label_softness->setEnabled(m_view.luma_fade->isChecked() && enable);
120     m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
121 }
122
123 void SlideshowClip::slotEnableThumbs(int state)
124 {
125     if (state == Qt::Checked) {
126         KdenliveSettings::setShowslideshowthumbs(true);
127         slotGenerateThumbs();
128     } else {
129         KdenliveSettings::setShowslideshowthumbs(false);
130         if (m_thumbJob) {
131             disconnect(m_thumbJob, SIGNAL(gotPreview(const KFileItem &, const QPixmap &)), this, SLOT(slotSetPixmap(const KFileItem &, const QPixmap &)));
132             m_thumbJob->kill();
133             m_thumbJob = NULL;
134         }
135     }
136
137 }
138
139 void SlideshowClip::slotEnableLumaFile(int state)
140 {
141     bool enable = false;
142     if (state == Qt::Checked) enable = true;
143     m_view.luma_file->setEnabled(enable);
144     m_view.luma_softness->setEnabled(enable);
145     m_view.label_softness->setEnabled(enable);
146 }
147
148 void SlideshowClip::parseFolder()
149 {
150     m_view.icon_list->clear();
151     QDir dir(m_view.folder_url->url().path());
152     QStringList filters;
153     QString filter = m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
154     filters << "*." + filter;
155     // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
156     // << "*.jpeg";
157
158     dir.setNameFilters(filters);
159     const QStringList result = dir.entryList(QDir::Files);
160     m_count = result.count();
161     if (m_count == 0) m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
162     else m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
163     m_view.label_info->setText(i18np("1 image found", "%1 images found", m_count));
164     QListWidgetItem *item;
165     int i = 0;
166     KIcon unknownicon("unknown");
167     foreach(const QString &path, result) {
168         i++;
169         item = new QListWidgetItem(unknownicon, KUrl(path).fileName());
170         item->setData(Qt::UserRole, dir.filePath(path));
171         m_view.icon_list->addItem(item);
172     }
173     if (m_view.show_thumbs->isChecked()) slotGenerateThumbs();
174     m_view.icon_list->setCurrentRow(0);
175 }
176
177 void SlideshowClip::slotGenerateThumbs()
178 {
179     if (m_thumbJob) {
180         delete m_thumbJob;
181     };
182     KFileItemList fileList;
183     for (int i = 0; i < m_view.icon_list->count(); i++) {
184         QListWidgetItem* item = m_view.icon_list->item(i);
185         if (item) {
186             QString path = item->data(Qt::UserRole).toString();
187             if (!path.isEmpty()) {
188                 fileList.append(KFileItem(KFileItem::Unknown, KFileItem::Unknown, KUrl(path)));
189             }
190         }
191     }
192     m_thumbJob = new KIO::PreviewJob(fileList, 50, 0, 0, 0, true, true, 0);
193     m_thumbJob->setAutoDelete(false);
194     connect(m_thumbJob, SIGNAL(gotPreview(const KFileItem &, const QPixmap &)), this, SLOT(slotSetPixmap(const KFileItem &, const QPixmap &)));
195     m_thumbJob->start();
196 }
197
198 void SlideshowClip::slotSetPixmap(const KFileItem &fileItem, const QPixmap &pix)
199 {
200     for (int i = 0; i < m_view.icon_list->count(); i++) {
201         QListWidgetItem* item = m_view.icon_list->item(i);
202         if (item) {
203             QString path = item->data(Qt::UserRole).toString();
204             if (path == fileItem.url().path()) {
205                 item->setIcon(KIcon(pix));
206                 item->setData(Qt::UserRole, QString());
207                 break;
208             }
209         }
210     }
211 }
212
213
214 QString SlideshowClip::selectedPath() const
215 {
216     QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
217     return m_view.folder_url->url().path() + extension;
218 }
219
220
221 QString SlideshowClip::clipName() const
222 {
223     return m_view.clip_name->text();
224 }
225
226 QString SlideshowClip::clipDuration() const
227 {
228     if (m_view.clip_duration_format->currentIndex() == 1) {
229         // we are in frames mode
230         return m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value());
231     }
232     return m_view.clip_duration->text();
233 }
234
235 int SlideshowClip::imageCount() const
236 {
237     return m_count;
238 }
239
240 int SlideshowClip::softness() const
241 {
242     return m_view.luma_softness->value();
243 }
244
245 bool SlideshowClip::loop() const
246 {
247     return m_view.slide_loop->isChecked();
248 }
249
250 bool SlideshowClip::fade() const
251 {
252     return m_view.slide_fade->isChecked();
253 }
254
255 QString SlideshowClip::lumaDuration() const
256 {
257     if (m_view.clip_duration_format->currentIndex() == 1) {
258         // we are in frames mode
259         return m_timecode.getTimecodeFromFrames(m_view.luma_duration_frames->value());
260     }
261     return m_view.luma_duration->text();
262 }
263
264 QString SlideshowClip::lumaFile() const
265 {
266     if (!m_view.luma_fade->isChecked() || !m_view.luma_file->isEnabled()) return QString();
267     return m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
268 }
269
270 void SlideshowClip::slotUpdateDurationFormat(int ix)
271 {
272     bool framesFormat = ix == 1;
273     if (framesFormat) {
274         // switching to frames count, update widget
275         m_view.clip_duration_frames->setValue(m_timecode.getFrameCount(m_view.clip_duration->text()));
276         m_view.luma_duration_frames->setValue(m_timecode.getFrameCount(m_view.luma_duration->text()));
277     } else {
278         // switching to timecode format
279         m_view.clip_duration->setInputMask("");
280         m_view.clip_duration->setValidator(m_timecode.validator());
281         m_view.clip_duration->setText(m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value()));
282         m_view.luma_duration->setInputMask("");
283         m_view.luma_duration->setValidator(m_timecode.validator());
284         m_view.luma_duration->setText(m_timecode.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
285     }
286     m_view.clip_duration_frames->setHidden(!framesFormat);
287     m_view.clip_duration->setHidden(framesFormat);
288     m_view.luma_duration_frames->setHidden(!framesFormat);
289     m_view.luma_duration->setHidden(framesFormat);
290 }
291
292 #include "slideshowclip.moc"
293
294