]> git.sesse.net Git - kdenlive/blob - src/clipitem.cpp
05dbb2feb156e75e99f70051f7f3ef9fbc1fd5ed
[kdenlive] / src / clipitem.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 "clipitem.h"
22 #include "customtrackview.h"
23 #include "customtrackscene.h"
24 #include "renderer.h"
25 #include "docclipbase.h"
26 #include "transition.h"
27 #include "kdenlivesettings.h"
28 #include "kthumb.h"
29 #include "profilesdialog.h"
30
31 #include <KDebug>
32 #include <KIcon>
33
34 #include <QPainter>
35 #include <QTimer>
36 #include <QStyleOptionGraphicsItem>
37 #include <QGraphicsScene>
38 #include <QMimeData>
39
40 ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, int strobe, bool generateThumbs) :
41         AbstractClipItem(info, QRectF(), fps),
42         m_clip(clip),
43         m_startFade(0),
44         m_endFade(0),
45         m_audioOnly(false),
46         m_videoOnly(false),
47         m_startPix(QPixmap()),
48         m_endPix(QPixmap()),
49         m_hasThumbs(false),
50         m_selectedEffect(-1),
51         m_timeLine(0),
52         m_startThumbRequested(false),
53         m_endThumbRequested(false),
54         //m_hover(false),
55         m_speed(speed),
56         m_strobe(strobe),
57         m_framePixelWidth(0)
58 {
59     setZValue(2);
60     setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double)(KdenliveSettings::trackheight() - 2));
61     setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1);
62
63     // set speed independant info
64     m_speedIndependantInfo = m_info;
65     m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * m_speed), m_fps);
66     m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * m_speed), m_fps);
67
68     m_videoPix = KIcon("kdenlive-show-video").pixmap(QSize(16, 16));
69     m_audioPix = KIcon("kdenlive-show-audio").pixmap(QSize(16, 16));
70
71     if (m_speed == 1.0) m_clipName = m_clip->name();
72     else {
73         m_clipName = m_clip->name() + " - " + QString::number(m_speed * 100, 'f', 0) + '%';
74     }
75     m_producer = m_clip->getId();
76     m_clipType = m_clip->clipType();
77     //m_cropStart = info.cropStart;
78     m_maxDuration = m_clip->maxDuration();
79     setAcceptDrops(true);
80     m_audioThumbReady = m_clip->audioThumbCreated();
81     //setAcceptsHoverEvents(true);
82     connect(this , SIGNAL(prepareAudioThumb(double, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int)));
83
84     if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
85         m_baseColor = QColor(141, 166, 215);
86         m_hasThumbs = true;
87         m_startThumbTimer.setSingleShot(true);
88         connect(&m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
89         m_endThumbTimer.setSingleShot(true);
90         connect(&m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
91
92         connect(this, SIGNAL(getThumb(int, int)), m_clip->thumbProducer(), SLOT(extractImage(int, int)));
93
94         connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
95         connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
96         if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
97
98     } else if (m_clipType == COLOR) {
99         QString colour = m_clip->getProperty("colour");
100         colour = colour.replace(0, 2, "#");
101         m_baseColor = QColor(colour.left(7));
102     } else if (m_clipType == IMAGE || m_clipType == TEXT) {
103         m_baseColor = QColor(141, 166, 215);
104         if (m_clipType == TEXT) {
105             connect(this, SIGNAL(getThumb(int, int)), m_clip->thumbProducer(), SLOT(extractImage(int, int)));
106             connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
107         }
108         //m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
109     } else if (m_clipType == AUDIO) {
110         m_baseColor = QColor(141, 215, 166);
111         connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
112     }
113 }
114
115
116 ClipItem::~ClipItem()
117 {
118     blockSignals(true);
119     if (scene()) scene()->removeItem(this);
120     if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
121         disconnect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
122         disconnect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
123     }
124     delete m_timeLine;
125 }
126
127 ClipItem *ClipItem::clone(ItemInfo info) const
128 {
129     ClipItem *duplicate = new ClipItem(m_clip, info, m_fps, m_speed, m_strobe);
130     if (m_clipType == IMAGE || m_clipType == TEXT) duplicate->slotSetStartThumb(m_startPix);
131     else if (m_clipType != COLOR) {
132         if (info.cropStart == m_info.cropStart) duplicate->slotSetStartThumb(m_startPix);
133         if (info.cropStart + (info.endPos - info.startPos) == m_info.cropStart + (m_info.endPos - m_info.startPos)) duplicate->slotSetEndThumb(m_endPix);
134     }
135     //kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
136     duplicate->setEffectList(m_effectList);
137     duplicate->setVideoOnly(m_videoOnly);
138     duplicate->setAudioOnly(m_audioOnly);
139     //duplicate->setSpeed(m_speed);
140     return duplicate;
141 }
142
143 void ClipItem::setEffectList(const EffectsList effectList)
144 {
145     m_effectList.clone(effectList);
146     m_effectNames = m_effectList.effectNames().join(" / ");
147     if (!m_effectList.isEmpty()) setSelectedEffect(0);
148 }
149
150 const EffectsList ClipItem::effectList() const
151 {
152     return m_effectList;
153 }
154
155 int ClipItem::selectedEffectIndex() const
156 {
157     return m_selectedEffect;
158 }
159
160 void ClipItem::initEffect(QDomElement effect, int diff)
161 {
162     // the kdenlive_ix int is used to identify an effect in mlt's playlist, should
163     // not be changed
164     if (effect.attribute("kdenlive_ix").toInt() == 0)
165         effect.setAttribute("kdenlive_ix", QString::number(effectsCounter()));
166
167     if (effect.attribute("id") == "freeze" && diff > 0) {
168         EffectsList::setParameter(effect, "frame", QString::number(diff));
169     }
170
171     // Init parameter value & keyframes if required
172     QDomNodeList params = effect.elementsByTagName("parameter");
173     for (int i = 0; i < params.count(); i++) {
174         QDomElement e = params.item(i).toElement();
175         kDebug() << "// init eff: " << e.attribute("name");
176
177         // Check if this effect has a variable parameter
178         if (e.attribute("default").startsWith('%')) {
179             double evaluatedValue = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("default"));
180             e.setAttribute("default", evaluatedValue);
181             if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) {
182                 e.setAttribute("value", evaluatedValue);
183             }
184         }
185
186         if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
187             QString def = e.attribute("default");
188             // Effect has a keyframe type parameter, we need to set the values
189             if (e.attribute("keyframes").isEmpty()) {
190                 e.setAttribute("keyframes", QString::number(cropStart().frames(m_fps)) + ':' + def + ';' + QString::number((cropStart() + cropDuration()).frames(m_fps) - 1) + ':' + def);
191                 //kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
192                 //break;
193             }
194         }
195     }
196     if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
197         if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
198             int end = (cropDuration() + cropStart()).frames(m_fps);
199             int start = end;
200             if (effect.attribute("id") == "fadeout") {
201                 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
202                     int effectDuration = EffectsList::parameter(effect, "in").toInt();
203                     if (effectDuration > cropDuration().frames(m_fps)) {
204                         effectDuration = cropDuration().frames(m_fps) / 2;
205                     }
206                     start -= effectDuration;
207                 } else {
208                     QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
209                     start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
210                 }
211             } else if (effect.attribute("id") == "fade_to_black") {
212                 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
213                     int effectDuration = EffectsList::parameter(effect, "in").toInt();
214                     if (effectDuration > cropDuration().frames(m_fps)) {
215                         effectDuration = cropDuration().frames(m_fps) / 2;
216                     }
217                     start -= effectDuration;
218                 } else {
219                     QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
220                     start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
221                 }
222             }
223             EffectsList::setParameter(effect, "in", QString::number(start));
224             EffectsList::setParameter(effect, "out", QString::number(end));
225         } else if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
226             int start = cropStart().frames(m_fps);
227             int end = start;
228             if (effect.attribute("id") == "fadein") {
229                 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
230                     int effectDuration = EffectsList::parameter(effect, "out").toInt();
231                     if (effectDuration > cropDuration().frames(m_fps)) {
232                         effectDuration = cropDuration().frames(m_fps) / 2;
233                     }
234                     end += effectDuration;
235                 } else
236                     end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fade_from_black"), "out").toInt();
237             } else if (effect.attribute("id") == "fade_from_black") {
238                 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
239                     int effectDuration = EffectsList::parameter(effect, "out").toInt();
240                     if (effectDuration > cropDuration().frames(m_fps)) {
241                         effectDuration = cropDuration().frames(m_fps) / 2;
242                     }
243                     end += effectDuration;
244                 } else
245                     end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fadein"), "out").toInt();
246             }
247             EffectsList::setParameter(effect, "in", QString::number(start));
248             EffectsList::setParameter(effect, "out", QString::number(end));
249         }
250     }
251 }
252
253 bool ClipItem::checkKeyFrames()
254 {
255     bool clipEffectsModified = false;
256     for (int ix = 0; ix < m_effectList.count(); ix ++) {
257         QString kfr = keyframes(ix);
258         if (!kfr.isEmpty()) {
259             const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
260             QStringList newKeyFrames;
261             bool cutKeyFrame = false;
262             bool modified = false;
263             int lastPos = -1;
264             double lastValue = -1;
265             int start = cropStart().frames(m_fps);
266             int end = (cropStart() + cropDuration()).frames(m_fps);
267             foreach(const QString &str, keyframes) {
268                 int pos = str.section(':', 0, 0).toInt();
269                 double val = str.section(':', 1, 1).toDouble();
270                 if (pos - start < 0) {
271                     // a keyframe is defined before the start of the clip
272                     cutKeyFrame = true;
273                 } else if (cutKeyFrame) {
274                     // create new keyframe at clip start, calculate interpolated value
275                     if (pos > start) {
276                         int diff = pos - lastPos;
277                         double ratio = (double)(start - lastPos) / diff;
278                         double newValue = lastValue + (val - lastValue) * ratio;
279                         newKeyFrames.append(QString::number(start) + ':' + QString::number(newValue));
280                         modified = true;
281                     }
282                     cutKeyFrame = false;
283                 }
284                 if (!cutKeyFrame) {
285                     if (pos > end) {
286                         // create new keyframe at clip end, calculate interpolated value
287                         int diff = pos - lastPos;
288                         if (diff != 0) {
289                             double ratio = (double)(end - lastPos) / diff;
290                             double newValue = lastValue + (val - lastValue) * ratio;
291                             newKeyFrames.append(QString::number(end) + ':' + QString::number(newValue));
292                             modified = true;
293                         }
294                         break;
295                     } else {
296                         newKeyFrames.append(QString::number(pos) + ':' + QString::number(val));
297                     }
298                 }
299                 lastPos = pos;
300                 lastValue = val;
301             }
302             if (modified) {
303                 // update KeyFrames
304                 setKeyframes(ix, newKeyFrames.join(";"));
305                 clipEffectsModified = true;
306             }
307         }
308     }
309     return clipEffectsModified;
310 }
311
312 void ClipItem::setKeyframes(const int ix, const QString keyframes)
313 {
314     QDomElement effect = getEffectAt(ix);
315     if (effect.attribute("disabled") == "1") return;
316     QDomNodeList params = effect.elementsByTagName("parameter");
317     for (int i = 0; i < params.count(); i++) {
318         QDomElement e = params.item(i).toElement();
319         if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
320             e.setAttribute("keyframes", keyframes);
321             if (ix == m_selectedEffect) {
322                 m_keyframes.clear();
323                 double max = e.attribute("max").toDouble();
324                 double min = e.attribute("min").toDouble();
325                 m_keyframeFactor = 100.0 / (max - min);
326                 m_keyframeDefault = e.attribute("default").toDouble();
327                 m_selectedKeyframe = 0;
328                 m_editedKeyframe = -1;
329                 // parse keyframes
330                 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
331                 foreach(const QString &str, keyframes) {
332                     int pos = str.section(':', 0, 0).toInt();
333                     double val = str.section(':', 1, 1).toDouble();
334                     m_keyframes[pos] = val;
335                 }
336                 update();
337                 return;
338             }
339             break;
340         }
341     }
342 }
343
344
345 void ClipItem::setSelectedEffect(const int ix)
346 {
347     m_selectedEffect = ix;
348     QDomElement effect = effectAt(m_selectedEffect);
349     if (effect.isNull() == false) {
350         QDomNodeList params = effect.elementsByTagName("parameter");
351         if (effect.attribute("disabled") != "1")
352             for (int i = 0; i < params.count(); i++) {
353                 QDomElement e = params.item(i).toElement();
354                 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
355                     m_keyframes.clear();
356                     double max = e.attribute("max").toDouble();
357                     double min = e.attribute("min").toDouble();
358                     m_keyframeFactor = 100.0 / (max - min);
359                     m_keyframeDefault = e.attribute("default").toDouble();
360                     m_selectedKeyframe = 0;
361                     m_editedKeyframe = -1;
362                     // parse keyframes
363                     const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
364                     foreach(const QString &str, keyframes) {
365                         int pos = str.section(':', 0, 0).toInt();
366                         double val = str.section(':', 1, 1).toDouble();
367                         m_keyframes[pos] = val;
368                     }
369                     update();
370                     return;
371                 }
372             }
373     }
374     if (!m_keyframes.isEmpty()) {
375         m_keyframes.clear();
376         update();
377     }
378 }
379
380 QString ClipItem::keyframes(const int index)
381 {
382     QString result;
383     QDomElement effect = effectAt(index);
384     QDomNodeList params = effect.elementsByTagName("parameter");
385
386     for (int i = 0; i < params.count(); i++) {
387         QDomElement e = params.item(i).toElement();
388         if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
389             result = e.attribute("keyframes");
390             break;
391         }
392     }
393     return result;
394 }
395
396 void ClipItem::updateKeyframeEffect()
397 {
398     // regenerate xml parameter from the clip keyframes
399     QDomElement effect = getEffectAt(m_selectedEffect);
400     if (effect.attribute("disabled") == "1") return;
401     QDomNodeList params = effect.elementsByTagName("parameter");
402
403     for (int i = 0; i < params.count(); i++) {
404         QDomElement e = params.item(i).toElement();
405         if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
406             QString keyframes;
407             if (m_keyframes.count() > 0) {
408                 QMap<int, int>::const_iterator i = m_keyframes.constBegin();
409                 while (i != m_keyframes.constEnd()) {
410                     keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
411                     ++i;
412                 }
413             }
414             // Effect has a keyframe type parameter, we need to set the values
415             //kDebug() << ":::::::::::::::   SETTING EFFECT KEYFRAMES: " << keyframes;
416             e.setAttribute("keyframes", keyframes);
417             break;
418         }
419     }
420 }
421
422 QDomElement ClipItem::selectedEffect()
423 {
424     if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
425     return effectAt(m_selectedEffect);
426 }
427
428 void ClipItem::resetThumbs(bool clearExistingThumbs)
429 {
430     if (clearExistingThumbs) {
431         m_startPix = QPixmap();
432         m_endPix = QPixmap();
433         m_audioThumbCachePic.clear();
434     }
435     slotFetchThumbs();
436 }
437
438
439 void ClipItem::refreshClip(bool checkDuration)
440 {
441     if (checkDuration && (m_maxDuration != m_clip->maxDuration())) {
442         m_maxDuration = m_clip->maxDuration();
443         if (m_clipType != IMAGE && m_clipType != TEXT && m_clipType != COLOR) {
444             if (m_maxDuration != GenTime() && m_info.cropStart + m_info.cropDuration > m_maxDuration) {
445                 // Clip duration changed, make sure to stay in correct range
446                 if (m_info.cropStart > m_maxDuration) {
447                     m_info.cropStart = GenTime();
448                     m_info.cropDuration = qMin(m_info.cropDuration, m_maxDuration);
449                     updateRectGeometry();
450                 } else {
451                     m_info.cropDuration = m_maxDuration;
452                     updateRectGeometry();
453                 }
454             }
455         }
456     }
457     if (m_clipType == COLOR) {
458         QString colour = m_clip->getProperty("colour");
459         colour = colour.replace(0, 2, "#");
460         m_baseColor = QColor(colour.left(7));
461     } else resetThumbs(checkDuration);
462 }
463
464 void ClipItem::slotFetchThumbs()
465 {
466     if (scene() == NULL || m_clipType == AUDIO || m_clipType == COLOR) return;
467     if (m_clipType == IMAGE) {
468         if (m_startPix.isNull()) {
469             m_startPix = KThumb::getImage(KUrl(m_clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
470             update();
471         }
472         return;
473     }
474
475     if (m_clipType == TEXT) {
476         if (m_startPix.isNull()) slotGetStartThumb();
477         return;
478     }
479
480     if (m_endPix.isNull() && m_startPix.isNull()) {
481         m_startThumbRequested = true;
482         m_endThumbRequested = true;
483         emit getThumb((int)m_speedIndependantInfo.cropStart.frames(m_fps), (int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
484     } else {
485         if (m_endPix.isNull()) {
486             slotGetEndThumb();
487         }
488         if (m_startPix.isNull()) {
489             slotGetStartThumb();
490         }
491     }
492 }
493
494 void ClipItem::slotGetStartThumb()
495 {
496     m_startThumbRequested = true;
497     emit getThumb((int)m_speedIndependantInfo.cropStart.frames(m_fps), -1);
498 }
499
500 void ClipItem::slotGetEndThumb()
501 {
502     m_endThumbRequested = true;
503     emit getThumb(-1, (int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
504 }
505
506
507 void ClipItem::slotSetStartThumb(QImage img)
508 {
509     if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
510         QPixmap pix = QPixmap::fromImage(img);
511         m_startPix = pix;
512         QRectF r = sceneBoundingRect();
513         r.setRight(pix.width() + 2);
514         update(r);
515     }
516 }
517
518 void ClipItem::slotSetEndThumb(QImage img)
519 {
520     if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
521         QPixmap pix = QPixmap::fromImage(img);
522         m_endPix = pix;
523         QRectF r = sceneBoundingRect();
524         r.setLeft(r.right() - pix.width() - 2);
525         update(r);
526     }
527 }
528
529 void ClipItem::slotThumbReady(int frame, QImage img)
530 {
531     if (scene() == NULL) return;
532     QRectF r = boundingRect();
533     QPixmap pix = QPixmap::fromImage(img);
534     double width = pix.width() / projectScene()->scale().x();
535     if (m_startThumbRequested && frame == m_speedIndependantInfo.cropStart.frames(m_fps)) {
536         m_startPix = pix;
537         m_startThumbRequested = false;
538         update(r.left(), r.top(), width, pix.height());
539         if (m_clipType == IMAGE || m_clipType == TEXT) {
540             update(r.right() - width, r.top(), width, pix.height());
541         }
542     } else if (m_endThumbRequested && frame == (m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1) {
543         m_endPix = pix;
544         m_endThumbRequested = false;
545         update(r.right() - width, r.top(), width, pix.height());
546     }
547 }
548
549 void ClipItem::slotSetStartThumb(const QPixmap pix)
550 {
551     m_startPix = pix;
552 }
553
554 void ClipItem::slotSetEndThumb(const QPixmap pix)
555 {
556     m_endPix = pix;
557 }
558
559 QPixmap ClipItem::startThumb() const
560 {
561     return m_startPix;
562 }
563
564 QPixmap ClipItem::endThumb() const
565 {
566     return m_endPix;
567 }
568
569 void ClipItem::slotGotAudioData()
570 {
571     m_audioThumbReady = true;
572     if (m_clipType == AV && !isAudioOnly()) {
573         QRectF r = boundingRect();
574         r.setTop(r.top() + r.height() / 2 - 1);
575         update(r);
576     } else update();
577 }
578
579 int ClipItem::type() const
580 {
581     return AVWIDGET;
582 }
583
584 DocClipBase *ClipItem::baseClip() const
585 {
586     return m_clip;
587 }
588
589 QDomElement ClipItem::xml() const
590 {
591     QDomElement xml = m_clip->toXML();
592     if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
593     if (m_strobe > 1) xml.setAttribute("strobe", m_strobe);
594     if (m_audioOnly) xml.setAttribute("audio_only", 1);
595     else if (m_videoOnly) xml.setAttribute("video_only", 1);
596     return xml;
597 }
598
599 int ClipItem::clipType() const
600 {
601     return m_clipType;
602 }
603
604 QString ClipItem::clipName() const
605 {
606     return m_clipName;
607 }
608
609 void ClipItem::setClipName(const QString &name)
610 {
611     m_clipName = name;
612 }
613
614 const QString ClipItem::clipProducer() const
615 {
616     return m_producer;
617 }
618
619 void ClipItem::flashClip()
620 {
621     if (m_timeLine == 0) {
622         m_timeLine = new QTimeLine(750, this);
623         m_timeLine->setUpdateInterval(80);
624         m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
625         m_timeLine->setFrameRange(0, 100);
626         connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
627     }
628     //m_timeLine->start();
629 }
630
631 void ClipItem::animate(qreal /*value*/)
632 {
633     QRectF r = boundingRect();
634     r.setHeight(20);
635     update(r);
636 }
637
638 // virtual
639 void ClipItem::paint(QPainter *painter,
640                      const QStyleOptionGraphicsItem *option,
641                      QWidget *)
642 {
643     QColor paintColor;
644     if (parentItem()) paintColor = QColor(255, 248, 149);
645     else paintColor = m_baseColor;
646     if (isSelected() || (parentItem() && parentItem()->isSelected())) paintColor = paintColor.darker();
647
648     painter->setMatrixEnabled(false);
649     const QRectF mapped = painter->matrix().mapRect(rect()).adjusted(0.5, 0, 0.5, 0);
650     const QRectF exposed = option->exposedRect;
651     painter->setClipRect(mapped);
652     painter->fillRect(mapped, paintColor);
653
654     // draw thumbnails
655     if (KdenliveSettings::videothumbnails() && !isAudioOnly()) {
656         QPen pen = painter->pen();
657         pen.setColor(QColor(255, 255, 255, 150));
658         const QRectF source(0.0, 0.0, (double) m_startPix.width(), (double) m_startPix.height());
659         painter->setPen(pen);
660         if ((m_clipType == IMAGE || m_clipType == TEXT) && !m_startPix.isNull()) {
661             const QPointF top = mapped.topRight() - QPointF(m_startPix.width() - 1, 0);
662             painter->drawPixmap(top, m_startPix);
663             QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
664             painter->drawLine(l2);
665         } else if (!m_endPix.isNull()) {
666             const QPointF top = mapped.topRight() - QPointF(m_endPix.width() - 1, 0);
667             painter->drawPixmap(top, m_endPix);
668             QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
669             painter->drawLine(l2);
670         }
671         if (!m_startPix.isNull()) {
672             painter->drawPixmap(mapped.topLeft(), m_startPix);
673             QLineF l2(mapped.left() + m_startPix.width(), mapped.top(), mapped.left() + m_startPix.width(), mapped.bottom());
674             painter->drawLine(l2);
675         }
676         painter->setPen(Qt::black);
677     }
678
679     // draw audio thumbnails
680     if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (rect().height() / 2) || isAudioOnly())) || m_clipType == AUDIO) && m_audioThumbReady) {
681
682         double startpixel = exposed.left();
683         if (startpixel < 0)
684             startpixel = 0;
685         double endpixel = exposed.right();
686         if (endpixel < 0)
687             endpixel = 0;
688         //kDebug()<<"///  REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
689
690         /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
691         QRectF mappedRect;
692         if (m_clipType == AV && !isAudioOnly()) {
693             mappedRect = mapped;
694             mappedRect.setTop(mappedRect.bottom() - mapped.height() / 2);
695         } else mappedRect = mapped;
696
697         double scale = painter->matrix().m11();
698         int channels = baseClip()->getProperty("channels").toInt();
699         if (scale != m_framePixelWidth)
700             m_audioThumbCachePic.clear();
701         double cropLeft = m_info.cropStart.frames(m_fps);
702         const int clipStart = mappedRect.x();
703         const int mappedStartPixel =  painter->matrix().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
704         const int mappedEndPixel =  painter->matrix().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
705         cropLeft = cropLeft * scale;
706
707         if (channels >= 1) {
708             emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
709         }
710
711         for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
712             if (m_audioThumbCachePic.contains(startCache) && !m_audioThumbCachePic[startCache].isNull())
713                 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(),  m_audioThumbCachePic[startCache]);
714         }
715     }
716
717     // Draw effects names
718     if (!m_effectNames.isEmpty() && mapped.width() > 40) {
719         QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
720         QColor bgColor;
721         if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
722             qreal value = m_timeLine->currentValue();
723             txtBounding.setWidth(txtBounding.width() * value);
724             bgColor.setRgb(50 + 200 *(1.0 - value), 50, 50, 100 + 50 * value);
725         } else bgColor.setRgb(50, 50, 90, 180);
726
727         QPainterPath rounded;
728         rounded.moveTo(txtBounding.bottomRight());
729         rounded.arcTo(txtBounding.right() - txtBounding.height() - 2, txtBounding.top() - txtBounding.height(), txtBounding.height() * 2, txtBounding.height() * 2, 270, 90);
730         rounded.lineTo(txtBounding.topLeft());
731         rounded.lineTo(txtBounding.bottomLeft());
732         painter->fillPath(rounded, bgColor);
733         painter->setPen(Qt::lightGray);
734         painter->drawText(txtBounding.adjusted(1, 0, 1, 0), Qt::AlignCenter, m_effectNames);
735     }
736
737     // Draw clip name
738     QColor frameColor(paintColor.darker());
739     if (isSelected() || (parentItem() && parentItem()->isSelected())) {
740         frameColor = QColor(Qt::red);
741     }
742     frameColor.setAlpha(160);
743
744     const QRectF txtBounding2 = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, ' ' + m_clipName + ' ');
745     //painter->fillRect(txtBounding2, frameColor);
746     painter->setBrush(frameColor);
747     painter->setPen(Qt::NoPen);
748     painter->drawRoundedRect(txtBounding2, 3, 3);
749     painter->setBrush(QBrush(Qt::NoBrush));
750
751     //painter->setPen(QColor(0, 0, 0, 180));
752     //painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
753     if (m_videoOnly) {
754         painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_videoPix);
755     } else if (m_audioOnly) {
756         painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_audioPix);
757     }
758     painter->setPen(Qt::white);
759     painter->drawText(txtBounding2, Qt::AlignCenter, m_clipName);
760
761
762     // draw markers
763     QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
764     QList < CommentedTime >::Iterator it = markers.begin();
765     GenTime pos;
766     double framepos;
767     QBrush markerBrush(QColor(120, 120, 0, 140));
768     QPen pen = painter->pen();
769     pen.setColor(QColor(255, 255, 255, 200));
770     pen.setStyle(Qt::DotLine);
771
772     for (; it != markers.end(); ++it) {
773         pos = GenTime((int)((*it).time().frames(m_fps) / m_speed + 0.5), m_fps) - cropStart();
774         if (pos > GenTime()) {
775             if (pos > cropDuration()) break;
776             QLineF l(rect().x() + pos.frames(m_fps), rect().y(), rect().x() + pos.frames(m_fps), rect().bottom());
777             QLineF l2 = painter->matrix().map(l);
778             //framepos = scale * pos.frames(m_fps);
779             //QLineF l(framepos, 5, framepos, itemHeight - 5);
780             painter->setPen(pen);
781             painter->drawLine(l2);
782             if (KdenliveSettings::showmarkers()) {
783                 framepos = rect().x() + pos.frames(m_fps);
784                 const QRectF r1(framepos + 0.04, 10, rect().width() - framepos - 2, rect().height() - 10);
785                 const QRectF r2 = painter->matrix().mapRect(r1);
786                 const QRectF txtBounding3 = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, ' ' + (*it).comment() + ' ');
787                 painter->setBrush(markerBrush);
788                 painter->setPen(Qt::NoPen);
789                 painter->drawRoundedRect(txtBounding3, 3, 3);
790                 painter->setBrush(QBrush(Qt::NoBrush));
791                 painter->setPen(Qt::white);
792                 painter->drawText(txtBounding3, Qt::AlignCenter, (*it).comment());
793             }
794             //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
795         }
796     }
797
798     // draw start / end fades
799     QBrush fades;
800     if (isSelected()) {
801         fades = QBrush(QColor(200, 50, 50, 150));
802     } else fades = QBrush(QColor(200, 200, 200, 200));
803
804     if (m_startFade != 0) {
805         QPainterPath fadeInPath;
806         fadeInPath.moveTo(0, 0);
807         fadeInPath.lineTo(0, rect().height());
808         fadeInPath.lineTo(m_startFade, 0);
809         fadeInPath.closeSubpath();
810         QPainterPath f1 = painter->matrix().map(fadeInPath);
811         painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
812         /*if (isSelected()) {
813             QLineF l(m_startFade * scale, 0, 0, itemHeight);
814             painter->drawLine(l);
815         }*/
816     }
817     if (m_endFade != 0) {
818         QPainterPath fadeOutPath;
819         fadeOutPath.moveTo(rect().width(), 0);
820         fadeOutPath.lineTo(rect().width(), rect().height());
821         fadeOutPath.lineTo(rect().width() - m_endFade, 0);
822         fadeOutPath.closeSubpath();
823         QPainterPath f1 = painter->matrix().map(fadeOutPath);
824         painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
825         /*if (isSelected()) {
826             QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
827             painter->drawLine(l);
828         }*/
829     }
830
831
832     painter->setPen(QPen(Qt::lightGray));
833     // draw effect or transition keyframes
834     if (mapped.width() > 20) drawKeyFrames(painter, exposed);
835
836     //painter->setMatrixEnabled(true);
837
838     // draw clip border
839     // expand clip rect to allow correct painting of clip border
840     QPen pen1(frameColor);
841     painter->setPen(pen1);
842     painter->setClipping(false);
843     painter->drawRect(painter->matrix().mapRect(rect()));
844 }
845
846
847 OPERATIONTYPE ClipItem::operationMode(QPointF pos)
848 {
849     if (isItemLocked()) return NONE;
850     const double scale = projectScene()->scale().x();
851     double maximumOffset = 6 / scale;
852     if (isSelected() || (parentItem() && parentItem()->isSelected())) {
853         m_editedKeyframe = mouseOverKeyFrames(pos, maximumOffset);
854         if (m_editedKeyframe != -1) return KEYFRAME;
855     }
856     QRectF rect = sceneBoundingRect();
857     int addtransitionOffset = 10;
858     // Don't allow add transition if track height is very small
859     if (rect.height() < 30) addtransitionOffset = 0;
860
861     if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset  && qAbs((int)(pos.y() - rect.y())) < 6) {
862         if (m_startFade == 0) setToolTip(i18n("Add audio fade"));
863         // xgettext:no-c-format
864         else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_startFade, m_fps).seconds()));
865         return FADEIN;
866     } else if (pos.x() - rect.x() < maximumOffset && (rect.bottom() - pos.y() > addtransitionOffset)) {
867         // xgettext:no-c-format
868         setToolTip(i18n("Crop from start: %1s", cropStart().seconds()));
869         return RESIZESTART;
870     } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
871         if (m_endFade == 0) setToolTip(i18n("Add audio fade"));
872         // xgettext:no-c-format
873         else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
874         return FADEOUT;
875     } else if ((rect.right() - pos.x() < maximumOffset) && (rect.bottom() - pos.y() > addtransitionOffset)) {
876         // xgettext:no-c-format
877         setToolTip(i18n("Clip duration: %1s", cropDuration().seconds()));
878         return RESIZEEND;
879     } else if ((pos.x() - rect.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
880         setToolTip(i18n("Add transition"));
881         return TRANSITIONSTART;
882     } else if ((rect.right() - pos.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
883         setToolTip(i18n("Add transition"));
884         return TRANSITIONEND;
885     }
886     setToolTip(QString());
887     return MOVE;
888 }
889
890 QList <GenTime> ClipItem::snapMarkers() const
891 {
892     QList < GenTime > snaps;
893     QList < GenTime > markers = baseClip()->snapMarkers();
894     GenTime pos;
895
896     for (int i = 0; i < markers.size(); i++) {
897
898         pos = GenTime((int)(markers.at(i).frames(m_fps) / m_speed + 0.5), m_fps) - cropStart();
899         if (pos > GenTime()) {
900             if (pos > cropDuration()) break;
901             else snaps.append(pos + startPos());
902         }
903     }
904     return snaps;
905 }
906
907 QList <CommentedTime> ClipItem::commentedSnapMarkers() const
908 {
909     QList < CommentedTime > snaps;
910     QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
911     GenTime pos;
912
913     for (int i = 0; i < markers.size(); i++) {
914         pos = GenTime((int)(markers.at(i).time().frames(m_fps) / m_speed + 0.5), m_fps) - cropStart();
915         if (pos > GenTime()) {
916             if (pos > cropDuration()) break;
917             else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
918         }
919     }
920     return snaps;
921 }
922
923 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels)
924 {
925     QRectF re =  sceneBoundingRect();
926     if (m_clipType == AV && !isAudioOnly()) re.setTop(re.y() + re.height() / 2);
927
928     //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
929     //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
930
931     for (int startCache = startpixel - startpixel % 100; startCache < endpixel; startCache += 100) {
932         //kDebug() << "creating " << startCache;
933         //if (framePixelWidth!=pixelForOneFrame  ||
934         if (m_framePixelWidth == pixelForOneFrame && m_audioThumbCachePic.contains(startCache))
935             continue;
936         if (m_audioThumbCachePic[startCache].isNull() || m_framePixelWidth != pixelForOneFrame) {
937             m_audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
938             m_audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
939         }
940         bool fullAreaDraw = pixelForOneFrame < 10;
941         QMap<int, QPainterPath > positiveChannelPaths;
942         QMap<int, QPainterPath > negativeChannelPaths;
943         QPainter pixpainter(&m_audioThumbCachePic[startCache]);
944         QPen audiopen;
945         audiopen.setWidth(0);
946         pixpainter.setPen(audiopen);
947         //pixpainter.setRenderHint(QPainter::Antialiasing,true);
948         //pixpainter.drawLine(0,0,100,re.height());
949         // Bail out, if caller provided invalid data
950         if (channels <= 0) {
951             kWarning() << "Unable to draw image with " << channels << "number of channels";
952             return;
953         }
954
955         int channelHeight = m_audioThumbCachePic[startCache].height() / channels;
956
957         for (int i = 0; i < channels; i++) {
958
959             positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
960             negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
961         }
962
963         for (int samples = 0; samples <= 100; samples++) {
964             double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
965             int sample = (int)((frame - (int)(frame)) * 20);   // AUDIO_FRAME_SIZE
966             if (frame < 0 || sample < 0 || sample > 19)
967                 continue;
968             QMap<int, QByteArray> frame_channel_data = baseClip()->m_audioFrameCache[(int)frame];
969
970             for (int channel = 0; channel < channels && frame_channel_data[channel].size() > 0; channel++) {
971
972                 int y = channelHeight * channel + channelHeight / 2;
973                 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2)  * channelHeight / 64;
974                 if (fullAreaDraw) {
975                     positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
976                     negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
977                 } else {
978                     positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
979                     negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
980                 }
981             }
982             for (int channel = 0; channel < channels ; channel++)
983                 if (fullAreaDraw && samples == 100) {
984                     positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
985                     negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
986                     positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
987                     negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
988                 }
989
990         }
991         pixpainter.setPen(QPen(QColor(0, 0, 0)));
992         pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
993
994         for (int i = 0; i < channels; i++) {
995             if (fullAreaDraw) {
996                 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
997                 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
998             } else
999                 pixpainter.drawPath(positiveChannelPaths[i]);
1000         }
1001     }
1002     //audioThumbWasDrawn=true;
1003     m_framePixelWidth = pixelForOneFrame;
1004
1005     //}
1006 }
1007
1008 int ClipItem::fadeIn() const
1009 {
1010     return m_startFade;
1011 }
1012
1013 int ClipItem::fadeOut() const
1014 {
1015     return m_endFade;
1016 }
1017
1018
1019 void ClipItem::setFadeIn(int pos)
1020 {
1021     if (pos == m_startFade) return;
1022     int oldIn = m_startFade;
1023     if (pos < 0) pos = 0;
1024     if (pos > cropDuration().frames(m_fps)) pos = (int)(cropDuration().frames(m_fps));
1025     m_startFade = pos;
1026     QRectF rect = boundingRect();
1027     update(rect.x(), rect.y(), qMax(oldIn, pos), rect.height());
1028 }
1029
1030 void ClipItem::setFadeOut(int pos)
1031 {
1032     if (pos == m_endFade) return;
1033     int oldOut = m_endFade;
1034     if (pos < 0) pos = 0;
1035     if (pos > cropDuration().frames(m_fps)) pos = (int)(cropDuration().frames(m_fps));
1036     m_endFade = pos;
1037     QRectF rect = boundingRect();
1038     update(rect.x() + rect.width() - qMax(oldOut, pos), rect.y(), qMax(oldOut, pos), rect.height());
1039
1040 }
1041
1042 /*
1043 //virtual
1044 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
1045 {
1046     //if (e->pos().x() < 20) m_hover = true;
1047     return;
1048     if (isItemLocked()) return;
1049     m_hover = true;
1050     QRectF r = boundingRect();
1051     double width = 35 / projectScene()->scale().x();
1052     double height = r.height() / 2;
1053     //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1054     update(r.x(), r.y() + height, width, height);
1055     update(r.right() - width, r.y() + height, width, height);
1056 }
1057
1058 //virtual
1059 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
1060 {
1061     if (isItemLocked()) return;
1062     m_hover = false;
1063     QRectF r = boundingRect();
1064     double width = 35 / projectScene()->scale().x();
1065     double height = r.height() / 2;
1066     //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1067     update(r.x(), r.y() + height, width, height);
1068     update(r.right() - width, r.y() + height, width, height);
1069 }
1070 */
1071
1072 void ClipItem::resizeStart(int posx)
1073 {
1074     const int min = (startPos() - cropStart()).frames(m_fps);
1075     if (posx < min) posx = min;
1076     if (posx == startPos().frames(m_fps)) return;
1077     const int previous = cropStart().frames(m_fps);
1078     AbstractClipItem::resizeStart(posx);
1079
1080     // set speed independant info
1081     m_speedIndependantInfo = m_info;
1082     m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * m_speed), m_fps);
1083     m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * m_speed), m_fps);
1084
1085     if ((int) cropStart().frames(m_fps) != previous) {
1086         if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1087             m_startThumbTimer.start(150);
1088         }
1089     }
1090 }
1091
1092 void ClipItem::resizeEnd(int posx)
1093 {
1094     const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps);
1095     if (posx > max && maxDuration() != GenTime()) posx = max;
1096     if (posx == endPos().frames(m_fps)) return;
1097     //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
1098     const int previous = cropDuration().frames(m_fps);
1099     AbstractClipItem::resizeEnd(posx);
1100
1101     // set speed independant info
1102     m_speedIndependantInfo = m_info;
1103     m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * m_speed), m_fps);
1104     m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * m_speed), m_fps);
1105
1106     if ((int) cropDuration().frames(m_fps) != previous) {
1107         if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1108             m_endThumbTimer.start(150);
1109         }
1110     }
1111 }
1112
1113
1114 bool ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart)
1115 {
1116     bool modified = false;
1117     for (int i = 0; i < m_effectList.count(); i++) {
1118         QDomElement effect = m_effectList.at(i);
1119         QDomNodeList params = effect.elementsByTagName("parameter");
1120         for (int j = 0; j < params.count(); j++) {
1121             QDomElement e = params.item(i).toElement();
1122             if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1123                 // parse keyframes and adjust values
1124                 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1125                 QMap <int, double> kfr;
1126                 int pos;
1127                 double val;
1128                 foreach(const QString &str, keyframes) {
1129                     pos = str.section(':', 0, 0).toInt();
1130                     val = str.section(':', 1, 1).toDouble();
1131                     if (pos == previous) {
1132                         kfr[current] = val;
1133                         modified = true;
1134                     } else {
1135                         if ((fromStart && pos >= current) || (!fromStart && pos <= current)) {
1136                             kfr[pos] = val;
1137                             modified = true;
1138                         }
1139                     }
1140                 }
1141                 if (modified) {
1142                     QString newkfr;
1143                     QMap<int, double>::const_iterator k = kfr.constBegin();
1144                     while (k != kfr.constEnd()) {
1145                         newkfr.append(QString::number(k.key()) + ':' + QString::number(k.value()) + ';');
1146                         ++k;
1147                     }
1148                     e.setAttribute("keyframes", newkfr);
1149                     break;
1150                 }
1151             }
1152         }
1153     }
1154     if (modified && m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect);
1155     return modified;
1156 }
1157
1158 //virtual
1159 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
1160 {
1161     if (change == QGraphicsItem::ItemSelectedChange) {
1162         if (value.toBool()) setZValue(10);
1163         else setZValue(2);
1164     }
1165     if (change == ItemPositionChange && scene()) {
1166         // calculate new position.
1167         //if (parentItem()) return pos();
1168         QPointF newPos = value.toPointF();
1169         //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1170         int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1171         xpos = qMax(xpos, 0);
1172         newPos.setX(xpos);
1173         int newTrack = newPos.y() / KdenliveSettings::trackheight();
1174         newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1175         newTrack = qMax(newTrack, 0);
1176         newPos.setY((int)(newTrack  * KdenliveSettings::trackheight() + 1));
1177         // Only one clip is moving
1178         QRectF sceneShape = rect();
1179         sceneShape.translate(newPos);
1180         QList<QGraphicsItem*> items;
1181         if (projectScene()->editMode() == NORMALEDIT)
1182             items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1183         items.removeAll(this);
1184         bool forwardMove = newPos.x() > pos().x();
1185         int offset = 0;
1186         if (!items.isEmpty()) {
1187             for (int i = 0; i < items.count(); i++) {
1188                 if (!items.at(i)->isEnabled()) continue;
1189                 if (items.at(i)->type() == type()) {
1190                     // Collision!
1191                     QPointF otherPos = items.at(i)->pos();
1192                     if ((int) otherPos.y() != (int) pos().y()) {
1193                         return pos();
1194                     }
1195                     if (forwardMove) {
1196                         offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
1197                     } else {
1198                         offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1199                     }
1200
1201                     if (offset > 0) {
1202                         if (forwardMove) {
1203                             sceneShape.translate(QPointF(-offset, 0));
1204                             newPos.setX(newPos.x() - offset);
1205                         } else {
1206                             sceneShape.translate(QPointF(offset, 0));
1207                             newPos.setX(newPos.x() + offset);
1208                         }
1209                         QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1210                         subitems.removeAll(this);
1211                         for (int j = 0; j < subitems.count(); j++) {
1212                             if (!subitems.at(j)->isEnabled()) continue;
1213                             if (subitems.at(j)->type() == type()) {
1214                                 // move was not successful, revert to previous pos
1215                                 m_info.startPos = GenTime((int) pos().x(), m_fps);
1216                                 return pos();
1217                             }
1218                         }
1219                     }
1220
1221                     m_info.track = newTrack;
1222                     m_info.startPos = GenTime((int) newPos.x(), m_fps);
1223
1224                     return newPos;
1225                 }
1226             }
1227         }
1228         m_info.track = newTrack;
1229         m_info.startPos = GenTime((int) newPos.x(), m_fps);
1230         //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1231         return newPos;
1232     }
1233     return QGraphicsItem::itemChange(change, value);
1234 }
1235
1236 // virtual
1237 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1238 }*/
1239
1240 int ClipItem::effectsCounter()
1241 {
1242     return effectsCount() + 1;
1243 }
1244
1245 int ClipItem::effectsCount()
1246 {
1247     return m_effectList.count();
1248 }
1249
1250 int ClipItem::hasEffect(const QString &tag, const QString &id) const
1251 {
1252     return m_effectList.hasEffect(tag, id);
1253 }
1254
1255 QStringList ClipItem::effectNames()
1256 {
1257     return m_effectList.effectNames();
1258 }
1259
1260 QDomElement ClipItem::effectAt(int ix) const
1261 {
1262     if (ix > m_effectList.count() - 1 || ix < 0 || m_effectList.at(ix).isNull()) return QDomElement();
1263     return m_effectList.at(ix).cloneNode().toElement();
1264 }
1265
1266 QDomElement ClipItem::getEffectAt(int ix) const
1267 {
1268     if (ix > m_effectList.count() - 1 || ix < 0 || m_effectList.at(ix).isNull()) return QDomElement();
1269     return m_effectList.at(ix);
1270 }
1271
1272 void ClipItem::setEffectAt(int ix, QDomElement effect)
1273 {
1274     if (ix < 0 || ix > (m_effectList.count() - 1) || effect.isNull()) {
1275         kDebug() << "Invalid effect index: " << ix;
1276         return;
1277     }
1278     //kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1279     effect.setAttribute("kdenlive_ix", ix + 1);
1280     m_effectList.replace(ix, effect);
1281     m_effectNames = m_effectList.effectNames().join(" / ");
1282     QString id = effect.attribute("id");
1283     if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1284         update();
1285     else {
1286         QRectF r = boundingRect();
1287         r.setHeight(20);
1288         update(r);
1289     }
1290 }
1291
1292 EffectsParameterList ClipItem::addEffect(const QDomElement effect, bool /*animate*/)
1293 {
1294     bool needRepaint = false;
1295     int ix;
1296     if (!effect.hasAttribute("kdenlive_ix")) {
1297         ix = effectsCounter();
1298     } else ix = effect.attribute("kdenlive_ix").toInt();
1299     if (!m_effectList.isEmpty() && ix <= m_effectList.count()) {
1300         needRepaint = true;
1301         m_effectList.insert(ix - 1, effect);
1302         for (int i = ix; i < m_effectList.count(); i++) {
1303             int index = m_effectList.item(i).attribute("kdenlive_ix").toInt();
1304             if (index >= ix) m_effectList.item(i).setAttribute("kdenlive_ix", index + 1);
1305         }
1306     } else m_effectList.append(effect);
1307     EffectsParameterList parameters;
1308     parameters.addParam("tag", effect.attribute("tag"));
1309     parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1310     if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1311     if (effect.hasAttribute("disabled")) parameters.addParam("disabled", effect.attribute("disabled"));
1312
1313
1314     QString effectId = effect.attribute("id");
1315     if (effectId.isEmpty()) effectId = effect.attribute("tag");
1316     parameters.addParam("id", effectId);
1317
1318     QDomNodeList params = effect.elementsByTagName("parameter");
1319     int fade = 0;
1320     for (int i = 0; i < params.count(); i++) {
1321         QDomElement e = params.item(i).toElement();
1322         if (!e.isNull()) {
1323             if (e.attribute("type") == "simplekeyframe") {
1324                 QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
1325                 double factor = e.attribute("factor", "1").toDouble();
1326                 if (factor != 1) {
1327                     for (int j = 0; j < values.count(); j++) {
1328                         QString pos = values.at(j).section(":", 0, 0);
1329                         double val = values.at(j).section(":", 1, 1).toDouble() / factor;
1330                         values[j] = pos + "=" + QString::number(val);
1331                     }
1332                 }
1333                 parameters.addParam(e.attribute("name"), values.join(";"));
1334                 /*parameters.addParam("max", e.attribute("max"));
1335                 parameters.addParam("min", e.attribute("min"));
1336                 parameters.addParam("factor", );*/
1337             } else if (e.attribute("type") == "keyframe") {
1338                 parameters.addParam("keyframes", e.attribute("keyframes"));
1339                 parameters.addParam("max", e.attribute("max"));
1340                 parameters.addParam("min", e.attribute("min"));
1341                 parameters.addParam("factor", e.attribute("factor", "1"));
1342                 parameters.addParam("starttag", e.attribute("starttag", "start"));
1343                 parameters.addParam("endtag", e.attribute("endtag", "end"));
1344             } else if (e.attribute("factor", "1") == "1") {
1345                 parameters.addParam(e.attribute("name"), e.attribute("value"));
1346
1347                 // check if it is a fade effect
1348                 if (effectId == "fadein") {
1349                     needRepaint = true;
1350                     if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
1351                         if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1352                         else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1353                     } else {
1354                         QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
1355                         if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1356                         else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1357                     }
1358                 } else if (effectId == "fade_from_black") {
1359                     needRepaint = true;
1360                     if (m_effectList.hasEffect(QString(), "fadein") == -1) {
1361                         if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1362                         else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1363                     } else {
1364                         QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
1365                         if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1366                         else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1367                     }
1368                 } else if (effectId == "fadeout") {
1369                     needRepaint = true;
1370                     if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
1371                         if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1372                         else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1373                     } else {
1374                         QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
1375                         if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1376                         else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1377                     }
1378                 } else if (effectId == "fade_to_black") {
1379                     needRepaint = true;
1380                     if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
1381                         if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1382                         else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1383                     } else {
1384                         QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
1385                         if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1386                         else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1387                     }
1388                 }
1389             } else {
1390                 double fact;
1391                 if (e.attribute("factor").startsWith('%')) {
1392                     fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor"));
1393                 } else fact = e.attribute("factor", "1").toDouble();
1394                 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact));
1395             }
1396         }
1397     }
1398     m_effectNames = m_effectList.effectNames().join(" / ");
1399     if (fade > 0) m_startFade = fade;
1400     else if (fade < 0) m_endFade = -fade;
1401
1402     if (m_selectedEffect == -1) {
1403         setSelectedEffect(0);
1404     } else if (m_selectedEffect == ix - 1) setSelectedEffect(m_selectedEffect);
1405     if (needRepaint) update(boundingRect());
1406     /*if (animate) {
1407         flashClip();
1408     } */
1409     else { /*if (!needRepaint) */
1410         QRectF r = boundingRect();
1411         r.setHeight(20);
1412         update(r);
1413     }
1414     return parameters;
1415 }
1416
1417 EffectsParameterList ClipItem::getEffectArgs(const QDomElement effect)
1418 {
1419     EffectsParameterList parameters;
1420     parameters.addParam("tag", effect.attribute("tag"));
1421     parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1422     parameters.addParam("id", effect.attribute("id"));
1423     if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1424     if (effect.hasAttribute("disabled")) parameters.addParam("disabled", effect.attribute("disabled"));
1425
1426     QDomNodeList params = effect.elementsByTagName("parameter");
1427     for (int i = 0; i < params.count(); i++) {
1428         QDomElement e = params.item(i).toElement();
1429         //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
1430         if (e.attribute("type") == "simplekeyframe") {
1431
1432             QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
1433             double factor = e.attribute("factor", "1").toDouble();
1434             for (int j = 0; j < values.count(); j++) {
1435                 QString pos = values.at(j).section(":", 0, 0);
1436                 double val = values.at(j).section(":", 1, 1).toDouble() / factor;
1437                 values[j] = pos + "=" + QString::number(val);
1438             }
1439             // kDebug() << "/ / / /SENDING KEYFR:" << values;
1440             parameters.addParam(e.attribute("name"), values.join(";"));
1441             /*parameters.addParam(e.attribute("name"), e.attribute("keyframes").replace(":", "="));
1442             parameters.addParam("max", e.attribute("max"));
1443             parameters.addParam("min", e.attribute("min"));
1444             parameters.addParam("factor", e.attribute("factor", "1"));*/
1445         } else if (e.attribute("type") == "keyframe") {
1446             kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
1447             parameters.addParam("keyframes", e.attribute("keyframes"));
1448             parameters.addParam("max", e.attribute("max"));
1449             parameters.addParam("min", e.attribute("min"));
1450             parameters.addParam("factor", e.attribute("factor", "1"));
1451             parameters.addParam("starttag", e.attribute("starttag", "start"));
1452             parameters.addParam("endtag", e.attribute("endtag", "end"));
1453         } else if (e.attribute("namedesc").contains(';')) {
1454             QString format = e.attribute("format");
1455             QStringList separators = format.split("%d", QString::SkipEmptyParts);
1456             QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1457             QString neu;
1458             QTextStream txtNeu(&neu);
1459             if (values.size() > 0)
1460                 txtNeu << (int)values[0].toDouble();
1461             for (int i = 0; i < separators.size() && i + 1 < values.size(); i++) {
1462                 txtNeu << separators[i];
1463                 txtNeu << (int)(values[i+1].toDouble());
1464             }
1465             parameters.addParam("start", neu);
1466         } else {
1467             if (e.attribute("factor", "1") != "1") {
1468                 double fact;
1469                 if (e.attribute("factor").startsWith('%')) {
1470                     fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor"));
1471                 } else fact = e.attribute("factor", "1").toDouble();
1472                 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact));
1473             } else {
1474                 parameters.addParam(e.attribute("name"), e.attribute("value"));
1475             }
1476         }
1477     }
1478     return parameters;
1479 }
1480
1481 void ClipItem::deleteEffect(QString index)
1482 {
1483     bool needRepaint = false;
1484     QString ix;
1485
1486     for (int i = 0; i < m_effectList.count(); ++i) {
1487         ix = m_effectList.at(i).attribute("kdenlive_ix");
1488         if (ix == index) {
1489             QString effectId = m_effectList.at(i).attribute("id");
1490             if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
1491                     (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
1492                 m_startFade = 0;
1493                 needRepaint = true;
1494             } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
1495                        (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
1496                 m_endFade = 0;
1497                 needRepaint = true;
1498             } else if (EffectsList::hasKeyFrames(m_effectList.at(i))) needRepaint = true;
1499             m_effectList.removeAt(i);
1500             i--;
1501         } else if (ix.toInt() > index.toInt()) {
1502             m_effectList.item(i).setAttribute("kdenlive_ix", ix.toInt() - 1);
1503         }
1504     }
1505     m_effectNames = m_effectList.effectNames().join(" / ");
1506
1507     if (m_effectList.isEmpty() || m_selectedEffect + 1 == index.toInt()) {
1508         // Current effect was removed
1509         if (index.toInt() > m_effectList.count() - 1) {
1510             setSelectedEffect(m_effectList.count() - 1);
1511         } else setSelectedEffect(index.toInt());
1512     }
1513     if (needRepaint) update(boundingRect());
1514     else {
1515         QRectF r = boundingRect();
1516         r.setHeight(20);
1517         update(r);
1518     }
1519     //if (!m_effectList.isEmpty()) flashClip();
1520 }
1521
1522 double ClipItem::speed() const
1523 {
1524     return m_speed;
1525 }
1526
1527 int ClipItem::strobe() const
1528 {
1529     return m_strobe;
1530 }
1531
1532 void ClipItem::setSpeed(const double speed, const int strobe)
1533 {
1534     m_speed = speed;
1535     m_strobe = strobe;
1536     if (m_speed == 1.0) m_clipName = baseClip()->name();
1537     else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
1538     m_info.cropStart = GenTime((int)(m_speedIndependantInfo.cropStart.frames(m_fps) / m_speed + 0.5), m_fps);
1539     m_info.cropDuration = GenTime((int)(m_speedIndependantInfo.cropDuration.frames(m_fps) / m_speed + 0.5), m_fps);
1540     //update();
1541 }
1542
1543 GenTime ClipItem::maxDuration() const
1544 {
1545     return GenTime((int)(m_maxDuration.frames(m_fps) / m_speed + 0.5), m_fps);
1546 }
1547
1548 GenTime ClipItem::speedIndependantCropStart() const
1549 {
1550     return m_speedIndependantInfo.cropStart;
1551 }
1552
1553 GenTime ClipItem::speedIndependantCropDuration() const
1554 {
1555     return m_speedIndependantInfo.cropDuration;
1556 }
1557
1558
1559 const ItemInfo ClipItem::speedIndependantInfo() const
1560 {
1561     return m_speedIndependantInfo;
1562 }
1563
1564 //virtual
1565 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
1566 {
1567     const QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
1568     QDomDocument doc;
1569     doc.setContent(effects, true);
1570     const QDomElement e = doc.documentElement();
1571     if (scene() && !scene()->views().isEmpty()) {
1572         event->accept();
1573         CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1574         if (view) view->slotAddEffect(e, m_info.startPos, track());
1575     }
1576 }
1577
1578 //virtual
1579 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
1580 {
1581     if (isItemLocked()) event->setAccepted(false);
1582     else event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
1583 }
1584
1585 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
1586 {
1587     Q_UNUSED(event);
1588 }
1589
1590 void ClipItem::addTransition(Transition* t)
1591 {
1592     m_transitionsList.append(t);
1593     //CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1594     QDomDocument doc;
1595     QDomElement e = doc.documentElement();
1596     //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1597 }
1598
1599 void ClipItem::setVideoOnly(bool force)
1600 {
1601     m_videoOnly = force;
1602 }
1603
1604 void ClipItem::setAudioOnly(bool force)
1605 {
1606     m_audioOnly = force;
1607     if (m_audioOnly) m_baseColor = QColor(141, 215, 166);
1608     else {
1609         if (m_clipType == COLOR) {
1610             QString colour = m_clip->getProperty("colour");
1611             colour = colour.replace(0, 2, "#");
1612             m_baseColor = QColor(colour.left(7));
1613         } else if (m_clipType == AUDIO) m_baseColor = QColor(141, 215, 166);
1614         else m_baseColor = QColor(141, 166, 215);
1615     }
1616     m_audioThumbCachePic.clear();
1617 }
1618
1619 bool ClipItem::isAudioOnly() const
1620 {
1621     return m_audioOnly;
1622 }
1623
1624 bool ClipItem::isVideoOnly() const
1625 {
1626     return m_videoOnly;
1627 }
1628
1629
1630 #include "clipitem.moc"