From abef5a873a707bbc7c880c85a49319a0e4c5047b Mon Sep 17 00:00:00 2001 From: Marco Gittler Date: Fri, 21 Mar 2008 23:09:19 +0000 Subject: [PATCH] rect calc moved into abstract class svn path=/branches/KDE4/; revision=2094 --- src/abstractclipitem.cpp | 63 ++++++++++++++++++++++++++++++++++++++++ src/abstractclipitem.h | 4 ++- src/clipitem.cpp | 60 +++++++++----------------------------- src/transition.cpp | 50 ++++++++++--------------------- 4 files changed, 96 insertions(+), 81 deletions(-) diff --git a/src/abstractclipitem.cpp b/src/abstractclipitem.cpp index 1d62b93f..660e76a4 100644 --- a/src/abstractclipitem.cpp +++ b/src/abstractclipitem.cpp @@ -1,5 +1,8 @@ #include "abstractclipitem.h" #include +#include +#include +#include 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; +} diff --git a/src/abstractclipitem.h b/src/abstractclipitem.h index 6620745b..42cfc90a 100644 --- a/src/abstractclipitem.h +++ b/src/abstractclipitem.h @@ -34,7 +34,9 @@ protected: double m_fps; uint m_startFade; uint m_endFade; - + QPainterPath upperRectPart(QRectF); + QPainterPath lowerRectPart(QRectF); + QRect visibleRect(); }; #endif diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 745f50b5..8eb1abda 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -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)); diff --git a/src/transition.cpp b/src/transition.cpp index 004ea19f..31238184 100644 --- a/src/transition.cpp +++ b/src/transition.cpp @@ -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)); } -- 2.39.2