]> git.sesse.net Git - kdenlive/blob - src/projectitem.cpp
Load clip info & thumbnail one after another so that we don't freeze the system when...
[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 // folder
42 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, const QString &clipId)
43         : QTreeWidgetItem(parent, strings), m_clipType(FOLDER), m_clipId(clipId), m_clip(NULL), m_groupname(strings.at(1)) {
44     setSizeHint(0, QSize(65, 45));
45     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
46     setIcon(0, KIcon("folder"));
47     setToolTip(1, "<qt><b>" + i18n("Folder"));
48 }
49
50 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip)
51         : QTreeWidgetItem(parent) {
52     setSizeHint(0, QSize(65, 45));
53     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
54     m_clip = clip;
55     m_clipId = clip->getId();
56     QString name = m_clip->getProperty("name");
57     if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
58     m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
59     setText(1, name);
60     setText(2, m_clip->description());
61     //setFlags(Qt::NoItemFlags);
62     //kDebug() << "PROJECT ITE;. ADDING LCIP: " << m_clipId;
63 }
64
65 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip)
66         : QTreeWidgetItem(parent) {
67     setSizeHint(0, QSize(65, 45));
68     setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
69     m_clip = clip;
70     m_clipId = clip->getId();
71     QString name = m_clip->getProperty("name");
72     if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
73     m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
74     setText(1, name);
75     setText(2, m_clip->description());
76     //setFlags(Qt::NoItemFlags);
77     //kDebug() << "PROJECT ITE;. ADDING LCIP: " << m_clipId;
78 }
79
80
81 ProjectItem::~ProjectItem() {
82 }
83
84 int ProjectItem::numReferences() const {
85     if (!m_clip) return 0;
86     return m_clip->numReferences();
87 }
88
89 const QString &ProjectItem::clipId() const {
90     return m_clipId;
91 }
92
93 CLIPTYPE ProjectItem::clipType() const {
94     return m_clipType;
95 }
96
97 int ProjectItem::clipMaxDuration() const {
98     return m_clip->getProperty("duration").toInt();
99 }
100
101 bool ProjectItem::isGroup() const {
102     return m_clipType == FOLDER;
103 }
104
105 QStringList ProjectItem::names() const {
106     QStringList result;
107     result.append(text(0));
108     result.append(text(1));
109     result.append(text(2));
110     return result;
111 }
112
113 QDomElement ProjectItem::toXml() const {
114     return m_clip->toXML();
115 }
116
117 const KUrl ProjectItem::clipUrl() const {
118     if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN && m_clipType != FOLDER)
119         return KUrl(m_clip->getProperty("resource"));
120     else return KUrl();
121 }
122
123 void ProjectItem::changeDuration(int frames) {
124     setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
125 }
126
127 void ProjectItem::setProperties(QMap <QString, QString> props) {
128     if (m_clip == NULL) return;
129     m_clip->setProperties(props);
130 }
131
132 void ProjectItem::setProperty(const QString &key, const QString &value) {
133     if (m_clip == NULL) return;
134     m_clip->setProperty(key, value);
135 }
136
137 void ProjectItem::clearProperty(const QString &key) {
138     if (m_clip == NULL) return;
139     m_clip->clearProperty(key);
140 }
141
142 const QString ProjectItem::groupName() const {
143     return m_groupname;
144 }
145
146 void ProjectItem::setGroupName(const QString name) {
147     m_groupname = name;
148     setText(1, name);
149 }
150
151 DocClipBase *ProjectItem::referencedClip() {
152     return m_clip;
153 }
154
155 void ProjectItem::slotSetToolTip() {
156     QString tip = "<qt><b>";
157     switch (m_clipType) {
158     case 1:
159         tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
160         break;
161     case 2:
162         tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
163         break;
164     case 3:
165         tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
166         break;
167     case 4:
168         tip.append(i18n("Color clip"));
169         break;
170     case 5:
171         tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
172         break;
173     case 6:
174         tip.append(i18n("Text clip"));
175         break;
176     case 7:
177         tip.append(i18n("Slideshow clip"));
178         break;
179     case 8:
180         tip.append(i18n("Virtual clip"));
181         break;
182     case 9:
183         tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
184         break;
185     default:
186         tip.append(i18n("Unknown clip"));
187         break;
188     }
189
190     setToolTip(1, tip);
191 }
192
193
194 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata) {
195     if (m_clip == NULL) return;
196     //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
197     if (attributes.contains("duration")) {
198         //if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV)
199         //m_clip->setProperty("duration", attributes["duration"]);
200         GenTime duration = GenTime(attributes["duration"].toInt(), KdenliveSettings::project_fps());
201         setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
202         m_clip->setDuration(duration);
203         //kDebug() << "//// LOADED CLIP, DURATION SET TO: " << duration.frames(KdenliveSettings::project_fps());
204     } else  {
205         // No duration known, use an arbitrary one until it is.
206     }
207
208
209     //extend attributes -reh
210
211     if (m_clipType == UNKNOWN) {
212         if (attributes.contains("type")) {
213             if (attributes["type"] == "audio")
214                 m_clipType = AUDIO;
215             else if (attributes["type"] == "video")
216                 m_clipType = VIDEO;
217             else if (attributes["type"] == "av")
218                 m_clipType = AV;
219             else if (attributes["type"] == "playlist")
220                 m_clipType = PLAYLIST;
221         } else {
222             m_clipType = AV;
223         }
224         m_clip->setClipType(m_clipType);
225     }
226     slotSetToolTip();
227     if ((m_clipType == AV || m_clipType == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->slotRequestAudioThumbs();
228
229     m_clip->setProperties(attributes);
230
231     if (m_clip->description().isEmpty()) {
232         if (metadata.contains("description")) {
233             m_clip->setProperty("description", metadata["description"]);
234             setText(2, m_clip->description());
235         } else if (metadata.contains("comment")) {
236             m_clip->setProperty("description", metadata["comment"]);
237             setText(2, m_clip->description());
238         }
239     }
240 }
241