]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Display mouse timecode position in statusbar
[kdenlive] / src / customtrackview.cpp
index 6258358a16d1930bb26da87ab5e63bb9496b3f9d..1ca8a722a49f8771d86edc5d94fe33b04011eb8a 100644 (file)
@@ -34,8 +34,8 @@
 #include "resizeclipcommand.h"
 #include "addtimelineclipcommand.h"
 
-CustomTrackView::CustomTrackView(KUndoStack *commandStack, QGraphicsScene * scene, QWidget *parent)
-    : QGraphicsView(scene, 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)
+CustomTrackView::CustomTrackView(KUndoStack *commandStack, QGraphicsScene * projectscene, QWidget *parent)
+    : 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)
 {
   setMouseTracking(true);
   setAcceptDrops(true);
@@ -44,18 +44,23 @@ CustomTrackView::CustomTrackView(KUndoStack *commandStack, QGraphicsScene * scen
   m_animationTimer->setUpdateInterval(100);
   m_animationTimer->setLoopCount(0);
   m_tipColor = QColor(230, 50, 0, 150);
+  setContentsMargins(0, 0, 0, 0);
+  if (projectscene) {
+    m_cursorLine = projectscene->addLine(0, 0, 0, 50);
+    m_cursorLine->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIgnoresTransformations);
+    m_cursorLine->setZValue(1000);
+  }
 }
 
 void CustomTrackView::initView()
 {
-  m_cursorLine = scene()->addLine(0, 0, 0, height());
-  m_cursorLine->setZValue(1000);
+
 }
 
 // virtual
 void CustomTrackView::resizeEvent ( QResizeEvent * event )
 {
-  if (m_cursorLine) m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), height());
+  QGraphicsView::resizeEvent(event);
 }
 
 // virtual
@@ -76,14 +81,46 @@ void CustomTrackView::wheelEvent ( QWheelEvent * e )
 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 (event->button() == Qt::LeftButton) {
+      if (m_dragItem) { //event->button() == Qt::LeftButton) {
        // a button was pressed, delete visual tips
+       if (m_operationMode == MOVE) {
+         int snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint);
+         int 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;
@@ -104,7 +141,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
     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;
@@ -166,7 +203,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
       }
       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);
@@ -176,7 +213,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
          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));
@@ -187,7 +224,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
       }
       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);
@@ -197,7 +234,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
          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));
@@ -225,33 +262,28 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
 {
   int pos = event->x();
+  updateSnapPoints();
   if (event->modifiers() == Qt::ControlModifier) 
     setDragMode(QGraphicsView::ScrollHandDrag);
   else if (event->modifiers() == Qt::ShiftModifier) 
     setDragMode(QGraphicsView::RubberBandDrag);
   else {
-    QGraphicsItem * item = itemAt(event->pos());
-    if (item && item->type() != 70000) item = item->parentItem();
-    if (item && item->type() == 70000) {
-      m_dragItem = (ClipItem *) item;
-      m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())));
-      if (m_operationMode == MOVE || m_operationMode == RESIZESTART) m_startPos = QPointF(m_dragItem->rect().x(), m_dragItem->rect().y());
-      else if (m_operationMode == RESIZEEND) m_startPos = QPointF(m_dragItem->rect().x() + m_dragItem->rect().width(), m_dragItem->rect().y());
-
-     kDebug()<<"//////// ITEM CLICKED: "<<m_startPos;
-      /*while (item->parentItem()) 
-       item = item->parentItem();
-
-       int cursorPos = event->x();
-       QRectF itemRect = item->sceneBoundingRect();
-       int itemStart = mapFromScene(itemRect.x(), 0).x();
-       int itemEnd = mapFromScene(itemRect.x() + itemRect.width(), 0).x();
-       if (abs(itemStart - cursorPos) < 6)
-         ((ClipItem *) item )->setResizeMode(1);
-       else if (abs(itemEnd - cursorPos) < 6)
-         ((ClipItem *) item )->setResizeMode(2);
-    */}
-    else {
+    bool collision = false;
+    QList<QGraphicsItem *> collisionList = items(event->pos());
+    for (int i = 0; i < collisionList.size(); ++i) {
+      QGraphicsItem *item = collisionList.at(i);
+      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_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;
+       collision = true;
+       break;
+      }
+    }
+    if (!collision) {
       kDebug()<<"//////// NO ITEM FOUND ON CLICK";
       m_dragItem = NULL;
       setCursor(Qt::ArrowCursor);
@@ -279,13 +311,11 @@ void CustomTrackView::addItem(QString producer, QPoint pos)
   doc.setContent(producer);
   QDomElement elem = doc.documentElement();
   int in = elem.attribute("in", 0).toInt();
-  int out = elem.attribute("duration", 0).toInt();
-  if (out == 0) out = elem.attribute("out", 0).toInt() - in;
+  int out = elem.attribute("out", 0).toInt() - in;
+  if (out == 0) out = elem.attribute("duration", 0).toInt();
   kDebug()<<"ADDING CLIP: "<<producer<<", OUT: "<<out<<", POS: "<<mapToScene(pos);
   int trackTop = ((int) mapToScene(pos).y()/50) * 50 + 1;
-  QString clipName = elem.attribute("name");
-  if (clipName.isEmpty()) clipName = KUrl(elem.attribute("resource")).fileName();
-  m_dropItem = new ClipItem(elem.attribute("type").toInt(), clipName, elem.attribute("id").toInt(), out, QRectF(mapToScene(pos).x(), trackTop, out, 49));
+  m_dropItem = new ClipItem(elem, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out);
   scene()->addItem(m_dropItem);
 }
 
