X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fabstractclipitem.cpp;h=2046a6cbde58619f39a0b74af79cd96597ecc7cc;hb=08a49ce40071207043020d0d8f3c804703ee7af8;hp=5b990206630a4f9138e4c94dc692232b0e7b5711;hpb=2132b23b05cd9f8f766c2b7a91d770563d7b9463;p=kdenlive diff --git a/src/abstractclipitem.cpp b/src/abstractclipitem.cpp index 5b990206..2046a6cb 100644 --- a/src/abstractclipitem.cpp +++ b/src/abstractclipitem.cpp @@ -44,6 +44,7 @@ AbstractClipItem::AbstractClipItem(const ItemInfo info, const QRectF& rect, doub setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); #if QT_VERSION >= 0x040600 setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true); #endif } @@ -124,39 +125,36 @@ void AbstractClipItem::updateRectGeometry() 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; } - //kDebug()<<"// DURATION DIFF: "< GenTime()) { QList collisionList = collidingItems(Qt::IntersectsItemBoundingRect); for (int i = 0; i < collisionList.size(); ++i) { - if (!collisionList.at(i)->isEnabled()) continue; + if (!collisionList.at(i)->isEnabled()) continue; QGraphicsItem *item = collisionList.at(i); if (item->type() == type() && item->pos().x() > pos().x()) { kDebug() << "///////// COLLISION DETECTED!!!!!!!!!"; @@ -241,7 +239,8 @@ GenTime AbstractClipItem::maxDuration() const 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; @@ -272,12 +271,21 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/) 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); @@ -299,7 +307,7 @@ int AbstractClipItem::mouseOverKeyFrames(QPointF pos, double maxOffset) 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::const_iterator i = m_keyframes.constBegin(); double x1; double y1; @@ -309,7 +317,9 @@ int AbstractClipItem::mouseOverKeyFrames(QPointF pos, double maxOffset) 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; } } @@ -319,7 +329,8 @@ int AbstractClipItem::mouseOverKeyFrames(QPointF pos, double maxOffset) 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; @@ -328,44 +339,55 @@ void AbstractClipItem::updateSelectedKeyFrame() 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::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(); } @@ -374,7 +396,7 @@ double AbstractClipItem::keyFrameFactor() const 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; @@ -384,6 +406,7 @@ void AbstractClipItem::addKeyFrame(const GenTime pos, const double value) m_keyframes[newpos] = newval; m_selectedKeyframe = newpos; update(); + return newval; } bool AbstractClipItem::hasKeyFrames() const @@ -404,20 +427,18 @@ bool AbstractClipItem::hasKeyFrames() const CustomTrackScene* AbstractClipItem::projectScene() { - if (scene()) return static_cast (scene()); + if (scene()) + return static_cast (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 @@ -431,6 +452,8 @@ void AbstractClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) 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); + } }