1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include <QMouseEvent>
21 #include <QStylePainter>
22 #include <QGraphicsItem>
23 #include <QDomDocument>
30 #include "customtrackview.h"
32 #include "definitions.h"
33 #include "moveclipcommand.h"
34 #include "resizeclipcommand.h"
35 #include "addtimelineclipcommand.h"
36 #include "addeffectcommand.h"
38 CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent)
39 : QGraphicsView(projectscene, parent), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_startPos(QPointF()), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(0), m_document(doc)
41 if (doc) m_commandStack = doc->commandStack();
42 else m_commandStack == NULL;
43 setMouseTracking(true);
45 m_animationTimer = new QTimeLine(800);
46 m_animationTimer->setFrameRange(0, 5);
47 m_animationTimer->setUpdateInterval(100);
48 m_animationTimer->setLoopCount(0);
49 m_tipColor = QColor(230, 50, 0, 150);
50 setContentsMargins(0, 0, 0, 0);
52 m_cursorLine = projectscene->addLine(0, 0, 0, 50);
53 m_cursorLine->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIgnoresTransformations);
54 m_cursorLine->setZValue(1000);
58 void CustomTrackView::initView()
64 void CustomTrackView::resizeEvent ( QResizeEvent * event )
66 QGraphicsView::resizeEvent(event);
70 void CustomTrackView::wheelEvent ( QWheelEvent * e )
72 if (e->modifiers() == Qt::ControlModifier) {
73 if (e->delta() > 0) emit zoomIn();
77 if (e->delta() > 0) horizontalScrollBar()->setValue (horizontalScrollBar()->value() + horizontalScrollBar()->singleStep ());
78 else horizontalScrollBar()->setValue (horizontalScrollBar()->value() - horizontalScrollBar()->singleStep ());
84 void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
87 emit mousePosition(mapToScene(event->pos()).x() / m_scale);
88 /*if (event->modifiers() == Qt::ControlModifier)
89 setDragMode(QGraphicsView::ScrollHandDrag);
90 else if (event->modifiers() == Qt::ShiftModifier)
91 setDragMode(QGraphicsView::RubberBandDrag);
94 if (m_dragItem) { //event->button() == Qt::LeftButton) {
95 // a button was pressed, delete visual tips
96 if (m_operationMode == MOVE) {
97 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint);
98 double moveX = snappedPos; //mapToScene(event->pos()).x();
99 //kDebug()<<"/////// MOVE CLIP, EVENT Y: "<<event->scenePos().y()<<", SCENE HEIGHT: "<<scene()->sceneRect().height();
100 int moveTrack = (int) mapToScene(event->pos()).y() / 50;
101 int currentTrack = m_dragItem->track();
103 if (moveTrack > m_tracksCount - 1) moveTrack = m_tracksCount - 1;
104 else if (moveTrack < 0) moveTrack = 0;
106 int offset = moveTrack - currentTrack;
107 if (offset != 0) offset = 50 * offset;
108 m_dragItem->moveTo(moveX / m_scale, m_scale, offset, moveTrack);
110 else if (m_operationMode == RESIZESTART) {
111 int pos = mapToScene(event->pos()).x();
112 m_dragItem->resizeStart(pos / m_scale, m_scale);
114 else if (m_operationMode == RESIZEEND) {
115 int pos = mapToScene(event->pos()).x();
116 m_dragItem->resizeEnd(pos / m_scale, m_scale);
118 else if (m_operationMode == FADEIN) {
119 int pos = mapToScene(event->pos()).x() / m_scale;
120 m_dragItem->setFadeIn(pos - m_dragItem->startPos(), m_scale);
122 else if (m_operationMode == FADEOUT) {
123 int pos = mapToScene(event->pos()).x() / m_scale;
124 m_dragItem->setFadeOut(m_dragItem->endPos() - pos, m_scale);
127 if (m_animation) delete m_animation;
129 if (m_visualTip) delete m_visualTip;
131 QGraphicsView::mouseMoveEvent(event);
135 QList<QGraphicsItem *> itemList = items( event->pos());
137 QGraphicsItem *item = NULL;
138 for (int i = 0; i < itemList.count(); i++) {
139 if (itemList.at(i)->type() == 70000) {
140 item = itemList.at(i);
145 ClipItem *clip = (ClipItem*) item;
146 double size = mapToScene(QPoint(8, 0)).x();
147 OPERATIONTYPE opMode = clip->operationMode(mapToScene(event->pos()), m_scale);
148 if (opMode == m_moveOpMode) {
149 QGraphicsView::mouseMoveEvent(event);
154 if (m_animation) delete m_animation;
160 m_moveOpMode = opMode;
161 if (opMode == MOVE) {
162 setCursor(Qt::OpenHandCursor);
164 else if (opMode == RESIZESTART) {
165 kDebug()<<"******** RESIZE CLIP START; WIDTH: "<<size;
166 if (m_visualTip == NULL) {
167 m_visualTip = new QGraphicsRectItem(clip->rect().x(), clip->rect().y(), size, clip->rect().height());
168 ((QGraphicsRectItem*) m_visualTip)->setBrush(m_tipColor);
169 ((QGraphicsRectItem*) m_visualTip)->setPen(QPen(Qt::transparent));
170 m_visualTip->setZValue (100);
171 m_animation = new QGraphicsItemAnimation;
172 m_animation->setItem(m_visualTip);
173 m_animation->setTimeLine(m_animationTimer);
174 m_visualTip->setPos(0, 0);
176 m_animation->setScaleAt(.5, scale, 1);
177 m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
179 m_animation->setScaleAt(1, scale, 1);
180 m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
181 scene()->addItem(m_visualTip);
182 m_animationTimer->start();
184 setCursor(Qt::SizeHorCursor);
186 else if (opMode == RESIZEEND) {
187 if (m_visualTip == NULL) {
188 m_visualTip = new QGraphicsRectItem(clip->rect().x() + clip->rect().width() - size, clip->rect().y(), size, clip->rect().height());
189 ((QGraphicsRectItem*) m_visualTip)->setBrush(m_tipColor);
190 ((QGraphicsRectItem*) m_visualTip)->setPen(QPen(Qt::transparent));
191 m_visualTip->setZValue (100);
192 m_animation = new QGraphicsItemAnimation;
193 m_animation->setItem(m_visualTip);
194 m_animation->setTimeLine(m_animationTimer);
195 m_visualTip->setPos(0, 0);
197 m_animation->setScaleAt(.5, scale, 1);
198 m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width(), 0));
200 m_animation->setScaleAt(1, scale, 1);
201 m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
202 scene()->addItem(m_visualTip);
203 m_animationTimer->start();
205 setCursor(Qt::SizeHorCursor);
207 else if (opMode == FADEIN) {
208 if (m_visualTip == NULL) {
209 m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->fadeIn() * m_scale - size, clip->rect().y() - 8, size * 2, 16);
210 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
211 ((QGraphicsEllipseItem*) m_visualTip)->setPen(QPen(Qt::transparent));
212 m_visualTip->setZValue (100);
213 m_animation = new QGraphicsItemAnimation;
214 m_animation->setItem(m_visualTip);
215 m_animation->setTimeLine(m_animationTimer);
216 m_visualTip->setPos(0, 0);
218 m_animation->setScaleAt(.5, scale, scale);
219 m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->fadeIn() * m_scale, clip->rect().y() - clip->rect().y() * scale));
221 m_animation->setScaleAt(1, scale, scale);
222 m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale));
223 scene()->addItem(m_visualTip);
224 m_animationTimer->start();
226 setCursor(Qt::PointingHandCursor);
228 else if (opMode == FADEOUT) {
229 if (m_visualTip == NULL) {
230 m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->rect().width() - clip->fadeOut() * m_scale - size, clip->rect().y() - 8, size*2, 16);
231 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
232 ((QGraphicsEllipseItem*) m_visualTip)->setPen(QPen(Qt::transparent));
233 m_visualTip->setZValue (100);
234 m_animation = new QGraphicsItemAnimation;
235 m_animation->setItem(m_visualTip);
236 m_animation->setTimeLine(m_animationTimer);
237 m_visualTip->setPos(0, 0);
239 m_animation->setScaleAt(.5, scale, scale);
240 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));
242 m_animation->setScaleAt(1, scale, scale);
243 m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale));
244 scene()->addItem(m_visualTip);
245 m_animationTimer->start();
247 setCursor(Qt::PointingHandCursor);
253 if (m_animation) delete m_animation;
258 setCursor(Qt::ArrowCursor);
261 QGraphicsView::mouseMoveEvent(event);
265 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
267 kDebug()<<"-- TIMELINE MSE PRESSED";
268 int pos = event->x();
269 if (event->modifiers() == Qt::ControlModifier)
270 setDragMode(QGraphicsView::ScrollHandDrag);
271 else if (event->modifiers() == Qt::ShiftModifier)
272 setDragMode(QGraphicsView::RubberBandDrag);
274 bool collision = false;
275 QList<QGraphicsItem *> collisionList = items(event->pos());
276 for (int i = 0; i < collisionList.size(); ++i) {
277 QGraphicsItem *item = collisionList.at(i);
278 if (item->type() == 70000) {
279 m_dragItem = (ClipItem *) item;
280 m_clickPoint = mapToScene(event->pos()).x() - m_dragItem->startPos() * m_scale;
281 m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale);
282 if (m_operationMode == MOVE || m_operationMode == RESIZESTART)
283 m_startPos = QPointF(m_dragItem->startPos(), m_dragItem->track());
284 else if (m_operationMode == RESIZEEND)
285 m_startPos = QPointF(m_dragItem->endPos(), m_dragItem->track());
286 kDebug()<<"//////// ITEM CLICKED: "<<m_startPos;
292 kDebug()<<"//////// NO ITEM FOUND ON CLICK";
294 setCursor(Qt::ArrowCursor);
295 setCursorPos((int) mapToScene(event->x(), 0).x());
296 emit cursorMoved(cursorPos());
299 updateSnapPoints(m_dragItem);
301 QGraphicsView::mousePressEvent(event);
304 void CustomTrackView::dragEnterEvent ( QDragEnterEvent * event )
306 if (event->mimeData()->hasText()) {
307 kDebug()<<"/////////////// DRAG ENTERED, TEXT: "<<event->mimeData()->text();
308 QStringList ids = QString(event->mimeData()->text()).split(";");
309 //TODO: drop of several clips
310 for (int i = 0; i < ids.size(); ++i) {
312 DocClipBase *clip = m_document->getBaseClip(ids.at(0).toInt());
313 if (clip == NULL) kDebug()<<" WARNING))))))))) CLIP NOT FOUND : "<<ids.at(0).toInt();
314 addItem(clip, event->pos());
315 event->acceptProposedAction();
319 void CustomTrackView::addEffect(int track, GenTime pos, QString tag, QMap <QString, QString> args)
321 m_document->renderer()->mltAddEffect(track, pos, tag, args);
324 void CustomTrackView::deleteEffect(int track, GenTime pos, QString tag)
326 m_document->renderer()->mltRemoveEffect(track, pos, tag, -1);
329 void CustomTrackView::slotAddEffect(QMap <QString, QString> filter)
331 QList<QGraphicsItem *> itemList = items();
332 for (int i = 0; i < itemList.count(); i++) {
333 if (itemList.at(i)->type() == 70000 && itemList.at(i)->isSelected()) {
334 ClipItem *item = (ClipItem *)itemList.at(i);
335 QString tag = filter.value("mlt_service");
336 AddEffectCommand *command = new AddEffectCommand(this, m_tracksCount - item->track(),GenTime(item->startPos(), 25), tag, filter, true);
337 m_commandStack->push(command);
342 void CustomTrackView::addItem(DocClipBase *clip, QPoint pos)
345 int out = clip->duration().frames(m_document->fps());
346 //kdDebug()<<"- - - -CREATING CLIP, duration = "<<out<<", URL: "<<clip->fileURL();
347 int trackTop = ((int) mapToScene(pos).y()/50) * 50 + 1;
348 m_dropItem = new ClipItem(clip, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out);
349 scene()->addItem(m_dropItem);
353 void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) {
354 event->setDropAction(Qt::IgnoreAction);
356 int track = (int) mapToScene(event->pos()).y()/50; //) * (m_scale * 50) + m_scale;
357 kDebug()<<"+++++++++++++ DRAG MOVE, : "<<mapToScene(event->pos()).x()<<", SCAL: "<<m_scale;
358 m_dropItem->moveTo(mapToScene(event->pos()).x() / m_scale, m_scale, (track - m_dropItem->track()) * 50, track);
361 event->setDropAction(Qt::MoveAction);
362 if (event->mimeData()->hasText()) {
363 event->acceptProposedAction();
368 void CustomTrackView::dragLeaveEvent ( QDragLeaveEvent * event ) {
375 void CustomTrackView::dropEvent ( QDropEvent * event ) {
377 AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->clipProducer(), m_dropItem->track(), m_dropItem->startPos(), m_dropItem->rect(), m_dropItem->duration(), false, false);
378 m_commandStack->push(command);
379 m_dropItem->baseClip()->addReference();
380 m_document->updateClip(m_dropItem->baseClip()->getId());
381 kDebug()<<"IIIIIIIIIIIIIIIIIIIIIIII TRAX CNT: "<<m_tracksCount<<", DROP: "<<m_dropItem->track();
382 m_document->renderer()->mltInsertClip(m_tracksCount - m_dropItem->track(), GenTime(m_dropItem->startPos(), 25), m_dropItem->xml());
388 QStringList CustomTrackView::mimeTypes () const
390 QStringList qstrList;
391 // list of accepted mime types for drop
392 qstrList.append("text/plain");
396 Qt::DropActions CustomTrackView::supportedDropActions () const
398 // returns what actions are supported when dropping
399 return Qt::MoveAction;
402 void CustomTrackView::setDuration(int duration)
404 kDebug()<<"///////////// PRO DUR: "<<duration<<", height: "<<50 * m_tracksCount;
405 m_projectDuration = duration;
406 scene()->setSceneRect(0, 0, m_projectDuration + 500, scene()->sceneRect().height()); //50 * m_tracksCount);
410 void CustomTrackView::addTrack ()
413 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount);
414 //setSceneRect(0, 0, sceneRect().width(), 50 * m_tracksCount);
415 //verticalScrollBar()->setMaximum(50 * m_tracksCount);
416 //setFixedHeight(50 * m_tracksCount);
419 void CustomTrackView::removeTrack ()
422 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount);
425 void CustomTrackView::deleteClip(int clipId)
427 QList<QGraphicsItem *> itemList = items();
428 for (int i = 0; i < itemList.count(); i++) {
429 if (itemList.at(i)->type() == 70000) {
430 ClipItem *item = (ClipItem *)itemList.at(i);
431 if (item->clipProducer() == clipId) {
432 AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->track(), item->startPos(), item->rect(), item->duration(), true, true);
433 m_commandStack->push(command);
440 void CustomTrackView::setCursorPos(int pos, bool seek)
443 m_cursorLine->setPos(pos, 0);
444 int frame = mapToScene(QPoint(pos, 0)).x() / m_scale;
445 if (seek) m_document->renderer()->seek(GenTime(frame, 25));
448 int CustomTrackView::cursorPos()
453 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
455 QGraphicsView::mouseReleaseEvent(event);
456 setDragMode(QGraphicsView::NoDrag);
457 if (m_dragItem == NULL) return;
458 //kDebug()<<"/// MOVING CLIP: "<<m_startPos<<", END: "<<QPoint(m_dragItem->rect().x(),m_dragItem->rect().y());
459 if (m_operationMode == MOVE) {
461 MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), false);
462 m_commandStack->push(command);
463 m_document->renderer()->mltMoveClip(m_tracksCount - m_startPos.y(), m_tracksCount - m_dragItem->track(), m_startPos.x(), m_dragItem->startPos());
465 else if (m_operationMode == RESIZESTART) {
467 ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), true, false);
469 m_document->renderer()->mltResizeClipStart(m_tracksCount - m_dragItem->track(), GenTime(m_dragItem->endPos(), 25), GenTime(m_dragItem->startPos(), 25), GenTime(m_startPos.x(), 25), GenTime(m_dragItem->cropStart(), 25), GenTime(m_dragItem->cropStart(), 25) + GenTime(m_dragItem->endPos(), 25) - GenTime(m_dragItem->startPos(), 25));
470 m_commandStack->push(command);
471 m_document->renderer()->doRefresh();
473 else if (m_operationMode == RESIZEEND) {
475 ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->endPos(), m_dragItem->track()), false, false);
477 m_document->renderer()->mltResizeClipEnd(m_tracksCount - m_dragItem->track(), GenTime(m_dragItem->startPos(), 25), GenTime(m_dragItem->cropStart(), 25), GenTime(m_dragItem->cropStart(), 25) + GenTime(m_dragItem->endPos(), 25) - GenTime(m_dragItem->startPos(), 25));
478 m_commandStack->push(command);
479 m_document->renderer()->doRefresh();
481 m_operationMode = NONE;
485 void CustomTrackView::deleteClip (int track, int startpos, const QRectF &rect )
487 ClipItem *item = (ClipItem *) scene()->itemAt(rect.x() + 1, rect.y() + 1);
489 kDebug()<<"---------------- ERROR, CANNOT find clip to move at: "<<rect.x();
492 item->baseClip()->removeReference();
493 m_document->updateClip(item->baseClip()->getId());
495 m_document->renderer()->mltRemoveClip(m_tracksCount - track, GenTime(startpos, 25));
496 m_document->renderer()->doRefresh();
499 void CustomTrackView::addClip ( QDomElement xml, int clipId, int track, int startpos, const QRectF &rect, int duration )
501 QRect r(startpos * m_scale, 50 * track, duration * m_scale, 49);
502 DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId);
503 ClipItem *item = new ClipItem(baseclip, track, startpos, r, duration);
504 scene()->addItem(item);
505 baseclip->addReference();
506 m_document->updateClip(baseclip->getId());
507 m_document->renderer()->mltInsertClip(m_tracksCount - track, GenTime(startpos, 25), xml);
508 m_document->renderer()->doRefresh();
511 void CustomTrackView::moveClip ( const QPointF &startPos, const QPointF &endPos )
513 ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + 1) * m_scale, startPos.y() * 50 + 25);
515 kDebug()<<"---------------- ERROR, CANNOT find clip to move at: "<<startPos.x() * m_scale * FRAME_SIZE + 1<<", "<<startPos.y() * 50 + 25;
518 kDebug()<<"---------------- Move CLIP FROM: "<<startPos.x()<<", END:"<<endPos.x();
519 item->moveTo(endPos.x(), m_scale, (endPos.y() - startPos.y()) * 50, endPos.y());
520 m_document->renderer()->mltMoveClip(m_tracksCount - startPos.y(), m_tracksCount - endPos.y(), startPos.x(), endPos.x());
523 void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPos, bool resizeClipStart )
526 if (resizeClipStart) offset = 1;
528 ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + offset) * m_scale, startPos.y() * 50 + 25);
530 kDebug()<<"---------------- ERROR, CANNOT find clip to resize at: "<<startPos;
533 qreal diff = endPos.x() - startPos.x();
534 if (resizeClipStart) {
535 m_document->renderer()->mltResizeClipStart(m_tracksCount - item->track(), GenTime(item->endPos(), 25), GenTime(endPos.x(), 25), GenTime(item->startPos(), 25), GenTime(item->cropStart() + diff, 25), GenTime(item->cropStart() + diff, 25) + GenTime(item->endPos(), 25) - GenTime(endPos.x(), 25));
536 item->resizeStart(endPos.x(), m_scale);
539 m_document->renderer()->mltResizeClipEnd(m_tracksCount - item->track(), GenTime(item->startPos(), 25), GenTime(item->cropStart(), 25), GenTime(item->cropStart(), 25) + GenTime(endPos.x(), 25) - GenTime(item->startPos(), 25));
540 item->resizeEnd(endPos.x(), m_scale);
542 m_document->renderer()->doRefresh();
545 double CustomTrackView::getSnapPointForPos(double pos)
547 for (int i = 0; i < m_snapPoints.size(); ++i) {
548 //kDebug()<<"SNAP POINT: "<<m_snapPoints.at(i);
549 if (abs(pos - m_snapPoints.at(i) * m_scale) < 6 * m_scale) {
550 //kDebug()<<" FOUND SNAP POINT AT: "<<m_snapPoints.at(i)<<", current pos: "<<pos / m_scale;
551 return m_snapPoints.at(i) * m_scale + 0.5;
553 if (m_snapPoints.at(i) > pos) break;
558 void CustomTrackView::updateSnapPoints(ClipItem *selected)
560 m_snapPoints.clear();
562 if (selected) offset = selected->duration();
563 QList<QGraphicsItem *> itemList = items();
564 for (int i = 0; i < itemList.count(); i++) {
565 if (itemList.at(i)->type() == 70000 && itemList.at(i) != selected) {
566 ClipItem *item = (ClipItem *)itemList.at(i);
567 int start = item->startPos();
568 int fadein = item->fadeIn() + start;
569 int end = item->endPos();
570 int fadeout = end - item->fadeOut();
571 m_snapPoints.append(start);
572 if (fadein != start) m_snapPoints.append(fadein);
573 m_snapPoints.append(end);
574 if (fadeout != end) m_snapPoints.append(fadeout);
576 m_snapPoints.append(start - offset);
577 if (fadein != start) m_snapPoints.append(fadein - offset);
578 m_snapPoints.append(end - offset);
579 if (fadeout != end) m_snapPoints.append(fadeout - offset);
583 kDebug()<<" GOT SNAPPOINTS TOTAL: "<<m_snapPoints.count();
585 for (int i = 0; i < m_snapPoints.size(); ++i)
586 kDebug()<<"SNAP POINT: "<<m_snapPoints.at(i);
590 void CustomTrackView::setScale(double scaleFactor)
592 //scale(scaleFactor, scaleFactor);
593 m_scale = scaleFactor;
594 kDebug()<<" HHHHHHHH SCALING: "<<m_scale;
595 QList<QGraphicsItem *> itemList = items();
597 for (int i = 0; i < itemList.count(); i++) {
598 if (itemList.at(i)->type() == 70000) {
599 ClipItem *clip = (ClipItem *)itemList.at(i);
600 clip->setRect(clip->startPos() * m_scale, clip->rect().y(), clip->duration() * m_scale, clip->rect().height());
602 /*else if (itemList.at(i)->type() == 70001) {
603 LabelItem *label = (LabelItem *)itemList.at(i);
604 QGraphicsItem *parent = label->parentItem();
605 QRectF r = label->boundingRect();
606 QRectF p = parent->boundingRect();
607 label->setPos(p.x() + p.width() / 2 - r.width() / 2, p.y() + p.height() / 2 - r.height() / 2);
608 //label->setRect(clip->startPos() * m_scale, clip->rect().y(), clip->duration() * m_scale, clip->rect().height());
613 void CustomTrackView::drawBackground ( QPainter * painter, const QRectF & rect )
615 QColor base = palette().button().color();
616 //painter->setPen(base);
617 painter->setClipRect(rect);
618 painter->drawLine(0, 0, rect.width(), 0);
619 for (uint i = 0; i < m_tracksCount;i++)
621 painter->drawLine(0, 50 * (i+1), width(), 50 * (i+1));
622 painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i + 1));
624 int lowerLimit = 50 * m_tracksCount;
625 if (height() > lowerLimit)
626 painter->fillRect(QRectF(0, lowerLimit, rect.width(), height() - lowerLimit), QBrush(base));
629 void CustomTrackView::drawForeground ( QPainter * painter, const QRectF & rect )
631 //kDebug()<<"///// DRAWING FB: "<<rect.x()<<", width: "<<rect.width();
632 painter->fillRect(rect, QColor(50, rand() % 250,50,100));
633 painter->drawLine(m_cursorPos, rect.y(), m_cursorPos, rect.y() + rect.height());
636 #include "customtrackview.moc"