]> git.sesse.net Git - kdenlive/blob - src/customtrackview.cpp
adapt to latest MLT changes
[kdenlive] / src / customtrackview.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20 #include <QMouseEvent>
21 #include <QStylePainter>
22 #include <QGraphicsItem>
23 #include <QDomDocument>
24 #include <QScrollBar>
25
26 #include <KDebug>
27 #include <KLocale>
28 #include <KUrl>
29
30 #include "customtrackview.h"
31 #include "clipitem.h"
32 #include "definitions.h"
33 #include "moveclipcommand.h"
34 #include "resizeclipcommand.h"
35 #include "addtimelineclipcommand.h"
36
37 CustomTrackView::CustomTrackView(KUndoStack *commandStack, QGraphicsScene * projectscene, QWidget *parent)
38     : QGraphicsView(projectscene, parent), m_commandStack(commandStack), 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)
39 {
40   setMouseTracking(true);
41   setAcceptDrops(true);
42   m_animationTimer = new QTimeLine(800);
43   m_animationTimer->setFrameRange(0, 5);
44   m_animationTimer->setUpdateInterval(100);
45   m_animationTimer->setLoopCount(0);
46   m_tipColor = QColor(230, 50, 0, 150);
47   setContentsMargins(0, 0, 0, 0);
48   if (projectscene) {
49     m_cursorLine = projectscene->addLine(0, 0, 0, 50);
50     m_cursorLine->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIgnoresTransformations);
51     m_cursorLine->setZValue(1000);
52   }
53 }
54
55 void CustomTrackView::initView()
56 {
57
58 }
59
60 // virtual
61 void CustomTrackView::resizeEvent ( QResizeEvent * event )
62 {
63   QGraphicsView::resizeEvent(event);
64 }
65
66 // virtual
67 void CustomTrackView::wheelEvent ( QWheelEvent * e ) 
68 {
69   if (e->modifiers() == Qt::ControlModifier) {
70     if (e->delta() > 0) emit zoomIn();
71     else emit zoomOut();
72   }
73   else {
74     if (e->delta() > 0) horizontalScrollBar()->setValue (horizontalScrollBar()->value() + horizontalScrollBar()->singleStep ());
75     else  horizontalScrollBar()->setValue (horizontalScrollBar()->value() - horizontalScrollBar()->singleStep ());
76   }
77 }
78
79
80 // virtual 
81 void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
82 {
83   int pos = event->x();
84   emit mousePosition(mapToScene(event->pos()).x() / m_scale);
85   /*if (event->modifiers() == Qt::ControlModifier)
86     setDragMode(QGraphicsView::ScrollHandDrag);
87   else if (event->modifiers() == Qt::ShiftModifier) 
88     setDragMode(QGraphicsView::RubberBandDrag);
89   else*/ {
90
91       if (m_dragItem) { //event->button() == Qt::LeftButton) {
92         // a button was pressed, delete visual tips
93         if (m_operationMode == MOVE) {
94           double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint);
95           double moveX = snappedPos; //mapToScene(event->pos()).x();
96           //kDebug()<<"///////  MOVE CLIP, EVENT Y: "<<event->scenePos().y()<<", SCENE HEIGHT: "<<scene()->sceneRect().height();
97           int moveTrack = (int)  mapToScene(event->pos()).y() / 50;
98           int currentTrack = m_dragItem->track();
99
100           if (moveTrack > m_tracksCount - 1) moveTrack = m_tracksCount - 1;
101           else if (moveTrack < 0) moveTrack = 0;
102
103           int offset = moveTrack - currentTrack;
104           if (offset != 0) offset = 50 * offset;
105           m_dragItem->moveTo(moveX / m_scale, m_scale, offset, moveTrack);
106         }
107         else if (m_operationMode == RESIZESTART) {
108           int pos = mapToScene(event->pos()).x();
109           m_dragItem->resizeStart(pos / m_scale, m_scale);
110         }
111         else if (m_operationMode == RESIZEEND) {
112           int pos = mapToScene(event->pos()).x();
113           m_dragItem->resizeEnd(pos / m_scale, m_scale);
114         }
115         else if (m_operationMode == FADEIN) {
116           int pos = mapToScene(event->pos()).x() / m_scale;
117           m_dragItem->setFadeIn(pos - m_dragItem->startPos(), m_scale);
118         }
119         else if (m_operationMode == FADEOUT) {
120           int pos = mapToScene(event->pos()).x() / m_scale;
121           m_dragItem->setFadeOut(m_dragItem->endPos() - pos, m_scale);
122         }
123
124         if (m_animation) delete m_animation;
125         m_animation = NULL;
126         if (m_visualTip) delete m_visualTip;
127         m_visualTip = NULL;
128         QGraphicsView::mouseMoveEvent(event);
129         return;
130       }
131
132     QList<QGraphicsItem *> itemList = items( event->pos());
133     int i = 0;
134     QGraphicsItem *item = NULL;
135     for (int i = 0; i < itemList.count(); i++) {
136       if (itemList.at(i)->type() == 70000) {
137         item = itemList.at(i);
138         break;
139       }
140     }
141     if (item) {
142       ClipItem *clip = (ClipItem*) item;
143       double size = mapToScene(QPoint(8, 0)).x();
144       OPERATIONTYPE opMode = clip->operationMode(mapToScene(event->pos()), m_scale);
145       if (opMode == m_moveOpMode) {
146         QGraphicsView::mouseMoveEvent(event);
147         return;
148       }
149       else {
150       if (m_visualTip) {
151         if (m_animation) delete m_animation;
152         m_animation = NULL;
153         delete m_visualTip;
154         m_visualTip = NULL;
155       }
156       }
157       m_moveOpMode = opMode;
158       if (opMode == MOVE) {
159         setCursor(Qt::OpenHandCursor);
160       }
161       else if (opMode == RESIZESTART) {
162         kDebug()<<"********  RESIZE CLIP START; WIDTH: "<<size;
163         if (m_visualTip == NULL) {
164           m_visualTip = new QGraphicsRectItem(clip->rect().x(), clip->rect().y(), size, clip->rect().height());
165           ((QGraphicsRectItem*) m_visualTip)->setBrush(m_tipColor);
166           ((QGraphicsRectItem*) m_visualTip)->setPen(QPen(Qt::transparent));
167           m_visualTip->setZValue (100);
168           m_animation = new QGraphicsItemAnimation;
169           m_animation->setItem(m_visualTip);
170           m_animation->setTimeLine(m_animationTimer);
171           m_visualTip->setPos(0, 0);
172           double scale = 2.0;
173           m_animation->setScaleAt(.5, scale, 1);
174           m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
175           scale = 1.0;
176           m_animation->setScaleAt(1, scale, 1);
177           m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
178           scene()->addItem(m_visualTip);
179           m_animationTimer->start();
180         }
181         setCursor(Qt::SizeHorCursor);
182       }
183       else if (opMode == RESIZEEND) {
184         if (m_visualTip == NULL) {
185           m_visualTip = new QGraphicsRectItem(clip->rect().x() + clip->rect().width() - size, clip->rect().y(), size, clip->rect().height());
186           ((QGraphicsRectItem*) m_visualTip)->setBrush(m_tipColor);
187           ((QGraphicsRectItem*) m_visualTip)->setPen(QPen(Qt::transparent));
188           m_visualTip->setZValue (100);
189           m_animation = new QGraphicsItemAnimation;
190           m_animation->setItem(m_visualTip);
191           m_animation->setTimeLine(m_animationTimer);
192           m_visualTip->setPos(0, 0);
193           double scale = 2.0;
194           m_animation->setScaleAt(.5, scale, 1);
195           m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width(), 0));
196           scale = 1.0;
197           m_animation->setScaleAt(1, scale, 1);
198           m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
199           scene()->addItem(m_visualTip);
200           m_animationTimer->start();
201         }
202         setCursor(Qt::SizeHorCursor);
203       }
204       else if (opMode == FADEIN) {
205         if (m_visualTip == NULL) {
206           m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->fadeIn() * m_scale - size, clip->rect().y() - 8, size * 2, 16);
207           ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
208           ((QGraphicsEllipseItem*) m_visualTip)->setPen(QPen(Qt::transparent));
209           m_visualTip->setZValue (100);
210           m_animation = new QGraphicsItemAnimation;
211           m_animation->setItem(m_visualTip);
212           m_animation->setTimeLine(m_animationTimer);
213           m_visualTip->setPos(0, 0);
214           double scale = 2.0;
215           m_animation->setScaleAt(.5, scale, scale);
216           m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale -  clip->fadeIn() * m_scale, clip->rect().y() - clip->rect().y() * scale));
217           scale = 1.0;
218           m_animation->setScaleAt(1, scale, scale);
219           m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale));
220           scene()->addItem(m_visualTip);
221           m_animationTimer->start();
222         }
223         setCursor(Qt::PointingHandCursor);
224       }
225       else if (opMode == FADEOUT) {
226         if (m_visualTip == NULL) {
227           m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->rect().width() - clip->fadeOut() * m_scale - size, clip->rect().y() - 8, size*2, 16);
228           ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
229           ((QGraphicsEllipseItem*) m_visualTip)->setPen(QPen(Qt::transparent));
230           m_visualTip->setZValue (100);
231           m_animation = new QGraphicsItemAnimation;
232           m_animation->setItem(m_visualTip);
233           m_animation->setTimeLine(m_animationTimer);
234           m_visualTip->setPos(0, 0);
235           double scale = 2.0;
236           m_animation->setScaleAt(.5, scale, scale);      
237           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));
238           scale = 1.0;
239           m_animation->setScaleAt(1, scale, scale);
240           m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale));
241           scene()->addItem(m_visualTip);
242           m_animationTimer->start();
243         }
244         setCursor(Qt::PointingHandCursor);
245       }
246     }
247     else {
248       m_moveOpMode = NONE;
249       if (m_visualTip) {
250         if (m_animation) delete m_animation;
251         m_animation = NULL;
252         delete m_visualTip;
253         m_visualTip = NULL;
254       }
255       setCursor(Qt::ArrowCursor);
256     }
257   }
258   QGraphicsView::mouseMoveEvent(event);
259 }
260
261 // virtual 
262 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
263 {
264   kDebug()<<"-- TIMELINE MSE PRESSED";
265   int pos = event->x();
266   if (event->modifiers() == Qt::ControlModifier) 
267     setDragMode(QGraphicsView::ScrollHandDrag);
268   else if (event->modifiers() == Qt::ShiftModifier) 
269     setDragMode(QGraphicsView::RubberBandDrag);
270   else {
271     bool collision = false;
272     QList<QGraphicsItem *> collisionList = items(event->pos());
273     for (int i = 0; i < collisionList.size(); ++i) {
274       QGraphicsItem *item = collisionList.at(i);
275       if (item->type() == 70000) {
276         m_dragItem = (ClipItem *) item;
277         m_clickPoint = mapToScene(event->pos()).x() - m_dragItem->startPos() * m_scale;
278         m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale);
279         if (m_operationMode == MOVE || m_operationMode == RESIZESTART) m_startPos = QPointF(m_dragItem->startPos(), m_dragItem->track());
280         else if (m_operationMode == RESIZEEND) m_startPos = QPointF(m_dragItem->endPos(), m_dragItem->track());
281         kDebug()<<"//////// ITEM CLICKED: "<<m_startPos;
282         collision = true;
283         break;
284       }
285     }
286     if (!collision) {
287       kDebug()<<"//////// NO ITEM FOUND ON CLICK";
288       m_dragItem = NULL;
289       setCursor(Qt::ArrowCursor);
290       setCursorPos((int) mapToScene(event->x(), 0).x());
291       emit cursorMoved(cursorPos());
292     }
293   }
294   updateSnapPoints(m_dragItem);
295   //kDebug()<<pos;
296   QGraphicsView::mousePressEvent(event);
297 }
298
299 void CustomTrackView::dragEnterEvent ( QDragEnterEvent * event )
300 {
301   if (event->mimeData()->hasText()) {
302     QString clip = event->mimeData()->text();
303     addItem(clip, event->pos());
304     event->acceptProposedAction();
305   }
306 }
307
308
309 void CustomTrackView::addItem(QString producer, QPoint pos)
310 {
311   QDomDocument doc;
312   doc.setContent(producer);
313   QDomElement elem = doc.documentElement();
314   int in = elem.attribute("in", 0).toInt();
315   int out = elem.attribute("out", 0).toInt() - in;
316   if (out == 0) out = elem.attribute("duration", 0).toInt();
317   kDebug()<<"ADDING CLIP: "<<producer<<", OUT: "<<out<<", POS: "<<mapToScene(pos);
318   int trackTop = ((int) mapToScene(pos).y()/50) * 50 + 1;
319   m_dropItem = new ClipItem(elem, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out);
320   scene()->addItem(m_dropItem);
321 }
322
323
324 void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) {
325   event->setDropAction(Qt::IgnoreAction);
326   if (m_dropItem) {
327     int track = (int) mapToScene(event->pos()).y()/50; //) * (m_scale * 50) + m_scale;
328      kDebug()<<"+++++++++++++   DRAG MOVE, : "<<mapToScene(event->pos()).x()<<", SCAL: "<<m_scale;
329     m_dropItem->moveTo(mapToScene(event->pos()).x() / m_scale, m_scale, (track - m_dropItem->track()) * 50, track);
330   }
331        //if (item) {
332   event->setDropAction(Qt::MoveAction);
333   if (event->mimeData()->hasText()) {
334     event->acceptProposedAction();
335   }
336         //}
337 }
338
339 void CustomTrackView::dragLeaveEvent ( QDragLeaveEvent * event ) {
340   if (m_dropItem) {
341     delete m_dropItem;
342     m_dropItem = NULL;
343   }
344 }
345
346 void CustomTrackView::dropEvent ( QDropEvent * event ) {
347   if (m_dropItem) {
348     AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->track(), m_dropItem->startPos(), m_dropItem->rect(), m_dropItem->duration(), false);
349     m_commandStack->push(command);
350   }
351   m_dropItem = NULL;
352 }
353
354
355 QStringList CustomTrackView::mimeTypes () const
356 {
357     QStringList qstrList;
358     // list of accepted mime types for drop
359     qstrList.append("text/plain");
360     return qstrList;
361 }
362
363 Qt::DropActions CustomTrackView::supportedDropActions () const
364 {
365     // returns what actions are supported when dropping
366     return Qt::MoveAction;
367 }
368
369 void CustomTrackView::setDuration(int duration)
370 {
371   kDebug()<<"/////////////  PRO DUR: "<<duration<<", height: "<<50 * m_tracksCount;
372   m_projectDuration = duration;
373   scene()->setSceneRect(0, 0, m_projectDuration + 500, scene()->sceneRect().height()); //50 * m_tracksCount);
374 }
375
376
377 void CustomTrackView::addTrack ()
378 {
379   m_tracksCount++;
380   m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount);
381   //setSceneRect(0, 0, sceneRect().width(), 50 * m_tracksCount);
382   //verticalScrollBar()->setMaximum(50 * m_tracksCount); 
383   //setFixedHeight(50 * m_tracksCount);
384 }
385
386 void CustomTrackView::removeTrack ()
387 {
388   m_tracksCount--;
389   m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount);
390 }
391
392 void CustomTrackView::setCursorPos(int pos)
393 {
394   m_cursorPos = pos;
395   m_cursorLine->setPos(pos, 0);
396 }
397
398 int CustomTrackView::cursorPos()
399 {
400   return m_cursorPos;
401 }
402
403 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
404 {
405   QGraphicsView::mouseReleaseEvent(event);
406   setDragMode(QGraphicsView::NoDrag);
407   if (m_dragItem == NULL) return;
408   //kDebug()<<"/// MOVING CLIP: "<<m_startPos<<", END: "<<QPoint(m_dragItem->rect().x(),m_dragItem->rect().y());
409   if (m_operationMode == MOVE) {
410     // move clip
411     MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), false);
412     m_commandStack->push(command);
413   }
414   else if (m_operationMode == RESIZESTART) {
415     // resize start
416     ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), true, false);
417     m_commandStack->push(command);
418   }
419   else if (m_operationMode == RESIZEEND) {
420     // resize end
421     ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->endPos(), m_dragItem->track()), false, false);
422     m_commandStack->push(command);
423   }
424   m_operationMode = NONE;
425   m_dragItem = NULL; 
426 }
427
428 void CustomTrackView::deleteClip ( const QRectF &rect )
429 {
430   ClipItem *item = (ClipItem *) scene()->itemAt(rect.x() + 1, rect.y() + 1);
431   if (!item) {
432     kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<<rect.x();
433     return;
434   }
435   delete item;
436 }
437
438 void CustomTrackView::addClip ( QDomElement xml, int track, int startpos, const QRectF &rect, int duration )
439 {
440   QRect r(startpos * m_scale, 50 * track, duration * m_scale, 49); 
441   ClipItem *item = new ClipItem(xml, track, startpos, r, duration);
442   scene()->addItem(item);
443 }
444
445 void CustomTrackView::moveClip ( const QPointF &startPos, const QPointF &endPos )
446 {
447   ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + 1) * m_scale, startPos.y() * 50 + 25);
448   if (!item) {
449     kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<<startPos.x() * m_scale * FRAME_SIZE + 1<<", "<<startPos.y() * 50 + 25;
450     return;
451   }
452   kDebug()<<"----------------  Move CLIP FROM: "<<startPos.x()<<", END:"<<endPos.x();
453   item->moveTo(endPos.x(), m_scale, (endPos.y() - startPos.y()) * 50, endPos.y());
454 }
455
456 void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPos, bool resizeClipStart )
457 {
458   int offset;
459   if (resizeClipStart) offset = 1;
460   else offset = -1;
461   ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + offset) * m_scale, startPos.y() * 50 + 25);
462   if (!item) {
463     kDebug()<<"----------------  ERROR, CANNOT find clip to resize at: "<<startPos;
464     return;
465   }
466   qreal diff = endPos.x() - startPos.x();
467   if (resizeClipStart) {
468     item->resizeStart(endPos.x(), m_scale);
469   }
470   else {
471     item->resizeEnd(endPos.x(), m_scale);
472   }
473 }
474
475 double CustomTrackView::getSnapPointForPos(double pos)
476 {
477   for (int i = 0; i < m_snapPoints.size(); ++i) {
478     //kDebug()<<"SNAP POINT: "<<m_snapPoints.at(i);
479     if (abs(pos - m_snapPoints.at(i) * m_scale) < 6 * m_scale) {
480       //kDebug()<<" FOUND SNAP POINT AT: "<<m_snapPoints.at(i)<<", current pos: "<<pos / m_scale;
481       return m_snapPoints.at(i) * m_scale + 0.5;
482     }
483     if (m_snapPoints.at(i) > pos) break;
484   }
485   return pos;
486 }
487
488 void CustomTrackView::updateSnapPoints(ClipItem *selected)
489 {
490   m_snapPoints.clear();
491   int offset = 0;
492   if (selected) offset = selected->duration();
493   QList<QGraphicsItem *> itemList = items();
494   for (int i = 0; i < itemList.count(); i++) {
495     if (itemList.at(i)->type() == 70000 && itemList.at(i) != selected) {
496       ClipItem *item = (ClipItem *)itemList.at(i);
497       int start = item->startPos();
498       int fadein = item->fadeIn() + start;
499       int end = item->endPos();
500       int fadeout = end - item->fadeOut();
501       m_snapPoints.append(start);
502       if (fadein != start) m_snapPoints.append(fadein);
503       m_snapPoints.append(end);
504       if (fadeout != end) m_snapPoints.append(fadeout);
505       if (offset != 0) {
506         m_snapPoints.append(start - offset);
507         if (fadein != start) m_snapPoints.append(fadein - offset);
508         m_snapPoints.append(end - offset);
509         if (fadeout != end) m_snapPoints.append(fadeout - offset);
510       }
511     }
512   }
513   kDebug()<<" GOT SNAPPOINTS TOTAL: "<<m_snapPoints.count();
514   qSort(m_snapPoints);
515   for (int i = 0; i < m_snapPoints.size(); ++i)
516     kDebug()<<"SNAP POINT: "<<m_snapPoints.at(i);
517 }
518
519
520 void CustomTrackView::setScale(double scaleFactor)
521 {
522   //scale(scaleFactor, scaleFactor);
523   m_scale = scaleFactor;
524   kDebug()<<" HHHHHHHH  SCALING: "<<m_scale;
525   QList<QGraphicsItem *> itemList = items();
526
527   for (int i = 0; i < itemList.count(); i++) {
528       if (itemList.at(i)->type() == 70000) {
529         ClipItem *clip = (ClipItem *)itemList.at(i);
530         clip->setRect(clip->startPos() * m_scale, clip->rect().y(), clip->duration() * m_scale, clip->rect().height());
531       }
532       /*else if (itemList.at(i)->type() == 70001) {
533         LabelItem *label = (LabelItem *)itemList.at(i);
534         QGraphicsItem *parent = label->parentItem();
535         QRectF r = label->boundingRect();
536         QRectF p = parent->boundingRect();
537         label->setPos(p.x() + p.width() / 2 - r.width() / 2, p.y() + p.height() / 2 - r.height() / 2);
538         //label->setRect(clip->startPos() * m_scale, clip->rect().y(), clip->duration() * m_scale, clip->rect().height());
539       }*/
540     }
541 }
542
543 void CustomTrackView::drawBackground ( QPainter * painter, const QRectF & rect )  
544 {
545   QColor base = palette().button().color();
546   painter->setPen(base);
547   painter->setClipRect(rect);
548   painter->drawLine(0, 0, rect.width(), 0);
549     for (uint i = 0; i < m_tracksCount;i++)
550     {
551     painter->drawLine(0, 50 * (i+1), width(), 50 * (i+1));
552       //painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i));
553     }
554   int lowerLimit = 50 * m_tracksCount;
555   if (height() > lowerLimit)
556   painter->fillRect(QRectF(0, lowerLimit, rect.width(), height() - lowerLimit), QBrush(base));
557 }
558 /*
559 void CustomTrackView::drawForeground ( QPainter * painter, const QRectF & rect )  
560 {
561   //kDebug()<<"/////  DRAWING FB: "<<rect.x()<<", width: "<<rect.width();
562   painter->fillRect(rect, QColor(50, rand() % 250,50,100));
563   painter->drawLine(m_cursorPos, rect.y(), m_cursorPos, rect.y() + rect.height());
564 }
565 */
566 #include "customtrackview.moc"