]> git.sesse.net Git - kdenlive/commitdiff
rect calc moved into abstract class
authorMarco Gittler <marco@gitma.de>
Fri, 21 Mar 2008 23:09:19 +0000 (23:09 +0000)
committerMarco Gittler <marco@gitma.de>
Fri, 21 Mar 2008 23:09:19 +0000 (23:09 +0000)
svn path=/branches/KDE4/; revision=2094

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

index 1d62b93f86537ab14b29f76c1e5c65b98a8266a2..660e76a43602d8653fdaaea7f51d3bd985be2654 100644 (file)
@@ -1,5 +1,8 @@
 #include "abstractclipitem.h"
 #include <KDebug>
+#include <QGraphicsScene>
+#include <QGraphicsView>
+#include <QScrollBar>
 
 AbstractClipItem::AbstractClipItem(const QRectF& rect): QGraphicsRectItem(rect), m_startFade(0), m_endFade(0) {
     setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
@@ -143,3 +146,63 @@ int AbstractClipItem::fadeOut() const {
 GenTime AbstractClipItem::maxDuration() const {
     return m_maxDuration;
 }
+
+QPainterPath AbstractClipItem::upperRectPart(QRectF br) {
+    QPainterPath roundRectPathUpper;
+    double roundingY = 20;
+    double roundingX = 20;
+    double offset = 1;
+
+    while (roundingX > br.width() / 2) {
+        roundingX = roundingX / 2;
+        roundingY = roundingY / 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());
+
+    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);
+
+    return roundRectPathUpper;
+}
+
+QPainterPath AbstractClipItem::lowerRectPart(QRectF br) {
+    QPainterPath roundRectPathLower;
+    double roundingY = 20;
+    double roundingX = 20;
+    double offset = 1;
+
+    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() - 1);
+
+    while (roundingX > br.width() / 2) {
+        roundingX = roundingX / 2;
+        roundingY = roundingY / 2;
+    }
+    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);
+    return roundRectPathLower;
+}
+
+QRect AbstractClipItem::visibleRect() {
+    QRect rectInView;
+    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();
+    }
+    return rectInView;
+}
index 6620745b6cdfe4b33193b6fd00c9b2e08cc8d538..42cfc90a7c97f8907b9ee9c0ca5c8db1a40c6467 100644 (file)
@@ -34,7 +34,9 @@ protected:
     double m_fps;
     uint m_startFade;
     uint m_endFade;
-
+    QPainterPath upperRectPart(QRectF);
+    QPainterPath lowerRectPart(QRectF);
+    QRect visibleRect();
 };
 
 #endif
index 745f50b55c2d8a5439812d29086aacfd3cc13eca..8eb1abda39dd93ad87cf507784c8734080ac78fc 100644 (file)
@@ -182,13 +182,8 @@ void ClipItem::paint(QPainter *painter,
     if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
     QRectF br = rect();
     double scale = br.width() / m_cropDuration.frames(m_fps);
-    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();
-    }
+    QRect rectInView = visibleRect();//this is the rect that is visible by the user
+
     if (rectInView.isNull())
         return;
     QPainterPath clippath;
@@ -204,43 +199,11 @@ void ClipItem::paint(QPainter *painter,
 
     //painter->setRenderHints(QPainter::Antialiasing);
 
-    QPainterPath roundRectPathUpper, roundRectPathLower;
-    double roundingY = 20;
-    double roundingX = 20;
-    double offset = 1;
+    QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
+
     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());
-    int left_upper = 0, left_lower = 0, right_upper = 0, right_lower = 0;
-
-    if (m_hover && false) {
-        if (!true) /*TRANSITIONSTART to upper clip*/
-            left_upper = 40;
-        if (!false) /*TRANSITIONSTART to lower clip*/
-            left_lower = 40;
-        if (!true) /*TRANSITIONEND to upper clip*/
-            right_upper = 40;
-        if (!false) /*TRANSITIONEND to lower clip*/
-            right_lower = 40;
-    }
 
     // build path around clip
-    roundRectPathUpper.moveTo(br_endx - right_upper , br_halfy);
-    roundRectPathUpper.arcTo(br_endx - roundingX - right_upper , br_starty , roundingX, roundingY, 0.0, 90.0);
-    roundRectPathUpper.lineTo(br_startx + roundingX + left_upper, br_starty);
-    roundRectPathUpper.arcTo(br_startx + left_upper, br_starty , roundingX, roundingY, 90.0, 90.0);
-    roundRectPathUpper.lineTo(br_startx + left_upper, br_halfy);
-
-    roundRectPathLower.moveTo(br_startx + left_lower, br_halfy);
-    roundRectPathLower.arcTo(br_startx + left_lower, br_endy - roundingY , roundingX, roundingY, 180.0, 90.0);
-    roundRectPathLower.lineTo(br_endx - roundingX - right_lower , br_endy);
-    roundRectPathLower.arcTo(br_endx - roundingX - right_lower , br_endy - roundingY, roundingX, roundingY, 270.0, 90.0);
-    roundRectPathLower.lineTo(br_endx - right_lower , br_halfy);
 
     QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
 
@@ -292,8 +255,8 @@ void ClipItem::paint(QPainter *painter,
 
     if (m_startFade != 0) {
         QPainterPath fadeInPath;
-        fadeInPath.moveTo(br.x() - offset, br.y());
-        fadeInPath.lineTo(br.x() - offset, br.y() + br.height());
+        fadeInPath.moveTo(br.x() , br.y());
+        fadeInPath.lineTo(br.x() , br.y() + br.height());
         fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
         fadeInPath.closeSubpath();
         painter->fillPath(fadeInPath, fades);
@@ -357,9 +320,14 @@ void ClipItem::paint(QPainter *painter,
     painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
 
     // draw frame around clip
-    pen.setColor(Qt::red);
-    pen.setWidth(2);
-    if (isSelected()) painter->setPen(pen);
+    if (isSelected()) {
+        pen.setColor(Qt::red);
+        pen.setWidth(2);
+    } else {
+        pen.setColor(Qt::black);
+        pen.setWidth(1);
+    }
+    painter->setPen(pen);
     painter->setClipRect(option->exposedRect);
     painter->drawPath(resultClipPath.intersected(clippath));
 
index 004ea19f245e17c4592510086485e6736160b1a6..3123818482906b5ca9b3234287a6405c68e8ca16 100644 (file)
@@ -181,44 +181,14 @@ GenTime Transition::transitionEndTime() const {
 void Transition::paint(QPainter *painter,
                        const QStyleOptionGraphicsItem *option,
                        QWidget *widget) {
-    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();
-    }
+    QRect rectInView = visibleRect();//this is the rect that is visible by the user
+
     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 roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
 
     QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
 
@@ -226,7 +196,19 @@ void Transition::paint(QPainter *painter,
     //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
     painter->fillRect(br.intersected(rectInView), QBrush(QColor(200, 200, 0, 160)/*,Qt::Dense4Pattern*/));
     painter->setClipRect(option->exposedRect);
-    painter->drawPixmap(br_startx + 10, br_starty + 10, transitionPixmap());
+    painter->drawPixmap(br.x() + 10, br.y() + 10, transitionPixmap());
+    painter->drawPath(resultClipPath.intersected(clippath));
+
+    QPen pen = painter->pen();
+    if (isSelected()) {
+        pen.setColor(Qt::red);
+        pen.setWidth(2);
+    } else {
+        pen.setColor(Qt::black);
+        pen.setWidth(1);
+    }
+    painter->setPen(pen);
+    painter->setClipRect(option->exposedRect);
     painter->drawPath(resultClipPath.intersected(clippath));
 }