X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fclipitem.cpp;h=b2af83a82cbf8552f6c3c34078bc212dca212ba3;hb=e17f9f3cafb3f9cd62a069d578797ad89b13ee4e;hp=83b387bedd6732791239b3c02ac2bd2ec592bb70;hpb=ba1ba937af590000157599aca776708ded840a28;p=kdenlive diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 83b387be..b2af83a8 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -42,7 +42,7 @@ static int FRAME_SIZE; -ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, int strobe, int frame_width, bool generateThumbs) : +ClipItem::ClipItem(DocClipBase *clip, const ItemInfo& info, double fps, double speed, int strobe, int frame_width, bool generateThumbs) : AbstractClipItem(info, QRectF(), fps), m_clip(clip), m_startFade(0), @@ -90,7 +90,7 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, i setAcceptDrops(true); m_audioThumbReady = m_clip->audioThumbCreated(); //setAcceptsHoverEvents(true); - connect(this , SIGNAL(prepareAudioThumb(double, int, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int, int))); + connect(this , SIGNAL(prepareAudioThumb(double,int,int,int,int)) , this, SLOT(slotPrepareAudioThumb(double,int,int,int,int))); if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) { m_baseColor = QColor(141, 166, 215); @@ -100,7 +100,7 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, i connect(&m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb())); m_endThumbTimer.setSingleShot(true); connect(&m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb())); - connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage))); + connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int,QImage)), this, SLOT(slotThumbReady(int,QImage))); connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData())); if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs())); } @@ -112,13 +112,14 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, i } else if (m_clipType == IMAGE || m_clipType == TEXT) { m_baseColor = QColor(141, 166, 215); if (m_clipType == TEXT) { - connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage))); + connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int,QImage)), this, SLOT(slotThumbReady(int,QImage))); } //m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight()); } else if (m_clipType == AUDIO) { m_baseColor = QColor(141, 215, 166); connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData())); } + m_paintColor = m_baseColor; } @@ -127,15 +128,16 @@ ClipItem::~ClipItem() blockSignals(true); m_endThumbTimer.stop(); m_startThumbTimer.stop(); - if (scene()) scene()->removeItem(this); + if (scene()) + scene()->removeItem(this); if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) { - //disconnect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage))); + //disconnect(m_clip->thumbProducer(), SIGNAL(thumbReady(int,QImage)), this, SLOT(slotThumbReady(int,QImage))); //disconnect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData())); } delete m_timeLine; } -ClipItem *ClipItem::clone(ItemInfo info) const +ClipItem *ClipItem::clone(const ItemInfo &info) const { ClipItem *duplicate = new ClipItem(m_clip, info, m_fps, m_speed, m_strobe, FRAME_SIZE); if (m_clipType == IMAGE || m_clipType == TEXT) duplicate->slotSetStartThumb(m_startPix); @@ -154,12 +156,12 @@ ClipItem *ClipItem::clone(ItemInfo info) const return duplicate; } -void ClipItem::setEffectList(const EffectsList effectList) +void ClipItem::setEffectList(const EffectsList &effectList) { m_effectList.clone(effectList); m_effectNames = m_effectList.effectNames().join(" / "); if (!m_effectList.isEmpty()) { - for (int i = 0; i < m_effectList.count(); i++) { + for (int i = 0; i < m_effectList.count(); ++i) { QDomElement effect = m_effectList.at(i); QString effectId = effect.attribute("id"); // check if it is a fade effect @@ -237,7 +239,7 @@ void ClipItem::initEffect(QDomElement effect, int diff, int offset) // Init parameter value & keyframes if required QDomNodeList params = effect.elementsByTagName("parameter"); - for (int i = 0; i < params.count(); i++) { + for (int i = 0; i < params.count(); ++i) { QDomElement e = params.item(i).toElement(); if (e.isNull()) @@ -336,15 +338,15 @@ void ClipItem::initEffect(QDomElement effect, int diff, int offset) } } -const QString ClipItem::adjustKeyframes(QString keyframes, int offset) +const QString ClipItem::adjustKeyframes(const QString &keyframes, int offset) { QStringList result; // Simple keyframes const QStringList list = keyframes.split(';', QString::SkipEmptyParts); foreach(const QString &keyframe, list) { - int pos = keyframe.section(':', 0, 0).toInt() - offset; - QString newKey = QString::number(pos) + ":" + keyframe.section(':', 1); - result.append(newKey); + int pos = keyframe.section(':', 0, 0).toInt() - offset; + QString newKey = QString::number(pos) + ":" + keyframe.section(':', 1); + result.append(newKey); } return result.join(";"); } @@ -425,14 +427,14 @@ bool ClipItem::checkKeyFrames(int width, int height, int previousDuration, int c return clipEffectsModified; } -void ClipItem::setKeyframes(const int ix, const QStringList keyframes) +void ClipItem::setKeyframes(const int ix, const QStringList &keyframes) { QDomElement effect = m_effectList.at(ix); if (effect.attribute("disable") == "1") return; QLocale locale; QDomNodeList params = effect.elementsByTagName("parameter"); int keyframeParams = 0; - for (int i = 0; i < params.count(); i++) { + for (int i = 0; i < params.count(); ++i) { QDomElement e = params.item(i).toElement(); if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && (!e.hasAttribute("intimeline") || e.attribute("intimeline") == "1")) { e.setAttribute("keyframes", keyframes.at(keyframeParams)); @@ -469,7 +471,7 @@ void ClipItem::setSelectedEffect(const int ix) QDomElement effect = effectAtIndex(m_selectedEffect); if (!effect.isNull() && effect.attribute("disable") != "1") { QDomNodeList params = effect.elementsByTagName("parameter"); - for (int i = 0; i < params.count(); i++) { + for (int i = 0; i < params.count(); ++i) { QDomElement e = params.item(i).toElement(); if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && (!e.hasAttribute("intimeline") || e.attribute("intimeline") == "1")) { m_keyframes.clear(); @@ -509,7 +511,7 @@ void ClipItem::resizeGeometries(const int index, int width, int height, int prev QDomElement effect = m_effectList.at(index); QDomNodeList params = effect.elementsByTagName("parameter"); - for (int i = 0; i < params.count(); i++) { + for (int i = 0; i < params.count(); ++i) { QDomElement e = params.item(i).toElement(); if (!e.isNull() && e.attribute("type") == "geometry") { geom = e.attribute("value"); @@ -525,7 +527,7 @@ QStringList ClipItem::keyframes(const int index) QDomElement effect = m_effectList.at(index); QDomNodeList params = effect.elementsByTagName("parameter"); - for (int i = 0; i < params.count(); i++) { + for (int i = 0; i < params.count(); ++i) { QDomElement e = params.item(i).toElement(); if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) result.append(e.attribute("keyframes")); @@ -647,7 +649,7 @@ void ClipItem::slotGetEndThumb() } -void ClipItem::slotSetStartThumb(QImage img) +void ClipItem::slotSetStartThumb(const QImage &img) { if (!img.isNull() && img.format() == QImage::Format_ARGB32) { QPixmap pix = QPixmap::fromImage(img); @@ -658,7 +660,7 @@ void ClipItem::slotSetStartThumb(QImage img) } } -void ClipItem::slotSetEndThumb(QImage img) +void ClipItem::slotSetEndThumb(const QImage &img) { if (!img.isNull() && img.format() == QImage::Format_ARGB32) { QPixmap pix = QPixmap::fromImage(img); @@ -669,7 +671,7 @@ void ClipItem::slotSetEndThumb(QImage img) } } -void ClipItem::slotThumbReady(int frame, QImage img) +void ClipItem::slotThumbReady(int frame, const QImage &img) { if (scene() == NULL) return; QRectF r = boundingRect(); @@ -689,12 +691,12 @@ void ClipItem::slotThumbReady(int frame, QImage img) } } -void ClipItem::slotSetStartThumb(const QPixmap pix) +void ClipItem::slotSetStartThumb(const QPixmap &pix) { m_startPix = pix; } -void ClipItem::slotSetEndThumb(const QPixmap pix) +void ClipItem::slotSetEndThumb(const QPixmap &pix) { m_endPix = pix; } @@ -789,23 +791,21 @@ void ClipItem::paint(QPainter *painter, QWidget *) { QPalette palette = scene()->palette(); - QColor paintColor; + QColor paintColor = m_paintColor; QColor textColor; QColor textBgColor; QPen framePen; - if (parentItem()) paintColor = QColor(255, 248, 149); - else paintColor = m_baseColor; if (isSelected() || (parentItem() && parentItem()->isSelected())) { textColor = palette.highlightedText().color(); textBgColor = palette.highlight().color(); - paintColor = paintColor.darker(); framePen.setColor(textBgColor); + paintColor.setRed(qMin(paintColor.red() * 2, 255)); } else { textColor = palette.text().color(); textBgColor = palette.window().color(); textBgColor.setAlpha(200); - framePen.setColor(paintColor.darker()); + framePen.setColor(m_paintColor.darker()); } const QRectF exposed = option->exposedRect; const QTransform transformation = painter->worldTransform(); @@ -820,7 +820,7 @@ void ClipItem::paint(QPainter *painter, painter->setClipPath(p.intersected(q)); painter->setPen(Qt::NoPen); painter->fillRect(mappedExposed, paintColor); - painter->setPen(paintColor.darker()); + painter->setPen(m_paintColor.darker()); // draw thumbnails if (KdenliveSettings::videothumbnails() && !isAudioOnly()) { QRectF thumbRect; @@ -858,7 +858,7 @@ void ClipItem::paint(QPainter *painter, QPointF startPos = mapped.topLeft(); int startOffset = m_info.cropStart.frames(m_fps); if (clipType() == IMAGE || clipType() == TEXT) { - for (int i = left; i <= right; i++) { + for (int i = left; i <= right; ++i) { painter->drawPixmap(startPos + QPointF(FRAME_SIZE *(i - startOffset), 0), m_startPix); } } @@ -870,7 +870,7 @@ void ClipItem::paint(QPainter *painter, QPen pen(Qt::white); pen.setStyle(Qt::DotLine); QList missing; - for (int i = left; i <= right; i++) { + for (int i = left; i <= right; ++i) { img = m_clip->thumbProducer()->findCachedThumb(path + QString::number(i)); QPointF xpos = startPos + QPointF(FRAME_SIZE *(i - startOffset), 0); if (img.isNull()) missing << i; @@ -932,8 +932,8 @@ void ClipItem::paint(QPainter *painter, } if (m_isMainSelectedClip) { - framePen.setColor(Qt::red); - textBgColor = Qt::red; + framePen.setColor(Qt::red); + textBgColor = Qt::red; } // only paint details if clip is big enough @@ -1058,7 +1058,7 @@ void ClipItem::paint(QPainter *painter, } -OPERATIONTYPE ClipItem::operationMode(QPointF pos) +OPERATIONTYPE ClipItem::operationMode(const QPointF &pos) { if (isItemLocked()) return NONE; const double scale = projectScene()->scale().x(); @@ -1082,7 +1082,7 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos) if (parentItem()) { QGraphicsItemGroup *dragGroup = static_cast (parentItem()); QList list = dragGroup->childItems(); - for (int i = 0; i < list.count(); i++) { + for (int i = 0; i < list.count(); ++i) { if (list.at(i)->type() == AVWIDGET) { ClipItem *c = static_cast (list.at(i)); if (c->startPos() != startPos()) return MOVE; @@ -1097,7 +1097,7 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos) if (parentItem()) { QGraphicsItemGroup *dragGroup = static_cast (parentItem()); QList list = dragGroup->childItems(); - for (int i = 0; i < list.count(); i++) { + for (int i = 0; i < list.count(); ++i) { if (list.at(i)->type() == AVWIDGET) { ClipItem *c = static_cast (list.at(i)); if (c->endPos() != endPos()) return MOVE; @@ -1132,7 +1132,7 @@ QList ClipItem::snapMarkers() const QList < GenTime > markers = m_clip->snapMarkers(); GenTime pos; - for (int i = 0; i < markers.size(); i++) { + for (int i = 0; i < markers.size(); ++i) { pos = GenTime((int)(markers.at(i).frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart(); if (pos > GenTime()) { if (pos > cropDuration()) break; @@ -1149,7 +1149,7 @@ QList ClipItem::commentedSnapMarkers() const QList < CommentedTime > markers = m_clip->commentedSnapMarkers(); GenTime pos; - for (int i = 0; i < markers.size(); i++) { + for (int i = 0; i < markers.size(); ++i) { pos = GenTime((int)(markers.at(i).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart(); if (pos > GenTime()) { if (pos > cropDuration()) break; @@ -1195,7 +1195,7 @@ void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, in QPainter pixpainter(&m_audioThumbCachePic[startCache]); - for (int i = 0; i < channels; i++) { + for (int i = 0; i < channels; ++i) { if (simplifiedAudio) { positiveChannelPaths[i].moveTo(-1, channelHeight); } @@ -1253,7 +1253,7 @@ void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, in pixpainter.setBrush(Qt::NoBrush); } pixpainter.setRenderHint(QPainter::Antialiasing, false); - for (int i = 0; i < channels; i++) { + for (int i = 0; i < channels; ++i) { if (fullAreaDraw) { pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths.value(i))); } else @@ -1386,8 +1386,10 @@ void ClipItem::resizeEnd(int posx, bool emitChange) QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == QGraphicsItem::ItemSelectedChange) { - if (value.toBool()) setZValue(10); - else setZValue(2); + if (value.toBool()) + setZValue(10); + else + setZValue(2); } if (change == ItemPositionChange && scene()) { // calculate new position. @@ -1418,7 +1420,7 @@ QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) bool forwardMove = newPos.x() > pos().x(); int offset = 0; if (!items.isEmpty()) { - for (int i = 0; i < items.count(); i++) { + for (int i = 0; i < items.count(); ++i) { if (!items.at(i)->isEnabled()) continue; if (items.at(i)->type() == type()) { // Collision! @@ -1464,6 +1466,11 @@ QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) //kDebug()<<"// ITEM NEW POS: "<(); + if (parent) m_paintColor = m_baseColor.lighter(135); + else m_paintColor = m_baseColor; + } return QGraphicsItem::itemChange(change, value); } @@ -1633,7 +1640,7 @@ EffectsParameterList ClipItem::addEffect(QDomElement effect, bool /*animate*/) }*/ } - for (int i = 0; i < params.count(); i++) { + for (int i = 0; i < params.count(); ++i) { QDomElement e = params.item(i).toElement(); if (!e.isNull()) { if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) { @@ -1783,7 +1790,7 @@ const ItemInfo ClipItem::speedIndependantInfo() const int ClipItem::nextFreeEffectGroupIndex() const { int freeGroupIndex = 0; - for (int i = 0; i < m_effectList.count(); i++) { + for (int i = 0; i < m_effectList.count(); ++i) { QDomElement effect = m_effectList.at(i); EffectInfo effectInfo; effectInfo.fromString(effect.attribute("kdenlive_info")); @@ -1808,7 +1815,7 @@ void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) QDomNodeList effectlist = e.elementsByTagName("effect"); int freeGroupIndex = nextFreeEffectGroupIndex(); EffectInfo effectInfo; - for (int i = 0; i < effectlist.count(); i++) { + for (int i = 0; i < effectlist.count(); ++i) { QDomElement effect = effectlist.at(i).toElement(); effectInfo.fromString(effect.attribute("kdenlive_info")); effectInfo.groupIndex = freeGroupIndex; @@ -1865,6 +1872,10 @@ void ClipItem::setAudioOnly(bool force) } else if (m_clipType == AUDIO) m_baseColor = QColor(141, 215, 166); else m_baseColor = QColor(141, 166, 215); } + if (parentItem()) + m_paintColor = m_baseColor.lighter(135); + else + m_paintColor = m_baseColor; m_audioThumbCachePic.clear(); } @@ -1885,7 +1896,7 @@ void ClipItem::insertKeyframe(QDomElement effect, int pos, int val) effect.setAttribute("active_keyframe", pos); m_editedKeyframe = pos; QDomNodeList params = effect.elementsByTagName("parameter"); - for (int i = 0; i < params.count(); i++) { + for (int i = 0; i < params.count(); ++i) { QDomElement e = params.item(i).toElement(); if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) { QString kfr = e.attribute("keyframes"); @@ -1925,7 +1936,7 @@ void ClipItem::movedKeyframe(QDomElement effect, int oldpos, int newpos, double QDomNodeList params = effect.elementsByTagName("parameter"); int start = cropStart().frames(m_fps); int end = (cropStart() + cropDuration()).frames(m_fps) - 1; - for (int i = 0; i < params.count(); i++) { + for (int i = 0; i < params.count(); ++i) { QDomElement e = params.item(i).toElement(); if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) { QString kfr = e.attribute("keyframes"); @@ -1985,7 +1996,7 @@ Mlt::Producer *ClipItem::getProducer(int track, bool trackSpecific) QMap ClipItem::adjustEffectsToDuration(int width, int height, ItemInfo oldInfo) { QMap effects; - for (int i = 0; i < m_effectList.count(); i++) { + for (int i = 0; i < m_effectList.count(); ++i) { QDomElement effect = m_effectList.at(i); if (effect.attribute("id").startsWith("fade")) {