]> git.sesse.net Git - kdenlive/blob - src/slideshowclip.cpp
some progress on slideshow clips
[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 }
87
88 void SlideshowClip::parseFolder() {
89     m_view.icon_list->clear();
90     QDir dir(m_view.folder_url->url().path());
91
92     QStringList filters;
93     switch (m_view.image_type->currentIndex()) {
94     case TYPE_PNG:
95         filters << "*.png";
96         break;
97     case TYPE_BMP:
98         filters << "*.bmp";
99         break;
100     case TYPE_GIF:
101         filters << "*.gif";
102         break;
103     default:
104         filters << "*.jpg" << "*.jpeg";
105         break;
106     }
107
108     dir.setNameFilters(filters);
109     QStringList result = dir.entryList(QDir::Files);
110     m_count = result.count();
111     if (m_count == 0) m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
112     else m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
113     m_view.label_info->setText(i18n("%1 images found", m_count));
114     foreach(const QString &path, result) {
115         QIcon icon(dir.filePath(path));
116         QListWidgetItem *item = new QListWidgetItem(icon, KUrl(path).fileName());
117         m_view.icon_list->addItem(item);
118     }
119 }
120
121 QString SlideshowClip::selectedPath() const {
122     QString extension;
123     switch (m_view.image_type->currentIndex()) {
124     case TYPE_PNG:
125         extension = "/.all.png";
126         break;
127     case TYPE_BMP:
128         extension = "/.all.bmp";
129         break;
130     case TYPE_GIF:
131         extension = "/.all.gif";
132         break;
133     default:
134         extension = "/.all.jpg";
135         break;
136     }
137     return m_view.folder_url->url().path() + extension;
138 }
139
140
141 QString SlideshowClip::clipName() const {
142     return m_view.clip_name->text();
143 }
144
145 QString SlideshowClip::clipDuration() const {
146     return m_view.clip_duration->text();
147 }
148
149 int SlideshowClip::imageCount() const {
150     return m_count;
151 }
152
153 bool SlideshowClip::loop() const {
154     return m_view.slide_loop->isChecked();
155 }
156
157 bool SlideshowClip::fade() const {
158     return m_view.slide_fade->isChecked();
159 }
160
161 QString SlideshowClip::lumaDuration() const {
162     return m_view.luma_duration->text();
163 }
164
165 QString SlideshowClip::lumaFile() const {
166     if (!m_view.luma_fade->isChecked() || !m_view.luma_file->isEnabled()) return QString();
167     return m_view.luma_file->itemData(m_view.luma_file->currentIndex()).toString();
168 }
169
170 #include "slideshowclip.moc"
171
172