From 4a6855a3af88f23c8a79b062f67de95ef37ec481 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sun, 8 Jun 2008 13:40:24 +0000 Subject: [PATCH] * small arrow instead of ellipse as transition handle * mouse middle click in timeline now does play / pause * correctly load effects from saved doc svn path=/branches/KDE4/; revision=2233 --- src/clipitem.cpp | 82 +++++++++++++++++++++-------------------- src/customtrackview.cpp | 15 ++++++-- src/effectslist.cpp | 16 +++++++- src/effectslist.h | 2 +- src/renderer.cpp | 18 +++++---- src/trackview.cpp | 10 ++++- 6 files changed, 87 insertions(+), 56 deletions(-) diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 27998602..869a35c9 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -337,24 +337,6 @@ void ClipItem::paint(QPainter *painter, painter->setPen(Qt::black); } - /* - // For testing puspose only: draw transitions count - { - painter->setPen(pen); - QFont font = painter->font(); - QFont smallFont = font; - smallFont.setPointSize(8); - painter->setFont(smallFont); - QString txt = " Transitions: " + QString::number(m_transitionsList.count()) + " "; - QRectF txtBoundin = painter->boundingRect(br, Qt::AlignRight | Qt::AlignTop, txt); - painter->fillRect(txtBoundin, QBrush(QColor(0, 0, 0, 150))); - painter->drawText(txtBoundin, Qt::AlignCenter, txt); - pen.setColor(Qt::black); - painter->setPen(pen); - painter->setFont(font); - } - */ - // Draw clip name QRectF txtBounding = painter->boundingRect(br, Qt::AlignHCenter | Qt::AlignTop, " " + m_clipName + " "); //painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150))); @@ -395,28 +377,47 @@ void ClipItem::paint(QPainter *painter, // painter->drawRect(boundingRect()); //painter->drawRoundRect(-10, -10, 20, 20); if (m_hover) { - int pointy = (int)(br.y() + br.height() / 2 - 5); + painter->setBrush(QColor(180, 180, 50, 180)); //gradient); + + // draw transitions handles + QPainterPath transitionHandle; + const int handle_size = 4; + transitionHandle.moveTo(0, 0); + transitionHandle.lineTo(handle_size, handle_size); + transitionHandle.lineTo(handle_size * 2, 0); + transitionHandle.lineTo(handle_size * 3, handle_size); + transitionHandle.lineTo(handle_size * 2, handle_size * 2); + transitionHandle.lineTo(handle_size * 3, handle_size * 3); + transitionHandle.lineTo(0, handle_size * 3); + transitionHandle.closeSubpath(); + int pointy = (int)(br.y() + br.height() / 2); int pointx1 = (int)(br.x() + 10); - int pointx2 = (int)(br.x() + br.width() - 20); + int pointx2 = (int)(br.x() + br.width() - (10 + handle_size * 3)); #if 0 painter->setPen(QPen(Qt::black)); painter->setBrush(QBrush(QColor(50, 50, 0))); #else - QRadialGradient gradient(pointx1 + 5, pointy + 5 , 5, 2, 2); + /*QRadialGradient gradient(pointx1 + 5, pointy + 5 , 5, 2, 2); gradient.setColorAt(0.2, Qt::white); gradient.setColorAt(0.8, Qt::yellow); - gradient.setColorAt(1, Qt::black); - painter->setBrush(gradient); -#endif - painter->drawEllipse(pointx1, pointy , 10, 10); - - QRadialGradient gradient1(pointx2 + 5, pointy + 5 , 5, 2, 2); - gradient1.setColorAt(0.2, Qt::white); - gradient1.setColorAt(0.8, Qt::yellow); - gradient1.setColorAt(1, Qt::black); - painter->setBrush(gradient1); - painter->drawEllipse(pointx2, pointy, 10, 10); + gradient.setColorAt(1, Qt::black);*/ +#endif + painter->translate(pointx1, pointy); + painter->drawPath(transitionHandle); //Ellipse(0, 0 , 10, 10); + painter->translate(-pointx1, -pointy); + + /* QRadialGradient gradient1(pointx2 + 5, pointy + 5 , 5, 2, 2); + gradient1.setColorAt(0.2, Qt::white); + gradient1.setColorAt(0.8, Qt::yellow); + gradient1.setColorAt(1, Qt::black); + painter->setBrush(gradient1);*/ + QMatrix m; + m.scale(-1.0, 1.0); + painter->setMatrix(m); + painter->translate(-pointx2 - handle_size * 3, pointy); + painter->drawPath(transitionHandle); // Ellipse(0, 0, 10, 10); + painter->translate(pointx2, -pointy); } } @@ -426,8 +427,8 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) { else if (qAbs((int)(pos.x() - rect().x())) < 6) return RESIZESTART; else if (qAbs((int)(pos.x() - (rect().x() + rect().width() - scale * m_endFade))) < 6 && qAbs((int)(pos.y() - rect().y())) < 6) return FADEOUT; else if (qAbs((int)(pos.x() - (rect().x() + rect().width()))) < 6) return RESIZEEND; - else if (qAbs((int)(pos.x() - (rect().x() + 10))) < 6 && qAbs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONSTART; - else if (qAbs((int)(pos.x() - (rect().x() + rect().width() - 20))) < 6 && qAbs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONEND; + else if (qAbs((int)(pos.x() - (rect().x() + 16))) < 10 && qAbs((int)(pos.y() - (rect().y() + rect().height() / 2 + 5))) < 8) return TRANSITIONSTART; + else if (qAbs((int)(pos.x() - (rect().x() + rect().width() - 21))) < 10 && qAbs((int)(pos.y() - (rect().y() + rect().height() / 2 + 5))) < 8) return TRANSITIONEND; return MOVE; } @@ -630,6 +631,8 @@ QMap ClipItem::addEffect(QDomElement effect, bool animate) { m_effectList.append(effect); effectParams["tag"] = effect.attribute("tag"); QString effectId = effect.attribute("id"); + if (effectId.isEmpty()) effectId = effect.attribute("tag"); + effectParams["id"] = effectId; effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix"); QString state = effect.attribute("disabled"); if (!state.isEmpty()) effectParams["disabled"] = state; @@ -667,6 +670,7 @@ QMap ClipItem::getEffectArgs(QDomElement effect) { QMap effectParams; effectParams["tag"] = effect.attribute("tag"); effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix"); + effectParams["id"] = effect.attribute("id"); QString state = effect.attribute("disabled"); if (!state.isEmpty()) effectParams["disabled"] = state; QDomNodeList params = effect.elementsByTagName("parameter"); @@ -685,12 +689,10 @@ QMap ClipItem::getEffectArgs(QDomElement effect) { txtNeu << (int)(values[i+1].toDouble()); } effectParams["start"] = neu; - } else - if (!e.isNull()) { - effectParams[e.attribute("name")] = e.attribute("value"); - } - if (!e.attribute("factor").isEmpty()) { - effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble()); + } else if (!e.isNull()) { + if (!e.attribute("factor").isEmpty()) + effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble()); + else effectParams[e.attribute("name")] = e.attribute("value"); } } return effectParams; diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 58a43a4a..397ea031 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -337,7 +337,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) { m_animation = new QGraphicsItemAnimation; m_animation->setItem(m_visualTip); m_animation->setTimeLine(m_animationTimer); - m_visualTip->setPos(clip->rect().x() + 15, clip->rect().y() + clip->rect().height() / 2); + m_visualTip->setPos(clip->rect().x() + 10, clip->rect().y() + clip->rect().height() / 2 + 12); double scale = 2.0; m_animation->setScaleAt(.5, scale, scale); scale = 1.0; @@ -355,7 +355,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) { m_animation = new QGraphicsItemAnimation; m_animation->setItem(m_visualTip); m_animation->setTimeLine(m_animationTimer); - m_visualTip->setPos(clip->rect().x() + clip->rect().width() - 15 , clip->rect().y() + clip->rect().height() / 2); + m_visualTip->setPos(clip->rect().x() + clip->rect().width() - 10 , clip->rect().y() + clip->rect().height() / 2 + 12); double scale = 2.0; m_animation->setScaleAt(.5, scale, scale); scale = 1.0; @@ -388,6 +388,10 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) { void CustomTrackView::mousePressEvent(QMouseEvent * event) { activateMonitor(); m_clickEvent = event->pos(); + if (event->button() == Qt::MidButton) { + m_document->renderer()->switchPlay(); + return; + } if (event->modifiers() == Qt::ControlModifier) { setDragMode(QGraphicsView::ScrollHandDrag); QGraphicsView::mousePressEvent(event); @@ -832,6 +836,9 @@ void CustomTrackView::checkScrolling() { } void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) { + if (event->button() == Qt::MidButton) { + return; + } QGraphicsView::mouseReleaseEvent(event); setDragMode(QGraphicsView::NoDrag); if (m_dragItem == NULL) { @@ -905,7 +912,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) { EffectsList::setParameter(effect, "out", QString::number(end)); slotUpdateClipEffect(item, oldeffect, effect); } - } else { + } else if (item->fadeIn() != 0) { QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade in"); int start = item->cropStart().frames(m_document->fps()); int end = item->fadeIn() + start; @@ -930,7 +937,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) { EffectsList::setParameter(effect, "out", QString::number(end)); slotUpdateClipEffect(item, oldeffect, effect); } - } else { + } else if (item->fadeOut() != 0) { QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade out"); int end = (item->duration() + item->cropStart()).frames(m_document->fps()); int start = end - item->fadeOut(); diff --git a/src/effectslist.cpp b/src/effectslist.cpp index 58152ad6..c5b7d621 100644 --- a/src/effectslist.cpp +++ b/src/effectslist.cpp @@ -64,8 +64,20 @@ QDomElement EffectsList::getEffectByName(const QString & name) const { return QDomElement(); } -QDomElement EffectsList::getEffectByTag(const QString & tag) const { - QString effectName; +QDomElement EffectsList::getEffectByTag(const QString & tag, const QString & id) const { + + if (!id.isEmpty()) for (int i = 0; i < this->size(); ++i) { + QDomElement effect = this->at(i); + if (effect.attribute("id") == id) { + QDomNodeList params = effect.elementsByTagName("parameter"); + for (int i = 0; i < params.count(); i++) { + QDomElement e = params.item(i).toElement(); + e.setAttribute("value", e.attribute("default")); + } + return effect; + } + } + for (int i = 0; i < this->size(); ++i) { QDomElement effect = this->at(i); if (effect.attribute("tag") == tag) { diff --git a/src/effectslist.h b/src/effectslist.h index b5b87e7b..e7f6d28b 100644 --- a/src/effectslist.h +++ b/src/effectslist.h @@ -34,7 +34,7 @@ public: ~EffectsList(); /** Returns an XML version of this Effect.*/ QDomElement getEffectByName(const QString & name) const; - QDomElement getEffectByTag(const QString & tag) const; + QDomElement getEffectByTag(const QString & tag, const QString & id) const; QStringList effectNames(); QString getInfo(QString effectName); QMap effect(const QString & name); diff --git a/src/renderer.cpp b/src/renderer.cpp index ee68fea6..7540a71d 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -384,7 +384,6 @@ void Render::getFileProperties(const QDomElement &xml, int clipId) { QDomElement westley = doc.createElement("westley"); doc.appendChild(westley); westley.appendChild(doc.importNode(xml, true)); - //kDebug() << "////////////\n" << doc.toString() << "////////////////\n"; char *tmp = decodedString(doc.toString()); Mlt::Producer producer(*m_mltProfile, "westley-xml", tmp); @@ -427,14 +426,17 @@ void Render::getFileProperties(const QDomElement &xml, int clipId) { else filePropertyMap["type"] = "video"; - QPixmap pix(width, height); mlt_image_format format = mlt_image_rgb24a; - const uint8_t *thumb = frame->get_image(format, width, height); - QImage image(thumb, width, height, QImage::Format_ARGB32); + uint8_t* data = frame->get_image(format, width, height); + QImage image(data, width, height, QImage::Format_ARGB32); if (!image.isNull()) { pix = pix.fromImage(image); } else pix.fill(Qt::black); + QPixmap copy = pix; + copy.detach(); + pix = copy; + emit replyGetImage(clipId, 0, pix, width, height); } else if (frame->get_int("test_audio") == 0) { @@ -1126,8 +1128,9 @@ void Render::mltAddEffect(int track, GenTime position, QMap a QString tag = args.value("tag"); //kDebug()<<" / / INSERTING EFFECT: "<is_valid()) filter->set("kdenlive_id", filterId); else { @@ -1148,7 +1151,7 @@ void Render::mltAddEffect(int track, GenTime position, QMap a if (currentKeyFrameNumber != keyFrameNumber) { // attach filter to the clip clipService.attach(*filter); - filter = new Mlt::Filter(*m_mltProfile, filterId); + filter = new Mlt::Filter(*m_mltProfile, filterTag); filter->set("kdenlive_id", filterId); keyFrameNumber = currentKeyFrameNumber; } @@ -1163,6 +1166,7 @@ void Render::mltAddEffect(int track, GenTime position, QMap a // attach filter to the clip clipService.attach(*filter); delete[] filterId; + delete[] filterTag; m_isBlocked = false; if (doRefresh) refresh(); } diff --git a/src/trackview.cpp b/src/trackview.cpp index 9f0a8b73..680577fb 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -196,7 +196,7 @@ void TrackView::parseDocument(QDomDocument doc) { if (transitionAdd) { // Transition should be added to the scene ItemInfo transitionInfo; - QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service); + QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, QString()); for (int k = 0; k < transitionparams.count(); k++) { p = transitionparams.item(k).toElement(); @@ -349,6 +349,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool videotrack) { if (effect.tagName() == "filter") { // add effect to clip QString effecttag; + QString effectid; QString effectindex; // Get effect tag & index for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) { @@ -357,13 +358,18 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool videotrack) { if (effectparam.attribute("name") == "tag") { effecttag = effectparam.text(); } + if (effectparam.attribute("name") == "kdenlive_id") { + effectid = effectparam.text(); + } if (effectparam.attribute("name") == "kdenlive_ix") { effectindex = effectparam.text(); } } // get effect standard tags - QDomElement clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag); + QDomElement clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid); + if (clipeffect.isNull()) clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid); + if (clipeffect.isNull()) clipeffect = MainWindow::customEffects.getEffectByTag(effecttag, effectid); clipeffect.setAttribute("kdenlive_ix", effectindex); QDomNodeList clipeffectparams = clipeffect.childNodes(); -- 2.39.2