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