#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);
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;
+}
double m_fps;
uint m_startFade;
uint m_endFade;
-
+ QPainterPath upperRectPart(QRectF);
+ QPainterPath lowerRectPart(QRectF);
+ QRect visibleRect();
};
#endif
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;
//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);
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);
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));
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);
//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));
}