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