#include <QGraphicsScene>
#include <QMimeData>
-ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, bool generateThumbs)
- : AbstractClipItem(info, QRectF(), fps), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_startThumbRequested(false), m_endThumbRequested(false), m_startFade(0), m_endFade(0), m_hover(false), m_selectedEffect(-1), m_speed(speed), framePixelWidth(0), m_startPix(QPixmap()), m_endPix(QPixmap()), m_videoOnly(false), m_audioOnly(false)
+ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, bool generateThumbs) :
+ AbstractClipItem(info, QRectF(), fps),
+ m_clip(clip),
+ m_resizeMode(NONE),
+ m_startFade(0),
+ m_endFade(0),
+ m_audioOnly(false),
+ m_videoOnly(false),
+ m_startPix(QPixmap()),
+ m_endPix(QPixmap()),
+ m_hasThumbs(false),
+ m_startThumbTimer(NULL),
+ m_endThumbTimer(NULL),
+ m_selectedEffect(-1),
+ m_timeLine(0),
+ m_startThumbRequested(false),
+ m_endThumbRequested(false),
+ m_hover(false),
+ m_speed(speed),
+ m_framePixelWidth(0)
{
setZValue(1);
setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double)(KdenliveSettings::trackheight() - 2));
m_cropStart = info.cropStart;
m_maxDuration = clip->maxDuration();
setAcceptDrops(true);
- audioThumbReady = clip->audioThumbCreated();
+ m_audioThumbReady = clip->audioThumbCreated();
/*
m_cropStart = xml.attribute("in", 0).toInt();
if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
setBrush(QColor(141, 166, 215));
m_hasThumbs = true;
- startThumbTimer = new QTimer(this);
- startThumbTimer->setSingleShot(true);
- connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
- endThumbTimer = new QTimer(this);
- endThumbTimer->setSingleShot(true);
- connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
+ m_startThumbTimer = new QTimer(this);
+ m_startThumbTimer->setSingleShot(true);
+ connect(m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
+ m_endThumbTimer = new QTimer(this);
+ m_endThumbTimer->setSingleShot(true);
+ connect(m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
//connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(getVideoThumbs(int, int)));
ClipItem::~ClipItem()
{
- if (startThumbTimer) delete startThumbTimer;
- if (endThumbTimer) delete endThumbTimer;
- if (m_timeLine) delete m_timeLine;
+ delete m_startThumbTimer;
+ delete m_endThumbTimer;
+ delete m_timeLine;
}
ClipItem *ClipItem::clone(ItemInfo info) const
if (info.cropStart + (info.endPos - info.startPos) == m_cropStart + m_cropDuration) duplicate->slotSetEndThumb(m_endPix);
kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
duplicate->setEffectList(m_effectList.clone());
+ duplicate->setVideoOnly(m_videoOnly);
+ duplicate->setAudioOnly(m_audioOnly);
//duplicate->setSpeed(m_speed);
return duplicate;
}
m_startPix = QPixmap();
m_endPix = QPixmap();
slotFetchThumbs();
- audioThumbCachePic.clear();
+ m_audioThumbCachePic.clear();
}
-void ClipItem::refreshClip()
+void ClipItem::refreshClip(bool checkDuration)
{
- m_maxDuration = m_clip->maxDuration();
+ if (checkDuration && (m_maxDuration != m_clip->maxDuration())) {
+ m_maxDuration = m_clip->maxDuration();
+ if (m_clipType != IMAGE && m_clipType != TEXT && m_clipType != COLOR) {
+ if (m_cropStart + m_cropDuration > m_maxDuration) {
+ // Clip duration changed, make sure to stay in correct range
+ if (m_cropStart > m_maxDuration) {
+ m_cropStart = GenTime();
+ m_cropDuration = qMin(m_cropDuration, m_maxDuration);
+ updateRectGeometry();
+ } else {
+ m_cropDuration = m_maxDuration;
+ updateRectGeometry();
+ }
+ }
+ }
+ }
if (m_clipType == COLOR) {
QString colour = m_clip->getProperty("colour");
colour = colour.replace(0, 2, "#");
void ClipItem::slotGotAudioData()
{
- audioThumbReady = true;
+ m_audioThumbReady = true;
if (m_clipType == AV && !isAudioOnly()) {
QRectF r = boundingRect();
r.setTop(r.top() + r.height() / 2 - 1);
{
QDomElement xml = m_clip->toXML();
if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
+ if (m_audioOnly) xml.setAttribute("audio_only", 1);
+ else if (m_videoOnly) xml.setAttribute("video_only", 1);
return xml;
}
}
// draw audio thumbnails
- if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (itemHeight / 2) || isAudioOnly())) || m_clipType == AUDIO) && audioThumbReady) {
+ if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (itemHeight / 2) || isAudioOnly())) || m_clipType == AUDIO) && m_audioThumbReady) {
double startpixel = exposed.left();
if (startpixel < 0)
} else mappedRect = mapped;
int channels = baseClip()->getProperty("channels").toInt();
- if (scale != framePixelWidth)
- audioThumbCachePic.clear();
+ if (scale != m_framePixelWidth)
+ m_audioThumbCachePic.clear();
double cropLeft = m_cropStart.frames(m_fps);
const int clipStart = mappedRect.x();
const int mappedStartPixel = painter->matrix().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
}
for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
- if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
- painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), audioThumbCachePic[startCache]);
+ if (m_audioThumbCachePic.contains(startCache) && !m_audioThumbCachePic[startCache].isNull())
+ painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), m_audioThumbCachePic[startCache]);
}
}
for (int startCache = startpixel - startpixel % 100;startCache < endpixel;startCache += 100) {
//kDebug() << "creating " << startCache;
//if (framePixelWidth!=pixelForOneFrame ||
- if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
+ if (m_framePixelWidth == pixelForOneFrame && m_audioThumbCachePic.contains(startCache))
continue;
- if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
- audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
- audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
+ if (m_audioThumbCachePic[startCache].isNull() || m_framePixelWidth != pixelForOneFrame) {
+ m_audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
+ m_audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
}
bool fullAreaDraw = pixelForOneFrame < 10;
QMap<int, QPainterPath > positiveChannelPaths;
QMap<int, QPainterPath > negativeChannelPaths;
- QPainter pixpainter(&audioThumbCachePic[startCache]);
+ QPainter pixpainter(&m_audioThumbCachePic[startCache]);
QPen audiopen;
audiopen.setWidth(0);
pixpainter.setPen(audiopen);
return;
}
- int channelHeight = audioThumbCachePic[startCache].height() / channels;
+ int channelHeight = m_audioThumbCachePic[startCache].height() / channels;
for (int i = 0;i < channels;i++) {
int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
if (frame < 0 || sample < 0 || sample > 19)
continue;
- QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
+ QMap<int, QByteArray> frame_channel_data = baseClip()->m_audioFrameCache[(int)frame];
for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
}
}
//audioThumbWasDrawn=true;
- framePixelWidth = pixelForOneFrame;
+ m_framePixelWidth = pixelForOneFrame;
//}
}
-uint ClipItem::fadeIn() const
+int ClipItem::fadeIn() const
{
return m_startFade;
}
-uint ClipItem::fadeOut() const
+int ClipItem::fadeOut() const
{
return m_endFade;
}
checkEffectsKeyframesPos(previous, cropStart().frames(m_fps), true);
if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
/*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
- startThumbTimer->start(150);
+ m_startThumbTimer->start(150);
}
}
}
if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
/*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
- endThumbTimer->start(150);
+ m_endThumbTimer->start(150);
}
}
}
m_audioOnly = force;
if (m_audioOnly) setBrush(QColor(141, 215, 166));
else setBrush(QColor(141, 166, 215));
- audioThumbCachePic.clear();
+ m_audioThumbCachePic.clear();
}
bool ClipItem::isAudioOnly() const
}
-// virtual
-/*
-void CustomTrackView::mousePressEvent ( QMouseEvent * event )
-{
- int pos = event->x();
- if (event->modifiers() == Qt::ControlModifier)
- setDragMode(QGraphicsView::ScrollHandDrag);
- else if (event->modifiers() == Qt::ShiftModifier)
- setDragMode(QGraphicsView::RubberBandDrag);
- else {
- QGraphicsItem * item = itemAt(event->pos());
- if (item) {
- }
- else emit cursorMoved((int) mapToScene(event->x(), 0).x());
- }
- kDebug()<<pos;
- QGraphicsView::mousePressEvent(event);
-}
-
-void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
-{
- QGraphicsView::mouseReleaseEvent(event);
- setDragMode(QGraphicsView::NoDrag);
-}
-*/
-
#include "clipitem.moc"