]> git.sesse.net Git - kdenlive/blob - src/projectitem.cpp
Clip properties dialog
[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 <QMouseEvent>
22 #include <QStylePainter>
23 #include <QLabel>
24 #include <QLayout>
25
26 #include <KDebug>
27 #include <KLocale>
28 #include <KIcon>
29
30
31 #include "projectitem.h"
32 #include "timecode.h"
33 #include "kdenlivesettings.h"
34 #include "docclipbase.h"
35
36 const int NameRole = Qt::UserRole;
37 const int DurationRole = NameRole + 1;
38 const int UsageRole = NameRole + 2;
39
40
41 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, QDomElement xml, int clipId)
42         : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId) {
43     m_element = xml.cloneNode().toElement();
44     setSizeHint(0, QSize(65, 45));
45     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
46     if (!m_element.isNull()) {
47         m_element.setAttribute("id", clipId);
48         QString cType = m_element.attribute("type", QString::null);
49         if (!cType.isEmpty()) {
50             m_clipType = (CLIPTYPE) cType.toInt();
51             slotSetToolTip();
52         }
53
54         if (m_clipType == COLOR || m_clipType == IMAGE) m_element.setAttribute("duration", MAXCLIPDURATION);
55         else if (m_element.attribute("duration").isEmpty() && !m_element.attribute("out").isEmpty()) {
56             m_element.setAttribute("duration", m_element.attribute("out").toInt() - m_element.attribute("in").toInt());
57         }
58     }
59 }
60
61 ProjectItem::ProjectItem(QTreeWidgetItem * parent, const QStringList & strings, QDomElement xml, int clipId)
62         : QTreeWidgetItem(parent, strings, QTreeWidgetItem::UserType), m_clipType(UNKNOWN), m_clipId(clipId) {
63     m_element = xml.cloneNode().toElement();
64     setSizeHint(0, QSize(65, 45));
65     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
66     if (!m_element.isNull()) {
67         m_element.setAttribute("id", clipId);
68         QString cType = m_element.attribute("type", QString::null);
69         if (!cType.isEmpty()) {
70             m_clipType = (CLIPTYPE) cType.toInt();
71             slotSetToolTip();
72         }
73     }
74 }
75
76 // folder
77 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, int clipId)
78         : QTreeWidgetItem(parent, strings), m_element(QDomElement()), m_clipType(FOLDER), m_groupName(strings.at(1)), m_clipId(clipId), m_clip(NULL) {
79     setSizeHint(0, QSize(65, 45));
80     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
81     setIcon(0, KIcon("folder"));
82     setToolTip(1, "<qt><b>" + i18n("Folder"));
83 }
84
85 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip)
86         : QTreeWidgetItem(parent) {
87     setSizeHint(0, QSize(65, 45));
88     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
89     m_clip = clip;
90     m_element = clip->toXML();
91     m_clipId = clip->getId();
92     QString name = m_element.attribute("name");
93     if (name.isEmpty()) name = KUrl(m_element.attribute("resource")).fileName();
94     m_clipType = (CLIPTYPE) m_element.attribute("type").toInt();
95     setText(1, name);
96     kDebug() << "PROJECT ITE;. ADDING LCIP: " << m_clipId;
97 }
98
99 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip)
100         : QTreeWidgetItem(parent) {
101     setSizeHint(0, QSize(65, 45));
102     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
103     m_clip = clip;
104     m_element = clip->toXML();
105     m_clipId = clip->getId();
106     QString name = m_element.attribute("name");
107     if (name.isEmpty()) name = KUrl(m_element.attribute("resource")).fileName();
108     m_clipType = (CLIPTYPE) m_element.attribute("type").toInt();
109     setText(1, name);
110     kDebug() << "PROJECT ITE;. ADDING LCIP: " << m_clipId;
111 }
112
113
114 ProjectItem::~ProjectItem() {
115 }
116
117 int ProjectItem::numReferences() const {
118     if (!m_clip) return 0;
119     return m_clip->numReferences();
120 }
121
122 int ProjectItem::clipId() const {
123     return m_clipId;
124 }
125
126 CLIPTYPE ProjectItem::clipType() const {
127     return m_clipType;
128 }
129
130 int ProjectItem::clipMaxDuration() const {
131     return m_element.attribute("duration").toInt();
132 }
133
134 bool ProjectItem::isGroup() const {
135     return m_clipType == FOLDER;
136 }
137
138 const QString ProjectItem::groupName() const {
139     return m_groupName;
140 }
141
142 void ProjectItem::setGroupName(const QString name) {
143     m_groupName = name;
144 }
145
146 void ProjectItem::setGroup(const QString name, const QString id) {
147     if (m_clip) m_clip->setGroup(name, id);
148 }
149
150 QStringList ProjectItem::names() const {
151     QStringList result;
152     result.append(text(0));
153     result.append(text(1));
154     result.append(text(2));
155     return result;
156 }
157
158 QDomElement ProjectItem::toXml() const {
159     return m_element;
160 }
161
162 const KUrl ProjectItem::clipUrl() const {
163     if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
164         return KUrl(m_element.attribute("resource"));
165     else return KUrl();
166 }
167
168 void ProjectItem::changeDuration(int frames) {
169     m_element.setAttribute("duration", frames);
170     m_duration = GenTime(frames, 25);
171     setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
172     m_durationKnown = true;
173     m_clip->setDuration(m_duration);
174 }
175
176 void ProjectItem::setDescription(const QString &desc) {
177     m_clip->setDescription(desc);
178 }
179
180 DocClipBase *ProjectItem::referencedClip() {
181     return m_clip;
182 }
183
184 void ProjectItem::slotSetToolTip() {
185     QString tip = "<qt><b>";
186     switch (m_clipType) {
187     case 1:
188         tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
189         break;
190     case 2:
191         tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
192         break;
193     case 3:
194         tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
195         break;
196     case 4:
197         tip.append(i18n("Color clip"));
198         setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(m_element.attribute("out", "250").toInt(), 25), 25));
199         break;
200     case 5:
201         tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
202         break;
203     case 6:
204         tip.append(i18n("Text clip"));
205         break;
206     case 7:
207         tip.append(i18n("Slideshow clip"));
208         break;
209     case 8:
210         tip.append(i18n("Virtual clip"));
211         break;
212     case 9:
213         tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
214         break;
215     default:
216         tip.append(i18n("Unknown clip"));
217         break;
218     }
219
220     setToolTip(1, tip);
221 }
222
223 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata) {
224     if (attributes.contains("duration")) {
225         if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV) m_element.setAttribute("duration", attributes["duration"].toInt());
226         m_duration = GenTime(attributes["duration"].toInt(), 25);
227         setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
228         m_durationKnown = true;
229         m_clip->setDuration(m_duration);
230         kDebug() << "//// LOADED CLIP, DURATION SET TO: " << m_duration.frames(25);
231     } else {
232         // No duration known, use an arbitrary one until it is.
233         m_duration = GenTime(0.0);
234         m_durationKnown = false;
235     }
236
237
238     //extend attributes -reh
239
240     if (m_clipType == UNKNOWN) {
241         if (attributes.contains("type")) {
242             if (attributes["type"] == "audio")
243                 m_clipType = AUDIO;
244             else if (attributes["type"] == "video")
245                 m_clipType = VIDEO;
246             else if (attributes["type"] == "av")
247                 m_clipType = AV;
248             else if (attributes["type"] == "playlist")
249                 m_clipType = PLAYLIST;
250         } else {
251             m_clipType = AV;
252         }
253         m_clip->setClipType(m_clipType);
254     }
255     slotSetToolTip();
256     if (m_element.isNull()) {
257         QDomDocument doc;
258         m_element = doc.createElement("producer");
259     }
260     if (m_element.attribute("duration") == QString::null) m_element.setAttribute("duration", attributes["duration"].toInt());
261     m_element.setAttribute("resource", attributes["filename"]);
262     m_element.setAttribute("type", (int) m_clipType);
263
264     if (KdenliveSettings::audiothumbnails()) m_clip->slotRequestAudioThumbs();
265
266     m_clip->setProperties(attributes);
267     /*
268          m_metadata = metadata;
269
270          if (m_metadata.contains("description")) {
271              setDescription (m_metadata["description"]);
272          }
273          else if (m_metadata.contains("comment")) {
274              setDescription (m_metadata["comment"]);
275          }
276     */
277
278 }
279
280 #include "projectitem.moc"