]> git.sesse.net Git - kdenlive/blob - src/slideshowclip.cpp
Also show kdenlive lumas in the slideshow dialog
[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 <QDir>
21
22 #include <KStandardDirs>
23 #include <KDebug>
24 #include <KFileItem>
25
26 #include "kdenlivesettings.h"
27 #include "slideshowclip.h"
28
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;
33
34 SlideshowClip::SlideshowClip(QWidget * parent): QDialog(parent), m_count(0) {
35     setFont(KGlobalSettings::toolBarFont());
36     setWindowTitle(i18n("Add Slideshow Clip"));
37     m_view.setupUi(this);
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()));
43
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)));
46
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());
54
55
56     // Check for Kdenlive installed luma files
57     QStringList filters;
58     filters << "*.pgm" << "*.png";
59
60     QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
61     foreach(const QString &folder, customLumas) {
62         QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
63         foreach(const QString &fname, filesnames) {
64             m_view.luma_file->addItem(KIcon(folder + '/' + fname), fname, folder + '/' + fname);
65         }
66     }
67
68     // Check for MLT lumas
69     QString profilePath = KdenliveSettings::mltpath();
70     QString folder = profilePath.section('/', 0, -3);
71     folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
72     QDir lumafolder(folder);
73     QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
74     foreach(const QString &fname, filesnames) {
75         m_view.luma_file->addItem(KIcon(folder + '/' + fname), fname, folder + '/' + fname);
76     }
77
78     adjustSize();
79 }
80
81 void SlideshowClip::slotEnableLuma(int state) {
82     bool enable = false;
83     if (state == Qt::Checked) enable = true;
84     m_view.luma_duration->setEnabled(enable);
85     m_view.luma_fade->setEnabled(enable);
86     if (enable) m_view.luma_file->setEnabled(m_view.luma_fade->isChecked());
87     else m_view.luma_file->setEnabled(false);
88 }
89
90 void SlideshowClip::slotEnableLumaFile(int state) {
91     bool enable = false;
92     if (state == Qt::Checked) enable = true;
93     m_view.luma_file->setEnabled(enable);
94     m_view.luma_softness->setEnabled(enable);
95     m_view.label_softness->setEnabled(enable);
96 }
97
98 void SlideshowClip::parseFolder() {
99     m_view.icon_list->clear();
100     QDir dir(m_view.folder_url->url().path());
101
102     QStringList filters;
103     switch (m_view.image_type->currentIndex()) {
104     case TYPE_PNG:
105         filters << "*.png";
106         break;
107     case TYPE_BMP:
108         filters << "*.bmp";
109         break;
110     case TYPE_GIF:
111         filters << "*.gif";
112         break;
113     default:
114         filters << "*.jpg";
115         // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
116         // << "*.jpeg";
117         break;
118     }
119
120     dir.setNameFilters(filters);
121     const QStringList result = dir.entryList(QDir::Files);
122     m_count = result.count();
123     if (m_count == 0) m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
124     else m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
125     m_view.label_info->setText(i18n("%1 images found", m_count));
126     foreach(const QString &path, result) {
127         QIcon icon(dir.filePath(path));
128         QListWidgetItem *item = new QListWidgetItem(icon, KUrl(path).fileName());
129         m_view.icon_list->addItem(item);
130     }
131 }
132
133 QString SlideshowClip::selectedPath() const {
134     QString extension;
135     switch (m_view.image_type->currentIndex()) {
136     case TYPE_PNG:
137         extension = "/.all.png";
138         break;
139     case TYPE_BMP:
140         extension = "/.all.bmp";
141         break;
142     case TYPE_GIF:
143         extension = "/.all.gif";
144         break;
145     default:
146         extension = "/.all.jpg";
147         break;
148     }
149     return m_view.folder_url->url().path() + extension;
150 }
151
152
153 QString SlideshowClip::clipName() const {
154     return m_view.clip_name->text();
155 }
156
157 QString SlideshowClip::clipDuration() const {
158     return m_view.clip_duration->text();
159 }
160
161 int SlideshowClip::imageCount() const {
162     return m_count;
163 }
164
165 int SlideshowClip::softness() const {
166     return m_view.luma_softness->value();
167 }
168
169 bool SlideshowClip::loop() const {
170     return m_view.slide_loop->isChecked();
171 }
172
173 bool SlideshowClip::fade() const {
174     return m_view.slide_fade->isChecked();
175 }
176
177 QString SlideshowClip::lumaDuration() const {
178     return m_view.luma_duration->text();
179 }
180
181 QString SlideshowClip::lumaFile() const {
182     if (!m_view.luma_fade->isChecked() || !m_view.luma_file->isEnabled()) return QString();
183     return m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
184 }
185
186 #include "slideshowclip.moc"
187
188