]> git.sesse.net Git - kdenlive/commitdiff
use same paintingstyle for transitions
authorMarco Gittler <marco@gitma.de>
Mon, 10 Mar 2008 19:54:03 +0000 (19:54 +0000)
committerMarco Gittler <marco@gitma.de>
Mon, 10 Mar 2008 19:54:03 +0000 (19:54 +0000)
svn path=/branches/KDE4/; revision=2041

src/abstractclipitem.cpp
src/clipitem.cpp
src/clipitem.h
src/customtrackview.cpp
src/transition.cpp

index 6c35effc136ded9b9ee850afc6c4c7d65ca99dda..f8920aec2d95e6cfc2dfef50b48524021c7ccbe3 100644 (file)
@@ -14,7 +14,7 @@ void AbstractClipItem::moveTo(int x, double scale, double offset, int newTrack)
     if (collisionList.size() == 0) m_track = newTrack;
     for (int i = 0; i < collisionList.size(); ++i) {
         QGraphicsItem *item = collisionList.at(i);
-        if (item->type() == 70000 || item->type() == 70001) {
+        if (item->type() == type()) {
             if (offset == 0) {
                 QRectF other = ((QGraphicsRectItem *)item)->rect();
                 if (x < m_startPos.frames(m_fps)) {
index 2d113f902506ddcc557d1b9e4b8f51792203e36f..19413d3076347108c1ad3a504b4c6dfff6105ec8 100644 (file)
@@ -535,46 +535,6 @@ void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
     update();
 }
 
-void ClipItem::moveTo(int x, double scale, double offset, int newTrack) {
-    double origX = rect().x();
-    double origY = rect().y();
-    bool success = true;
-    if (x < 0) return;
-    setRect(x * scale, origY + offset, rect().width(), rect().height());
-    QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
-    if (collisionList.size() == 0) m_track = newTrack;
-    for (int i = 0; i < collisionList.size(); ++i) {
-        QGraphicsItem *item = collisionList.at(i);
-        if (item->type() == 70000) {
-            if (offset == 0) {
-                QRectF other = ((QGraphicsRectItem *)item)->rect();
-                if (x < m_startPos.frames(m_fps)) {
-                    kDebug() << "COLLISION, MOVING TO------";
-                    m_startPos = ((ClipItem *)item)->endPos() + GenTime(1, m_fps);
-                    origX = m_startPos.frames(m_fps) * scale;
-                } else {
-                    kDebug() << "COLLISION, MOVING TO+++";
-                    m_startPos = ((ClipItem *)item)->startPos() - m_cropDuration;
-                    origX = m_startPos.frames(m_fps) * scale;
-                }
-            }
-            setRect(origX, origY, rect().width(), rect().height());
-            offset = 0;
-            origX = rect().x();
-            success = false;
-            break;
-        }
-    }
-    if (success) {
-        m_track = newTrack;
-        m_startPos = GenTime(x, m_fps);
-    }
-    /*    QList <QGraphicsItem *> childrenList = QGraphicsItem::children();
-        for (int i = 0; i < childrenList.size(); ++i) {
-          childrenList.at(i)->moveBy(rect().x() - origX , offset);
-        }*/
-}
-
 void ClipItem::resizeStart(int posx, double scale) {
     GenTime durationDiff = GenTime(posx, m_fps) - m_startPos;
     if (durationDiff == GenTime()) return;
index ef11d0daeaa865a3160e557b7d9cc045ca5a7c10..ce6b50c38d6cdb7846f084d70ca1df4513d7391d 100644 (file)
@@ -44,7 +44,6 @@ public:
                        const QStyleOptionGraphicsItem *option,
                        QWidget *widget);
     virtual int type() const;
-    void moveTo(int x, double scale, double offset, int newTrack);
     void resizeStart(int posx, double scale);
     void resizeEnd(int posx, double scale);
     OPERATIONTYPE operationMode(QPointF pos, double scale);
index aa418b45c983ce59f15cb753341598cd64733cc6..bd6327600f54cc6aaa556c994a9c67f1bbbc19af 100644 (file)
@@ -347,7 +347,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) {
                 else if (m_operationMode == RESIZEEND)
                     m_startPos = QPointF(m_dragItem->endPos().frames(m_document->fps()), m_dragItem->track());
                 else if (m_operationMode == TRANSITIONSTART) {
-                    Transition *tr = new Transition(QRect(10 , 10, 20, 20), (ClipItem*)m_dragItem, LUMA_TRANSITION, m_dragItem->startPos(), m_dragItem->startPos() + GenTime(2.5), m_document->fps());
+                    Transition *tr = new Transition(QRect(m_dragItem->rect().x() , m_dragItem->rect().height() / 2, (m_dragItem->startPos() + GenTime(2.5)).frames(25.0) ,  m_dragItem->rect().height()), (ClipItem*)m_dragItem, LUMA_TRANSITION, m_dragItem->startPos(), m_dragItem->startPos() + GenTime(2.5), m_document->fps());
                     scene()->addItem(tr);
                     //m_dragItem->addTransition(tra);
                 }
@@ -719,8 +719,8 @@ void CustomTrackView::setScale(double scaleFactor) {
     QList<QGraphicsItem *> itemList = items();
 
     for (int i = 0; i < itemList.count(); i++) {
-        if (itemList.at(i)->type() == 70000) {
-            ClipItem *clip = (ClipItem *)itemList.at(i);
+        if (itemList.at(i)->type() == 70000 || itemList.at(i)->type() == 70001) {
+            AbstractClipItem *clip = (AbstractClipItem *)itemList.at(i);
             clip->setRect(clip->startPos().frames(m_document->fps()) * m_scale, clip->rect().y(), clip->duration().frames(m_document->fps()) * m_scale, clip->rect().height());
         }
     }
index 1fca5cb98199d74ab70fad868a9d9bed3ac98d74..a925fb795e5f823aea250de11c7ac0ba788be329 100644 (file)
 #include <QBrush>
 #include <qdom.h>
 #include <QPainter>
+#include <QGraphicsScene>
+#include <QGraphicsView>
+#include <QScrollBar>
+#include <QStyleOptionGraphicsItem>
 
 #include <kdebug.h>
 #include <KIcon>
@@ -36,8 +40,8 @@ Transition::Transition(const QRectF& rect , ClipItem * clipa, const TRANSITIONTY
     m_transitionType = type;
     m_transitionName = getTransitionName(m_transitionType);
     m_fps = fps;
-    GenTime duration = endTime - startTime;
-
+    m_cropDuration = endTime - startTime;
+    m_startPos = startTime;
     // Default duration = 2.5 seconds
     GenTime defaultTransitionDuration = GenTime(2.5);
 
@@ -46,11 +50,12 @@ Transition::Transition(const QRectF& rect , ClipItem * clipa, const TRANSITIONTY
     else if (startTime > m_referenceClip->endPos()) m_transitionStart = m_referenceClip->duration() - defaultTransitionDuration;
     else m_transitionStart = startTime - m_referenceClip->startPos();
 
-    if (m_transitionStart + duration > m_referenceClip->duration())
+    if (m_transitionStart + m_cropDuration > m_referenceClip->duration())
         m_transitionDuration = m_referenceClip->duration() - m_transitionStart;
-    else m_transitionDuration = duration;
+    else m_transitionDuration = m_cropDuration;
     m_secondClip = 0;
     setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+    setZValue(2);
 }
 
 // create a transition from XML
@@ -218,7 +223,52 @@ GenTime Transition::transitionEndTime() const {
 void Transition::paint(QPainter *painter,
                        const QStyleOptionGraphicsItem *option,
                        QWidget *widget) {
-    painter->fillRect(rect(), QBrush(Qt::green));
+    QRect rectInView;//this is the rect that is visible by the user
+    if (scene()->views().size() > 0) {
+        rectInView = scene()->views()[0]->viewport()->rect();
+        rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(), scene()->views()[0]->verticalScrollBar()->value());
+        rectInView.adjust(-10, -10, 10, 10);//make view rect 10 pixel greater on each site, or repaint after scroll event
+        //kDebug() << scene()->views()[0]->viewport()->rect() << " " <<  scene()->views()[0]->horizontalScrollBar()->value();
+    }
+    if (rectInView.isNull())
+        return;
+    QPainterPath clippath;
+    clippath.addRect(rectInView);
+    QRectF br = rect();
+    QPainterPath roundRectPathUpper, roundRectPathLower;
+    double roundingY = 20;
+    double roundingX = 20;
+    double offset = 1;
+    painter->setClipRect(option->exposedRect);
+    if (roundingX > br.width() / 2) roundingX = br.width() / 2;
+
+    int br_endx = (int)(br.x() + br .width() - offset);
+    int br_startx = (int)(br.x() + offset);
+    int br_starty = (int)(br.y());
+    int br_halfy = (int)(br.y() + br.height() / 2 - offset);
+    int br_endy = (int)(br.y() + br.height());
+
+
+    // build path around clip
+    roundRectPathUpper.moveTo(br_endx , br_halfy);
+    roundRectPathUpper.arcTo(br_endx - roundingX  , br_starty , roundingX, roundingY, 0.0, 90.0);
+    roundRectPathUpper.lineTo(br_startx + roundingX , br_starty);
+    roundRectPathUpper.arcTo(br_startx , br_starty , roundingX, roundingY, 90.0, 90.0);
+    roundRectPathUpper.lineTo(br_startx, br_halfy);
+
+    roundRectPathLower.moveTo(br_startx , br_halfy);
+    roundRectPathLower.arcTo(br_startx , br_endy - roundingY , roundingX, roundingY, 180.0, 90.0);
+    roundRectPathLower.lineTo(br_endx - roundingX , br_endy);
+    roundRectPathLower.arcTo(br_endx - roundingX , br_endy - roundingY, roundingX, roundingY, 270.0, 90.0);
+    roundRectPathLower.lineTo(br_endx , br_halfy);
+
+    QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
+
+    painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
+    //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
+    painter->fillRect(br.intersected(rectInView), QBrush(QColor(200, 200, 0, 160)));
+    painter->setClipRect(option->exposedRect);
+    painter->drawPath(resultClipPath.intersected(clippath));
 }
 
 int Transition::type() const {