]> git.sesse.net Git - kdenlive/blob - src/clipproperties.cpp
several updates for slideshow clips
[kdenlive] / src / clipproperties.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 "clipproperties.h"
28 #include "kthumb.h"
29
30 #define VIDEOTAB 0
31 #define AUDIOTAB 1
32 #define COLORTAB 2
33 #define SLIDETAB 3
34 #define ADVANCEDTAB 4
35
36 #define TYPE_JPEG 0
37 #define TYPE_PNG 1
38 #define TYPE_BMP 2
39 #define TYPE_GIF 3
40
41 ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidget * parent): QDialog(parent), m_tc(tc), m_clip(clip), m_fps(fps), m_clipNeedsRefresh(false), m_count(0) {
42     setFont(KGlobalSettings::toolBarFont());
43     m_view.setupUi(this);
44     KUrl url = m_clip->fileURL();
45     m_view.clip_path->setText(url.path());
46     m_view.clip_description->setText(m_clip->description());
47     QMap <QString, QString> props = m_clip->properties();
48
49     if (props.contains("audiocodec"))
50         m_view.clip_acodec->setText(props.value("audiocodec"));
51     if (props.contains("frequency"))
52         m_view.clip_frequency->setText(props.value("frequency"));
53     if (props.contains("channels"))
54         m_view.clip_channels->setText(props.value("channels"));
55
56     CLIPTYPE t = m_clip->clipType();
57     if (t == COLOR) {
58         m_view.clip_path->setEnabled(false);
59         m_view.tabWidget->removeTab(SLIDETAB);
60         m_view.tabWidget->removeTab(AUDIOTAB);
61         m_view.tabWidget->removeTab(VIDEOTAB);
62         m_view.clip_thumb->setHidden(true);
63         m_view.clip_color->setColor(QColor("#" + props.value("colour").right(8).left(6)));
64     } else if (t == SLIDESHOW) {
65         m_view.clip_path->setText(url.directory());
66         m_view.tabWidget->removeTab(COLORTAB);
67         m_view.tabWidget->removeTab(AUDIOTAB);
68         m_view.tabWidget->removeTab(VIDEOTAB);
69         QStringList types;
70         types << "JPG" << "PNG" << "BMP" << "GIF";
71         m_view.image_type->addItems(types);
72         m_view.slide_loop->setChecked(props.value("loop").toInt());
73         QString path = props.value("resource");
74         if (path.endsWith("png")) m_view.image_type->setCurrentIndex(TYPE_PNG);
75         else if (path.endsWith("bmp")) m_view.image_type->setCurrentIndex(TYPE_BMP);
76         else if (path.endsWith("gif")) m_view.image_type->setCurrentIndex(TYPE_GIF);
77         m_view.slide_duration->setText(tc.getTimecodeFromFrames(props.value("ttl").toInt()));
78         parseFolder();
79         connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
80     } else if (t != AUDIO) {
81         m_view.tabWidget->removeTab(SLIDETAB);
82         m_view.tabWidget->removeTab(COLORTAB);
83         if (props.contains("frame_size"))
84             m_view.clip_size->setText(props.value("frame_size"));
85         if (props.contains("videocodec"))
86             m_view.clip_vcodec->setText(props.value("videocodec"));
87         if (props.contains("fps"))
88             m_view.clip_fps->setText(props.value("fps"));
89         if (props.contains("aspect_ratio"))
90             m_view.clip_ratio->setText(props.value("aspect_ratio"));
91
92         QPixmap pix = m_clip->thumbProducer()->getImage(url, 240, 180);
93         m_view.clip_thumb->setPixmap(pix);
94         if (t == IMAGE || t == VIDEO) m_view.tabWidget->removeTab(AUDIOTAB);
95     } else {
96         m_view.tabWidget->removeTab(SLIDETAB);
97         m_view.tabWidget->removeTab(COLORTAB);
98         m_view.tabWidget->removeTab(VIDEOTAB);
99         m_view.clip_thumb->setHidden(true);
100     }
101     if (t != IMAGE && t != COLOR && t != TEXT) m_view.clip_duration->setReadOnly(true);
102
103     KFileItem f(KFileItem::Unknown, KFileItem::Unknown, url, true);
104     m_view.clip_filesize->setText(KIO::convertSize(f.size()));
105     m_view.clip_duration->setText(tc.getTimecode(m_clip->duration(), m_fps));
106     adjustSize();
107 }
108
109 int ClipProperties::clipId() const {
110     return m_clip->getId();
111 }
112
113
114 QMap <QString, QString> ClipProperties::properties() {
115     QMap <QString, QString> props;
116     props["description"] = m_view.clip_description->text();
117     CLIPTYPE t = m_clip->clipType();
118     if (t == COLOR) {
119         QMap <QString, QString> old_props = m_clip->properties();
120         QString new_color = m_view.clip_color->color().name();
121         if (new_color != QString("#" + old_props.value("colour").right(8).left(6))) {
122             m_clipNeedsRefresh = true;
123             props["colour"] = "0x" + new_color.right(6) + "ff";
124         }
125     } else if (t == SLIDESHOW) {
126         props["loop"] = QString::number((int) m_view.slide_loop->isChecked());
127         QMap <QString, QString> old_props = m_clip->properties();
128         QString extension;
129         switch (m_view.image_type->currentIndex()) {
130         case TYPE_PNG:
131             extension = "/.all.png";
132             break;
133         case TYPE_BMP:
134             extension = "/.all.bmp";
135             break;
136         case TYPE_GIF:
137             extension = "/.all.gif";
138             break;
139         default:
140             extension = "/.all.jpg";
141             break;
142         }
143         QString new_path = m_view.clip_path->text() + extension;
144         if (new_path != old_props.value("resource")) {
145             m_clipNeedsRefresh = true;
146             props["resource"] = new_path;
147             kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << old_props.value("resource");
148         }
149         int duration = m_tc.getFrameCount(m_view.slide_duration->text(), m_fps);
150         if (duration != old_props.value("ttl").toInt()) {
151             m_clipNeedsRefresh = true;
152             props["ttl"] = QString::number(duration);
153             props["out"] = QString::number(duration * m_count);
154         }
155         if (duration * m_count != old_props.value("out").toInt()) {
156             m_clipNeedsRefresh = true;
157             props["out"] = QString::number(duration * m_count);
158         }
159
160     }
161     return props;
162 }
163
164 bool ClipProperties::needsTimelineRefresh() const {
165     return m_clipNeedsRefresh;
166 }
167
168 void ClipProperties::parseFolder() {
169
170     QDir dir(m_view.clip_path->text());
171     QStringList filters;
172     QString extension;
173     switch (m_view.image_type->currentIndex()) {
174     case TYPE_PNG:
175         filters << "*.png";
176         extension = "/.all.png";
177         break;
178     case TYPE_BMP:
179         filters << "*.bmp";
180         extension = "/.all.bmp";
181         break;
182     case TYPE_GIF:
183         filters << "*.gif";
184         extension = "/.all.gif";
185         break;
186     default:
187         filters << "*.jpg" << "*.jpeg";
188         extension = "/.all.jpg";
189         break;
190     }
191
192     dir.setNameFilters(filters);
193     QStringList result = dir.entryList(QDir::Files);
194     m_count = result.count();
195     m_view.slide_info->setText(i18n("%1 images found", m_count));
196     QDomElement xml = m_clip->toXML();
197     xml.setAttribute("resource", m_view.clip_path->text() + extension);
198     QPixmap pix = m_clip->thumbProducer()->getImage(xml, 1, 240, 180);
199     QMap <QString, QString> props = m_clip->properties();
200     m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
201     m_view.clip_thumb->setPixmap(pix);
202 }
203
204 #include "clipproperties.moc"
205
206