@@ -293,14 +323,15 @@ void CustomTrackView::addItem(QString producer, QPoint pos)
 void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) {
   event->setDropAction(Qt::IgnoreAction);
   if (m_dropItem) {
-    int trackTop = ((int) mapToScene(event->pos()).y()/50) * 50 + 1;
-    m_dropItem->moveTo(mapToScene(event->pos()).x(), trackTop - m_dropItem->rect().y());
+    int track = (int) mapToScene(event->pos()).y()/50; //) * (m_scale * 50) + m_scale;
+     kDebug()<<"+++++++++++++   DRAG MOVE, : "<<mapToScene(event->pos()).x()<<", SCAL: "<<m_scale;
+    m_dropItem->moveTo(mapToScene(event->pos()).x() / m_scale, m_scale, (track - m_dropItem->track()) * 50, track);
+  }
+       //if (item) {
+  event->setDropAction(Qt::MoveAction);
+  if (event->mimeData()->hasText()) {
+    event->acceptProposedAction();
   }
-        //if (item) {
-                event->setDropAction(Qt::MoveAction);
-                if (event->mimeData()->hasText()) {
-                        event->acceptProposedAction();
-                }
         //}
 }
 
@@ -313,7 +344,7 @@ void CustomTrackView::dragLeaveEvent ( QDragLeaveEvent * event ) {
 
 void CustomTrackView::dropEvent ( QDropEvent * event ) {
   if (m_dropItem) {
-    AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->clipType(), m_dropItem->clipName(), m_dropItem->clipProducer(), m_dropItem->maxDuration(), m_dropItem->rect(), false);
+    AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->track(), m_dropItem->startPos(), m_dropItem->rect(), m_dropItem->duration(), false);
     m_commandStack->push(command);
   }
   m_dropItem = NULL;
@@ -334,14 +365,27 @@ Qt::DropActions CustomTrackView::supportedDropActions () const
     return Qt::MoveAction;
 }
 
+void CustomTrackView::setDuration(int duration)
+{
+  kDebug()<<"/////////////  PRO DUR: "<<duration<<", height: "<<50 * m_tracksCount;
+  m_projectDuration = duration;
+  scene()->setSceneRect(0, 0, m_projectDuration + 500, scene()->sceneRect().height()); //50 * m_tracksCount);
+}
+
+
 void CustomTrackView::addTrack ()
 {
   m_tracksCount++;
+  m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount);
+  //setSceneRect(0, 0, sceneRect().width(), 50 * m_tracksCount);
+  //verticalScrollBar()->setMaximum(50 * m_tracksCount); 
+  //setFixedHeight(50 * m_tracksCount);
 }
 
 void CustomTrackView::removeTrack ()
 {
   m_tracksCount--;
+  m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount);
 }
 
 void CustomTrackView::setCursorPos(int pos)
