]> git.sesse.net Git - kdenlive/blob - src/customtrackview.cpp
Display mouse timecode position in statusbar
[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           int snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint);
95           int 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   int pos = event->x();
265   updateSnapPoints();
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   //kDebug()<<pos;
295   QGraphicsView::mousePressEvent(event);
296 }
297
298 void CustomTrackView::dragEnterEvent ( QDragEnterEvent * event )
299 {
300   if (event->mimeData()->hasText()) {
301     QString clip = event->mimeData()->text();
302     addItem(clip, event->pos());
303     event->acceptProposedAction();
304   }
305 }
306
307
308 void CustomTrackView::addItem(QString producer, QPoint pos)
309 {
310   QDomDocument doc;
311   doc.setContent(producer);
312   QDomElement elem = doc.documentElement();
313   int in = elem.attribute("in", 0).toInt();
314   int out = elem.attribute("out", 0).toInt() - in;
315   if (out == 0) out = elem.attribute("duration", 0).toInt();
316   kDebug()<<"ADDING CLIP: "<<producer<<", OUT: "<<out<<", POS: "<<mapToScene(pos);
317   int trackTop = ((int) mapToScene(pos).y()/50) * 50 + 1;
318   m_dropItem = new ClipItem(elem, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out);
319   scene()->addItem(m_dropItem);
320 }
321
322
323 void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) {
324   event->setDropAction(Qt::IgnoreAction);
325   if (m_dropItem) {
326     int track = (int) mapToScene(event->pos()).y()/50; //) * (m_scale * 50) + m_scale;
327      kDebug()<<"+++++++++++++   DRAG MOVE, : "<<mapToScene(event->pos()).x()<<", SCAL: "<<m_scale;
328     m_dropItem->moveTo(mapToScene(event->pos()).x() / m_scale, m_scale, (track - m_dropItem->track()) * 50, track);
329   }
330        //if (item) {
331   event->setDropAction(Qt::MoveAction);
332   if (event->mimeData()->hasText()) {
333     event->acceptProposedAction();
334   }
335         //}
336 }
337
338 void CustomTrackView::dragLeaveEvent ( QDragLeaveEvent * event ) {
339   if (m_dropItem) {
340     delete m_dropItem;
341     m_dropItem = NULL;
342   }
343 }
344
345 void CustomTrackView::dropEvent ( QDropEvent * event ) {
346   if (m_dropItem) {
347     AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->track(), m_dropItem->startPos(), m_dropItem->rect(), m_dropItem->duration(), false);
348     m_commandStack->push(command);
349   }
350   m_dropItem = NULL;
351 }
352
353
354 QStringList CustomTrackView::mimeTypes () const
355 {
356     QStringList qstrList;
357     // list of accepted mime types for drop
358     qstrList.append("text/plain");
359     return qstrList;
360 }
361
362 Qt::DropActions CustomTrackView::supportedDropActions () const
363 {
364     // returns what actions are supported when dropping
365     return Qt::MoveAction;
366 }
367
368 void CustomTrackView::setDuration(int duration)
369 {
370   kDebug()<<"/////////////  PRO DUR: "<<duration<<", height: "<<50 * m_tracksCount;
371   m_projectDuration = duration;
372   scene()->setSceneRect(0, 0, m_projectDuration + 500, scene()->sceneRect().height()); //50 * m_tracksCount);
373 }
374
375
376 void CustomTrackView::addTrack ()
377 {
378   m_tracksCount++;
379   m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount);
380   //setSceneRect(0, 0, sceneRect().width(), 50 * m_tracksCount);
381   //verticalScrollBar()->setMaximum(50 * m_tracksCount); 
382   //setFixedHeight(50 * m_tracksCount);
383 }
384
385 void CustomTrackView::removeTrack ()
386 {
387   m_tracksCount--;
388   m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount);
389 }
390
391 void CustomTrackView::setCursorPos(int pos)
392 {
393   m_cursorPos = pos;
394   m_cursorLine->setPos(pos, 0);
395 }
396
397 int CustomTrackView::cursorPos()
398 {
399   return m_cursorPos;
400 }
401
402 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
403 {
404   QGraphicsView::mouseReleaseEvent(event);
405   setDragMode(QGraphicsView::NoDrag);
406   if (m_dragItem == NULL) return;
407   //kDebug()<<"/// MOVING CLIP: "<<m_startPos<<", END: "<<QPoint(m_dragItem->rect().x(),m_dragItem->rect().y());
408   if (m_operationMode == MOVE) {
409     // move clip
410     MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), false);
411     m_commandStack->push(command);
412   }
413   else if (m_operationMode == RESIZESTART) {
414     // resize start
415     ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), true, false);
416     m_commandStack->push(command);
417   }
418   else if (m_operationMode == RESIZEEND) {
419     // resize end
420     ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->endPos(), m_dragItem->track()), false, false);
421     m_commandStack->push(command);
422   }
423   m_operationMode = NONE;
424   m_dragItem = NULL; 
425 }
426
427 void CustomTrackView::deleteClip ( const QRectF &rect )
428 {
429   ClipItem *item = (ClipItem *) scene()->itemAt(rect.x() + 1, rect.y() + 1);
430   if (!item) {
431     kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<<rect.x();
432     return;
433   }
434   delete item;
435 }
436
437 void CustomTrackView::addClip ( QDomElement xml, int track, int startpos, const QRectF &rect, int duration )
438 {
439   QRect r(startpos * m_scale, 50 * track, duration * m_scale, 49); 
440   ClipItem *item = new ClipItem(xml, track, startpos, r, duration);
441   scene()->addItem(item);
442 }
443
444 void CustomTrackView::moveClip ( const QPointF &startPos, const QPointF &endPos )
445 {
446   ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + 1) * m_scale, startPos.y() * 50 + 25);
447   if (!item) {
448     kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<<startPos.x() * m_scale * FRAME_SIZE + 1<<", "<<startPos.y() * 50 + 25;
449     return;
450   }
451   kDebug()<<"----------------  Move CLIP FROM: "<<startPos.x()<<", END:"<<endPos.x();
452   item->moveTo(endPos.x(), m_scale, (endPos.y() - startPos.y()) * 50, endPos.y());
453 }
454
455 void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPos, bool resizeClipStart )
456 {
457   int offset;
458   if (resizeClipStart) offset = 1;
459   else offset = -1;
460   ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + offset) * m_scale, startPos.y() * 50 + 25);
461   if (!item) {
462     kDebug()<<"----------------  ERROR, CANNOT find clip to resize at: "<<startPos;
463     return;
464   }
465   qreal diff = endPos.x() - startPos.x();
466   if (resizeClipStart) {
467     item->resizeStart(endPos.x(), m_scale);
468   }
469   else {
470     item->resizeEnd(endPos.x(), m_scale);
471   }
472 }
473
474 double CustomTrackView::getSnapPointForPos(double pos)
475 {
476   for (int i = 0; i < m_snapPoints.size(); ++i) {
477     if (abs(pos - m_snapPoints.at(i) * m_scale) < 6) return m_snapPoints.at(i) * m_scale;
478     if (m_snapPoints.at(i) > pos) break;
479   }
480   return pos;
481 }
482
483 void CustomTrackView::updateSnapPoints()
484 {
485   m_snapPoints.clear();
486   QList<QGraphicsItem *> itemList = items();
487   for (int i = 0; i < itemList.count(); i++) {
488     if (itemList.at(i)->type() == 70000) {
489       ClipItem *item = (ClipItem *)itemList.at(i);
490       m_snapPoints.append(item->startPos());
491       if (item->fadeIn() != 0) m_snapPoints.append(item->startPos() + item->fadeIn());
492       m_snapPoints.append(item->endPos());
493       if (item->fadeOut() != 0) m_snapPoints.append(item->endPos() - item->fadeOut());      
494     }
495   }
496   qSort(m_snapPoints);
497 }
498
499
500 void CustomTrackView::setScale(double scaleFactor)
501 {
502   //scale(scaleFactor, scaleFactor);
503   m_scale = scaleFactor;
504   kDebug()<<" HHHHHHHH  SCALING: "<<m_scale;
505   QList<QGraphicsItem *> itemList = items();
506
507   for (int i = 0; i < itemList.count(); i++) {
508       if (itemList.at(i)->type() == 70000) {
509         ClipItem *clip = (ClipItem *)itemList.at(i);
510         clip->setRect(clip->startPos() * m_scale, clip->rect().y(), clip->duration() * m_scale, clip->rect().height());
511       }
512       /*else if (itemList.at(i)->type() == 70001) {
513         LabelItem *label = (LabelItem *)itemList.at(i);
514         QGraphicsItem *parent = label->parentItem();
515         QRectF r = label->boundingRect();
516         QRectF p = parent->boundingRect();
517         label->setPos(p.x() + p.width() / 2 - r.width() / 2, p.y() + p.height() / 2 - r.height() / 2);
518         //label->setRect(clip->startPos() * m_scale, clip->rect().y(), clip->duration() * m_scale, clip->rect().height());
519       }*/
520     }
521 }
522
523 void CustomTrackView::drawBackground ( QPainter * painter, const QRectF & rect )  
524 {
525   QColor base = palette().button().color();
526   painter->setPen(base);
527   painter->setClipRect(rect);
528   painter->drawLine(0, 0, rect.width(), 0);
529     for (uint i = 0; i < m_tracksCount;i++)
530     {
531     painter->drawLine(0, 50 * (i+1), width(), 50 * (i+1));
532       //painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i));
533     }
534   int lowerLimit = 50 * m_tracksCount;
535   if (height() > lowerLimit)
536   painter->fillRect(QRectF(0, lowerLimit, rect.width(), height() - lowerLimit), QBrush(base));
537 }
538 /*
539 void CustomTrackView::drawForeground ( QPainter * painter, const QRectF & rect )  
540 {
541   //kDebug()<<"/////  DRAWING FB: "<<rect.x()<<", width: "<<rect.width();
542   painter->fillRect(rect, QColor(50, rand() % 250,50,100));
543   painter->drawLine(m_cursorPos, rect.y(), m_cursorPos, rect.y() + rect.height());
544 }
545 */
546 #include "customtrackview.moc"