#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);
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, 150));
+
+ 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);
}
void moveTo(int x, double scale, double offset, int newTrack);
void resizeStart(int posx, double scale);
void resizeEnd(int posx, double scale);
- OPERATIONTYPE operationMode(QPointF pos);
+ OPERATIONTYPE operationMode(QPointF pos, double scale);
int clipProducer();
int clipType();
QString clipName();
int endPos();
int duration();
QDomElement xml() const;
+ int fadeIn() const;
+ int fadeOut() const;
+ void setFadeOut(int pos, double scale);
+ void setFadeIn(int pos, double scale);
protected:
virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
KThumb *m_thumbProd;
QTimer *startThumbTimer;
QTimer *endThumbTimer;
+ uint m_startFade;
+ uint m_endFade;
private slots:
void slotThumbReady(int frame, QPixmap pix);
int pos = mapToScene(event->pos()).x();
m_dragItem->resizeEnd(pos / m_scale, m_scale);
}
+ else if (m_operationMode == FADEIN) {
+ int pos = mapToScene(event->pos()).x() / m_scale;
+ m_dragItem->setFadeIn(pos - m_dragItem->startPos(), m_scale);
+ }
+ else if (m_operationMode == FADEOUT) {
+ int pos = mapToScene(event->pos()).x() / m_scale;
+ m_dragItem->setFadeOut(m_dragItem->endPos() - pos, m_scale);
+ }
+
if (m_animation) delete m_animation;
m_animation = NULL;
if (m_visualTip) delete m_visualTip;
if (item) {
ClipItem *clip = (ClipItem*) item;
double size = mapToScene(QPoint(8, 0)).x();
- OPERATIONTYPE opMode = clip->operationMode(mapToScene(event->pos()));
+ OPERATIONTYPE opMode = clip->operationMode(mapToScene(event->pos()), m_scale);
if (opMode == m_moveOpMode) {
QGraphicsView::mouseMoveEvent(event);
return;
}
else if (opMode == FADEIN) {
if (m_visualTip == NULL) {
- m_visualTip = new QGraphicsEllipseItem(clip->rect().x() - size, clip->rect().y() - 8, size * 2, 16);
+ m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->fadeIn() * m_scale - size, clip->rect().y() - 8, size * 2, 16);
((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
((QGraphicsEllipseItem*) m_visualTip)->setPen(QPen(Qt::transparent));
m_visualTip->setZValue (100);
m_visualTip->setPos(0, 0);
double scale = 2.0;
m_animation->setScaleAt(.5, scale, scale);
- m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale));
+ m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->fadeIn() * m_scale, clip->rect().y() - clip->rect().y() * scale));
scale = 1.0;
m_animation->setScaleAt(1, scale, scale);
m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale));
}
else if (opMode == FADEOUT) {
if (m_visualTip == NULL) {
- m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->rect().width() - size, clip->rect().y() - 8, size*2, 16);
+ m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->rect().width() - clip->fadeOut() * m_scale - size, clip->rect().y() - 8, size*2, 16);
((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
((QGraphicsEllipseItem*) m_visualTip)->setPen(QPen(Qt::transparent));
m_visualTip->setZValue (100);
m_visualTip->setPos(0, 0);
double scale = 2.0;
m_animation->setScaleAt(.5, scale, scale);
- m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width(), clip->rect().y() - clip->rect().y() * scale));
+ m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width() + clip->fadeOut() * m_scale, clip->rect().y() - clip->rect().y() * scale));
scale = 1.0;
m_animation->setScaleAt(1, scale, scale);
m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale));
if (item->type() == 70000) {
m_dragItem = (ClipItem *) item;
m_clickPoint = mapToScene(event->pos()).x() - m_dragItem->startPos() * m_scale;
- m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())));
+ m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale);
if (m_operationMode == MOVE || m_operationMode == RESIZESTART) m_startPos = QPointF(m_dragItem->startPos(), m_dragItem->track());
else if (m_operationMode == RESIZEEND) m_startPos = QPointF(m_dragItem->endPos(), m_dragItem->track());
kDebug()<<"//////// ITEMÂ CLICKED: "<<m_startPos;
ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->endPos(), m_dragItem->track()), false, false);
m_commandStack->push(command);
}
+ m_operationMode = NONE;
m_dragItem = NULL;
}
connect(m_trackview, SIGNAL(zoomOut ()), this, SLOT(slotZoomOut()));
connect(m_trackview->horizontalScrollBar(), SIGNAL(sliderMoved( int )), m_ruler, SLOT(slotMoveRuler( int )));
- view->horizontalSlider->setValue(0);
+ view->horizontalSlider->setValue(4);
m_currentZoom = view->horizontalSlider->value();
m_trackview->initView();
}