]> git.sesse.net Git - kdenlive/blob - src/slideshowclip.cpp
Reindent the codebase using 'linux' bracket placement.
[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(QWidget * parent): QDialog(parent), m_count(0)
30 {
31     setFont(KGlobalSettings::toolBarFont());
32     setWindowTitle(i18n("Add Slideshow Clip"));
33     m_view.setupUi(this);
34     m_view.clip_name->setText(i18n("Slideshow Clip"));
35     m_view.folder_url->setMode(KFile::Directory);
36     m_view.icon_list->setIconSize(QSize(50, 50));
37     connect(m_view.folder_url, SIGNAL(textChanged(const QString &)), this, SLOT(parseFolder()));
38     connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
39
40     connect(m_view.slide_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLuma(int)));
41     connect(m_view.luma_fade, SIGNAL(stateChanged(int)), this, SLOT(slotEnableLumaFile(int)));
42
43     m_view.image_type->addItem("JPG (*.jpg)", "jpg");
44     m_view.image_type->addItem("JPEG (*.jpeg)", "jpeg");
45     m_view.image_type->addItem("PNG (*.png)", "png");
46     m_view.image_type->addItem("BMP (*.bmp)", "bmp");
47     m_view.image_type->addItem("GIF (*.gif)", "gif");
48     m_view.image_type->addItem("TGA (*.tga)", "tga");
49     m_view.image_type->addItem("TIFF (*.tiff)", "tiff");
50     m_view.image_type->addItem("Open EXR (*.exr)", "exr");
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 {
83     bool enable = false;
84     if (state == Qt::Checked) enable = true;
85     m_view.luma_duration->setEnabled(enable);
86     m_view.luma_fade->setEnabled(enable);
87     if (enable) {
88         m_view.luma_file->setEnabled(m_view.luma_fade->isChecked());
89     } else m_view.luma_file->setEnabled(false);
90     m_view.label_softness->setEnabled(m_view.luma_fade->isChecked() && enable);
91     m_view.luma_softness->setEnabled(m_view.label_softness->isEnabled());
92 }
93
94 void SlideshowClip::slotEnableLumaFile(int state)
95 {
96     bool enable = false;
97     if (state == Qt::Checked) enable = true;
98     m_view.luma_file->setEnabled(enable);
99     m_view.luma_softness->setEnabled(enable);
100     m_view.label_softness->setEnabled(enable);
101 }
102
103 void SlideshowClip::parseFolder()
104 {
105     m_view.icon_list->clear();
106     QDir dir(m_view.folder_url->url().path());
107
108     QStringList filters;
109     QString filter = m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
110     filters << "*." + filter;
111     // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
112     // << "*.jpeg";
113
114     dir.setNameFilters(filters);
115     const QStringList result = dir.entryList(QDir::Files);
116     m_count = result.count();
117     if (m_count == 0) m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
118     else m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
119     m_view.label_info->setText(i18n("%1 images found", m_count));
120     QListWidgetItem *item;
121     int i = 0;
122     KIcon unknownicon("unknown");
123     foreach(const QString &path, result) {
124         i++;
125         if (i < 80) {
126             QIcon icon(dir.filePath(path));
127             item = new QListWidgetItem(icon, KUrl(path).fileName());
128         } else {
129             item = new QListWidgetItem(unknownicon, KUrl(path).fileName());
130             item->setData(Qt::UserRole, dir.filePath(path));
131         }
132         m_view.icon_list->addItem(item);
133     }
134     if (m_count >= 80) connect(m_view.icon_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotSetItemIcon(int)));
135     m_view.icon_list->setCurrentRow(0);
136 }
137
138 void SlideshowClip::slotSetItemIcon(int row)
139 {
140     QListWidgetItem * item = m_view.icon_list->item(row);
141     if (item) {
142         QString path = item->data(Qt::UserRole).toString();
143         if (!path.isEmpty()) {
144             KIcon icon(path);
145             item->setIcon(icon);
146             item->setData(Qt::UserRole, QString());
147         }
148     }
149 }
150
151 QString SlideshowClip::selectedPath() const
152 {
153     QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
154     return m_view.folder_url->url().path() + extension;
155 }
156
157
158 QString SlideshowClip::clipName() const
159 {
160     return m_view.clip_name->text();
161 }
162
163 QString SlideshowClip::clipDuration() const
164 {
165     return m_view.clip_duration->text();
166 }
167
168 int SlideshowClip::imageCount() const
169 {
170     return m_count;
171 }
172
173 int SlideshowClip::softness() const
174 {
175     return m_view.luma_softness->value();
176 }
177
178 bool SlideshowClip::loop() const
179 {
180     return m_view.slide_loop->isChecked();
181 }
182
183 bool SlideshowClip::fade() const
184 {
185     return m_view.slide_fade->isChecked();
186 }
187
188 QString SlideshowClip::lumaDuration() const
189 {
190     return m_view.luma_duration->text();
191 }
192
193 QString SlideshowClip::lumaFile() const
194 {
195     if (!m_view.luma_fade->isChecked() || !m_view.luma_file->isEnabled()) return QString();
196     return m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
197 }
198
199 #include "slideshowclip.moc"
200
201