+// 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 = visibleRect();//this is the rect that is visible by the user
+
+ 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 = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
+
+ painter->setClipRect(option->exposedRect);
+
+ // build path around clip
+
+ 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 = (int)((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() , 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);
+ 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
+ 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));
+
+ //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());