#include "kdenlivesettings.h"
ClipItem::ClipItem(QDomElement xml, int track, int startpos, const QRectF & rect, int duration)
- : QGraphicsRectItem(rect), m_xml(xml), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_track(track), m_startPos(startpos), m_thumbProd(NULL), startThumbTimer(NULL), endThumbTimer(NULL)
+ : QGraphicsRectItem(rect), m_xml(xml), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_track(track), m_startPos(startpos), m_thumbProd(NULL), startThumbTimer(NULL), endThumbTimer(NULL), m_startFade(0), m_endFade(0)
{
//setToolTip(name);
setBrush(QColor(100, 100, 150));
if (m_clipType == VIDEO || m_clipType == AV) {
- m_thumbProd = new KThumb(KUrl(xml.attribute("resource")));
- connect(this, SIGNAL(getThumb(int, int, int, int)), m_thumbProd, SLOT(extractImage(int, int, int, int)));
+ m_thumbProd = new KThumb(KUrl(xml.attribute("resource")), KdenliveSettings::track_height() * KdenliveSettings::project_display_ratio(), KdenliveSettings::track_height());
+ connect(this, SIGNAL(getThumb(int, int)), m_thumbProd, SLOT(extractImage(int, int)));
connect(m_thumbProd, SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
QTimer::singleShot(300, this, SLOT(slotFetchThumbs()));
else if (m_clipType == IMAGE) {
m_startPix = KThumb::getImage(KUrl(xml.attribute("resource")), 50 * KdenliveSettings::project_display_ratio(), 50);
}
- //m_startPix.load("/home/one/Desktop/thumb.jpg");
}
ClipItem::~ClipItem()
void ClipItem::slotFetchThumbs()
{
- emit getThumb(m_cropStart, m_cropStart + m_cropDuration, 50 * KdenliveSettings::project_display_ratio(), 50);
+ emit getThumb(m_cropStart, m_cropStart + m_cropDuration);
}
void ClipItem::slotGetStartThumb()
{
- emit getThumb(m_cropStart, -1, 50 * KdenliveSettings::project_display_ratio(), 50);
+ emit getThumb(m_cropStart, -1);
}
void ClipItem::slotGetEndThumb()
{
- emit getThumb(-1, m_cropStart + m_cropDuration, 50 * KdenliveSettings::project_display_ratio(), 50);
+ emit getThumb(-1, m_cropStart + m_cropDuration);
}
void ClipItem::slotThumbReady(int frame, QPixmap pix)
QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
painter->drawLine(l2);
}
+
+ // draw start / end fades
+ double scale = br.width() / m_cropDuration;
+ 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);
+ }
+ }
+
painter->setClipRect(option->exposedRect);
QPen pen = painter->pen();
pen.setColor(Qt::red);
}
-OPERATIONTYPE ClipItem::operationMode(QPointF pos)
+OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale)
{
- if (abs(pos.x() - rect().x()) < 6) {
- if (abs(pos.y() - rect().y()) < 6) return FADEIN;
- return RESIZESTART;
- }
- else if (abs(pos.x() - (rect().x() + rect().width())) < 6) {
- if (abs(pos.y() - rect().y()) < 6) return FADEOUT;
- return RESIZEEND;
- }
+ if (abs(pos.x() - (rect().x() + scale * m_startFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEIN;
+ else if (abs(pos.x() - rect().x()) < 6) return RESIZESTART;
+ else if (abs(pos.x() - (rect().x() + rect().width() - scale * m_endFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEOUT;
+ else if (abs(pos.x() - (rect().x() + rect().width())) < 6) return RESIZEEND;
return MOVE;
}
+int ClipItem::fadeIn() const
+{
+ return m_startFade;
+}
+
+int 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) pos = m_cropDuration / 2;
+ m_startFade = pos;
+ if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
+ else update(rect().x(), rect().y(), pos * scale, rect().height());
+}
+
+void ClipItem::setFadeOut(int pos, double scale)
+{
+ int oldOut = m_endFade;
+ if (pos < 0) pos = 0;
+ if (pos > m_cropDuration) pos = m_cropDuration / 2;
+ m_endFade = pos;
+ if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
+ else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
+
+}
+
// virtual
void ClipItem::mousePressEvent ( QGraphicsSceneMouseEvent * event )
{
- m_resizeMode = operationMode(event->pos());
+ /*m_resizeMode = operationMode(event->pos());
if (m_resizeMode == MOVE) {
m_maxTrack = scene()->sceneRect().height();
m_grabPoint = (int) (event->pos().x() - rect().x());
- }
+ }*/
QGraphicsRectItem::mousePressEvent(event);
}