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