]> git.sesse.net Git - kdenlive/blob - src/slideshowclip.cpp
Cleanup and add mimetype for TGA images, also add EXR, TIFF and TGA to the list of...
[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 SlideshowClip::SlideshowClip(QWidget * parent): QDialog(parent), m_count(0) {
30     setFont(KGlobalSettings::toolBarFont());
31     setWindowTitle(i18n("Add Slideshow Clip"));
32     m_view.setupUi(this);
33     m_view.clip_name->setText(i18n("Slideshow Clip"));
34     m_view.folder_url->setMode(KFile::Directory);
35     m_view.icon_list->setIconSize(QSize(50, 50));
36     connect(m_view.folder_url, SIGNAL(textChanged(const QString &)), this, SLOT(parseFolder()));
37     connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
38
39     connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
40     connect(m_view.luma_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
41
42     m_view.image_type->addItem("JPG (*.jpg)", "jpg");
43     m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
44     m_view.image_type->addItem("PNG (*.png)", "png");
45     m_view.image_type->addItem("BMP (*.bmp)", "bmp");
46     m_view.image_type->addItem("GIF (*.gif)", "gif");
47     m_view.image_type->addItem("TGA (*.tga)", "tga");
48     m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
49     m_view.image_type->addItem("Open EXR (*.exr)", "exr");
50     m_view.clip_duration->setText(KdenliveSettings::image_duration());
51     m_view.luma_duration->setText("00:00:00:24");
52     m_view.folder_url->setUrl(QDir::homePath());
53
54
55     // Check for Kdenlive installed luma files
56     QStringList filters;
57     filters << "*.pgm" << "*.png";
58
59     QStringList customLumas = KGlobal::dirs()->findDirs("appdata", "lumas");
60     foreach(const QString &folder, customLumas) {
61         QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
62         foreach(const QString &fname, filesnames) {
63             m_view.luma_file->addItem(KIcon(folder + '/' + fname), fname, folder + '/' + fname);
64         }
65     }
66
67     // Check for MLT lumas
68     QString profilePath = KdenliveSettings::mltpath();
69     QString folder = profilePath.section('/', 0, -3);
70     folder.append("/lumas/PAL"); // TODO: cleanup the PAL / NTSC mess in luma files
71     QDir lumafolder(folder);
72     QStringList filesnames = lumafolder.entryList(filters, QDir::Files);
73     foreach(const QString &fname, filesnames) {
74         m_view.luma_file->addItem(KIcon(folder + '/' + fname), fname, folder + '/' + fname);
75     }
76
77     adjustSize();
78 }
79
80 void SlideshowClip::slotEnableLuma(int state) {
81     bool enable = false;
82     if (state == Qt::Checked) enable = true;
83     m_view.luma_duration->setEnabled(enable);
84     m_view.luma_fade->setEnabled(enable);
85     if (enable) {
86         m_view.luma_file->setEnabled(m_view.luma_fade->isChecked());
87     } else m_view.luma_file->setEnabled(false);
88     m_view.label_softness->setEnabled(m_view.luma_fade->isChecked() && enable);
89     m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
90 }
91
92 void SlideshowClip::slotEnableLumaFile(int state) {
93     bool enable = false;
94     if (state == Qt::Checked) enable = true;
95     m_view.luma_file->setEnabled(enable);
96     m_view.luma_softness->setEnabled(enable);
97     m_view.label_softness->setEnabled(enable);
98 }
99
100 void SlideshowClip::parseFolder() {
101     m_view.icon_list->clear();
102     QDir dir(m_view.folder_url->url().path());
103
104     QStringList filters;
105     QString filter = m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
106     filters << "*." + filter;
107         // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
108         // << "*.jpeg";
109
110     dir.setNameFilters(filters);
111     const QStringList result = dir.entryList(QDir::Files);
112     m_count = result.count();
113     if (m_count == 0) m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
114     else m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
115     m_view.label_info->setText(i18n("%1 images found", m_count));
116     QListWidgetItem *item;
117     int i = 0;
118     KIcon unknownicon("unknown");
119     foreach(const QString &path, result) {
120         i++;
121         if (i < 80) {
122             QIcon icon(dir.filePath(path));
123             item = new QListWidgetItem(icon, KUrl(path).fileName());
124         } else {
125             item = new QListWidgetItem(unknownicon, KUrl(path).fileName());
126             item->setData(Qt::UserRole, dir.filePath(path));
127         }
128         m_view.icon_list->addItem(item);
129     }
130     if (m_count >= 80) connect(m_view.icon_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotSetItemIcon(int)));
131     m_view.icon_list->setCurrentRow(0);
132 }
133
134 void SlideshowClip::slotSetItemIcon(int row) {
135     QListWidgetItem * item = m_view.icon_list->item(row);
136     if (item) {
137         QString path = item->data(Qt::UserRole).toString();
138         if (!path.isEmpty()) {
139             KIcon icon(path);
140             item->setIcon(icon);
141             item->setData(Qt::UserRole, QString());
142         }
143     }
144 }
145
146 QString SlideshowClip::selectedPath() const {
147     QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
148     return m_view.folder_url->url().path() + extension;
149 }
150
151
152 QString SlideshowClip::clipName() const {
153     return m_view.clip_name->text();
154 }
155
156 QString SlideshowClip::clipDuration() const {
157     return m_view.clip_duration->text();
158 }
159
160 int SlideshowClip::imageCount() const {
161     return m_count;
162 }
163
164 int SlideshowClip::softness() const {
165     return m_view.luma_softness->value();
166 }
167
168 bool SlideshowClip::loop() const {
169     return m_view.slide_loop->isChecked();
170 }
171
172 bool SlideshowClip::fade() const {
173     return m_view.slide_fade->isChecked();
174 }
175
176 QString SlideshowClip::lumaDuration() const {
177     return m_view.luma_duration->text();
178 }
179
180 QString SlideshowClip::lumaFile() const {
181     if (!m_view.luma_fade->isChecked() || !m_view.luma_file->isEnabled()) return QString();
182     return m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
183 }
184
185 #include "slideshowclip.moc"
186
187