@@ -363,19 +407,21 @@ void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
   //kDebug()<<"/// MOVING CLIP: "<<m_startPos<<", END: "<<QPoint(m_dragItem->rect().x(),m_dragItem->rect().y());
   if (m_operationMode == MOVE) {
     // move clip
-    MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->rect().x(), m_dragItem->rect().y()), false);
+    MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), false);
     m_commandStack->push(command);
   }
   else if (m_operationMode == RESIZESTART) {
     // resize start
-    ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->rect().x(), m_dragItem->rect().y()), true, false);
+    ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), true, false);
     m_commandStack->push(command);
   }
   else if (m_operationMode == RESIZEEND) {
     // resize end
-    ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->rect().x() + m_dragItem->rect().width(), m_dragItem->rect().y()), false, false);
+    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; 
 }
 
 void CustomTrackView::deleteClip ( const QRectF &rect )
@@ -388,24 +434,22 @@ void CustomTrackView::deleteClip ( const QRectF &rect )
   delete item;
 }
 
-void CustomTrackView::addClip ( int clipType, QString clipName, int clipProducer, int maxDuration, const QRectF &rect )
+void CustomTrackView::addClip ( QDomElement xml, int track, int startpos, const QRectF &rect, int duration )
 {
-  ClipItem *item = new ClipItem(clipType, clipName, clipProducer, maxDuration, rect);
+  QRect r(startpos * m_scale, 50 * track, duration * m_scale, 49); 
+  ClipItem *item = new ClipItem(xml, track, startpos, r, duration);
   scene()->addItem(item);
 }
 
 void CustomTrackView::moveClip ( const QPointF &startPos, const QPointF &endPos )
 {
-  ClipItem *item = (ClipItem *) scene()->itemAt(startPos.x() + 1, startPos.y() + 1);
+  ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + 1) * m_scale, startPos.y() * 50 + 25);
   if (!item) {
-    kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<<startPos;
+    kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<<startPos.x() * m_scale * FRAME_SIZE + 1<<", "<<startPos.y() * 50 + 25;
     return;
   }
-  item->setRect(QRectF(endPos.x(), endPos.y(), item->rect().width(), item->rect().height()));
-  QList <QGraphicsItem *> childrenList = item->children();
-  for (int i = 0; i < childrenList.size(); ++i) {
-    childrenList.at(i)->moveBy(endPos.x() - startPos.x() , endPos.y() - startPos.y());
-  }
+  kDebug()<<"----------------  Move CLIP FROM: "<<startPos.x()<<", END:"<<endPos.x();
+  item->moveTo(endPos.x(), m_scale, (endPos.y() - startPos.y()) * 50, endPos.y());
 }
 
 void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPos, bool resizeClipStart )
@@ -413,40 +457,83 @@ void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPo
   int offset;
   if (resizeClipStart) offset = 1;
   else offset = -1;
