-// virtual
-void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
-{
- int pos = event->x();
- emit mousePosition(mapToScene(event->pos()).x() / m_scale);
- /*if (event->modifiers() == Qt::ControlModifier)
- setDragMode(QGraphicsView::ScrollHandDrag);
- else if (event->modifiers() == Qt::ShiftModifier)
- setDragMode(QGraphicsView::RubberBandDrag);
- else*/ {
-
- if (m_dragItem) { //event->button() == Qt::LeftButton) {
- // a button was pressed, delete visual tips
- if (m_operationMode == MOVE) {
- double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint);
- double moveX = snappedPos; //mapToScene(event->pos()).x();
- //kDebug()<<"/////// MOVE CLIP, EVENT Y: "<<event->scenePos().y()<<", SCENE HEIGHT: "<<scene()->sceneRect().height();
- int moveTrack = (int) mapToScene(event->pos()).y() / 50;
- int currentTrack = m_dragItem->track();
-
- if (moveTrack > m_tracksCount - 1) moveTrack = m_tracksCount - 1;
- else if (moveTrack < 0) moveTrack = 0;
-
- int offset = moveTrack - currentTrack;
- if (offset != 0) offset = 50 * offset;
- m_dragItem->moveTo(moveX / m_scale, m_scale, offset, moveTrack);
- }
- else if (m_operationMode == RESIZESTART) {
- int pos = mapToScene(event->pos()).x();
- m_dragItem->resizeStart(pos / m_scale, m_scale);
- }
- else if (m_operationMode == RESIZEEND) {
- 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;
- m_visualTip = NULL;
- QGraphicsView::mouseMoveEvent(event);
- return;
- }
-
- QList<QGraphicsItem *> itemList = items( event->pos());
- int i = 0;
- QGraphicsItem *item = NULL;
- for (int i = 0; i < itemList.count(); i++) {
- if (itemList.at(i)->type() == 70000) {
- item = itemList.at(i);
- break;
- }
- }
- if (item && event->buttons() == Qt::NoButton) {
- ClipItem *clip = (ClipItem*) item;
- double size = 8;
- OPERATIONTYPE opMode = clip->operationMode(mapToScene(event->pos()), m_scale);
- if (opMode == m_moveOpMode) {
- QGraphicsView::mouseMoveEvent(event);
- return;
- }
- else {
- if (m_visualTip) {
- if (m_animation) delete m_animation;
- m_animation = NULL;
- m_animationTimer->stop();
- delete m_visualTip;
- m_visualTip = NULL;
- }
- }
- m_moveOpMode = opMode;
- if (opMode == MOVE) {
- setCursor(Qt::OpenHandCursor);
- }
- else if (opMode == RESIZESTART) {
- kDebug()<<"******** RESIZE CLIP START; WIDTH: "<<size;
- if (m_visualTip == NULL) {
- QPolygon polygon;
- polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 - size * 2);
- polygon << QPoint(clip->rect().x() + size * 2, clip->rect().y() + clip->rect().height() / 2 );
- polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 + size * 2);
- polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 - size * 2);
-
- m_visualTip = new QGraphicsPolygonItem(polygon);
- ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
- ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
- m_visualTip->setZValue (100);
- m_animation = new QGraphicsItemAnimation;
- m_animation->setItem(m_visualTip);
- m_animation->setTimeLine(m_animationTimer);
- m_visualTip->setPos(0, 0);
- double scale = 2.0;
- m_animation->setScaleAt(.5, scale, 1);
- m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
- scale = 1.0;
- m_animation->setScaleAt(1, scale, 1);
- m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
- scene()->addItem(m_visualTip);
- m_animationTimer->start();
- }
- setCursor(Qt::SizeHorCursor);
- }
- else if (opMode == RESIZEEND) {
- if (m_visualTip == NULL) {
- QPolygon polygon;
- polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 - size * 2);
- polygon << QPoint(clip->rect().x() + clip->rect().width() - size * 2, clip->rect().y() + clip->rect().height() / 2 );
- polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 + size * 2);
- polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 - size * 2);
-
- m_visualTip = new QGraphicsPolygonItem(polygon);
- ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
- ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
-
- m_visualTip->setZValue (100);
- m_animation = new QGraphicsItemAnimation;
- m_animation->setItem(m_visualTip);
- m_animation->setTimeLine(m_animationTimer);
- m_visualTip->setPos(0, 0);
- double scale = 2.0;
- m_animation->setScaleAt(.5, scale, 1);
- m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width(), 0));
- scale = 1.0;
- m_animation->setScaleAt(1, scale, 1);
- m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
- scene()->addItem(m_visualTip);
- m_animationTimer->start();
- }
- setCursor(Qt::SizeHorCursor);
- }
- else if (opMode == FADEIN) {
- if (m_visualTip == NULL) {
- 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(m_tipPen);
- m_visualTip->setZValue (100);
- m_animation = new QGraphicsItemAnimation;
- m_animation->setItem(m_visualTip);
- m_animation->setTimeLine(m_animationTimer);
- 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->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));
- scene()->addItem(m_visualTip);
- m_animationTimer->start();
- }
- setCursor(Qt::PointingHandCursor);
- }
- else if (opMode == FADEOUT) {
- if (m_visualTip == NULL) {
- 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(m_tipPen);
- m_visualTip->setZValue (100);
- m_animation = new QGraphicsItemAnimation;
- m_animation->setItem(m_visualTip);
- m_animation->setTimeLine(m_animationTimer);
- 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->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));
- scene()->addItem(m_visualTip);
- m_animationTimer->start();
- }
- setCursor(Qt::PointingHandCursor);
- }
- }
- else {
- m_moveOpMode = NONE;
- if (event->buttons() != Qt::NoButton)
- {
- setCursorPos((int) mapToScene(event->pos().x(), 0).x());
- emit cursorMoved(cursorPos());
- }
- if (m_visualTip) {
- if (m_animation) delete m_animation;
- m_animationTimer->stop();
- m_animation = NULL;
- delete m_visualTip;
- m_visualTip = NULL;
-
- }
- setCursor(Qt::ArrowCursor);
+// virtual
+void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
+ int pos = event->x();
+ emit mousePosition(mapToScene(event->pos()).x() / m_scale);
+ /*if (event->modifiers() == Qt::ControlModifier)
+ setDragMode(QGraphicsView::ScrollHandDrag);
+ else if (event->modifiers() == Qt::ShiftModifier)
+ setDragMode(QGraphicsView::RubberBandDrag);
+ else*/
+ {
+
+ if (m_dragItem) { //event->button() == Qt::LeftButton) {
+ // a button was pressed, delete visual tips
+ if (m_operationMode == MOVE) {
+ double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint);
+ double moveX = snappedPos; //mapToScene(event->pos()).x();
+ //kDebug()<<"/////// MOVE CLIP, EVENT Y: "<<event->scenePos().y()<<", SCENE HEIGHT: "<<scene()->sceneRect().height();
+ int moveTrack = (int) mapToScene(event->pos()).y() / 50;
+ int currentTrack = m_dragItem->track();
+
+ if (moveTrack > m_tracksCount - 1) moveTrack = m_tracksCount - 1;
+ else if (moveTrack < 0) moveTrack = 0;
+
+ int offset = moveTrack - currentTrack;
+ if (offset != 0) offset = 50 * offset;
+ m_dragItem->moveTo(moveX / m_scale, m_scale, offset, moveTrack);
+ } else if (m_operationMode == RESIZESTART) {
+ int pos = mapToScene(event->pos()).x();
+ m_dragItem->resizeStart(pos / m_scale, m_scale);
+ } else if (m_operationMode == RESIZEEND) {
+ 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;
+ m_visualTip = NULL;
+ QGraphicsView::mouseMoveEvent(event);
+ return;
+ }
+
+ QList<QGraphicsItem *> itemList = items(event->pos());
+ int i = 0;
+ QGraphicsItem *item = NULL;
+ for (int i = 0; i < itemList.count(); i++) {
+ if (itemList.at(i)->type() == 70000) {
+ item = itemList.at(i);
+ break;
+ }
+ }
+ if (item && event->buttons() == Qt::NoButton) {
+ ClipItem *clip = (ClipItem*) item;
+ double size = 8;
+ OPERATIONTYPE opMode = clip->operationMode(mapToScene(event->pos()), m_scale);
+ if (opMode == m_moveOpMode) {
+ QGraphicsView::mouseMoveEvent(event);
+ return;
+ } else {
+ if (m_visualTip) {
+ if (m_animation) delete m_animation;
+ m_animation = NULL;
+ m_animationTimer->stop();
+ delete m_visualTip;
+ m_visualTip = NULL;
+ }
+ }
+ m_moveOpMode = opMode;
+ if (opMode == MOVE) {
+ setCursor(Qt::OpenHandCursor);
+ } else if (opMode == RESIZESTART) {
+ kDebug() << "******** RESIZE CLIP START; WIDTH: " << size;
+ if (m_visualTip == NULL) {
+ QPolygon polygon;
+ polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 - size * 2);
+ polygon << QPoint(clip->rect().x() + size * 2, clip->rect().y() + clip->rect().height() / 2);
+ polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 + size * 2);
+ polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 - size * 2);
+
+ m_visualTip = new QGraphicsPolygonItem(polygon);
+ ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
+ ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
+ m_visualTip->setZValue(100);
+ m_animation = new QGraphicsItemAnimation;
+ m_animation->setItem(m_visualTip);
+ m_animation->setTimeLine(m_animationTimer);
+ m_visualTip->setPos(0, 0);
+ double scale = 2.0;
+ m_animation->setScaleAt(.5, scale, 1);
+ m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
+ scale = 1.0;
+ m_animation->setScaleAt(1, scale, 1);
+ m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
+ scene()->addItem(m_visualTip);
+ m_animationTimer->start();
+ }
+ setCursor(Qt::SizeHorCursor);
+ } else if (opMode == RESIZEEND) {
+ if (m_visualTip == NULL) {
+ QPolygon polygon;
+ polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 - size * 2);
+ polygon << QPoint(clip->rect().x() + clip->rect().width() - size * 2, clip->rect().y() + clip->rect().height() / 2);
+ polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 + size * 2);
+ polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 - size * 2);
+
+ m_visualTip = new QGraphicsPolygonItem(polygon);
+ ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
+ ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
+
+ m_visualTip->setZValue(100);
+ m_animation = new QGraphicsItemAnimation;
+ m_animation->setItem(m_visualTip);
+ m_animation->setTimeLine(m_animationTimer);
+ m_visualTip->setPos(0, 0);
+ double scale = 2.0;
+ m_animation->setScaleAt(.5, scale, 1);
+ m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width(), 0));
+ scale = 1.0;
+ m_animation->setScaleAt(1, scale, 1);
+ m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
+ scene()->addItem(m_visualTip);
+ m_animationTimer->start();
+ }
+ setCursor(Qt::SizeHorCursor);
+ } else if (opMode == FADEIN) {
+ if (m_visualTip == NULL) {
+ 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(m_tipPen);
+ m_visualTip->setZValue(100);
+ m_animation = new QGraphicsItemAnimation;
+ m_animation->setItem(m_visualTip);
+ m_animation->setTimeLine(m_animationTimer);
+ 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->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));
+ scene()->addItem(m_visualTip);
+ m_animationTimer->start();
+ }
+ setCursor(Qt::PointingHandCursor);
+ } else if (opMode == FADEOUT) {
+ if (m_visualTip == NULL) {
+ 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(m_tipPen);
+ m_visualTip->setZValue(100);
+ m_animation = new QGraphicsItemAnimation;
+ m_animation->setItem(m_visualTip);
+ m_animation->setTimeLine(m_animationTimer);
+ 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->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));
+ scene()->addItem(m_visualTip);
+ m_animationTimer->start();
+ }
+ setCursor(Qt::PointingHandCursor);
+ }
+ } else {
+ m_moveOpMode = NONE;
+ if (event->buttons() != Qt::NoButton) {
+ setCursorPos((int) mapToScene(event->pos().x(), 0).x());
+ emit cursorMoved(cursorPos());
+ }
+ if (m_visualTip) {
+ if (m_animation) delete m_animation;
+ m_animationTimer->stop();
+ m_animation = NULL;
+ delete m_visualTip;
+ m_visualTip = NULL;
+
+ }
+ setCursor(Qt::ArrowCursor);
+ }