]> git.sesse.net Git - kdenlive/blob - src/slideshowclip.cpp
Fix dropframe timecode, patch from John T. Mertz
[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 SlideshowClip::SlideshowClip(Timecode tc, QWidget * parent) :
30         QDialog(parent),
31         m_count(0),
32         m_timecode(tc)
33 {
34     setFont(KGlobalSettings::toolBarFont());
35     setWindowTitle(i18n("Add Slideshow Clip"));
36     m_view.setupUi(this);
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()));
42
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)));
45
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     
56     m_view.clip_duration->setInputMask(m_timecode.inputMask());
57     m_view.clip_duration->setText(m_timecode.reformatSeparators(KdenliveSettings::image_duration()));
58     m_view.luma_duration->setInputMask(m_timecode.inputMask());
59     m_view.luma_duration->setText(m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))));
60     m_view.folder_url->setUrl(QDir::homePath());
61
62     m_view.clip_duration_format->addItem(i18n("hh:mm:ss::ff"));
63     m_view.clip_duration_format->addItem(i18n("Frames"));
64     connect(m_view.clip_duration_format, SIGNAL(activated(int)), this, SLOT(slotUpdateDurationFormat(int)));
65     m_view.clip_duration_frames->setHidden(true);
66     m_view.luma_duration_frames->setHidden(true);
67
68     // Check for Kdenlive installed luma files
69     QStringList filters;
70     filters << "*.pgm" << "*.png";
71
72     QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
73     foreach(const QString &folder, customLumas) {
74         QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
75         foreach(const QString &fname, filesnames) {
76             QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
77             m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
78         }
79     }
80
81     // Check for MLT lumas
82     QString profilePath = KdenliveSettings::mltpath();
83     QString folder = profilePath.section('/', 0, -3);
84     folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
85     QDir lumafolder(folder);
86     QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
87     foreach(const QString &fname, filesnames) {
88         QString filePath = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
89         m_view.luma_file->addItem(KIcon(filePath), fname, filePath);
90     }
91
92     //adjustSize();
93 }
94
95 void SlideshowClip::slotEnableLuma(int state)
96 {
97     bool enable = false;
98     if (state == Qt::Checked) enable = true;
99     m_view.luma_duration->setEnabled(enable);
100     m_view.luma_duration_frames->setEnabled(enable);
101     m_view.luma_fade->setEnabled(enable);
102     if (enable) {
103         m_view.luma_file->setEnabled(m_view.luma_fade->isChecked());
104     } else m_view.luma_file->setEnabled(false);
105     m_view.label_softness->setEnabled(m_view.luma_fade->isChecked() && enable);
106     m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
107 }
108
109 void SlideshowClip::slotEnableLumaFile(int state)
110 {
111     bool enable = false;
112     if (state == Qt::Checked) enable = true;
113     m_view.luma_file->setEnabled(enable);
114     m_view.luma_softness->setEnabled(enable);
115     m_view.label_softness->setEnabled(enable);
116 }
117
118 void SlideshowClip::parseFolder()
119 {
120     m_view.icon_list->clear();
121     QDir dir(m_view.folder_url->url().path());
122
123     QStringList filters;
124     QString filter = m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
125     filters << "*." + filter;
126     // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
127     // << "*.jpeg";
128
129     dir.setNameFilters(filters);
130     const QStringList result = dir.entryList(QDir::Files);
131     m_count = result.count();
132     if (m_count == 0) m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
133     else m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
134     m_view.label_info->setText(i18np("1 image found", "%1 images found", m_count));
135     QListWidgetItem *item;
136     int i = 0;
137     KIcon unknownicon("unknown");
138     foreach(const QString &path, result) {
139         i++;
140         if (i < 80) {
141             QIcon icon(dir.filePath(path));
142             item = new QListWidgetItem(icon, KUrl(path).fileName());
143         } else {
144             item = new QListWidgetItem(unknownicon, KUrl(path).fileName());
145             item->setData(Qt::UserRole, dir.filePath(path));
146         }
147         m_view.icon_list->addItem(item);
148     }
149     if (m_count >= 80) connect(m_view.icon_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotSetItemIcon(int)));
150     m_view.icon_list->setCurrentRow(0);
151 }
152
153 void SlideshowClip::slotSetItemIcon(int row)
154 {
155     QListWidgetItem * item = m_view.icon_list->item(row);
156     if (item) {
157         QString path = item->data(Qt::UserRole).toString();
158         if (!path.isEmpty()) {
159             KIcon icon(path);
160             item->setIcon(icon);
161             item->setData(Qt::UserRole, QString());
162         }
163     }
164 }
165
166 QString SlideshowClip::selectedPath() const
167 {
168     QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
169     return m_view.folder_url->url().path() + extension;
170 }
171
172
173 QString SlideshowClip::clipName() const
174 {
175     return m_view.clip_name->text();
176 }
177
178 QString SlideshowClip::clipDuration() const
179 {
180     if (m_view.clip_duration_format->currentIndex() == 1) {
181         // we are in frames mode
182         return m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value());
183     }
184     return m_view.clip_duration->text();
185 }
186
187 int SlideshowClip::imageCount() const
188 {
189     return m_count;
190 }
191
192 int SlideshowClip::softness() const
193 {
194     return m_view.luma_softness->value();
195 }
196
197 bool SlideshowClip::loop() const
198 {
199     return m_view.slide_loop->isChecked();
200 }
201
202 bool SlideshowClip::fade() const
203 {
204     return m_view.slide_fade->isChecked();
205 }
206
207 QString SlideshowClip::lumaDuration() const
208 {
209     if (m_view.clip_duration_format->currentIndex() == 1) {
210         // we are in frames mode
211         return m_timecode.getTimecodeFromFrames(m_view.luma_duration_frames->value());
212     }
213     return m_view.luma_duration->text();
214 }
215
216 QString SlideshowClip::lumaFile() const
217 {
218     if (!m_view.luma_fade->isChecked() || !m_view.luma_file->isEnabled()) return QString();
219     return m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
220 }
221
222 void SlideshowClip::slotUpdateDurationFormat(int ix)
223 {
224     bool framesFormat = ix == 1;
225     if (framesFormat) {
226         // switching to frames count, update widget
227         m_view.clip_duration_frames->setValue(m_timecode.getFrameCount(m_view.clip_duration->text()));
228         m_view.luma_duration_frames->setValue(m_timecode.getFrameCount(m_view.luma_duration->text()));
229     } else {
230         // switching to timecode format
231         m_view.clip_duration->setInputMask(m_timecode.inputMask());
232         m_view.clip_duration->setText(m_timecode.getTimecodeFromFrames(m_view.clip_duration_frames->value()));
233         m_view.luma_duration->setInputMask(m_timecode.inputMask());
234         m_view.luma_duration->setText(m_timecode.getTimecodeFromFrames(m_view.luma_duration_frames->value()));
235     }
236     m_view.clip_duration_frames->setHidden(!framesFormat);
237     m_view.clip_duration->setHidden(framesFormat);
238     m_view.luma_duration_frames->setHidden(!framesFormat);
239     m_view.luma_duration->setHidden(framesFormat);
240 }
241
242 #include "slideshowclip.moc"
243
244