+
+ // draw markers
+ QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
+ QList < CommentedTime >::Iterator it = markers.begin();
+ GenTime pos;
+ double framepos;
+ const int markerwidth = 4;
+ QBrush markerBrush;
+ markerBrush = QBrush(QColor(120, 120, 0, 100));
+ QPen pen = painter->pen();
+ pen.setColor(QColor(255, 255, 255, 200));
+ pen.setStyle(Qt::DotLine);
+ painter->setPen(pen);
+ for (; it != markers.end(); ++it) {
+ pos = (*it).time() - cropStart();
+ if (pos > GenTime()) {
+ if (pos > duration()) break;
+ framepos = scale * pos.frames(m_fps);
+ QLineF l(br.x() + framepos, br.y() + 5, br.x() + framepos, br.y() + br.height() - 5);
+ painter->drawLine(l);
+ if (KdenliveSettings::showmarkers()) {
+ const QRectF txtBounding = painter->boundingRect(br.x() + framepos + 1, br.y() + 10, br.width() - framepos - 2, br.height() - 10, Qt::AlignLeft | Qt::AlignTop, " " + (*it).comment() + " ");
+ QPainterPath path;
+ path.addRoundedRect(txtBounding, 3, 3);
+ painter->fillPath(path, markerBrush);
+ painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment());
+ }
+ //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
+ }
+ }
+ pen.setColor(Qt::black);
+ pen.setStyle(Qt::SolidLine);
+ painter->setPen(pen);
+
+ // 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.bottom());
+ fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
+ fadeInPath.closeSubpath();
+ painter->fillPath(fadeInPath.intersected(resultClipPath), fades);
+ if (isSelected()) {
+ QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.bottom());
+ painter->drawLine(l);
+ }
+ }
+ if (m_endFade != 0) {
+ QPainterPath fadeOutPath;
+ fadeOutPath.moveTo(br.right(), br.y());
+ fadeOutPath.lineTo(br.right(), br.bottom());
+ fadeOutPath.lineTo(br.right() - m_endFade * scale, br.y());
+ fadeOutPath.closeSubpath();
+ painter->fillPath(fadeOutPath.intersected(resultClipPath), fades);
+ if (isSelected()) {
+ QLineF l(br.right() - m_endFade * scale, br.y(), br.x() + br.width(), br.bottom());
+ painter->drawLine(l);
+ }
+ }
+
+ // Draw effects names
+ if (!m_effectNames.isEmpty() && br.width() > 30) {
+ QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
+ txtBounding.setRight(txtBounding.right() + 15);
+ painter->setPen(Qt::white);
+ QBrush markerBrush(Qt::SolidPattern);
+ if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
+ qreal value = m_timeLine->currentValue();
+ txtBounding.setWidth(txtBounding.width() * value);
+ markerBrush.setColor(QColor(50 + 200 * (1.0 - value), 50, 50, 100 + 50 * value));
+ } else markerBrush.setColor(QColor(50, 50, 50, 150));
+ QPainterPath path;
+ path.addRoundedRect(txtBounding, 4, 4);
+ painter->fillPath(path.intersected(resultClipPath), markerBrush);
+ painter->drawText(txtBounding, Qt::AlignCenter, m_effectNames);
+ painter->setPen(Qt::black);
+ }
+
+ // Draw clip name
+ QRectF txtBounding = painter->boundingRect(br, Qt::AlignHCenter | Qt::AlignTop, " " + m_clipName + " ");
+ //painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150)));
+ painter->setPen(QColor(0, 0, 0, 180));
+ painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
+ txtBounding.translate(QPointF(1, 1));
+ painter->setPen(QColor(255, 255, 255, 255));
+ 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);
+
+ if (m_hover && br.width() > 30) {
+ painter->setBrush(QColor(180, 180, 50, 180)); //gradient);
+
+ // draw transitions handles
+ QPainterPath transitionHandle;
+ const int handle_size = 4;
+ transitionHandle.moveTo(0, 0);
+ transitionHandle.lineTo(handle_size, handle_size);
+ transitionHandle.lineTo(handle_size * 2, 0);
+ transitionHandle.lineTo(handle_size * 3, handle_size);
+ transitionHandle.lineTo(handle_size * 2, handle_size * 2);
+ transitionHandle.lineTo(handle_size * 3, handle_size * 3);
+ transitionHandle.lineTo(0, handle_size * 3);
+ transitionHandle.closeSubpath();
+ int pointy = (int)(br.y() + br.height() / 2);
+ int pointx1 = (int)(br.x() + 10);
+ int pointx2 = (int)(br.x() + br.width() - (10 + handle_size * 3));
+#if 0
+ painter->setPen(QPen(Qt::black));
+ painter->setBrush(QBrush(QColor(50, 50, 0)));
+#else
+ /*QRadialGradient gradient(pointx1 + 5, pointy + 5 , 5, 2, 2);
+ gradient.setColorAt(0.2, Qt::white);
+ gradient.setColorAt(0.8, Qt::yellow);
+ gradient.setColorAt(1, Qt::black);*/
+
+#endif
+ painter->translate(pointx1, pointy);
+ painter->drawPath(transitionHandle); //Ellipse(0, 0 , 10, 10);
+ painter->translate(-pointx1, -pointy);
+
+ /* QRadialGradient gradient1(pointx2 + 5, pointy + 5 , 5, 2, 2);
+ gradient1.setColorAt(0.2, Qt::white);
+ gradient1.setColorAt(0.8, Qt::yellow);
+ gradient1.setColorAt(1, Qt::black);
+ painter->setBrush(gradient1);*/
+ painter->translate(pointx2, pointy);
+ QMatrix m;
+ m.scale(-1.0, 1.0);
+ //painter->setMatrix(m);
+ painter->drawPath(transitionHandle); // Ellipse(0, 0, 10, 10);
+ //painter->setMatrix(m);
+ painter->translate(- pointx2, -pointy);
+ }
+}
+
+
+OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) {
+ if (qAbs((int)(pos.x() - (rect().x() + scale * m_startFade))) < 6 && qAbs((int)(pos.y() - rect().y())) < 6) return FADEIN;
+ else if (qAbs((int)(pos.x() - rect().x())) < 6) return RESIZESTART;
+ else if (qAbs((int)(pos.x() - (rect().x() + rect().width() - scale * m_endFade))) < 6 && qAbs((int)(pos.y() - rect().y())) < 6) return FADEOUT;
+ else if (qAbs((int)(pos.x() - (rect().x() + rect().width()))) < 6) return RESIZEEND;
+ else if (qAbs((int)(pos.x() - (rect().x() + 16))) < 10 && qAbs((int)(pos.y() - (rect().y() + rect().height() / 2 + 5))) < 8) return TRANSITIONSTART;
+ else if (qAbs((int)(pos.x() - (rect().x() + rect().width() - 21))) < 10 && qAbs((int)(pos.y() - (rect().y() + rect().height() / 2 + 5))) < 8) return TRANSITIONEND;
+
+ return MOVE;
+}
+
+QList <GenTime> ClipItem::snapMarkers() {
+ QList < GenTime > snaps;
+ QList < GenTime > markers = baseClip()->snapMarkers();
+ GenTime pos;
+ double framepos;
+
+ for (int i = 0; i < markers.size(); i++) {
+ pos = markers.at(i) - cropStart();
+ if (pos > GenTime()) {
+ if (pos > duration()) break;
+ else snaps.append(pos + startPos());
+ }
+ }
+ return snaps;
+}
+
+void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel) {
+ int channels = 2;
+
+ QRectF re = path.boundingRect();
+
+ //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
+
+ for (int startCache = startpixel - startpixel % 100;startCache + 100 < endpixel ;startCache += 100) {
+ //kDebug() << "creating " << startCache;
+ //if (framePixelWidth!=pixelForOneFrame ||
+ if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
+ continue;
+ if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
+ audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
+ audioThumbCachePic[startCache].fill(QColor(200, 200, 200, 0));
+ }
+ bool fullAreaDraw = pixelForOneFrame < 10;
+ QMap<int, QPainterPath > positiveChannelPaths;
+ QMap<int, QPainterPath > negativeChannelPaths;
+ QPainter pixpainter(&audioThumbCachePic[startCache]);
+ QPen audiopen;
+ audiopen.setWidth(0);
+ pixpainter.setPen(audiopen);
+ //pixpainter.setRenderHint(QPainter::Antialiasing,true);
+ //pixpainter.drawLine(0,0,100,re.height());
+ int channelHeight = audioThumbCachePic[startCache].height() / channels;
+
+ for (int i = 0;i < channels;i++) {
+
+ positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
+ negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
+ }
+
+ for (int samples = 0;samples <= 100;samples++) {
+ double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
+ int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
+ if (frame < 0 || sample < 0 || sample > 19)
+ continue;
+ QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
+
+ for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
+
+ int y = channelHeight * channel + channelHeight / 2;
+ int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
+ if (fullAreaDraw) {
+ positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
+ negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
+ } else {
+ positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
+ negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
+ }
+ }
+ for (int channel = 0;channel < channels ;channel++)
+ if (fullAreaDraw && samples == 100) {
+ positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
+ negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
+ positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
+ negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
+ }
+
+ }
+ if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
+ else {
+ pixpainter.setPen(QPen(QColor(0, 0, 0)));
+ pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
+ }
+ for (int i = 0;i < channels;i++) {
+ if (fullAreaDraw) {
+ //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
+ pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
+ } else
+ pixpainter.drawPath(positiveChannelPaths[i]);
+ }
+ }
+ //audioThumbWasDrawn=true;
+ framePixelWidth = pixelForOneFrame;
+
+ //}
+}
+
+uint ClipItem::fadeIn() const {
+ return m_startFade;
+}
+
+uint ClipItem::fadeOut() const {
+ return m_endFade;
+}
+
+
+void ClipItem::setFadeIn(int pos, double scale) {
+ int oldIn = m_startFade;
+ if (pos < 0) pos = 0;
+ if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
+ m_startFade = pos;
+ update(rect().x(), rect().y(), qMax(oldIn, pos) * scale, rect().height());
+}
+
+void ClipItem::setFadeOut(int pos, double scale) {
+ int oldOut = m_endFade;
+ if (pos < 0) pos = 0;
+ if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
+ m_endFade = pos;
+ update(rect().x() + rect().width() - qMax(oldOut, pos) * scale, rect().y(), pos * scale, rect().height());
+
+}
+
+// virtual
+void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
+ /*m_resizeMode = operationMode(event->pos());
+ if (m_resizeMode == MOVE) {
+ m_maxTrack = scene()->sceneRect().height();
+ m_grabPoint = (int) (event->pos().x() - rect().x());
+ }*/