]> git.sesse.net Git - kdenlive/blob - src/projectitem.cpp
First step for implementation of proxy editing (for testing purpose only)
[kdenlive] / src / projectitem.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 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
21 #include "projectitem.h"
22 #include "timecode.h"
23 #include "kdenlivesettings.h"
24 #include "docclipbase.h"
25
26 #include <KDebug>
27 #include <KLocale>
28 #include <KIcon>
29
30 const int DurationRole = Qt::UserRole + 1;
31 const int ProxyRole = Qt::UserRole + 5;
32 const int itemHeight = 38;
33
34 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) :
35         QTreeWidgetItem(parent, PROJECTCLIPTYPE)
36 {
37     setSizeHint(0, QSize(itemHeight * 3, itemHeight));
38     if (clip->isPlaceHolder()) setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
39     else setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
40     m_clip = clip;
41     m_clipId = clip->getId();
42     QString name = m_clip->getProperty("name");
43     if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
44     m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
45     if (m_clipType != UNKNOWN) slotSetToolTip();
46     setText(0, name);
47     setText(1, m_clip->description());
48     GenTime duration = m_clip->duration();
49     if (duration != GenTime()) setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
50     //setFlags(Qt::NoItemFlags);
51     //kDebug() << "Constructed with clipId: " << m_clipId;
52 }
53
54 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip) :
55         QTreeWidgetItem(parent, PROJECTCLIPTYPE)
56 {
57     setSizeHint(0, QSize(itemHeight * 3, itemHeight));
58     if (clip->isPlaceHolder()) setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
59     else setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
60     m_clip = clip;
61     m_clipId = clip->getId();
62     QString name = m_clip->getProperty("name");
63     if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
64     m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
65     setText(0, name);
66     setText(1, m_clip->description());
67     GenTime duration = m_clip->duration();
68     if (duration != GenTime()) setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
69     //setFlags(Qt::NoItemFlags);
70     //kDebug() << "Constructed with clipId: " << m_clipId;
71 }
72
73
74 ProjectItem::~ProjectItem()
75 {
76 }
77
78 //static
79 int ProjectItem::itemDefaultHeight()
80 {
81     return itemHeight;
82 }
83
84 int ProjectItem::numReferences() const
85 {
86     if (!m_clip) return 0;
87     return m_clip->numReferences();
88 }
89
90 const QString &ProjectItem::clipId() const
91 {
92     return m_clipId;
93 }
94
95 CLIPTYPE ProjectItem::clipType() const
96 {
97     return m_clipType;
98 }
99
100 int ProjectItem::clipMaxDuration() const
101 {
102     return m_clip->getProperty("duration").toInt();
103 }
104
105 QStringList ProjectItem::names() const
106 {
107     QStringList result;
108     result.append(text(0));
109     result.append(text(1));
110     result.append(text(2));
111     return result;
112 }
113
114 QDomElement ProjectItem::toXml() const
115 {
116     return m_clip->toXML();
117 }
118
119 const KUrl ProjectItem::clipUrl() const
120 {
121     if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
122         return KUrl(m_clip->getProperty("resource"));
123     else return KUrl();
124 }
125
126 void ProjectItem::changeDuration(int frames)
127 {
128     setData(0, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
129 }
130
131 void ProjectItem::setProperties(QMap <QString, QString> props)
132 {
133     if (m_clip == NULL) return;
134     m_clip->setProperties(props);
135 }
136
137 QString ProjectItem::getClipHash() const
138 {
139     if (m_clip == NULL) return QString();
140     return m_clip->getClipHash();
141 }
142
143 void ProjectItem::setProperty(const QString &key, const QString &value)
144 {
145     if (m_clip == NULL) return;
146     m_clip->setProperty(key, value);
147 }
148
149 void ProjectItem::clearProperty(const QString &key)
150 {
151     if (m_clip == NULL) return;
152     m_clip->clearProperty(key);
153 }
154
155 DocClipBase *ProjectItem::referencedClip()
156 {
157     return m_clip;
158 }
159
160 void ProjectItem::slotSetToolTip()
161 {
162     QString tip = "<b>";
163     if (m_clip->isPlaceHolder()) tip.append(i18n("Missing") + " | ");
164     switch (m_clipType) {
165     case AUDIO:
166         tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
167         break;
168     case VIDEO:
169         tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
170         break;
171     case AV:
172         tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
173         break;
174     case COLOR:
175         tip.append(i18n("Color clip"));
176         break;
177     case IMAGE:
178         tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
179         break;
180     case TEXT:
181         if (!clipUrl().isEmpty() && m_clip->getProperty("xmldata").isEmpty()) tip.append(i18n("Template text clip") + "</b><br />" + clipUrl().path());
182         else tip.append(i18n("Text clip") + "</b><br />" + clipUrl().path());
183         break;
184     case SLIDESHOW:
185         tip.append(i18n("Slideshow clip") + "</b><br />" + clipUrl().directory());
186         break;
187     case VIRTUAL:
188         tip.append(i18n("Virtual clip"));
189         break;
190     case PLAYLIST:
191         tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
192         break;
193     default:
194         tip.append(i18n("Unknown clip"));
195         break;
196     }
197
198     setToolTip(0, tip);
199 }
200
201
202 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
203 {
204     if (m_clip == NULL) return;
205     //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
206     if (attributes.contains("duration")) {
207         GenTime duration = GenTime(attributes.value("duration").toInt(), KdenliveSettings::project_fps());
208         setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
209         m_clip->setDuration(duration);
210     } else  {
211         // No duration known, use an arbitrary one until it is.
212     }
213
214
215     //extend attributes -reh
216
217     if (m_clipType == UNKNOWN) {
218         QString cliptype = attributes.value("type");
219         if (cliptype == "audio") m_clipType = AUDIO;
220         else if (cliptype == "video") m_clipType = VIDEO;
221         else if (cliptype == "av") m_clipType = AV;
222         else if (cliptype == "playlist") m_clipType = PLAYLIST;
223         else m_clipType = AV;
224
225         m_clip->setClipType(m_clipType);
226         slotSetToolTip();
227     }
228     m_clip->setProperties(attributes);
229     m_clip->setMetadata(metadata);
230
231     if (m_clip->description().isEmpty()) {
232         if (metadata.contains("description")) {
233             m_clip->setProperty("description", metadata.value("description"));
234             setText(1, m_clip->description());
235         } else if (metadata.contains("comment")) {
236             m_clip->setProperty("description", metadata.value("comment"));
237             setText(1, m_clip->description());
238         }
239     }
240 }
241
242 void ProjectItem::setProxyStatus(int status)
243 {
244     setData(0, ProxyRole, status);
245 }
246