]> git.sesse.net Git - kdenlive/commitdiff
* small arrow instead of ellipse as transition handle
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 8 Jun 2008 13:40:24 +0000 (13:40 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 8 Jun 2008 13:40:24 +0000 (13:40 +0000)
* mouse middle click in timeline now does play / pause
* correctly load effects from saved doc

svn path=/branches/KDE4/; revision=2233

src/clipitem.cpp
src/customtrackview.cpp
src/effectslist.cpp
src/effectslist.h
src/renderer.cpp
src/trackview.cpp

index 279986024d7a26c30459d7bf243c87c45cb52684..869a35c94be8459f2712a32034d6860e2213c167 100644 (file)
@@ -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 <QString, QString> 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 <QString, QString> ClipItem::getEffectArgs(QDomElement effect) {
     QMap <QString, QString> 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 <QString, QString> 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;
index 58a43a4ad6f2ea1525cc9ccb7b186277f6b8d8ec..397ea0310308e23897707dc7a11545baf1ba5750 100644 (file)
@@ -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();
index 58152ad63fb012b9e313257342fa6e0b79d3d336..c5b7d6219ebeefa42eff8ff798c17103e9db1a5e 100644 (file)
@@ -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) {
index b5b87e7b993e16cbe07ecc04f47ecbe39fff21ce..e7f6d28b9c24a8b8560733f859c2c3b926af953f 100644 (file)
@@ -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 <QString, QString> effect(const QString & name);
index ee68fea650aa8af404dba82f9cec19ba0db92743..7540a71d2a55e6c5687153e11d4c9f2f40dcf7c0 100644 (file)
@@ -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 <QString, QString> a
     QString tag = args.value("tag");
     //kDebug()<<" / / INSERTING EFFECT: "<<id;
     if (tag.startsWith("ladspa")) tag = "ladspa";
-    char *filterId = decodedString(tag);
-    Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterId);
+    char *filterTag = decodedString(tag);
+    char *filterId = decodedString(args.value("id"));
+    Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
     if (filter && filter->is_valid())
         filter->set("kdenlive_id", filterId);
     else {
@@ -1148,7 +1151,7 @@ void Render::mltAddEffect(int track, GenTime position, QMap <QString, QString> 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 <QString, QString> a
     // attach filter to the clip
     clipService.attach(*filter);
     delete[] filterId;
+    delete[] filterTag;
     m_isBlocked = false;
     if (doRefresh) refresh();
 }
index 9f0a8b73ab3ded87f247acaf7228522a2273de59..680577fbad1beb45b82f15178d5c0437652b9fa0 100644 (file)
@@ -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();