]> git.sesse.net Git - kdenlive/blob - src/slideshowclip.cpp
slideshow update
[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 #define TYPE_JPEG 0
30 #define TYPE_PNG 1
31 #define TYPE_BMP 2
32 #define 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     QString profilePath = KdenliveSettings::mltpath();
57     profilePath = profilePath.section('/', 0, -3);
58     profilePath += "/lumas/PAL/";
59
60     QDir dir(profilePath);
61     QStringList result = dir.entryList(QDir::Files);
62     QStringList imagefiles;
63     QStringList imagenamelist;
64     foreach(QString file, result) {
65         if (file.endsWith(".pgm")) {
66             m_view.luma_file->addItem(KIcon(profilePath + file), file, profilePath + file);
67         }
68     }
69
70     adjustSize();
71 }
72
73 void SlideshowClip::slotEnableLuma(int state) {
74     bool enable = false;
75     if (state == Qt::Checked) enable = true;
76     m_view.luma_duration->setEnabled(enable);
77     m_view.luma_fade->setEnabled(enable);
78     if (enable) m_view.luma_file->setEnabled(m_view.luma_fade->isChecked());
79     else m_view.luma_file->setEnabled(false);
80 }
81
82 void SlideshowClip::slotEnableLumaFile(int state) {
83     bool enable = false;
84     if (state == Qt::Checked) enable = true;
85     m_view.luma_file->setEnabled(enable);
86     m_view.luma_softness->setEnabled(enable);
87     m_view.label_softness->setEnabled(enable);
88 }
89
90 void SlideshowClip::parseFolder() {
91     m_view.icon_list->clear();
92     QDir dir(m_view.folder_url->url().path());
93
94     QStringList filters;
95     switch (m_view.image_type->currentIndex()) {
96     case TYPE_PNG:
97         filters << "*.png";
98         break;
99     case TYPE_BMP:
100         filters << "*.bmp";
101         break;
102     case TYPE_GIF:
103         filters << "*.gif";
104         break;
105     default:
106         filters << "*.jpg" << "*.jpeg";
107         break;
108     }
109
110     dir.setNameFilters(filters);
111     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     foreach(const QString &path, result) {
117         QIcon icon(dir.filePath(path));
118         QListWidgetItem *item = new QListWidgetItem(icon, KUrl(path).fileName());
119         m_view.icon_list->addItem(item);
120     }
121 }
122
123 QString SlideshowClip::selectedPath() const {
124     QString extension;
125     switch (m_view.image_type->currentIndex()) {
126     case TYPE_PNG:
127         extension = "/.all.png";
128         break;
129     case TYPE_BMP:
130         extension = "/.all.bmp";
131         break;
132     case TYPE_GIF:
133         extension = "/.all.gif";
134         break;
135     default:
136         extension = "/.all.jpg";
137         break;
138     }
139     return m_view.folder_url->url().path() + extension;
140 }
141
142
143 QString SlideshowClip::clipName() const {
144     return m_view.clip_name->text();
145 }
146
147 QString SlideshowClip::clipDuration() const {
148     return m_view.clip_duration->text();
149 }
150
151 int SlideshowClip::imageCount() const {
152     return m_count;
153 }
154
155 int SlideshowClip::softness() const {
156     return m_view.luma_softness->value();
157 }
158
159 bool SlideshowClip::loop() const {
160     return m_view.slide_loop->isChecked();
161 }
162
163 bool SlideshowClip::fade() const {
164     return m_view.slide_fade->isChecked();
165 }
166
167 QString SlideshowClip::lumaDuration() const {
168     return m_view.luma_duration->text();
169 }
170
171 QString SlideshowClip::lumaFile() const {
172     if (!m_view.luma_fade->isChecked() || !m_view.luma_file->isEnabled()) return QString();
173     return m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
174 }
175
176 #include "slideshowclip.moc"
177
178