-  ClipItem *item = (ClipItem *) scene()->itemAt(startPos.x() + offset, startPos.y() + 1);
+  ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + offset) * m_scale, startPos.y() * 50 + 25);
   if (!item) {
     kDebug()<<"----------------  ERROR, CANNOT find clip to resize at: "<<startPos;
     return;
   }
   qreal diff = endPos.x() - startPos.x();
   if (resizeClipStart) {
-    item->setRect(QRectF(endPos.x(), endPos.y(), item->rect().width() - diff, item->rect().height()));
-    QList <QGraphicsItem *> childrenList = item->children();
-    for (int i = 0; i < childrenList.size(); ++i) {
-      childrenList.at(i)->moveBy(diff / 2 , endPos.y() - startPos.y());
-    }
+    item->resizeStart(endPos.x(), m_scale);
   }
   else {
-    //kdDebug()<<"///////  RESIZE CLIP END: "<<item->rect().x()<<", "<<item->rect().width()<<", "<<startPos<<", "<<endPos;
-    item->setRect(QRectF(item->rect().x(), item->rect().y(), endPos.x() - item->rect().x(), item->rect().height()));
-    QList <QGraphicsItem *> childrenList = item->children();
-    for (int i = 0; i < childrenList.size(); ++i) {
-      childrenList.at(i)->moveBy(-diff/2, endPos.y() - startPos.y());
+    item->resizeEnd(endPos.x(), m_scale);
+  }
+}
+
+double CustomTrackView::getSnapPointForPos(double pos)
+{
+  for (int i = 0; i < m_snapPoints.size(); ++i) {
+    if (abs(pos - m_snapPoints.at(i) * m_scale) < 6) return m_snapPoints.at(i) * m_scale;
+    if (m_snapPoints.at(i) > pos) break;
+  }
+  return pos;
+}
+
+void CustomTrackView::updateSnapPoints()
+{
+  m_snapPoints.clear();
+  QList<QGraphicsItem *> itemList = items();
+  for (int i = 0; i < itemList.count(); i++) {
+    if (itemList.at(i)->type() == 70000) {
+      ClipItem *item = (ClipItem *)itemList.at(i);
+      m_snapPoints.append(item->startPos());
+      if (item->fadeIn() != 0) m_snapPoints.append(item->startPos() + item->fadeIn());
+      m_snapPoints.append(item->endPos());
+      if (item->fadeOut() != 0) m_snapPoints.append(item->endPos() - item->fadeOut());      
     }
   }
+  qSort(m_snapPoints);
 }
 
 
+void CustomTrackView::setScale(double scaleFactor)
+{
+  //scale(scaleFactor, scaleFactor);
+  m_scale = scaleFactor;
+  kDebug()<<" HHHHHHHH  SCALING: "<<m_scale;
+  QList<QGraphicsItem *> itemList = items();
+
+  for (int i = 0; i < itemList.count(); i++) {
+      if (itemList.at(i)->type() == 70000) {
+       ClipItem *clip = (ClipItem *)itemList.at(i);
+       clip->setRect(clip->startPos() * m_scale, clip->rect().y(), clip->duration() * m_scale, clip->rect().height());
+      }
+      /*else if (itemList.at(i)->type() == 70001) {
+       LabelItem *label = (LabelItem *)itemList.at(i);
+       QGraphicsItem *parent = label->parentItem();
+       QRectF r = label->boundingRect();
+       QRectF p = parent->boundingRect();
+       label->setPos(p.x() + p.width() / 2 - r.width() / 2, p.y() + p.height() / 2 - r.height() / 2);
+       //label->setRect(clip->startPos() * m_scale, clip->rect().y(), clip->duration() * m_scale, clip->rect().height());
+      }*/
+    }
+}
+
 void CustomTrackView::drawBackground ( QPainter * painter, const QRectF & rect )  
 {
-  //kDebug()<<"/////  DRAWING BG: "<<rect.x()<<", width: "<<rect.width();
-  painter->setPen(QColor(150, 150, 150, 255));
-  painter->drawLine(rect.x(), 0, rect.x() + rect.width(), 0);
+  QColor base = palette().button().color();
+  painter->setPen(base);
+  painter->setClipRect(rect);
+  painter->drawLine(0, 0, rect.width(), 0);
     for (uint i = 0; i < m_tracksCount;i++)
     {
-      painter->drawLine(rect.x(), 50 * (i+1), rect.x() + rect.width(), 50 * (i+1));
-      painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i));
+    painter->drawLine(0, 50 * (i+1), width(), 50 * (i+1));
+      //painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i));
     }
+  int lowerLimit = 50 * m_tracksCount;
+  if (height() > lowerLimit)
+  painter->fillRect(QRectF(0, lowerLimit, rect.width(), height() - lowerLimit), QBrush(base));
 }
 /*
 void CustomTrackView::drawForeground ( QPainter * painter, const QRectF & rect )