setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
+ setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
#endif
}
setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
}
-void AbstractClipItem::resizeStart(int posx)
+void AbstractClipItem::resizeStart(int posx, bool hasSizeLimit)
{
GenTime durationDiff = GenTime(posx, m_fps) - m_info.startPos;
if (durationDiff == GenTime()) return;
//kDebug() << "-- RESCALE DIFF=" << durationDiff.frames(25) << ", CLIP: " << startPos().frames(25) << "-" << endPos().frames(25);
- if (type() == AVWIDGET && cropStart() + durationDiff < GenTime()) {
+ if (type() == AVWIDGET && hasSizeLimit && (cropStart() + durationDiff < GenTime())) {
durationDiff = GenTime() - cropStart();
} else if (durationDiff >= cropDuration()) {
return;
- if (cropDuration() > GenTime(3, m_fps)) durationDiff = GenTime(3, m_fps);
- else return;
+ /*if (cropDuration() > GenTime(3, m_fps)) durationDiff = GenTime(3, m_fps);
+ else return;*/
}
- //kDebug()<<"// DURATION DIFF: "<<durationDiff.frames(25)<<", POS: "<<pos().x();
m_info.startPos += durationDiff;
+ // set to true if crop from start is negative (possible for color clips, images as they have no size limit)
+ bool negCropStart = false;
if (type() == AVWIDGET) {
m_info.cropStart += durationDiff;
+ if (m_info.cropStart < GenTime())
+ negCropStart = true;
}
- m_info.cropDuration = m_info.cropDuration - durationDiff;
+ m_info.cropDuration -= durationDiff;
setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
moveBy(durationDiff.frames(m_fps), 0);
if (m_info.startPos != GenTime(posx, m_fps)) {
- kDebug() << "__ RESIZE START OFFSET: ";
- //kDebug()<<"////// WARNING, DIFF IN XPOS: "<<pos().x()<<" == "<<m_startPos.frames(m_fps);
- GenTime diff = m_info.startPos - GenTime((int) posx, m_fps);
+ //kDebug() << "////// WARNING, DIFF IN XPOS: " << pos().x() << " == " << m_info.startPos.frames(m_fps);
+ GenTime diff = m_info.startPos - GenTime(posx, m_fps);
- if (type() == AVWIDGET) {
+ if (type() == AVWIDGET)
m_info.cropStart += diff;
- }
- m_info.cropDuration = m_info.cropDuration - diff;
+
+ m_info.cropDuration -= diff;
setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
//kDebug()<<"// NEW START: "<<m_startPos.frames(25)<<", NW DUR: "<<m_cropDuration.frames(25);
}
+ // set crop from start to 0 (isn't relevant as this only happens for color clips, images)
+ if (negCropStart)
+ m_info.cropStart = GenTime();
//kDebug() << "-- NEW CLIP=" << startPos().frames(25) << "-" << endPos().frames(25);
//setRect((double) m_startPos.frames(m_fps) * scale, rect().y(), (double) m_cropDuration.frames(m_fps) * scale, rect().height());
}
m_info.cropDuration += durationDiff;
+ m_info.endPos += durationDiff;
setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
if (durationDiff > GenTime()) {
void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/)
{
- if (m_keyframes.count() < 2) return;
+ if (m_keyframes.count() < 1)
+ return;
QRectF br = rect();
double maxw = br.width() / cropDuration().frames(m_fps);
double maxh = br.height() / 100.0 * m_keyframeFactor;
y1 = br.bottom() - i.value() * maxh;
QLineF l2;
while (i != m_keyframes.constEnd()) {
- if (i.key() == m_selectedKeyframe) color = QColor(Qt::red);
- else color = QColor(Qt::blue);
+ if (i.key() == m_editedKeyframe)
+ color = QColor(Qt::red);
+ else
+ color = QColor(Qt::blue);
++i;
- if (i == m_keyframes.constEnd()) break;
- x2 = br.x() + maxw * (i.key() - cropStart().frames(m_fps));
- y2 = br.bottom() - i.value() * maxh;
+ if (i == m_keyframes.constEnd() && m_keyframes.count() != 1)
+ break;
+
+ if (m_keyframes.count() == 1) {
+ x2 = br.right();
+ y2 = y1;
+ } else {
+ x2 = br.x() + maxw * (i.key() - cropStart().frames(m_fps));
+ y2 = br.bottom() - i.value() * maxh;
+ }
QLineF l(x1, y1, x2, y2);
l2 = painter->matrix().map(l);
painter->drawLine(l2);
const QRectF br = sceneBoundingRect();
double maxw = br.width() / cropDuration().frames(m_fps);
double maxh = br.height() / 100.0 * m_keyframeFactor;
- if (m_keyframes.count() > 1) {
+ if (m_keyframes.count() > 0) {
QMap<int, int>::const_iterator i = m_keyframes.constBegin();
double x1;
double y1;
if (qAbs(pos.x() - x1) < maxOffset && qAbs(pos.y() - y1) < 10) {
setToolTip('[' + QString::number((GenTime(i.key(), m_fps) - cropStart()).seconds(), 'f', 2) + i18n("seconds") + ", " + QString::number(i.value(), 'f', 1) + "%]");
return i.key();
- } else if (x1 > pos.x()) break;
+ } else if (x1 > pos.x()) {
+ break;
+ }
++i;
}
}
void AbstractClipItem::updateSelectedKeyFrame()
{
- if (m_editedKeyframe == -1) return;
+ if (m_editedKeyframe == -1)
+ return;
QRectF br = sceneBoundingRect();
double maxw = br.width() / cropDuration().frames(m_fps);
double maxh = br.height() / 100.0 * m_keyframeFactor;
update(br.x() + maxw *(m_selectedKeyframe - cropStart().frames(m_fps)) - 3, br.bottom() - m_keyframes[m_selectedKeyframe] * maxh - 3, 12, 12);
}
-int AbstractClipItem::selectedKeyFramePos() const
+int AbstractClipItem::editedKeyFramePos() const
{
return m_editedKeyframe;
}
+double AbstractClipItem::editedKeyFrameValue() const
+{
+ return m_keyframes.value(m_editedKeyframe);
+}
+
+int AbstractClipItem::selectedKeyFramePos() const
+{
+ return m_selectedKeyframe;
+}
+
double AbstractClipItem::selectedKeyFrameValue() const
{
- return m_keyframes[m_editedKeyframe];
+ return m_keyframes.value(m_selectedKeyframe);
}
void AbstractClipItem::updateKeyFramePos(const GenTime pos, const double value)
{
- if (!m_keyframes.contains(m_selectedKeyframe)) return;
- int newpos = (int) pos.frames(m_fps);
- int start = cropStart().frames(m_fps);
- int end = (cropStart() + cropDuration()).frames(m_fps) - 1;
- newpos = qMax(newpos, start);
- newpos = qMin(newpos, end);
- if (value < -50 && m_selectedKeyframe != start && m_selectedKeyframe != end) {
- // remove kexframe if it is dragged outside
- m_keyframes.remove(m_selectedKeyframe);
- m_selectedKeyframe = -1;
- update();
+ if (!m_keyframes.contains(m_editedKeyframe))
return;
+ int newpos = (int) pos.frames(m_fps);
+ int min = (int) cropStart().frames(m_fps) - 1;
+ int max = (int)(cropStart() + cropDuration()).frames(m_fps);
+ QMap<int, int>::const_iterator i = m_keyframes.constBegin();
+ while (i.key() < m_editedKeyframe) {
+ min = qMax(i.key(), min);
+ ++i;
}
- if (value > 150 && m_selectedKeyframe != start && m_selectedKeyframe != end) {
- // remove kexframe if it is dragged outside
- m_keyframes.remove(m_selectedKeyframe);
- m_selectedKeyframe = -1;
- update();
- return;
+ i = m_keyframes.constEnd() - 1;
+ while (i.key() > m_editedKeyframe) {
+ max = qMin(i.key(), max);
+ --i;
}
+ if (newpos <= min)
+ newpos = min + 1;
+ if (newpos >= max)
+ newpos = max - 1;
+
double newval = qMax(value, 0.0);
newval = qMin(newval, 100.0);
newval = newval / m_keyframeFactor;
- if (m_selectedKeyframe != newpos) m_keyframes.remove(m_selectedKeyframe);
+ if (m_editedKeyframe != newpos)
+ m_keyframes.remove(m_editedKeyframe);
m_keyframes[newpos] = (int) newval;
- m_selectedKeyframe = newpos;
+ m_editedKeyframe = newpos;
update();
}
return m_keyframeFactor;
}
-void AbstractClipItem::addKeyFrame(const GenTime pos, const double value)
+int AbstractClipItem::addKeyFrame(const GenTime pos, const double value)
{
QRectF br = sceneBoundingRect();
double maxh = 100.0 / br.height() / m_keyframeFactor;
m_keyframes[newpos] = newval;
m_selectedKeyframe = newpos;
update();
+ return newval;
}
bool AbstractClipItem::hasKeyFrames() const
CustomTrackScene* AbstractClipItem::projectScene()
{
- if (scene()) return static_cast <CustomTrackScene*>(scene());
+ if (scene())
+ return static_cast <CustomTrackScene*>(scene());
return NULL;
}
void AbstractClipItem::setItemLocked(bool locked)
{
- if (locked) {
+ if (locked)
setSelected(false);
- setFlag(QGraphicsItem::ItemIsMovable, false);
- setFlag(QGraphicsItem::ItemIsSelectable, false);
- } else {
- setFlag(QGraphicsItem::ItemIsMovable, true);
- setFlag(QGraphicsItem::ItemIsSelectable, true);
- }
+
+ setFlag(QGraphicsItem::ItemIsMovable, !locked);
+ setFlag(QGraphicsItem::ItemIsSelectable, !locked);
}
bool AbstractClipItem::isItemLocked() const
if (event->modifiers() & Qt::ShiftModifier) {
// User want to do a rectangle selection, so ignore the event to pass it to the view
event->ignore();
- } else QGraphicsItem::mousePressEvent(event);
+ } else {
+ QGraphicsItem::mousePressEvent(event);
+ }
}