]> git.sesse.net Git - kdenlive/blob - src/clipproperties.cpp
Show markers in clip properties
[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
107     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
108
109     for (uint count = 0; count < marks.count(); ++count) {
110         QString time = m_tc.getTimecode(marks[count].time(), m_tc.fps());
111         QStringList itemtext;
112         itemtext << time << marks[count].comment();
113         (void) new QTreeWidgetItem(m_view.markers_list, itemtext);
114     }
115     
116
117     adjustSize();
118 }
119
120 int ClipProperties::clipId() const {
121     return m_clip->getId();
122 }
123
124
125 QMap <QString, QString> ClipProperties::properties() {
126     QMap <QString, QString> props;
127     props["description"] = m_view.clip_description->text();
128     CLIPTYPE t = m_clip->clipType();
129     if (t == COLOR) {
130         QMap <QString, QString> old_props = m_clip->properties();
131         QString new_color = m_view.clip_color->color().name();
132         if (new_color != QString("#" + old_props.value("colour").right(8).left(6))) {
133             m_clipNeedsRefresh = true;
134             props["colour"] = "0x" + new_color.right(6) + "ff";
135         }
136     } else if (t == SLIDESHOW) {
137         props["loop"] = QString::number((int) m_view.slide_loop->isChecked());
138         QMap <QString, QString> old_props = m_clip->properties();
139         QString extension;
140         switch (m_view.image_type->currentIndex()) {
141         case TYPE_PNG:
142             extension = "/.all.png";
143             break;
144         case TYPE_BMP:
145             extension = "/.all.bmp";
146             break;
147         case TYPE_GIF:
148             extension = "/.all.gif";
149             break;
150         default:
151             extension = "/.all.jpg";
152             break;
153         }
154         QString new_path = m_view.clip_path->text() + extension;
155         if (new_path != old_props.value("resource")) {
156             m_clipNeedsRefresh = true;
157             props["resource"] = new_path;
158             kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << old_props.value("resource");
159         }
160         int duration = m_tc.getFrameCount(m_view.slide_duration->text(), m_fps);
161         if (duration != old_props.value("ttl").toInt()) {
162             m_clipNeedsRefresh = true;
163             props["ttl"] = QString::number(duration);
164             props["out"] = QString::number(duration * m_count);
165         }
166         if (duration * m_count != old_props.value("out").toInt()) {
167             m_clipNeedsRefresh = true;
168             props["out"] = QString::number(duration * m_count);
169         }
170
171     }
172     return props;
173 }
174
175 bool ClipProperties::needsTimelineRefresh() const {
176     return m_clipNeedsRefresh;
177 }
178
179 void ClipProperties::parseFolder() {
180
181     QDir dir(m_view.clip_path->text());
182     QStringList filters;
183     QString extension;
184     switch (m_view.image_type->currentIndex()) {
185     case TYPE_PNG:
186         filters << "*.png";
187         extension = "/.all.png";
188         break;
189     case TYPE_BMP:
190         filters << "*.bmp";
191         extension = "/.all.bmp";
192         break;
193     case TYPE_GIF:
194         filters << "*.gif";
195         extension = "/.all.gif";
196         break;
197     default:
198         filters << "*.jpg" << "*.jpeg";
199         extension = "/.all.jpg";
200         break;
201     }
202
203     dir.setNameFilters(filters);
204     QStringList result = dir.entryList(QDir::Files);
205     m_count = result.count();
206     m_view.slide_info->setText(i18n("%1 images found", m_count));
207     QDomElement xml = m_clip->toXML();
208     xml.setAttribute("resource", m_view.clip_path->text() + extension);
209     QPixmap pix = m_clip->thumbProducer()->getImage(xml, 1, 240, 180);
210     QMap <QString, QString> props = m_clip->properties();
211     m_view.clip_duration->setText(m_tc.getTimecodeFromFrames(props.value("ttl").toInt() * m_count));
212     m_view.clip_thumb->setPixmap(pix);
213 }
214
215 #include "clipproperties.moc"
216
217