+void ClipItem::animate(qreal value) {
+ m_opacity = value;
+ update();
+}
+
+// virtual
+void ClipItem::paint(QPainter *painter,
+ const QStyleOptionGraphicsItem *option,
+ QWidget *widget) {
+ painter->setOpacity(m_opacity);
+ QBrush paintColor = brush();
+
+ 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();
+ }
+ if (rectInView.isNull())
+ return;
+ QPainterPath clippath;
+ clippath.addRect(rectInView);
+
+ int startpixel = (int)(rectInView.x() - rect().x()); //start and endpixel that is viewable from rect()
+
+ if (startpixel < 0)
+ startpixel = 0;
+ int endpixel = rectInView.width() + rectInView.x();
+ if (endpixel < 0)
+ endpixel = 0;
+
+ //painter->setRenderHints(QPainter::Antialiasing);
+
+ 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());
+ 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);
+
+ painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
+ //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
+ painter->fillRect(br.intersected(rectInView), paintColor);
+ //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
+
+ // draw thumbnails
+ if (!m_startPix.isNull() && KdenliveSettings::videothumbnails()) {
+ if (m_clipType == IMAGE) {
+ painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
+ QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
+ painter->drawLine(l);
+ } else {
+ painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
+ QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
+ painter->drawLine(l);
+ }
+
+ painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
+ QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
+ painter->drawLine(l2);
+ }
+
+ // draw audio thumbnails
+ if ((m_clipType == AV || m_clipType == AUDIO) && audioThumbReady && KdenliveSettings::audiothumbnails()) {
+
+ QPainterPath path = m_clipType == AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
+ if (m_clipType == AV) painter->fillPath(path, QBrush(QColor(200, 200, 200, 140)));
+
+ int channels = 2;
+ if (scale != framePixelWidth)
+ audioThumbCachePic.clear();
+ emit prepareAudioThumb(scale, path, startpixel, endpixel + 200);//200 more for less missing parts before repaint after scrolling
+ int cropLeft = (m_cropStart).frames(m_fps) * scale;
+ for (int startCache = startpixel - startpixel % 100; startCache < endpixel + 300;startCache += 100) {
+ if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
+ painter->drawPixmap((int)(roundRectPathUpper.united(roundRectPathLower).boundingRect().x() + startCache - cropLeft), (int)(path.boundingRect().y()), audioThumbCachePic[startCache]);
+ }
+
+ }
+
+ // draw start / end fades
+ QBrush fades;
+ if (isSelected()) {
+ fades = QBrush(QColor(200, 50, 50, 150));
+ } else fades = QBrush(QColor(200, 200, 200, 200));
+
+ if (m_startFade != 0) {
+ QPainterPath fadeInPath;
+ fadeInPath.moveTo(br.x() - offset, br.y());
+ fadeInPath.lineTo(br.x() - offset, br.y() + br.height());
+ fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
+ fadeInPath.closeSubpath();
+ painter->fillPath(fadeInPath, fades);
+ if (isSelected()) {
+ QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
+ painter->drawLine(l);
+ }
+ }
+ if (m_endFade != 0) {
+ QPainterPath fadeOutPath;
+ fadeOutPath.moveTo(br.x() + br.width(), br.y());
+ fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
+ fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
+ fadeOutPath.closeSubpath();
+ painter->fillPath(fadeOutPath, fades);
+ if (isSelected()) {
+ QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
+ painter->drawLine(l);
+ }
+ }
+
+ QPen pen = painter->pen();
+ pen.setColor(Qt::white);
+ //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
+
+ // Draw effects names
+ QString effects = effectNames().join(" / ");
+ if (!effects.isEmpty()) {
+ painter->setPen(pen);
+ QFont font = painter->font();
+ QFont smallFont = font;
+ smallFont.setPointSize(8);
+ painter->setFont(smallFont);
+ QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
+ painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
+ painter->drawText(txtBounding, Qt::AlignCenter, effects);
+ pen.setColor(Qt::black);
+ painter->setPen(pen);
+ painter->setFont(font);
+ }
+
+ // 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)));
+ painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
+
+ // draw frame around clip
+ pen.setColor(Qt::red);
+ pen.setWidth(2);
+ if (isSelected()) painter->setPen(pen);
+ painter->setClipRect(option->exposedRect);
+ painter->drawPath(resultClipPath.intersected(clippath));
+
+ //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
+ //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
+
+ /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
+ painter->drawRect(recta);
+ painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
+ painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
+ painter->setPen(QPen(Qt::black, 1.0));
+ painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
+ painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
+
+ //QGraphicsRectItem::paint(painter, option, widget);
+ //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
+ //painter->setPen(pen);
+ //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());